diff options
author | pravindalve | 2020-06-22 16:37:47 +0530 |
---|---|---|
committer | GitHub | 2020-06-22 16:37:47 +0530 |
commit | cca55e231036850b2ea235ef0e1a1dc05db2a4b0 (patch) | |
tree | 8ff6b465e177e632a544471e1ec4b4add9279045 /src/main/python/shapes | |
parent | c3ca9374cfc2b91238e431055ab1cc2a0074a511 (diff) | |
parent | 5afc44d63266bb1e8a57a880d64b33f95b29e3d8 (diff) | |
download | Chemical-PFD-cca55e231036850b2ea235ef0e1a1dc05db2a4b0.tar.gz Chemical-PFD-cca55e231036850b2ea235ef0e1a1dc05db2a4b0.tar.bz2 Chemical-PFD-cca55e231036850b2ea235ef0e1a1dc05db2a4b0.zip |
Merge pull request #24 from Blakeinstein/master
Final PR
Diffstat (limited to 'src/main/python/shapes')
-rw-r--r-- | src/main/python/shapes/line.py | 18 | ||||
-rw-r--r-- | src/main/python/shapes/shapes.py | 69 |
2 files changed, 67 insertions, 20 deletions
diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index c893fe6..856869d 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'].items(): + self.values[key] = value def findIndex(line, pos): @@ -1008,8 +1011,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 { @@ -1022,8 +1026,14 @@ 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.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..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 @@ -244,7 +246,14 @@ class LineGripItem(QGraphicsPathItem): @property def m_location(self): - return directionsEnum[(self._m_location + self.parentItem().rotation)%4] + 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 + else: + index = (index + 2*self.parentItem().flipV)%4 + return directionsEnum[index] @m_location.setter def m_location(self, location): @@ -267,7 +276,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() @@ -451,22 +460,47 @@ class NodeItem(QGraphicsSvgItem): self.sizeGripItems = [] self.label = None self._rotation = 0 - + self.flipState = [False, False] + @property - def rotation(self): - return self._rotation + def flipH(self): + return self.flipState[0] - @rotation.setter - def rotation(self, rotation): - self._rotation = rotation % 4 + @property + def flipV(self): + return self.flipState[1] + + def updateTransformation(self): + # update transformation on flipstate or rotation change transform = QTransform() - transform.rotate(90*rotation) + 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.updateTransformation() + + @flipV.setter + def flipV(self, state): + self.flipState[1] = state + self.updateTransformation() + + @property + def rotation(self): + return self._rotation + + @rotation.setter + def rotation(self, rotation): + self._rotation = rotation % 4 + self.updateTransformation() def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and @@ -603,11 +637,12 @@ class NodeItem(QGraphicsSvgItem): """ # create a menu and add action contextMenu = QMenu() - addLableAction = contextMenu.addAction("add Label") # add action for text label + 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 { @@ -616,7 +651,9 @@ 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, + "flipstate": self.flipState } def __setstate__(self, dict): |