Skip to content
Permalink
Browse files

[processing] convert modeler icons to pictures to kill pixels when zo…

…omed
  • Loading branch information
nirvn committed Jan 2, 2017
1 parent a05096d commit d01e3feafcc3c48205a29b9de83a618da522c061
Binary file not shown.
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M11.023 2.707L8 5.73 4.974 2.708 2.707 4.975 5.732 8l-3.025 3.023 2.268 2.27L8 10.266l3.023 3.025 2.27-2.27L10.265 8l3.024-3.025z" fill-opacity=".059" stroke="#000" stroke-opacity=".435"/></svg>
Binary file not shown.
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><circle cx="4" cy="12" r="1.5" fill-opacity=".059" stroke="#000" stroke-linecap="round" stroke-opacity=".435"/><circle cx="8" cy="12" r="1.5" fill-opacity=".059" stroke="#000" stroke-linecap="round" stroke-opacity=".435"/><circle cx="12" cy="12" r="1.5" fill-opacity=".059" stroke="#000" stroke-linecap="round" stroke-opacity=".435"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M6.5 2.5v4h-4v3h4v4h3v-4h4v-3h-4v-4h-3z" fill="#87add9" stroke="#4673ad"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><g stroke="#5a8c5a" stroke-width=".265"><path d="M5.5 1.5v4h-4v5h4v4h5v-4h4v-5h-4v-4z" fill="#fff" stroke-width="1.00157545"/><path d="M3.5 8.5v-1h9v1z" fill="#5a8c5a" stroke-width="1.00157545"/><path d="M7.5 3.5h1v9h-1z" fill="#5a8c5a" stroke-width="1.00157545"/></g></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11" width="11" height="11"><path fill="#fff" d="M0 0h11v11H0z"/><path fill="none" stroke="#f0f3f2" stroke-linecap="square" d="M1.5 1.5h8v8h-8z"/><path d="M3.5 5.5h4" fill="none" stroke="#000" stroke-linecap="round"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11" width="11" height="11"><path d="M1 1h9v9H1z" fill="#fff" fill-opacity=".6"/><path fill="none" stroke="#f0f3f2" stroke-linecap="square" d="M1.5 1.5h8v8h-8z"/><path d="M3.5 5.5h4" fill="none" stroke="#000" stroke-linecap="round"/></svg>
@@ -1,62 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
inkscape:version="0.91 r13725"
version="1.1"
id="svg2"
viewBox="0 0 16 16"
width="16"
height="16"
sodipodi:docname="output.svg">
<sodipodi:namedview
inkscape:current-layer="svg2"
inkscape:window-maximized="1"
inkscape:window-y="24"
inkscape:window-x="55"
inkscape:cy="11.016124"
inkscape:cx="10.378316"
inkscape:zoom="7.4749867"
units="px"
showgrid="true"
id="namedview6"
inkscape:window-height="1056"
inkscape:window-width="1865"
inkscape:pageshadow="2"
inkscape:pageopacity="0"
guidetolerance="10"
gridtolerance="10"
objecttolerance="10"
borderopacity="1"
bordercolor="#666666"
pagecolor="#ffffff">
<inkscape:grid
type="xygrid"
id="grid3195" />
</sodipodi:namedview>
<defs
id="defs8" />
<metadata
id="metadata4">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<path
style="fill:#87add9;fill-opacity:1;stroke:#4673ad;stroke-width:1;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 9 1.7070312 L 8.5 2.2070312 L 8.5 5.5 L 0.5 5.5 L 0.5 10.5 L 8.5 10.5 L 8.5 13.792969 L 9 14.292969 L 15.292969 8 L 9 1.7070312 z "
id="rect3204" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path d="M0 5h8V0l8 8-8 8v-5H0z" fill="#5a8c5a"/><path d="M1 10V6h8V2.5L14.5 8 9 13.5V10z" fill="#fff"/><path d="M2 7v2h8v2l3.3-3L10 5v2z" fill="#5a8c5a"/></svg>
@@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11" width="11" height="11"><path fill="#fff" d="M0 0h11v11H0z"/><path fill="none" stroke="#f0f3f2" stroke-linecap="square" d="M1.5 1.5h8v8h-8z"/><path d="M3.5 5.5h4M5.5 3.5v4" fill="none" stroke="#000" stroke-linecap="round"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 11 11" width="11" height="11"><path d="M1 1h9v9H1z" fill="#fff" fill-opacity=".6"/><path d="M1.5 1.5h8v8h-8z" fill="none" stroke="#f0f3f2" stroke-linecap="square"/><path d="M3.5 5.5h4m-2-2v4" fill="none" stroke="#000" stroke-linecap="round"/></svg>
@@ -27,9 +27,12 @@
__revision__ = '$Format:%H$'

import os
import math

