개정판 ce9281d7
Apply changed color to engineering line
DTI_PID/DTI_PID/MainWindow.py | ||
---|---|---|
576 | 576 |
for pt in pts: |
577 | 577 |
processLine._pol.append(QPointF(pt[0] + round(area.x), pt[1] + round(area.y))) |
578 | 578 |
processLine.buildItem() |
579 |
processLine.setPen(QPen(Qt.blue, 5, Qt.SolidLine)) |
|
580 | 579 |
self.graphicsView.scene.addItem(processLine) |
581 | 580 | |
582 | 581 |
# trace line no |
... | ... | |
663 | 662 |
item.size = (width, height) |
664 | 663 |
item.angle = angle |
665 | 664 |
item.setPlainText(text) |
666 |
item.setDefaultTextColor(Qt.blue) |
|
667 | 665 |
item.removed.connect(self.resultTreeWidget.itemRemoved) |
668 | 666 |
item.addTextItemToScene(self.graphicsView.scene) |
669 | 667 | |
... | ... | |
680 | 678 |
item.size = (width, height) |
681 | 679 |
item.angle = angle |
682 | 680 |
item.setPlainText(text) |
683 |
item.setDefaultTextColor(Qt.blue) |
|
684 | 681 |
item.addTextItemToScene(self.graphicsView.scene) |
685 | 682 |
|
686 | 683 |
#self.graphicsView.scene.addItem(item) |
DTI_PID/DTI_PID/QResultTreeWidget.py | ||
---|---|---|
49 | 49 |
if len(indexes) > 0 and data is not None and type(data) is QEngineeringLineNoTextItem: |
50 | 50 |
index = indexes[0] |
51 | 51 |
menu = QMenu() |
52 |
pickColorAction = QAction(self.tr("Pick Color"))
|
|
52 |
pickColorAction = QAction(self.tr("색상 설정"))
|
|
53 | 53 |
pickColorAction.triggered.connect(lambda : self.pickColorClickEvent(item)) |
54 | 54 |
menu.addAction(pickColorAction) |
55 | 55 |
menu.exec_(self.viewport().mapToGlobal(position)) |
DTI_PID/DTI_PID/Shapes/QEngineeringAbstractItem.py | ||
---|---|---|
4 | 4 |
def __init__(self): |
5 | 5 |
super(QEngineeringAbstractItem, self).__init__() |
6 | 6 | |
7 |
self._color = '#0000FF' # default color |
|
7 | 8 |
self._owner = None |
8 | 9 | |
9 | 10 |
''' |
... | ... | |
14 | 15 |
def setColor(self, color): |
15 | 16 |
raise NotImplementedError |
16 | 17 | |
18 |
''' |
|
19 |
@brief return color |
|
20 |
@author Jeongwoo |
|
21 |
@date 2018.05.11 |
|
22 |
''' |
|
17 | 23 |
def getColor(self): |
18 |
raise NotImplementedError
|
|
24 |
return self._color
|
|
19 | 25 | |
20 | 26 |
''' |
21 | 27 |
@brief getter of owner |
DTI_PID/DTI_PID/Shapes/QEngineeringFlowArrowItem.py | ||
---|---|---|
64 | 64 |
self._pt[1] - self._dir[1]*self.SIZE*0.5 + perpendicular[1]*self.SIZE*0.25)) |
65 | 65 |
poly.append(QPointF(self._pt[0] - self._dir[0]*self.SIZE*0.5 - perpendicular[0]*self.SIZE*0.25, |
66 | 66 |
self._pt[1] - self._dir[1]*self.SIZE*0.5 - perpendicular[1]*self.SIZE*0.25)) |
67 |
poly.append(QPointF(self._pt[0] + self._dir[0]*self.SIZE*0.5, self._pt[1])) |
|
67 |
poly.append(QPointF(self._pt[0] + self._dir[0]*self.SIZE*0.5, self._pt[1] + self._dir[1]*self.SIZE*0.5))
|
|
68 | 68 |
poly.append(poly[0]) |
69 | 69 |
self._path.addPolygon(poly) |
70 | 70 |
self.setPath(self._path) |
DTI_PID/DTI_PID/Shapes/QEngineeringLineItem.py | ||
---|---|---|
23 | 23 | |
24 | 24 |
self.conns = [None, None] |
25 | 25 | |
26 |
self.setPen(QPen(Qt.blue, 5, Qt.SolidLine)) |
|
27 | 26 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
28 | 27 | |
29 | 28 |
self.setAcceptHoverEvents(True) |
DTI_PID/DTI_PID/Shapes/QEngineeringTextItem.py | ||
---|---|---|
17 | 17 |
from QGraphicsBoundingBoxItem import QGraphicsBoundingBoxItem |
18 | 18 |
import QOcrResultDialog |
19 | 19 |
from AppDocData import AppDocData |
20 |
import QEngineeringAbstractItem |
|
20 |
from QEngineeringAbstractItem import QEngineeringAbstractItem
|
|
21 | 21 | |
22 |
class QEngineeringTextItem(QGraphicsTextItem, QEngineeringAbstractItem.QEngineeringAbstractItem):
|
|
22 |
class QEngineeringTextItem(QGraphicsTextItem, QEngineeringAbstractItem): |
|
23 | 23 |
removed = pyqtSignal(QGraphicsItem) |
24 | 24 | |
25 | 25 |
def __init__(self, parent=None): |
26 | 26 |
import uuid |
27 | 27 | |
28 | 28 |
QGraphicsTextItem.__init__(self, parent) |
29 |
QEngineeringAbstractItem.__init__(self) |
|
29 | 30 | |
30 | 31 |
self.uid = uuid.uuid4() # generate UUID |
31 | 32 |
self.loc = None |
... | ... | |
36 | 37 |
self.setAcceptHoverEvents(True) |
37 | 38 |
self.setAcceptTouchEvents(True) |
38 | 39 | |
40 |
self.setColor(self._color) |
|
41 | ||
39 | 42 |
''' |
40 | 43 |
@brief return text string |
41 | 44 |
@author humkyung |
... | ... | |
61 | 64 |
def hoverMoveEvent(self, event): |
62 | 65 |
pass |
63 | 66 | |
64 | ||
65 | 67 |
''' |
66 | 68 |
@brief remove item when user press delete key |
67 | 69 |
@author humkyung |
... | ... | |
157 | 159 |
def getConnectedItems(self): |
158 | 160 |
visited = [] |
159 | 161 | |
160 |
if 1 == len(self.conns): |
|
161 |
# iterate connected items |
|
162 |
pool = [] |
|
163 |
visited = [] |
|
164 |
pool.append(self.conns[0]) |
|
165 |
while len(pool) > 0: |
|
166 |
it = pool.pop() |
|
167 |
visited.append(it) |
|
168 |
for conn in it.conns: |
|
169 |
if (conn is not None) and (conn not in visited): pool.append(conn) |
|
170 |
# up to here |
|
162 |
try: |
|
163 |
if 1 == len(self.conns): |
|
164 |
# iterate connected items |
|
165 |
pool = [] |
|
166 |
visited = [] |
|
167 |
pool.append(self.conns[0]) |
|
168 |
while len(pool) > 0: |
|
169 |
it = pool.pop() |
|
170 |
visited.append(it) |
|
171 |
for conn in it.conns: |
|
172 |
if (conn is not None) and (conn not in visited): pool.append(conn) |
|
173 |
# up to here |
|
174 |
except Exception as ex: |
|
175 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
|
171 | 176 | |
172 | 177 |
return visited |
173 | 178 | |
... | ... | |
295 | 300 |
@brief Set Color. Override QEngineeringAbstractItem's |
296 | 301 |
@author Jeongwoo |
297 | 302 |
@date 2018.05.11 |
303 |
@history humkyung 2018.05.13 update after change color |
|
298 | 304 |
''' |
299 | 305 |
def setColor(self, color): |
306 |
self._color = color |
|
300 | 307 |
c = QColor() |
301 | 308 |
c.setNamedColor(color) |
302 | 309 |
self.setDefaultTextColor(c) |
303 |
pass |
|
304 | ||
305 |
def getColor(self): |
|
306 |
return self.defaultTextColor().name() |
|
310 |
self.update() |
DTI_PID/DTI_PID/Shapes/QGraphicsPolylineItem.py | ||
---|---|---|
10 | 10 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QColor |
11 | 11 |
except ImportError: |
12 | 12 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
13 |
import QEngineeringAbstractItem |
|
13 |
from QEngineeringAbstractItem import QEngineeringAbstractItem
|
|
14 | 14 | |
15 |
class QGraphicsPolylineItem(QGraphicsPathItem, QEngineeringAbstractItem.QEngineeringAbstractItem):
|
|
15 |
class QGraphicsPolylineItem(QGraphicsPathItem, QEngineeringAbstractItem): |
|
16 | 16 |
''' |
17 | 17 |
@history 2018.05.11 Jeongwoo Declare variable self.pen |
18 | 18 |
''' |
... | ... | |
20 | 20 |
import uuid |
21 | 21 | |
22 | 22 |
QGraphicsPathItem.__init__(self, parent) |
23 |
QEngineeringAbstractItem.__init__(self) |
|
23 | 24 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
24 | 25 | |
25 | 26 |
self.uid = uuid.uuid4() # generate UUID |
... | ... | |
28 | 29 |
self._pt = None |
29 | 30 |
self._pol = QPolygonF() |
30 | 31 |
self._path = None |
31 |
self.pen = QPen(Qt.blue, 5, Qt.SolidLine) |
|
32 |
self.pen = QPen(Qt.blue, 5, Qt.SolidLine) # default pen |
|
33 |
self.setPen(self.pen) |
|
32 | 34 | |
33 | 35 |
''' |
34 | 36 |
@brief construct a polyline |
... | ... | |
92 | 94 |
''' |
93 | 95 |
def paint(self, painter, options=None, widget=None): |
94 | 96 |
if self.isCreated: |
97 |
painter.setPen(self.pen) |
|
95 | 98 |
QGraphicsPathItem.paint(self, painter, options, widget) |
96 | 99 |
elif len(self._vertices) > 0: |
97 | 100 |
painter.setPen(self.pen) |
... | ... | |
110 | 113 |
@brief Set Color. Override QEngineeringAbstractItem's |
111 | 114 |
@author Jeongwoo |
112 | 115 |
@date 2018.05.11 |
116 |
@history humkyung 2018.05.13 call setPen method to apply changed color |
|
113 | 117 |
''' |
114 | 118 |
def setColor(self, color): |
119 |
self._color = color |
|
115 | 120 |
c = QColor() |
116 | 121 |
c.setNamedColor(color) |
117 | 122 |
self.pen.setColor(c) |
118 |
self.update(self.boundingRect()) |
|
119 |
pass |
|
120 | ||
121 |
def getColor(self): |
|
122 |
return self.pen.color().name() |
|
123 |
self.setPen(self.pen) |
|
124 |
self.update() |
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
11 | 11 |
from PyQt5.QtXml import * |
12 | 12 | |
13 | 13 |
from QEngineeringConnectorItem import QEngineeringConnectorItem |
14 |
import QEngineeringAbstractItem |
|
14 |
from QEngineeringAbstractItem import QEngineeringAbstractItem
|
|
15 | 15 | |
16 |
class SymbolSvgItem(QGraphicsSvgItem, QEngineeringAbstractItem.QEngineeringAbstractItem):
|
|
16 |
class SymbolSvgItem(QGraphicsSvgItem, QEngineeringAbstractItem): |
|
17 | 17 |
clicked = pyqtSignal(QGraphicsSvgItem) |
18 | 18 |
removed = pyqtSignal(QGraphicsItem) |
19 | 19 | |
... | ... | |
25 | 25 |
import uuid |
26 | 26 | |
27 | 27 |
QGraphicsSvgItem.__init__(self) |
28 |
QEngineeringAbstractItem.__init__(self) |
|
28 | 29 | |
29 | 30 |
self.setFlags(QGraphicsItem.ItemIsSelectable|QGraphicsItem.ItemIsFocusable) |
30 | 31 |
#QGraphicsItem.ItemIsMovable) |
... | ... | |
32 | 33 |
self.uid = uuid.uuid4() # generate UUID |
33 | 34 |
self.name = '' |
34 | 35 |
self.type = '' |
35 |
self.color = '#0000FF' |
|
36 | 36 |
self.angle = 0 |
37 | 37 |
self.origin = None |
38 | 38 |
self.loc = None |
... | ... | |
58 | 58 |
finally: |
59 | 59 |
f.close() |
60 | 60 | |
61 |
self.setColor(self._color) |
|
62 | ||
61 | 63 |
''' |
62 | 64 |
@brief build symbol item |
63 | 65 |
@author humkyung |
... | ... | |
355 | 357 |
else: |
356 | 358 |
item = SymbolSvgItem(path) |
357 | 359 | |
358 |
item.setColor('#0000FF') |
|
359 | 360 |
return item |
360 | 361 | |
361 | 362 |
''' |
362 |
@brief change svg's color |
|
363 |
@author humkyung |
|
364 |
@date 2018.05.10 |
|
363 |
@brief change svg's color
|
|
364 |
@author humkyung
|
|
365 |
@date 2018.05.10
|
|
365 | 366 |
@history 2018.05.11 Jeongwoo Override QEngineeringAbstractItem's |
367 |
humkyung 2018.05.13 update after change color |
|
366 | 368 |
''' |
367 | 369 |
def setColor(self, color): |
368 |
self.color = color |
|
370 |
self._color = color
|
|
369 | 371 |
self.changeAttributes('fill', color) |
370 | 372 |
self.changeAttributes('stroke', color) |
371 | 373 |
self.renderer().load(self._document.toByteArray()) |
372 | ||
373 |
def getColor(self): |
|
374 |
return self.color |
|
374 |
self.update() |
|
375 | 375 | |
376 | 376 |
''' |
377 | 377 |
@brief change attributes |
내보내기 Unified diff