Skip to content
Permalink
Browse files
Merge pull request #2063 from HenningJagd/master
[processing] behavior of scroll zoom in the modeler
  • Loading branch information
alexbruy committed May 28, 2015
2 parents 352e824 + 8c624a3 commit c61d5f2cfcd93e3247aadd367514c50dae0c5315
@@ -47,7 +47,7 @@
"""

from PyQt4.QtCore import Qt, QPointF
from PyQt4.QtGui import QGraphicsPathItem, QPen, QGraphicsItem, QPainterPath, QPolygonF
from PyQt4.QtGui import QGraphicsPathItem, QPen, QGraphicsItem, QPainterPath, QPolygonF, QPainter
from processing.modeler.ModelerGraphicItem import ModelerGraphicItem
from processing.modeler.ModelerAlgorithm import Algorithm

@@ -61,56 +61,62 @@ def __init__(self, startItem, startIndex, endItem, endIndex,
self.startIndex = startIndex
self.startItem = startItem
self.endItem = endItem
self.endPoints = []
self.setFlag(QGraphicsItem.ItemIsSelectable, False)
self.myColor = Qt.gray
self.setPen(QPen(self.myColor, 1, Qt.SolidLine,
Qt.RoundCap, Qt.RoundJoin))
self.setZValue(0)

def paint(self, painter, option, widget=None):
myPen = self.pen()
myPen.setColor(self.myColor)
painter.setPen(myPen)
painter.setBrush(self.myColor)

def updatePath(self):
self.endPoints = []
controlPoints = []
endPt = self.endItem.getLinkPointForParameter(self.endIndex)
startPt = self.startItem.getLinkPointForOutput(self.startIndex)
if isinstance(self.startItem.element, Algorithm):
if self.startIndex != -1:
controlPoints.append(self.startItem.pos() + startPt)
controlPoints.append(self.startItem.pos() + startPt
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt
- QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
- QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt)
pt = QPointF(self.startItem.pos() + startPt
+ QPointF(-3, -3))
painter.drawEllipse(pt.x(), pt.y(), 6, 6)
self.endPoints.append(pt)
pt = QPointF(self.endItem.pos() + endPt +
QPointF(-3, -3))
painter.drawEllipse(pt.x(), pt.y(), 6, 6)
self.endPoints.append(pt)
else:
# Case where there is a dependency on an algorithm not
# on an output
controlPoints.append(self.startItem.pos() + startPt)
controlPoints.append(self.startItem.pos() + startPt
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt
- QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
- QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt)
else:
controlPoints.append(self.startItem.pos())
controlPoints.append(self.startItem.pos()
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
+ QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt
- QPointF(ModelerGraphicItem.BOX_WIDTH / 2, 0))
- QPointF(ModelerGraphicItem.BOX_WIDTH / 3, 0))
controlPoints.append(self.endItem.pos() + endPt)
pt = QPointF(self.endItem.pos() + endPt + QPointF(-3, -3))
painter.drawEllipse(pt.x(), pt.y(), 6, 6)

self.endPoints.append(pt)
path = QPainterPath()
path.moveTo(controlPoints[0])
path.cubicTo(*controlPoints[1:])
painter.strokePath(path, painter.pen())
self.setPath(path)

def paint(self, painter, option, widget=None):
myPen = self.pen()
myPen.setColor(self.myColor)
painter.setPen(myPen)
painter.setBrush(self.myColor)
painter.setRenderHint(QPainter.Antialiasing)

for point in self.endPoints:
painter.drawEllipse(point.x(), point.y(), 6, 6)
painter.strokePath(self.shape(), painter.pen())
@@ -106,7 +106,6 @@ def _wheelEvent(event):
if event.delta() > 0:
factor = 1/factor
self.view.scale(factor, factor)
self.view.centerOn(event.pos().x(), event.pos().y())
self.repaintModel()

def _enterEvent(e):
@@ -100,11 +100,15 @@ def foldInput(self, folded):
pt = self.getLinkPointForOutput(-1)
pt = QPointF(0, pt.y())
self.outButton.position = pt
for arrow in self.arrows:
arrow.updatePath()
self.update()

def foldOutput(self, folded):
self.element.outputsFolded = folded
self.prepareGeometryChange()
for arrow in self.arrows:
arrow.updatePath()
self.update()

def addArrow(self, arrow):
@@ -302,7 +306,7 @@ def getLinkPointForOutput(self, outputIndex):
def itemChange(self, change, value):
if change == QGraphicsItem.ItemPositionHasChanged:
for arrow in self.arrows:
arrow.updatePosition()
arrow.updatePath()
self.element.pos = self.pos()

return value
@@ -105,11 +105,17 @@ def paintModel(self, model):
sourceItems = self.getItemsFromParamValue(value)
for sourceItem, sourceIdx in sourceItems:
arrow = ModelerArrowItem(sourceItem, sourceIdx, self.algItems[alg.name], idx)
sourceItem.addArrow(arrow)
self.algItems[alg.name].addArrow(arrow)
arrow.updatePath()
self.addItem(arrow)
idx += 1
for depend in alg.dependencies:
arrow = ModelerArrowItem(self.algItems[depend], -1,
self.algItems[alg.name], -1)
self.algItems[depend].addArrow(arrow)
self.algItems[alg.name].addArrow(arrow)
arrow.updatePath()
self.addItem(arrow)

# And finally the outputs
@@ -132,6 +138,9 @@ def paintModel(self, model):
outputItems[key] = item
arrow = ModelerArrowItem(self.algItems[alg.name], idx, item,
-1)
self.algItems[alg.name].addArrow(arrow)
item.addArrow(arrow)
arrow.updatePath()
self.addItem(arrow)
idx += 1
else:

0 comments on commit c61d5f2

Please sign in to comment.