27
27
__revision__ = '$Format:%H$'
28
28
29
29
import os
30
+ import math
31
+
30
32
from qgis .PyQt .QtCore import Qt , QPointF , QRectF
31
- from qgis .PyQt .QtGui import QIcon , QFont , QFontMetricsF , QPen , QBrush , QColor , QPolygonF
33
+ from qgis .PyQt .QtGui import QIcon , QFont , QFontMetricsF , QPen , QBrush , QColor , QPolygonF , QPicture , QPainter
32
34
from qgis .PyQt .QtWidgets import QGraphicsItem , QMessageBox , QMenu
35
+ from qgis .PyQt .QtSvg import QSvgRenderer
33
36
from processing .modeler .ModelerAlgorithm import ModelerParameter , Algorithm , ModelerOutput
34
37
from processing .modeler .ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
35
38
from processing .modeler .ModelerParametersDialog import ModelerParametersDialog
@@ -47,13 +50,19 @@ def __init__(self, element, model):
47
50
self .model = model
48
51
self .element = element
49
52
if isinstance (element , ModelerParameter ):
50
- icon = QIcon (os .path .join (pluginPath , 'images' , 'input.svg' ))
51
- self .pixmap = icon .pixmap (16 , 16 , state = QIcon .On )
53
+ svg = QSvgRenderer (os .path .join (pluginPath , 'images' , 'input.svg' ))
54
+ self .picture = QPicture ()
55
+ painter = QPainter (self .picture )
56
+ svg .render (painter )
57
+ self .pixmap = None
52
58
self .text = element .param .description
53
59
elif isinstance (element , ModelerOutput ):
54
60
# Output name
55
- icon = QIcon (os .path .join (pluginPath , 'images' , 'output.svg' ))
56
- self .pixmap = icon .pixmap (16 , 16 , state = QIcon .On )
61
+ svg = QSvgRenderer (os .path .join (pluginPath , 'images' , 'output.svg' ))
62
+ self .picture = QPicture ()
63
+ painter = QPainter (self .picture )
64
+ svg .render (painter )
65
+ self .pixmap = None
57
66
self .text = element .description
58
67
else :
59
68
self .text = element .description
@@ -65,19 +74,25 @@ def __init__(self, element, model):
65
74
self .setZValue (1000 )
66
75
67
76
if not isinstance (element , ModelerOutput ):
68
- icon = QIcon (os .path .join (pluginPath , 'images' , 'edit.png' ))
77
+ svg = QSvgRenderer (os .path .join (pluginPath , 'images' , 'edit.svg' ))
78
+ picture = QPicture ()
79
+ painter = QPainter (picture )
80
+ svg .render (painter )
69
81
pt = QPointF (ModelerGraphicItem .BOX_WIDTH / 2
70
82
- FlatButtonGraphicItem .WIDTH / 2 ,
71
83
ModelerGraphicItem .BOX_HEIGHT / 2
72
- - FlatButtonGraphicItem .HEIGHT / 2 + 1 )
73
- self .editButton = FlatButtonGraphicItem (icon , pt , self .editElement )
84
+ - FlatButtonGraphicItem .HEIGHT / 2 )
85
+ self .editButton = FlatButtonGraphicItem (picture , pt , self .editElement )
74
86
self .editButton .setParentItem (self )
75
- icon = QIcon (os .path .join (pluginPath , 'images' , 'delete.png' ))
87
+ svg = QSvgRenderer (os .path .join (pluginPath , 'images' , 'delete.svg' ))
88
+ picture = QPicture ()
89
+ painter = QPainter (picture )
90
+ svg .render (painter )
76
91
pt = QPointF (ModelerGraphicItem .BOX_WIDTH / 2
77
92
- FlatButtonGraphicItem .WIDTH / 2 ,
78
93
- ModelerGraphicItem .BOX_HEIGHT / 2
79
- + FlatButtonGraphicItem .HEIGHT / 2 + 1 )
80
- self .deleteButton = FlatButtonGraphicItem (icon , pt ,
94
+ + FlatButtonGraphicItem .HEIGHT / 2 )
95
+ self .deleteButton = FlatButtonGraphicItem (picture , pt ,
81
96
self .removeElement )
82
97
self .deleteButton .setParentItem (self )
83
98
@@ -272,6 +287,9 @@ def paint(self, painter, option, widget=None):
272
287
if self .pixmap :
273
288
painter .drawPixmap (- (ModelerGraphicItem .BOX_WIDTH / 2.0 ) + 3 , - 8 ,
274
289
self .pixmap )
290
+ elif self .picture :
291
+ painter .drawPicture (- (ModelerGraphicItem .BOX_WIDTH / 2.0 ) + 3 , - 8 ,
292
+ self .picture )
275
293
276
294
def getLinkPointForParameter (self , paramIndex ):
277
295
offsetX = 25
@@ -335,12 +353,11 @@ class FlatButtonGraphicItem(QGraphicsItem):
335
353
WIDTH = 16
336
354
HEIGHT = 16
337
355
338
- def __init__ (self , icon , position , action ):
356
+ def __init__ (self , picture , position , action ):
339
357
super (FlatButtonGraphicItem , self ).__init__ (None )
340
358
self .setAcceptHoverEvents (True )
341
359
self .setFlag (QGraphicsItem .ItemIsMovable , False )
342
- self .pixmap = icon .pixmap (self .WIDTH , self .HEIGHT ,
343
- state = QIcon .On )
360
+ self .picture = picture
344
361
self .position = position
345
362
self .isIn = False
346
363
self .action = action
@@ -349,7 +366,7 @@ def mousePressEvent(self, event):
349
366
self .action ()
350
367
351
368
def paint (self , painter , option , widget = None ):
352
- pt = QPointF (- self .WIDTH / 2 , - self .HEIGHT / 2 ) + self .position
369
+ pt = QPointF (- math . floor ( self .WIDTH / 2 ) , - math . floor ( self .HEIGHT / 2 ) ) + self .position
353
370
rect = QRectF (pt .x (), pt .y (), self .WIDTH , self .HEIGHT )
354
371
if self .isIn :
355
372
painter .setPen (QPen (Qt .transparent , 1 ))
@@ -360,11 +377,11 @@ def paint(self, painter, option, widget=None):
360
377
painter .setBrush (QBrush (Qt .transparent ,
361
378
Qt .SolidPattern ))
362
379
painter .drawRect (rect )
363
- painter .drawPixmap (pt .x (), pt .y (), self .pixmap )
380
+ painter .drawPicture (pt .x (), pt .y (), self .picture )
364
381
365
382
def boundingRect (self ):
366
- rect = QRectF (self .position .x () - self .WIDTH / 2 ,
367
- self .position .y () - self .HEIGHT / 2 ,
383
+ rect = QRectF (self .position .x () - math . floor ( self .WIDTH / 2 ) ,
384
+ self .position .y () - math . floor ( self .HEIGHT / 2 ) ,
368
385
self .WIDTH ,
369
386
self .HEIGHT )
370
387
return rect
@@ -384,16 +401,24 @@ class FoldButtonGraphicItem(FlatButtonGraphicItem):
384
401
HEIGHT = 11
385
402
386
403
def __init__ (self , position , action , folded ):
387
- self .icons = {True : QIcon (os .path .join (pluginPath , 'images' , 'plus.svg' )),
388
- False : QIcon (os .path .join (pluginPath , 'images' , 'minus.svg' ))}
404
+ plus = QPicture ()
405
+ minus = QPicture ()
406
+
407
+ svg = QSvgRenderer (os .path .join (pluginPath , 'images' , 'plus.svg' ))
408
+ painter = QPainter (plus )
409
+ svg .render (painter )
410
+ svg = QSvgRenderer (os .path .join (pluginPath , 'images' , 'minus.svg' ))
411
+ painter = QPainter (minus )
412
+ svg .render (painter )
413
+
414
+ self .pictures = {True : plus ,
415
+ False : minus }
389
416
390
417
self .folded = folded
391
- icon = self .icons [self .folded ]
392
- super (FoldButtonGraphicItem , self ).__init__ (icon , position , action )
418
+ picture = self .pictures [self .folded ]
419
+ super (FoldButtonGraphicItem , self ).__init__ (picture , position , action )
393
420
394
421
def mousePressEvent (self , event ):
395
422
self .folded = not self .folded
396
- icon = self .icons [self .folded ]
397
- self .pixmap = icon .pixmap (self .WIDTH , self .HEIGHT ,
398
- state = QIcon .On )
423
+ self .picture = self .pictures [self .folded ]
399
424
self .action (self .folded )
0 commit comments