Skip to content

Commit d01e3fe

Browse files
committedJan 2, 2017
[processing] convert modeler icons to pictures to kill pixels when zoomed
1 parent a05096d commit d01e3fe

File tree

9 files changed

+56
-90
lines changed

9 files changed

+56
-90
lines changed
 
-323 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Loading
-510 Bytes
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 1 deletion
Loading
Lines changed: 1 addition & 62 deletions
Loading
Lines changed: 1 addition & 1 deletion
Loading

‎python/plugins/processing/modeler/ModelerGraphicItem.py

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
__revision__ = '$Format:%H$'
2828

2929
import os
30+
import math
31+
3032
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
3234
from qgis.PyQt.QtWidgets import QGraphicsItem, QMessageBox, QMenu
35+
from qgis.PyQt.QtSvg import QSvgRenderer
3336
from processing.modeler.ModelerAlgorithm import ModelerParameter, Algorithm, ModelerOutput
3437
from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
3538
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
@@ -47,13 +50,19 @@ def __init__(self, element, model):
4750
self.model = model
4851
self.element = element
4952
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
5258
self.text = element.param.description
5359
elif isinstance(element, ModelerOutput):
5460
# 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
5766
self.text = element.description
5867
else:
5968
self.text = element.description
@@ -65,19 +74,25 @@ def __init__(self, element, model):
6574
self.setZValue(1000)
6675

6776
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)
6981
pt = QPointF(ModelerGraphicItem.BOX_WIDTH / 2
7082
- FlatButtonGraphicItem.WIDTH / 2,
7183
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)
7486
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)
7691
pt = QPointF(ModelerGraphicItem.BOX_WIDTH / 2
7792
- FlatButtonGraphicItem.WIDTH / 2,
7893
- 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,
8196
self.removeElement)
8297
self.deleteButton.setParentItem(self)
8398

@@ -272,6 +287,9 @@ def paint(self, painter, option, widget=None):
272287
if self.pixmap:
273288
painter.drawPixmap(-(ModelerGraphicItem.BOX_WIDTH / 2.0) + 3, -8,
274289
self.pixmap)
290+
elif self.picture:
291+
painter.drawPicture(-(ModelerGraphicItem.BOX_WIDTH / 2.0) + 3, -8,
292+
self.picture)
275293

276294
def getLinkPointForParameter(self, paramIndex):
277295
offsetX = 25
@@ -335,12 +353,11 @@ class FlatButtonGraphicItem(QGraphicsItem):
335353
WIDTH = 16
336354
HEIGHT = 16
337355

338-
def __init__(self, icon, position, action):
356+
def __init__(self, picture, position, action):
339357
super(FlatButtonGraphicItem, self).__init__(None)
340358
self.setAcceptHoverEvents(True)
341359
self.setFlag(QGraphicsItem.ItemIsMovable, False)
342-
self.pixmap = icon.pixmap(self.WIDTH, self.HEIGHT,
343-
state=QIcon.On)
360+
self.picture = picture
344361
self.position = position
345362
self.isIn = False
346363
self.action = action
@@ -349,7 +366,7 @@ def mousePressEvent(self, event):
349366
self.action()
350367

351368
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
353370
rect = QRectF(pt.x(), pt.y(), self.WIDTH, self.HEIGHT)
354371
if self.isIn:
355372
painter.setPen(QPen(Qt.transparent, 1))
@@ -360,11 +377,11 @@ def paint(self, painter, option, widget=None):
360377
painter.setBrush(QBrush(Qt.transparent,
361378
Qt.SolidPattern))
362379
painter.drawRect(rect)
363-
painter.drawPixmap(pt.x(), pt.y(), self.pixmap)
380+
painter.drawPicture(pt.x(), pt.y(), self.picture)
364381

365382
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),
368385
self.WIDTH,
369386
self.HEIGHT)
370387
return rect
@@ -384,16 +401,24 @@ class FoldButtonGraphicItem(FlatButtonGraphicItem):
384401
HEIGHT = 11
385402

386403
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}
389416

390417
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)
393420

394421
def mousePressEvent(self, event):
395422
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]
399424
self.action(self.folded)

0 commit comments

Comments
 (0)
Please sign in to comment.