Ejemplo n.º 1
0
 def mouseMoveEvent(self, event):
     if self.__resizing:
         delta = event.pos() - event.lastPos()
         bottomRight = self.boundingRect().bottomRight() + delta
         newRect = QtCore.QRectF(0., 0., bottomRight.x(), bottomRight.y())
         if newRect.contains(
                 self.__headerContentRect.adjusted(0, 0, 0,
                                                   self.__handleSize)):
             self.setRect(newRect)
             self.__headerRect = QtCore.QRectF(
                 0., 0., bottomRight.x(), self.__headerContentRect.height())
             self.__moveHandleBottomRightTo(newRect.bottomRight())
     else:
         QtGui.QGraphicsRectItem.mouseMoveEvent(self, event)
Ejemplo n.º 2
0
 def mousePressEvent(self, event):
     pos = event.pos()
     bottomRight = self.boundingRect().bottomRight()
     x, y = bottomRight.x(), bottomRight.y()
     rect = QtCore.QRectF(x - 5, y - 5, x + 5, y + 5)
     if self.__handlePoly.containsPoint(pos, QtCore.Qt.OddEvenFill):
         self.__resizing = True
     else:
         QtGui.QGraphicsRectItem.mousePressEvent(self, event)
Ejemplo n.º 3
0
    def boundingRect(self, force=True):
        if force or self._boundCache is None:
            x, y, w, h = self._boundingRect()
            w = max(w, self._minWidth)
            h = max(h, self._minHeight)

            self._boundCache = QtCore.QRectF(x, y, w, h)
            if self._parent:
                self._parent.boundCache = None
        return self._boundCache
Ejemplo n.º 4
0
    def find_closest_connectable(self, pos, boxsize=10.0):
        # creation of a square to find connectables inside.
        if isinstance(pos, QtCore.QPointF) : pos = pos.x(), pos.y()
        rect = QtCore.QRectF((pos[0] - boxsize / 2), (pos[1] - boxsize / 2), boxsize, boxsize)
        dstPortItems = self.items(rect)
        dstPortItems = [item for item in dstPortItems if self.is_connectable(item)]

        distance = float('inf')
        dstPortItem = None
        for item in dstPortItems:
            d = sqrt((item.boundingRect().center().x() - pos[0]) ** 2 +
                        (item.boundingRect().center().y() - pos[1]) ** 2)
            if d < distance:
                distance = d
                dstPortItem = item
        return dstPortItem
Ejemplo n.º 5
0
    def paint_data(self, data, painter, rectangle, option=None):
        painter.save()

        pen = QtGui.QPen()
        if option and option.state & QtGui.QStyle.State_Selected:
            painter.fillRect(option.rect, option.palette.highlight())
            pen.setColor(option.palette.highlightedText().color())
        else:
            pen.setColor(QtCore.Qt.blue)
        painter.setPen(pen)

        painter.setRenderHint(painter.Antialiasing, True)

        text_option = QtGui.QTextOption()
        text_option.setAlignment(QtCore.Qt.AlignHCenter)
        painter.drawText(QtCore.QRectF(rectangle), data, text_option)
        painter.restore()
Ejemplo n.º 6
0
    def paint_data(self, data, painter, rectangle, option=None, **kwargs):
        if data is None:
            return
        painter.save()
        if option:
            rectangle = option.rect
            pen = QtGui.QPen()
            if option.state & QtGui.QStyle.State_Selected:
                pen.setColor(option.palette.highlightedText().color())
                painter.setPen(pen)
                painter.setRenderHint(painter.Antialiasing, True)
                painter.fillRect(rectangle, option.palette.highlight())

        x = rectangle.x()
        y = rectangle.y()
        size = min(rectangle.width(), rectangle.height())
        frame = QtCore.QRectF(x, y, size, size)
        painter.drawImage(frame, to_image(data))
        painter.restore()
Ejemplo n.º 7
0
    def drawSpan(self, painter, rect):
        opt = QtGui.QStyleOptionSlider()
        QtGui.QSlider.initStyleOption(self, opt)

        # area
        groove = self.style().subControlRect(QtGui.QStyle.CC_Slider, opt, QtGui.QStyle.SC_SliderGroove, self)
        if opt.orientation == QtCore.Qt.Horizontal:
            groove.adjust(0, 0, -1, 0)
        else:
            groove.adjust(0, 0, 0, -1)

        # pen & brush
        painter.setPen(QtGui.QPen(self.gradientLeft, 0))
        if opt.orientation == QtCore.Qt.Horizontal:
            self.setupPainter(painter, opt.orientation, groove.center().x(), groove.top(), groove.center().x(), groove.bottom())
        else:
            self.setupPainter(painter, opt.orientation, groove.left(), groove.center().y(), groove.right(), groove.center().y())

        # draw groove
        intersected = QtCore.QRectF(rect.intersected(groove))
        gradient = QtGui.QLinearGradient(intersected.topLeft(), intersected.topRight())
        gradient.setColorAt(0, self.gradientLeft)
        gradient.setColorAt(1, self.gradientRight)
        painter.fillRect(intersected, gradient)