Ejemplo n.º 1
0
 def __init__(self, rect, parent=None):
     QtGui.QGraphicsRectItem.__init__(self, rect, parent)
     self.__resizing = False
     self.__handlePoly = QtGui.QPolygonF([
         QtCore.QPointF(0, -self.__handleSize),
         QtCore.QPointF(0, 0),
         QtCore.QPointF(-self.__handleSize, 0)
     ])
     self.setFlag(QtGui.QGraphicsItem.ItemStacksBehindParent)
     # -- handle --
     self.__handlePos = QtCore.QPointF(0, 0)
     # -- header --
     self.__headerContentRect = None
     self.__headerRect = None
     # -- color --
     self.__color = None
     self.__darkerColor = None
     self.__shadowColor = None
     self.setColor(self.__defaultColor.darker(110))
     # -- optionnal cosmetics --
     if safeEffects:
         fx = QtGui.QGraphicsDropShadowEffect()
         fx.setOffset(2, 2)
         fx.setBlurRadius(5)
         self.setGraphicsEffect(fx)
Ejemplo n.º 2
0
    def get_selection_center(self, selection=None):
        """ """
        items = None
        if selection: items = selection
        else: items = self.get_selected_items()

        l = len(items)
        if (l == 0): return QtCore.QPointF(30, 30)

        sx = sum((i.pos().x() for i in items))
        sy = sum((i.pos().y() for i in items))
        return QtCore.QPointF(float(sx) / l, float(sy) / l)
Ejemplo n.º 3
0
    def paint(self, painter, paintOptions, widget):
        myRect = self.boundingRect()

        painter.fillRect(self.__headerRect, self.__darkerColor)
        gradTop = self.__headerRect.bottomLeft()
        gradBot = gradTop + QtCore.QPointF(0, 4)
        gradient = QtGui.QLinearGradient(gradTop, gradBot)
        gradient.setColorAt(0, self.__shadowColor)
        gradient.setColorAt(1, self.__color)
        brush = QtGui.QBrush(gradient)

        bottomRect = myRect.adjusted(0, self.__headerRect.bottom(), 0, 0)
        painter.fillRect(bottomRect, brush)

        if not safeEffects:
            oldPen = painter.pen()
            pen = QtGui.QPen()
            pen.setColor(QtGui.QColor(10, 10, 10, 100))
            pen.setWidth(1)
            painter.setPen(pen)
            painter.drawRect(myRect.adjusted(0.5, 0.5, -0.5, -0.5))
            painter.setPen(oldPen)

        painter.setBrush(QtGui.QBrush(self.__darkerColor))
        painter.drawConvexPolygon(self.__handlePoly)
Ejemplo n.º 4
0
    def __init__(self, edge=None, graph=None, src=None, dst=None):
        Element.__init__(self, edge, graph)
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable)
        self.setZValue(0.5)
        self.srcPoint = QtCore.QPointF()
        self.dstPoint = QtCore.QPointF()
        self.__edge_creator = self.set_edge_creator(edgefactory.LinearEdgePath())

        self.setPen(QtGui.QPen(QtCore.Qt.black, 2,
                               QtCore.Qt.SolidLine,
                               QtCore.Qt.RoundCap,
                               QtCore.Qt.RoundJoin))

        self.dstBBox = self.srcBBox = None
        if src is not None: self.set_observed_source(src)
        if dst is not None: self.set_observed_destination(dst)
        self.setPath(self.__edge_creator.get_path(self.srcPoint, self.dstPoint))
Ejemplo n.º 5
0
 def setPos(self, pos):
     offset = pos + QtCore.QPointF(self._x1, self._y1)
     innerOffset = QtCore.QPointF(self._ix1, self._iy1)
     items = self.visibleItems()
     selfWidth = self.boundingRect(force=False).width()
     for it in items:
         itRect = it.boundingRect()
         if self._center:
             offset.setX(pos.x() + (selfWidth - itRect.width()) / 2.)
         it.setPos(offset)
         offset += QtCore.QPointF(0., itRect.height()) + innerOffset
     if self._final and self._final.isVisible():
         if self._center:
             offset.setX(pos.x() +
                         (selfWidth - self._final.boundingRect().width()) /
                         2.)
         self._final.setPos(offset)