from qgis.PyQt.QtCore import Qt, QPointF, QRectF
from qgis.PyQt.QtGui import QIcon, QFont, QFontMetricsF, QPen, QBrush, QColor, QPolygonF
from qgis.PyQt.QtGui import QIcon, QFont, QFontMetricsF, QPen, QBrush, QColor, QPolygonF, QPicture, QPainter
from qgis.PyQt.QtWidgets import QGraphicsItem, QMessageBox, QMenu
from qgis.PyQt.QtSvg import QSvgRenderer
from processing.modeler.ModelerAlgorithm import ModelerParameter, Algorithm, ModelerOutput
from processing.modeler.ModelerParameterDefinitionDialog import ModelerParameterDefinitionDialog
from processing.modeler.ModelerParametersDialog import ModelerParametersDialog
@@ -47,13 +50,19 @@ def __init__(self, element, model):
self.model = model
self.element = element
if isinstance(element, ModelerParameter):
icon = QIcon(os.path.join(pluginPath, 'images', 'input.svg'))
self.pixmap = icon.pixmap(16, 16, state=QIcon.On)
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'input.svg'))
self.picture = QPicture()
painter = QPainter(self.picture)
svg.render(painter)
self.pixmap = None
self.text = element.param.description
elif isinstance(element, ModelerOutput):
# Output name
icon = QIcon(os.path.join(pluginPath, 'images', 'output.svg'))
self.pixmap = icon.pixmap(16, 16, state=QIcon.On)
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'output.svg'))
self.picture = QPicture()
painter = QPainter(self.picture)
svg.render(painter)
self.pixmap = None
self.text = element.description
else:
self.text = element.description
@@ -65,19 +74,25 @@ def __init__(self, element, model):
self.setZValue(1000)

if not isinstance(element, ModelerOutput):
icon = QIcon(os.path.join(pluginPath, 'images', 'edit.png'))
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'edit.svg'))
picture = QPicture()
painter = QPainter(picture)
svg.render(painter)
pt = QPointF(ModelerGraphicItem.BOX_WIDTH / 2
- FlatButtonGraphicItem.WIDTH / 2,
ModelerGraphicItem.BOX_HEIGHT / 2
- FlatButtonGraphicItem.HEIGHT / 2 + 1)
self.editButton = FlatButtonGraphicItem(icon, pt, self.editElement)
- FlatButtonGraphicItem.HEIGHT / 2)
self.editButton = FlatButtonGraphicItem(picture, pt, self.editElement)
self.editButton.setParentItem(self)
icon = QIcon(os.path.join(pluginPath, 'images', 'delete.png'))
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'delete.svg'))
picture = QPicture()
painter = QPainter(picture)
svg.render(painter)
pt = QPointF(ModelerGraphicItem.BOX_WIDTH / 2
- FlatButtonGraphicItem.WIDTH / 2,
- ModelerGraphicItem.BOX_HEIGHT / 2
+ FlatButtonGraphicItem.HEIGHT / 2 + 1)
self.deleteButton = FlatButtonGraphicItem(icon, pt,
+ FlatButtonGraphicItem.HEIGHT / 2)
self.deleteButton = FlatButtonGraphicItem(picture, pt,
self.removeElement)
self.deleteButton.setParentItem(self)

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

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

def __init__(self, icon, position, action):
def __init__(self, picture, position, action):
super(FlatButtonGraphicItem, self).__init__(None)
self.setAcceptHoverEvents(True)
self.setFlag(QGraphicsItem.ItemIsMovable, False)
self.pixmap = icon.pixmap(self.WIDTH, self.HEIGHT,
state=QIcon.On)
self.picture = picture
self.position = position
self.isIn = False
self.action = action
@@ -349,7 +366,7 @@ def mousePressEvent(self, event):
self.action()

def paint(self, painter, option, widget=None):
pt = QPointF(-self.WIDTH / 2, -self.HEIGHT / 2) + self.position
pt = QPointF(-math.floor(self.WIDTH / 2), -math.floor(self.HEIGHT / 2)) + self.position
rect = QRectF(pt.x(), pt.y(), self.WIDTH, self.HEIGHT)
if self.isIn:
painter.setPen(QPen(Qt.transparent, 1))
@@ -360,11 +377,11 @@ def paint(self, painter, option, widget=None):
painter.setBrush(QBrush(Qt.transparent,
Qt.SolidPattern))
painter.drawRect(rect)
painter.drawPixmap(pt.x(), pt.y(), self.pixmap)
painter.drawPicture(pt.x(), pt.y(), self.picture)

def boundingRect(self):
rect = QRectF(self.position.x() - self.WIDTH / 2,
self.position.y() - self.HEIGHT / 2,
rect = QRectF(self.position.x() - math.floor(self.WIDTH / 2),
self.position.y() - math.floor(self.HEIGHT / 2),
self.WIDTH,
self.HEIGHT)
return rect
@@ -384,16 +401,24 @@ class FoldButtonGraphicItem(FlatButtonGraphicItem):
HEIGHT = 11

def __init__(self, position, action, folded):
self.icons = {True: QIcon(os.path.join(pluginPath, 'images', 'plus.svg')),
False: QIcon(os.path.join(pluginPath, 'images', 'minus.svg'))}
plus = QPicture()
minus = QPicture()

svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'plus.svg'))
painter = QPainter(plus)
svg.render(painter)
svg = QSvgRenderer(os.path.join(pluginPath, 'images', 'minus.svg'))
painter = QPainter(minus)
svg.render(painter)

self.pictures = {True: plus,
False: minus}

self.folded = folded
icon = self.icons[self.folded]
super(FoldButtonGraphicItem, self).__init__(icon, position, action)
picture = self.pictures[self.folded]
super(FoldButtonGraphicItem, self).__init__(picture, position, action)

def mousePressEvent(self, event):
self.folded = not self.folded
icon = self.icons[self.folded]
self.pixmap = icon.pixmap(self.WIDTH, self.HEIGHT,
state=QIcon.On)
self.picture = self.pictures[self.folded]
self.action(self.folded)

0 comments on commit d01e3fe

Please sign in to comment.
You can’t perform that action at this time.