개정판 3ebd61eb
issue #000: fixed paint process
Change-Id: Ib58168c9994cc2b36cedbf7bf5799e2bed4d43e2
DTI_PID/DTI_PID/Shapes/EngineeringAbstractItem.py | ||
---|---|---|
9 | 9 |
2018.05.17 Jeongwoo Add DEFAULT_COLOR Variable |
10 | 10 |
''' |
11 | 11 |
DEFAULT_COLOR = '#0000FF' |
12 |
HOVER_COLOR = '#BC4438' |
|
13 | ||
12 | 14 |
def __init__(self, parent=None): |
13 | 15 |
self._color = self.DEFAULT_COLOR # default color |
14 | 16 |
self._owner = None |
17 |
self._hover = False |
|
15 | 18 |
self._area = None |
16 | 19 |
self.connectors = [] |
17 | 20 |
self.attrs = {} # attributes |
18 | 21 |
self._associations = {'Text Item':[], 'Symbol Item':[]} # associated items |
22 |
|
|
23 |
@property |
|
24 |
def hover(self): |
|
25 |
""" |
|
26 |
return hover |
|
27 |
""" |
|
28 |
return self._hover |
|
29 | ||
30 |
@hover.setter |
|
31 |
def hover(self, value): |
|
32 |
""" |
|
33 |
set hover |
|
34 |
""" |
|
35 |
self._hover = value |
|
19 | 36 | |
20 | 37 |
''' |
21 | 38 |
@brief Abstract method. Variable [color] is RGB hex code |
... | ... | |
31 | 48 |
@date 2018.05.11 |
32 | 49 |
''' |
33 | 50 |
def getColor(self): |
34 |
return self._color
|
|
51 |
return QEngineeringAbstractItem.HOVER_COLOR if self.hover else (self._owner._color if self._owner else self._color)
|
|
35 | 52 | |
36 | 53 |
''' |
37 | 54 |
@brief getter of owner |
DTI_PID/DTI_PID/Shapes/EngineeringLineItem.py | ||
---|---|---|
903 | 903 |
""" |
904 | 904 |
hilight item and it's children |
905 | 905 |
""" |
906 |
self._savedColor = self.getColor() |
|
907 |
self.setColor(QEngineeringLineItem.HIGHLIGHT) |
|
908 | ||
909 |
rect = self.sceneBoundingRect() |
|
910 |
rect.setRect(rect.left() - QEngineeringLineItem.ARROW_SIZE, rect.top() - QEngineeringLineItem.ARROW_SIZE, |
|
911 |
rect.width() + QEngineeringLineItem.ARROW_SIZE*2, rect.height() + QEngineeringLineItem.ARROW_SIZE*2) |
|
912 |
self.scene().invalidate(rect) |
|
913 | ||
914 |
c = QColor() |
|
915 |
c.setNamedColor(QEngineeringLineItem.HIGHLIGHT) |
|
916 |
for child in self.childItems(): |
|
917 |
child.setBrush(c) |
|
906 |
self.hover = True |
|
907 |
self.update() |
|
918 | 908 | |
919 | 909 |
def hoverLeaveEvent(self, event): |
920 | 910 |
""" |
921 | 911 |
restore original color |
922 | 912 |
""" |
923 |
try: |
|
924 |
self.setColor(self._savedColor) |
|
925 | ||
926 |
rect = self.sceneBoundingRect() |
|
927 |
rect.setRect(rect.left() - QEngineeringLineItem.ARROW_SIZE, rect.top() - QEngineeringLineItem.ARROW_SIZE, |
|
928 |
rect.width() + QEngineeringLineItem.ARROW_SIZE*2, rect.height() + QEngineeringLineItem.ARROW_SIZE*2) |
|
929 |
self.scene().invalidate(rect) |
|
930 | ||
931 |
for child in self.childItems(): |
|
932 |
child.setBrush(Qt.blue) |
|
933 |
except Exception as ex: |
|
934 |
from App import App |
|
935 |
from AppDocData import MessageType |
|
936 | ||
937 |
message = 'error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno) |
|
938 |
App.mainWnd().addMessage.emit(MessageType.Error, message) |
|
913 |
self.hover = False |
|
914 |
self.update() |
|
939 | 915 | |
940 | 916 |
def hoverMoveEvent(self, event): |
941 | 917 |
pass |
... | ... | |
975 | 951 |
@history humkyung 2018.08.30 draw flowmark only for Primary or Secondary |
976 | 952 |
''' |
977 | 953 |
def paint(self, painter, option, widget): |
954 |
color = self.getColor() |
|
955 |
self.setColor(color) |
|
956 | ||
978 | 957 |
QGraphicsLineItem.paint(self, painter, option, widget) |
979 |
|
|
958 |
for child in self.childItems(): |
|
959 |
child.setBrush(self.pen().color()) |
|
960 | ||
980 | 961 |
if self.lineType == 'Primary' or self.lineType == 'Secondary': |
981 | 962 |
## draw direction mark |
982 | 963 |
length = self.length() |
... | ... | |
1151 | 1132 |
@history humkyung 2018.05.13 call setPen method to apply changed color |
1152 | 1133 |
''' |
1153 | 1134 |
def setColor(self, color): |
1154 |
self._color = color |
|
1155 | 1135 |
c = QColor() |
1156 | 1136 |
c.setNamedColor(color) |
1157 | 1137 |
_pen = self.pen() |
... | ... | |
1159 | 1139 |
self.setPen(_pen) |
1160 | 1140 |
self.update() |
1161 | 1141 | |
1162 |
def getColor(self): |
|
1163 |
return self.pen().color().name() |
|
1164 | ||
1165 | ||
1166 | ||
1167 | 1142 |
''' |
1168 | 1143 |
@brief reshape line |
1169 | 1144 |
@author humkyung |
DTI_PID/DTI_PID/Shapes/EngineeringPolylineItem.py | ||
---|---|---|
210 | 210 |
@history humkyung 2018.05.13 call setPen method to apply changed color |
211 | 211 |
''' |
212 | 212 |
def setColor(self, color): |
213 |
self._color = color |
|
214 | 213 |
c = QColor() |
215 | 214 |
c.setNamedColor(color) |
216 | 215 |
_pen = self.pen() |
... | ... | |
218 | 217 |
self.setPen(_pen) |
219 | 218 |
self.update() |
220 | 219 | |
221 |
def getColor(self): |
|
222 |
return self.pen().color().name() |
|
223 | ||
224 | 220 |
''' |
225 | 221 |
@brief The class transfer pyqtSignal Event. Cause Subclass of QGraphicsRectItem can't use pyqtSignal |
226 | 222 |
@author Jeongwoo |
DTI_PID/DTI_PID/Shapes/EngineeringTextItem.py | ||
---|---|---|
112 | 112 |
@date |
113 | 113 |
''' |
114 | 114 |
def hoverEnterEvent(self, event): |
115 |
self.setHightlight() |
|
115 |
self.hover = True |
|
116 |
self.update() |
|
116 | 117 | |
117 | 118 |
def hoverLeaveEvent(self, event): |
118 |
self.unsetHightlight() |
|
119 |
self.hover = False |
|
120 |
self.update() |
|
119 | 121 | |
120 | 122 |
''' |
121 | 123 |
@brief set highlight |
... | ... | |
193 | 195 |
@date 2018.07.08 |
194 | 196 |
''' |
195 | 197 |
def paint(self, painter, options=None, widget=None): |
198 |
self.setColor(self.getColor()) |
|
199 | ||
196 | 200 |
if self.angle == 1.57 or self.angle == 4.71: |
197 | 201 |
rect = QRectF(0, 0, self.size[1], self.size[0]) |
198 | 202 |
else: |
... | ... | |
206 | 210 |
color = self.defaultTextColor() |
207 | 211 |
painter.setPen(QPen(color)) |
208 | 212 |
painter.drawText(rect, Qt.AlignCenter, self.text()) |
209 |
#QGraphicsTextItem.paint(self, painter, options, widget) |
|
213 | ||
210 | 214 |
if self.isSelected(): |
211 | 215 |
self.drawFocusRect(painter) |
212 | 216 | |
... | ... | |
585 | 589 |
@history humkyung 2018.05.13 update after change color |
586 | 590 |
''' |
587 | 591 |
def setColor(self, color): |
588 |
self._color = color |
|
589 | 592 |
c = QColor() |
590 | 593 |
c.setNamedColor(color) |
591 | 594 |
self.setDefaultTextColor(c) |
592 | 595 |
self.update() |
593 | 596 | |
594 |
def getColor(self): |
|
595 |
return self._color |
|
596 | ||
597 | 597 |
def toSql(self): |
598 | 598 |
""" |
599 | 599 |
convert instrument data to sql query for title block now on |
DTI_PID/DTI_PID/Shapes/EngineeringUnknownItem.py | ||
---|---|---|
1 | 1 |
# coding: utf-8 |
2 |
""" |
|
3 |
This is unknown item module |
|
4 |
""" |
|
5 | ||
2 | 6 |
import os.path |
3 | 7 |
import copy |
4 | 8 |
import sys |
... | ... | |
19 | 23 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
20 | 24 | |
21 | 25 |
class QEngineeringUnknownItem(QEngineeringPolylineItem, QEngineeringAbstractItem): |
26 |
""" |
|
27 |
This is unknown item class |
|
28 |
""" |
|
29 | ||
22 | 30 |
HIGHLIGHT = '#BC4438' |
23 | 31 |
ZVALUE = 60 |
24 | 32 | |
... | ... | |
55 | 63 | |
56 | 64 |
if self.lineIndicator == 'Match': |
57 | 65 |
self.setPen(QPen(Qt.blue, 1, Qt.SolidLine)) |
58 |
self.setBrush(QBrush(QColor(0, 0, 255, 255), Qt.SolidPattern)) |
|
66 |
color = QColor(0, 0, 255, 255) |
|
67 |
self.setBrush(QBrush(color, Qt.SolidPattern)) |
|
68 |
self._color = color.name() |
|
59 | 69 |
else: |
60 | 70 |
self.setPen(QPen(Qt.red, 1, Qt.DashDotLine)) |
61 |
self.setBrush(QBrush(QColor(255, 255, 0, 127))) |
|
71 |
color = QColor(255, 255, 0, 127) |
|
72 |
self.setBrush(QBrush(color)) |
|
73 |
self._color = color.name() |
|
62 | 74 | |
63 | 75 |
def hoverEnterEvent(self, event): |
64 |
self._savedColor = self.getColor() |
|
65 |
self.setColor(QEngineeringUnknownItem.HIGHLIGHT) |
|
76 |
self.hover = True |
|
66 | 77 |
self.update() |
67 | 78 | |
68 | 79 |
def hoverLeaveEvent(self, event): |
69 |
self.setColor(self._savedColor)
|
|
80 |
self.hover = False
|
|
70 | 81 |
self.update() |
71 | 82 | |
72 | 83 |
def hoverMoveEvent(self, event): |
... | ... | |
105 | 116 |
@date 2018.08.13 |
106 | 117 |
''' |
107 | 118 |
def setColor(self, color): |
108 |
self._color = color |
|
109 | 119 |
c = QColor() |
110 | 120 |
c.setNamedColor(color) |
111 | 121 |
if self.lineIndicator == 'Match': |
... | ... | |
116 | 126 |
self.update() |
117 | 127 | |
118 | 128 |
''' |
119 |
@brief return unknown item's color |
|
120 |
@author humkyung |
|
121 |
@date 2018.08.13 |
|
122 |
''' |
|
123 |
def getColor(self): |
|
124 |
return self.brush().color().name() |
|
125 | ||
126 |
''' |
|
127 | 129 |
@brief override paint(draw connection points) |
128 | 130 |
@author humkyung |
129 | 131 |
@date 2018.08.08 |
130 | 132 |
''' |
131 | 133 |
def paint(self, painter, options=None, widget=None): |
134 |
self.setColor(self.getColor()) |
|
135 | ||
132 | 136 |
painter.setClipRect(options.exposedRect) |
133 | 137 |
QEngineeringPolylineItem.paint(self, painter, options, widget) |
134 | 138 |
|
DTI_PID/DTI_PID/Shapes/SymbolSvgItem.py | ||
---|---|---|
19 | 19 |
class SymbolSvgItem(QGraphicsSvgItem, QEngineeringAbstractItem): |
20 | 20 |
clicked = pyqtSignal(QGraphicsSvgItem) |
21 | 21 |
ZVALUE = 50 |
22 |
HIGHLIGHT = '#BC4438'
|
|
22 |
HOVER_COLOR = 'url(#hover)'
|
|
23 | 23 | |
24 | 24 |
''' |
25 | 25 |
@history 18.04.11 Jeongwoo Add Variable (Name, Type) |
... | ... | |
59 | 59 |
self.transfer = Transfer() |
60 | 60 | |
61 | 61 |
try: |
62 |
#print(self.flip) |
|
63 |
#if self.flip is 1: |
|
64 |
# path = path.replace('.svg', '_Flip.svg') |
|
65 | 62 |
f = QFile(path) |
66 | 63 |
f.open(QIODevice.ReadOnly) |
67 | 64 |
array = f.readAll() |
... | ... | |
70 | 67 |
self._renderer = QSvgRenderer(self._document.toByteArray()) |
71 | 68 |
self.setSharedRenderer(self._renderer) |
72 | 69 | |
73 |
#self._savedColor = self.get_attribute('fill') |
|
74 |
#self.setColor(self._color) |
|
70 |
self._color = self.get_attribute('fill') |
|
75 | 71 |
except Exception as ex: |
76 | 72 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
77 | 73 |
finally: |
... | ... | |
430 | 426 |
''' |
431 | 427 |
def hoverEnterEvent(self, event): |
432 | 428 |
try: |
429 |
self.hover = True |
|
430 |
self.update() |
|
431 | ||
432 |
""" |
|
433 | 433 |
from EngineeringTextItem import QEngineeringTextItem |
434 | 434 |
self.setHightlight() |
435 | 435 |
self.currentCursor = int(Qt.OpenHandCursor) |
... | ... | |
444 | 444 |
elif issubclass(type(attr), SymbolSvgItem): |
445 | 445 |
attr.setColor('url(#hover)') |
446 | 446 |
attr.update() |
447 |
""" |
|
447 | 448 |
except Exception as ex: |
448 | 449 |
print('error occured({}) in {}:{}'.format(ex, sys.exc_info()[-1].tb_frame.f_code.co_filename, sys.exc_info()[-1].tb_lineno)) |
449 | 450 | |
... | ... | |
454 | 455 |
@history kyouho 2018.07.18 edit ArrowCursor |
455 | 456 |
''' |
456 | 457 |
def hoverLeaveEvent(self, event): |
458 |
self.hover = False |
|
459 |
self.update() |
|
460 | ||
461 |
""" |
|
457 | 462 |
from EngineeringTextItem import QEngineeringTextItem |
458 | 463 |
self.unsetHightlight() |
459 | 464 |
self.currentCursor = int(Qt.ArrowCursor) |
... | ... | |
468 | 473 |
elif issubclass(type(attr), SymbolSvgItem): |
469 | 474 |
attr.setColor('url(#normal)') |
470 | 475 |
attr.update() |
476 |
""" |
|
471 | 477 | |
472 | 478 |
''' |
473 | 479 |
@brief set highlight |
... | ... | |
494 | 500 |
''' |
495 | 501 |
def hoverMoveEvent(self, event): |
496 | 502 |
pass |
497 |
''' |
|
498 |
scenePos = self.mapToScene(event.pos()) |
|
499 |
connPt = self.getConnectionPointCloseTo((scenePos.x(), scenePos.y()), 5) |
|
500 |
if connPt is not None: |
|
501 |
cursor = QCursor(Qt.CrossCursor) |
|
502 |
QApplication.instance().changeOverrideCursor(cursor) |
|
503 |
else: |
|
504 |
cursor = QCursor(Qt.OpenHandCursor) |
|
505 |
QApplication.instance().changeOverrideCursor(cursor) |
|
506 | ||
507 |
self.update() |
|
508 |
''' |
|
509 | 503 | |
510 | 504 |
''' |
511 | 505 |
@brief Mouse Press Event |
... | ... | |
1043 | 1037 |
humkyung 2018.05.13 update after change color |
1044 | 1038 |
''' |
1045 | 1039 |
def setColor(self, color): |
1046 |
self._color = color |
|
1047 | 1040 |
self.changeAttributes('fill', color) |
1048 | 1041 |
self.changeAttributes('stroke', color) |
1049 | 1042 |
self.renderer().load(self._document.toByteArray()) |
1050 | 1043 |
self.update() |
1051 | 1044 | |
1052 |
''' |
|
1053 |
@brief Get Color code |
|
1054 |
@author Jeongwoo |
|
1055 |
@date 2018.05.17 |
|
1056 |
''' |
|
1057 | 1045 |
def getColor(self): |
1058 |
return self._color |
|
1046 |
""" |
|
1047 |
return hover color if mouse is over otherwise reutrn owner's color if owner exist else this color |
|
1048 |
""" |
|
1049 |
return SymbolSvgItem.HOVER_COLOR if self.hover else (self.owner._color if self._owner else self._color) |
|
1059 | 1050 | |
1060 | 1051 |
''' |
1061 | 1052 |
@brief get attributes from svg file |
... | ... | |
1165 | 1156 |
@date 2018.04.21 |
1166 | 1157 |
''' |
1167 | 1158 |
def paint(self, painter, options=None, widget=None): |
1159 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
|
1160 |
from EngineeringTextItem import QEngineeringTextItem |
|
1161 | ||
1162 |
self.setColor(self.getColor()) |
|
1163 | ||
1168 | 1164 |
painter.setClipRect(options.exposedRect) |
1169 | 1165 |
QGraphicsSvgItem.paint(self, painter, options, widget) |
1166 |
for attr in self.attrs: |
|
1167 |
if issubclass(type(attr), QEngineeringTextItem): |
|
1168 |
color = QEngineeringAbstractItem.HOVER_COLOR if self.hover else (self._owner._color if self._owner else QEngineeringAbstractItem.DEFAULT_COLOR) |
|
1169 |
attr.setColor(color) |
|
1170 |
elif issubclass(type(attr), SymbolSvgItem): |
|
1171 |
attr.setColor(self.getColor()) |
|
1172 |
attr.update() |
|
1173 | ||
1170 | 1174 |
if self.isSelected(): |
1171 | 1175 |
self.drawFocusRect(painter) |
1172 | 1176 |
내보내기 Unified diff