Ejemplo n.º 6
0
    def shape(self):
        path = QtGui.QPainterPath()

        # Enlarge selection zone
        diff = self.p2 - self.p1

        if (abs(diff.x()) > abs(diff.y())):
            dp = QtCore.QPointF(0, 10)
        else:
            dp = QtCore.QPointF(10, 0)

        p1 = self.p1 - dp
        p2 = self.p1 + dp
        p3 = self.p2 + dp
        p4 = self.p2 - dp
        poly = QtGui.QPolygonF([p1, p2, p3, p4])
        path.addPolygon(poly)

        return path
Ejemplo n.º 7
0
    def get_path(self, p1, p2):
        self.p1 = p1
        self.p2 = p2
        path = QtGui.QPainterPath(self.p1)

        sd = self.p2 - self.p1
        if abs(sd.x()) <= self.WIDTH:  # draw a line
            path.lineTo(self.p2)
        elif sd.y() < self.WIDTH:
            py = QtCore.QPointF(0, max(self.WIDTH, -sd.y()))
            path.cubicTo(self.p1 + py, self.p2 - py, self.p2)

        else:
            py = QtCore.QPointF(0, sd.y() / 2.)
            pm = (self.p1 + self.p2) / 2.
            path.quadTo(self.p1 + py, pm)
            path.quadTo(self.p2 - py, self.p2)

        return path
Ejemplo n.º 8
0
    def add_control(self, control, pos=None):

        widget = qt_editor(control, 'large')
        if widget:

            if pos is None:
                pos = QtCore.QPointF(0, 0)

            item = WidgetItem(widget, pos, control.name)
            item.set_mode(self._mode)
            self.witems.append(item)
            self.addItem(item)
Ejemplo n.º 9
0
    def get_path(self, p1, p2):
        self.p1 = p1
        self.p2 = p2
        path = QtGui.QPainterPath(self.p1)

        points = []

        sd = self.p2 - self.p1
        if abs(sd.x()) <= self.WIDTH:  # draw a line
            pass
        elif sd.y() < 2 * self.WIDTH:
            s1 = self.p1 + QtCore.QPointF(0, self.WIDTH)
            d1 = self.p2 - QtCore.QPointF(0, self.WIDTH)

            s1d1 = d1 - s1
            s2 = s1 + QtCore.QPointF(s1d1.x() / 2., 0)
            d2 = s2 + QtCore.QPointF(0, s1d1.y())
            points.extend([s1, s2, d2, d1])
        else:
            s1 = self.p1 + QtCore.QPointF(0, sd.y() / 2.)
            d1 = self.p2 - QtCore.QPointF(0, sd.y() / 2.)
            points.extend([s1, d1])

        points.append(self.p2)
        for pt in points:
            path.lineTo(pt)

        return path
Ejemplo n.º 10
0
    def itemChange(self, change, value):
        """ Used mainly to capture position changes from the QGraphicsScene
        and store it in the model so that it can be saved. """
        sc = self.scene()
        if sc:
            sc.invalidate()

        if change == QtGui.QGraphicsItem.ItemVisibleHasChanged:
            self.notify_position_change()

        elif change == qtutils.ItemPositionHasChanged:
            self.deaf(True)
            point = QtCore.QPointF(from_qvariant(value))
            self.store_view_data(position=[point.x(), point.y()])
            self.deaf(False)
            self.notify_position_change()

        return value
Ejemplo n.º 11
0
 def __init__(self):
     self.p1 = QtCore.QPointF()
     self.p2 = QtCore.QPointF()
Ejemplo n.º 12
0
 def position_changed(self, *args):
     """Updates the item's **graphical** position from
     model notifications. """
     point = QtCore.QPointF(args[0], args[1])
     self.setPos(point)
Ejemplo n.º 13
0
 def __init__(self, srcPoint, graph):
     Edge.__init__(self, None, graph, None, None)
     self.srcPoint = QtCore.QPointF(*srcPoint)
     self.dstPoint = QtCore.QPointF(self.srcPoint)
Ejemplo n.º 14
0
 def update_line_destination(self, *pos):
     self.dstPoint = QtCore.QPointF(*pos)
     path = self.__edge_creator.get_path(self.srcPoint, self.dstPoint)
     self.setPath(path)
Ejemplo n.º 15
0
    def refreshGeometry(self):
        rect = self.__layout.boundingRect(force=True)

        self.__layout.setPos(QtCore.QPointF(0., 0.))
        self.setRect(rect)