hytos / HYTOS / HYTOS / Shapes / EngineeringStreamNoTextItem.py @ 4f696492
이력 | 보기 | 이력해설 | 다운로드 (2.66 KB)
1 |
# coding: utf-8
|
---|---|
2 |
""" This is engineering stream no text item module """
|
3 |
|
4 |
import os.path |
5 |
import sys |
6 |
import copy |
7 |
|
8 |
try:
|
9 |
from PyQt5.QtCore import Qt, QPointF, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
10 |
from PyQt5.QtGui import QImage, QPixmap, QPainterPath, QPainter, QPolygonF, QBrush, QPen, QTransform, QFont, QColor |
11 |
from PyQt5.QtWidgets import QGraphicsView, QGraphicsScene, QFileDialog, QGraphicsItem, QAbstractGraphicsShapeItem, \ |
12 |
QGraphicsTextItem
|
13 |
except ImportError: |
14 |
try:
|
15 |
from PyQt4.QtCore import Qt, QRectF, pyqtSignal, QT_VERSION_STR, QRect |
16 |
from PyQt4.QtGui import QGraphicsView, QGraphicsScene, QImage, QPixmap, QPainterPath, QFileDialog, QFont |
17 |
except ImportError: |
18 |
raise ImportError("ImageViewerQt: Requires PyQt5 or PyQt4.") |
19 |
|
20 |
from AppDocData import AppDocData, MessageType |
21 |
from EngineeringAbstractItem import QEngineeringAbstractItem |
22 |
|
23 |
|
24 |
class QEngineeringStreamNoTextItem(QGraphicsTextItem): |
25 |
""" This is engineering stream no text item class """
|
26 |
|
27 |
def __init__(self, text, parent=None): |
28 |
import uuid |
29 |
|
30 |
QGraphicsTextItem.__init__(self, text, parent)
|
31 |
doc = self.document()
|
32 |
option = doc.defaultTextOption() |
33 |
option.setAlignment(Qt.AlignCenter) |
34 |
doc.setDefaultTextOption(option) |
35 |
self.type = 'STREAM NO' |
36 |
|
37 |
font = QFont('Arial', 15) |
38 |
font.setPointSizeF(4)
|
39 |
self.setFont(font)
|
40 |
|
41 |
def highlight(self, flag): |
42 |
if flag:
|
43 |
self.setDefaultTextColor(QColor(QEngineeringAbstractItem.HOVER_COLOR))
|
44 |
else:
|
45 |
self.setDefaultTextColor(Qt.black)
|
46 |
|
47 |
self.update()
|
48 |
|
49 |
def paint(self, painter, option, widget): |
50 |
""" override paint method """
|
51 |
|
52 |
rect = self.boundingRect()
|
53 |
r = rect.width()*0.5 if rect.width() > rect.height() else rect.height()*0.5 |
54 |
painter.drawPolygon(self.create_poly(4, r, 0)) |
55 |
|
56 |
super(QEngineeringStreamNoTextItem, self).paint(painter, option, widget) |
57 |
|
58 |
def create_poly(self, n, r, s): |
59 |
import math |
60 |
|
61 |
rect = self.boundingRect()
|
62 |
polygon = QPolygonF() |
63 |
w = 360 / n # angle per step |
64 |
for i in range(n): # add the points of polygon |
65 |
t = w * i + s |
66 |
x = r * math.cos(math.radians(t)) |
67 |
y = r * math.sin(math.radians(t)) |
68 |
polygon.append(QPointF(rect.width() * 0.5 + x, rect.height() * 0.5 + y)) |
69 |
|
70 |
return polygon
|
71 |
|
72 |
def set_font_size(self, size): |
73 |
"""set font size"""
|
74 |
|
75 |
_font = self.font()
|
76 |
_font.setPointSizeF(float(size))
|
77 |
self.setFont(_font)
|
78 |
|
79 |
def mouseDoubleClickEvent(self, event): |
80 |
"""call parent's mouseDoubleClickEvent"""
|
81 |
self.parentItem().mouseDoubleClickEvent(event)
|