1616from qwt .color_map import QwtColorMap
1717from qwt .scale_map import QwtScaleMap
1818
19- from qwt .qt .QtGui import (QPaintEngine , QApplication , QFont , QFontInfo , QFrame ,
20- QPixmap , QPainter , QPolygonF , QPalette , QStyle , QPen ,
21- QAbstractTextDocumentLayout , QStyleOptionFocusRect ,
22- QBrush , QLinearGradient , QPainterPath , QColor ,
23- QStyleOption , QTransform )
24- from qwt .qt .QtCore import (QSize , QRectF , Qt , QPointF , QSizeF , QRect , QPoint ,
25- QT_VERSION )
26-
27- import numpy as np
19+ from qwt .qt .QtGui import (QPaintEngine , QFrame , QPixmap , QPainter , QPalette ,
20+ QStyle , QPen , QStyleOptionFocusRect , QBrush ,
21+ QLinearGradient , QPainterPath , QColor , QStyleOption )
22+ from qwt .qt .QtCore import Qt , QRect , QPoint , QT_VERSION
2823
2924QWIDGETSIZE_MAX = (1 << 24 )- 1
3025
3126
32- def qwtScreenResolution ():
33- screenResolution = QSize ()
34- if not screenResolution .isValid ():
35- desktop = QApplication .desktop ()
36- if desktop is not None :
37- screenResolution .setWidth (desktop .logicalDpiX ())
38- screenResolution .setHeight (desktop .logicalDpiY ())
39- return screenResolution
40-
41-
42- def qwtUnscaleFont (painter ):
43- if painter .font ().pixelSize () >= 0 :
44- return
45- screenResolution = qwtScreenResolution ()
46- pd = painter .device ()
47- if pd .logicalDpiX () != screenResolution .width () or \
48- pd .logicalDpiY () != screenResolution .height ():
49- pixelFont = QFont (painter .font (), QApplication .desktop ())
50- pixelFont .setPixelSize (QFontInfo (pixelFont ).pixelSize ())
51- painter .setFont (pixelFont )
52-
53-
5427def isX11GraphicsSystem ():
5528 pm = QPixmap (1 , 1 )
5629 painter = QPainter (pm )
5730 isX11 = painter .paintEngine ().type () == QPaintEngine .X11
5831 del painter
5932 return isX11
6033
61-
62- class QwtPainterClass (object ):
63- """A collection of `QPainter` workarounds"""
64-
65- def drawText (self , * args ):
66- if len (args ) == 4 :
67- if isinstance (args [1 ], (QRectF , QRect )):
68- painter , rect , flags , text = args
69- painter .save ()
70- qwtUnscaleFont (painter )
71- painter .drawText (rect , flags , text )
72- painter .restore ()
73- else :
74- painter , x , y , text = args
75- self .drawText (painter , QPointF (x , y ), text )
76- elif len (args ) == 3 :
77- painter , pos , text = args
78- painter .save ()
79- qwtUnscaleFont (painter )
80- painter .drawText (pos , text )
81- painter .restore ()
82- elif len (args ) == 7 :
83- painter , x , y , w , h , flags , text = args
84- self .drawText (painter , QRectF ( x , y , w , h ), flags , text )
85- else :
86- raise TypeError ("QwtPainter.drawText() takes 3, 4 or 7 argument" \
87- "(s) (%s given)" % len (args ))
88-
89- def drawSimpleRichText (self , painter , rect , flags , text ):
90- """
91- Draw a text document into a rectangle
92-
93- :param QPainter painter: Painter
94- :param QRectF rect: Target rectangle
95- :param int flags: Alignments/Text flags, see `QPainter.drawText()`
96- :param QTextDocument text: Text document
97- """
98- txt = text .clone ()
34+ def qwtFillRect (widget , painter , rect , brush ):
35+ if brush .style () == Qt .TexturePattern :
9936 painter .save ()
100- unscaledRect = QRectF (rect )
101- if painter .font ().pixelSize () < 0 :
102- res = qwtScreenResolution ()
103- pd = painter .device ()
104- if pd .logicalDpiX () != res .width ()\
105- or pd .logicalDpiY () != res .height ():
106- transform = QTransform ()
107- transform .scale (res .width ()/ float (pd .logicalDpiX ()),
108- res .height ()/ float (pd .logicalDpiY ()))
109- painter .setWorldTransform (transform , True )
110- invtrans , _ok = transform .inverted ()
111- unscaledRect = invtrans .mapRect (rect )
112- txt .setDefaultFont (painter .font ())
113- txt .setPageSize (QSizeF (unscaledRect .width (), QWIDGETSIZE_MAX ))
114- layout = txt .documentLayout ()
115- height = layout .documentSize ().height ()
116- y = unscaledRect .y ()
117- if flags & Qt .AlignBottom :
118- y += unscaledRect .height ()- height
119- elif flags & Qt .AlignVCenter :
120- y += (unscaledRect .height ()- height )/ 2
121- context = QAbstractTextDocumentLayout .PaintContext ()
122- context .palette .setColor (QPalette .Text , painter .pen ().color ())
123- painter .translate (unscaledRect .x (), y )
124- layout .draw (painter , context )
37+ painter .setClipRect (rect )
38+ painter .drawTiledPixmap (rect , brush .texture (), rect .topLeft ())
12539 painter .restore ()
126-
127- def drawLine (self , * args ):
128- if len (args ) == 3 :
129- painter , p1 , p2 = args
130- if isinstance (p1 , QPointF ):
131- p1 = p1 .toPoint ()
132- if isinstance (p2 , QPointF ):
133- p2 = p2 .toPoint ()
134- painter .drawLine (p1 , p2 )
135- elif len (args ) == 5 :
136- painter , x1 , y1 , x2 , y2 = args
137- self .drawLine (painter , QPointF (x1 , y1 ), QPointF (x2 , y2 ))
138- elif len (args ) == 2 :
139- painter , line = args
140- self .drawLine (painter , line .p1 (), line .p2 ())
141- else :
142- raise TypeError ("QwtPainter.drawLine() takes 2, 3 or 5 argument" \
143- "(s) (%s given)" % len (args ))
40+ elif brush .gradient ():
41+ painter .save ()
42+ painter .setClipRect (rect )
43+ painter .fillRect (0 , 0 , widget .width (), widget .height (), brush )
44+ painter .restore ()
45+ else :
46+ painter .fillRect (rect , brush )
14447
145- def drawPoints (self , painter , * args ):
146- if len (args ) == 2 :
147- points , pointCount = args
148- else :
149- polygon , = args
150- points , pointCount = polygon .data (), polygon .size ()
151- if isinstance (polygon , QPolygonF ):
152- points .setsize (pointCount * np .finfo (float ).dtype .itemsize )
153- else :
154- points .setsize (pointCount * np .iinfo (int ).dtype .itemsize )
155- painter .drawPoints (polygon )
48+
49+ class QwtPainterClass (object ):
50+ """A collection of `QPainter` workarounds"""
15651
15752 def drawImage (self , painter , rect , image ):
15853 alignedRect = rect .toAlignedRect ()
@@ -548,19 +443,4 @@ def backingStore(self, widget, size):
548443 pm .x11SetScreen (widget .x11Info ().screen ())
549444 return pm
550445
551- QwtPainter = QwtPainterClass ()
552-
553-
554- def qwtFillRect (widget , painter , rect , brush ):
555- if brush .style () == Qt .TexturePattern :
556- painter .save ()
557- painter .setClipRect (rect )
558- painter .drawTiledPixmap (rect , brush .texture (), rect .topLeft ())
559- painter .restore ()
560- elif brush .gradient ():
561- painter .save ()
562- painter .setClipRect (rect )
563- painter .fillRect (0 , 0 , widget .width (), widget .height (), brush )
564- painter .restore ()
565- else :
566- painter .fillRect (rect , brush )
446+ QwtPainter = QwtPainterClass ()
0 commit comments