From 384bdf5f033ba1453efdbb8baf43cdaa9049c9df Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 18 Jun 2020 14:27:19 +0530 Subject: fix line updation --- src/main/python/shapes/line.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index c893fe6..6883662 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -1008,8 +1008,9 @@ class Line(QGraphicsPathItem): action = contextMenu.exec_(event.screenPos()) # check for label action and add text label as child if action == addLableAction: - print(event.scenePos(), event.pos()) - self.label.append(LineLabel(event.scenePos(), self)) # text label as child + label = LineLabel(event.scenePos(), self) + self.label.append(label) # text label as child + self.scene().labelAdded.emit(label) def __getstate__(self): return { -- cgit From c0c5fe6186ca5776c9ff8199b88c13c2ad0e72a8 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 18 Jun 2020 15:43:57 +0530 Subject: save fileupdate --- src/main/python/shapes/line.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 6883662..57778fa 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -292,13 +292,16 @@ class LineLabel(QGraphicsTextItem): "text": self.toPlainText(), "index": self.index, "gap": self.gap, - "pos": (self.pos().x(), self.pos().y()) + "pos": (self.pos().x(), self.pos().y()), + "values": self.values } def __setstate__(self, dict): self.setPlainText(dict['text']) self.index = dict['index'] self.gap = dict['gap'] + for key, value in dict['values']: + self.values[key] = value def findIndex(line, pos): @@ -1023,8 +1026,12 @@ class Line(QGraphicsPathItem): "refLine": hex(id(self.refLine)) if self.refLine else 0, "refIndex": self.refIndex, "label": [i for i in self.label], - "id": hex(id(self)) + "id": hex(id(self)), + "startGap": self.startGap, + "endGap": self.endGap } def __setstate__(self, dict): self.points = [QPointF(x, y) for x, y in dict["points"]] + self.startGap = dict['startGap'] + self.endGap = dict['endGap'] -- cgit From 85a2d6f42168a9e693b7649b979b86f7a94d6ca3 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 18 Jun 2020 15:59:40 +0530 Subject: save update 2 --- src/main/python/shapes/line.py | 4 +++- src/main/python/shapes/shapes.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 57778fa..856869d 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -300,7 +300,7 @@ class LineLabel(QGraphicsTextItem): self.setPlainText(dict['text']) self.index = dict['index'] self.gap = dict['gap'] - for key, value in dict['values']: + for key, value in dict['values'].items(): self.values[key] = value @@ -1033,5 +1033,7 @@ class Line(QGraphicsPathItem): def __setstate__(self, dict): self.points = [QPointF(x, y) for x, y in dict["points"]] + self.startPoint = QPointF(*dict['startPoint']) + self.endPoint = QPointF(*dict['endPoint']) self.startGap = dict['startGap'] self.endGap = dict['endGap'] diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 7205ba7..d492568 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -616,7 +616,8 @@ class NodeItem(QGraphicsSvgItem): "height": self.height, "pos": (self.pos().x(), self.pos().y()), "lineGripItems": [(hex(id(i)), i.m_index) for i in self.lineGripItems], - "label": self.label + "label": self.label, + "rotation": self.rotation } def __setstate__(self, dict): -- cgit From 7f0ed11a3763ed1463519905f0b7e522bbbd2ee2 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 18 Jun 2020 16:04:25 +0530 Subject: logging fix --- src/main/python/shapes/shapes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index d492568..0d28a00 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -267,7 +267,7 @@ class LineGripItem(QGraphicsPathItem): if self.size: painter.save() pen = self.pen() - pen.setWidth(-1) + pen.setWidth(1) painter.setPen(pen) painter.drawPath(self.path()) painter.restore() -- cgit From 420d0c3a68aa4a649991d36f0f72772fab0dd2d4 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 18 Jun 2020 16:55:12 +0530 Subject: flipping feature --- src/main/python/shapes/shapes.py | 59 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 0d28a00..f47ea28 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -244,7 +244,12 @@ class LineGripItem(QGraphicsPathItem): @property def m_location(self): - return directionsEnum[(self._m_location + self.parentItem().rotation)%4] + index = (self._m_location + self.parentItem().rotation) + if index%2: + index = (index + 2*self.parentItem().flipH)%4 + else: + index = (index + 2*self.parentItem().flipV)%4 + return directionsEnum[index] @m_location.setter def m_location(self, location): @@ -451,7 +456,55 @@ class NodeItem(QGraphicsSvgItem): self.sizeGripItems = [] self.label = None self._rotation = 0 + self.flipState = [False, False] + + @property + def flipH(self): + return self.flipState[0] + + @property + def flipV(self): + return self.flipState[1] + + @flipH.setter + def flipH(self, state): + transform = QTransform() + if self.flipV and state: + self.flipState = [False, False] + self.rotation = self.rotation % 4 + transform.scale(1, 1) + else: + self.flipState[0] = state + if state: + transform.scale(-1, 1) + else: + transform.scale(1, 1) + self.setTransform(transform) + for i in self.lineGripItems: + i.updatePosition() + for j in i.lines: + j.createPath() + @flipV.setter + def flipV(self, state): + transform = QTransform() + if self.flipH and state: + self.flipState = [False, False] + self.rotation = self.rotation % 4 + transform.scale(1, 1) + else: + self.flipState[1] = state + transform = QTransform() + if state: + transform.scale(1, -1) + else: + transform.scale(1, 1) + self.setTransform(transform) + for i in self.lineGripItems: + i.updatePosition() + for j in i.lines: + j.createPath() + @property def rotation(self): return self._rotation @@ -604,6 +657,10 @@ class NodeItem(QGraphicsSvgItem): # create a menu and add action contextMenu = QMenu() addLableAction = contextMenu.addAction("add Label") # add action for text label + contextMenu.addAction("Rotate right", lambda : setattr(self, "rotation", self.rotation + 1)) + contextMenu.addAction("Rotate left", lambda : setattr(self, "rotation", self.rotation - 1)) + contextMenu.addAction("Flip Horizontally", lambda: setattr(self, "flipH", not self.flipH)) + contextMenu.addAction("Flip Vertically", lambda: setattr(self, "flipV", not self.flipV)) action = contextMenu.exec_(event.screenPos()) # check for label action and add text label as child if action == addLableAction: -- cgit From 70e9fc3756d8e94c374f498a63105f7345d7e7e2 Mon Sep 17 00:00:00 2001 From: Blaine Date: Thu, 18 Jun 2020 16:57:38 +0530 Subject: flipstate --- src/main/python/shapes/shapes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index f47ea28..01ec196 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -674,7 +674,8 @@ class NodeItem(QGraphicsSvgItem): "pos": (self.pos().x(), self.pos().y()), "lineGripItems": [(hex(id(i)), i.m_index) for i in self.lineGripItems], "label": self.label, - "rotation": self.rotation + "rotation": self.rotation, + "flipstate": self.flipState } def __setstate__(self, dict): -- cgit From 025cd829d956f5081e034f60b69413ec4432e0e8 Mon Sep 17 00:00:00 2001 From: Blaine Date: Fri, 19 Jun 2020 03:03:41 +0530 Subject: rework flip feature --- src/main/python/shapes/shapes.py | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 01ec196..aae8f47 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -466,44 +466,26 @@ class NodeItem(QGraphicsSvgItem): def flipV(self): return self.flipState[1] - @flipH.setter - def flipH(self, state): + def flip(self): transform = QTransform() - if self.flipV and state: - self.flipState = [False, False] - self.rotation = self.rotation % 4 - transform.scale(1, 1) - else: - self.flipState[0] = state - if state: - transform.scale(-1, 1) - else: - transform.scale(1, 1) + h = -1 if self.flipH else 1 + w = -1 if self.flipV else 1 + transform.scale(h, w) self.setTransform(transform) for i in self.lineGripItems: i.updatePosition() for j in i.lines: j.createPath() + + @flipH.setter + def flipH(self, state): + self.flipState[0] = state + self.flip() @flipV.setter def flipV(self, state): - transform = QTransform() - if self.flipH and state: - self.flipState = [False, False] - self.rotation = self.rotation % 4 - transform.scale(1, 1) - else: - self.flipState[1] = state - transform = QTransform() - if state: - transform.scale(1, -1) - else: - transform.scale(1, 1) - self.setTransform(transform) - for i in self.lineGripItems: - i.updatePosition() - for j in i.lines: - j.createPath() + self.flipState[1] = state + self.flip() @property def rotation(self): -- cgit From 6a306ce01a9501f5580e81e9263cd34987ba7bc4 Mon Sep 17 00:00:00 2001 From: Blaine Date: Fri, 19 Jun 2020 11:40:28 +0530 Subject: unified transform --- src/main/python/shapes/shapes.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index aae8f47..3efabbc 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -244,6 +244,8 @@ class LineGripItem(QGraphicsPathItem): @property def m_location(self): + if self.parentItem().__class__ == Line: + return directionsEnum[self._m_location] index = (self._m_location + self.parentItem().rotation) if index%2: index = (index + 2*self.parentItem().flipH)%4 @@ -466,26 +468,27 @@ class NodeItem(QGraphicsSvgItem): def flipV(self): return self.flipState[1] - def flip(self): + def updateTransformation(self): transform = QTransform() h = -1 if self.flipH else 1 w = -1 if self.flipV else 1 + transform.rotate(90*self.rotation) transform.scale(h, w) self.setTransform(transform) + self.setTransform(transform) for i in self.lineGripItems: + i.setTransform(transform) i.updatePosition() - for j in i.lines: - j.createPath() @flipH.setter def flipH(self, state): self.flipState[0] = state - self.flip() + self.updateTransformation() @flipV.setter def flipV(self, state): self.flipState[1] = state - self.flip() + self.updateTransformation() @property def rotation(self): @@ -494,14 +497,7 @@ class NodeItem(QGraphicsSvgItem): @rotation.setter def rotation(self, rotation): self._rotation = rotation % 4 - transform = QTransform() - transform.rotate(90*rotation) - self.setTransform(transform) - for i in self.lineGripItems: - i.setTransform(transform) - i.updatePosition() - for j in i.lines: - j.createPath() + self.updateTransformation() def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and -- cgit From 26dbadc8840cbc5130411ac43f781f82e276bf7e Mon Sep 17 00:00:00 2001 From: Blaine Date: Fri, 19 Jun 2020 17:29:20 +0530 Subject: cleanup shapes context menu --- src/main/python/shapes/shapes.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 3efabbc..ca6490c 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -634,15 +634,12 @@ class NodeItem(QGraphicsSvgItem): """ # create a menu and add action contextMenu = QMenu() - addLableAction = contextMenu.addAction("add Label") # add action for text label - contextMenu.addAction("Rotate right", lambda : setattr(self, "rotation", self.rotation + 1)) - contextMenu.addAction("Rotate left", lambda : setattr(self, "rotation", self.rotation - 1)) + contextMenu.addAction("Add Label", lambda : setattr(self, "label", ItemLabel(self))) + contextMenu.addAction("Rotate right(E)", lambda : setattr(self, "rotation", self.rotation + 1)) + contextMenu.addAction("Rotate left(Q)", lambda : setattr(self, "rotation", self.rotation - 1)) contextMenu.addAction("Flip Horizontally", lambda: setattr(self, "flipH", not self.flipH)) contextMenu.addAction("Flip Vertically", lambda: setattr(self, "flipV", not self.flipV)) action = contextMenu.exec_(event.screenPos()) - # check for label action and add text label as child - if action == addLableAction: - self.label = ItemLabel(self) # text label as child def __getstate__(self): return { -- cgit From f8519766d7f7fc70180411f912ed8ca15abb6a95 Mon Sep 17 00:00:00 2001 From: Blaine Date: Sat, 20 Jun 2020 14:43:57 +0530 Subject: refactor and comment code --- src/main/python/shapes/shapes.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/main/python/shapes') diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index ca6490c..5876f6e 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -12,6 +12,7 @@ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, from .line import Line, findIndex from utils.app import fileImporter +# enum for all directions for line grip items directionsEnum = [ "top", "right", @@ -19,6 +20,7 @@ directionsEnum = [ "left" ] +# orientation enum for size grip items orientationEnum = [ Qt.Horizontal, Qt.Vertical @@ -469,6 +471,7 @@ class NodeItem(QGraphicsSvgItem): return self.flipState[1] def updateTransformation(self): + # update transformation on flipstate or rotation change transform = QTransform() h = -1 if self.flipH else 1 w = -1 if self.flipV else 1 -- cgit