diff options
author | pravindalve | 2020-06-19 11:29:04 +0530 |
---|---|---|
committer | GitHub | 2020-06-19 11:29:04 +0530 |
commit | c3ca9374cfc2b91238e431055ab1cc2a0074a511 (patch) | |
tree | be7eb793069c0d18a38e5da427235821541905df /src/main/python/shapes | |
parent | 75696d91982d07a33ff77729dc979bf7d8bb1a3f (diff) | |
parent | 79b0690d4ae7d9f8853aa90ba0cdbe58af7c1c4d (diff) | |
download | Chemical-PFD-c3ca9374cfc2b91238e431055ab1cc2a0074a511.tar.gz Chemical-PFD-c3ca9374cfc2b91238e431055ab1cc2a0074a511.tar.bz2 Chemical-PFD-c3ca9374cfc2b91238e431055ab1cc2a0074a511.zip |
Merge pull request #22 from Blakeinstein/Rotate-able-symbols
Implement Rotateable symbols
Diffstat (limited to 'src/main/python/shapes')
-rw-r--r-- | src/main/python/shapes/line.py | 4 | ||||
-rw-r--r-- | src/main/python/shapes/shapes.py | 49 |
2 files changed, 45 insertions, 8 deletions
diff --git a/src/main/python/shapes/line.py b/src/main/python/shapes/line.py index 1438fbc..c893fe6 100644 --- a/src/main/python/shapes/line.py +++ b/src/main/python/shapes/line.py @@ -284,10 +284,8 @@ class LineLabel(QGraphicsTextItem): def focusOutEvent(self, event): super(LineLabel, self).focusOutEvent(event) - self.setTextInteractionFlags(Qt.NoTextInteraction) - self.nameChanged.emit() - self.setTextInteractionFlags(Qt.NoTextInteraction) # set text non interactive + self.nameChanged.emit() def __getstate__(self): return { diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 117ffb8..7205ba7 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -12,6 +12,17 @@ from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, from .line import Line, findIndex from utils.app import fileImporter +directionsEnum = [ + "top", + "right", + "bottom", + "left" +] + +orientationEnum = [ + Qt.Horizontal, + Qt.Vertical +] class ItemLabel(QGraphicsTextItem): """Extends PyQt5's QGraphicsPathItem to create text label for svg item @@ -91,15 +102,22 @@ class SizeGripItem(QGraphicsPathItem): self.setPen(QPen(QColor("black"), 0)) self.setZValue(2) # property direction - self._direction = direction - self.m_index = index + self._direction = (orientationEnum.index(direction) + self.parentItem().rotation) % 4 + self._m_index = index @property + def m_index(self): + return (self._m_index + self.parentItem().rotation) % 4 + + @property def direction(self): """ property that returns the current intended resize direction of the grip item object """ - return self._direction + if self.parentItem().rotation % 2: + return orientationEnum[(self._direction + 1)%2] + else: + return orientationEnum[self._direction] def updatePath(self): """updates path of size grip item @@ -209,7 +227,7 @@ class LineGripItem(QGraphicsPathItem): # store position of self self.position = QPointF(grip[0], grip[1]) # set location - self._m_location = grip[2] + self._m_location = directionsEnum.index(grip[2]) # set size in case of rectangle grip self.size = grip[3] if len(grip) == 4 else None # stores current line which is in process @@ -226,7 +244,11 @@ class LineGripItem(QGraphicsPathItem): @property def m_location(self): - return self._m_location + return directionsEnum[(self._m_location + self.parentItem().rotation)%4] + + @m_location.setter + def m_location(self, location): + self._m_location = directionsEnum.index(location) def shape(self): # return interactive path @@ -428,7 +450,24 @@ class NodeItem(QGraphicsSvgItem): self.lineGripItems = [] self.sizeGripItems = [] self.label = None + self._rotation = 0 + @property + def rotation(self): + return self._rotation + + @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() + def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and returns a valid bounding |