示例#1
0
    def paintEvent(self, event):
        painter = QPainter(self)
        area_color = self.palette().color(QPalette.Active, QPalette.Highlight)

        if self._full_area_drop:
            r = self.rect()
            painter.fillRect(r, QBrush(area_color, Qt.Dense4Pattern))
            painter.setBrush(QBrush(area_color))
            painter.drawRect(r)
            return

        r = self.rect()
        drop_area = self.cursor_location()
        if drop_area == DropArea.TopDropArea:
            r.setHeight(r.height() * 0.5)
        elif drop_area == DropArea.RightDropArea:
            r.setX(r.width() * 0.5)
        elif drop_area == DropArea.BottomDropArea:
            r.setY(r.height() * 0.5)
        elif drop_area == DropArea.LeftDropArea:
            r.setWidth(r.width() * 0.5)
        elif drop_area == DropArea.CenterDropArea:
            r = self.rect()

        if not r.isNull():
            painter.fillRect(r, QBrush(area_color, Qt.Dense4Pattern))
            painter.setBrush(QBrush(area_color))
            painter.drawRect(r)
    def __init__(self, rect=None, parent=None):

        self.signals = CurveNodeItemSignals()
        gradient = QRadialGradient(
            self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75)
        gradient.setColorAt(0, self.theme().accent_color_6 if self.theme() else QColor.fromRgbF(1, 0.5, 0.01, 1))
        gradient.setColorAt(1, self.theme().accent_color_8 if self.theme() else QColor.fromRgbF(1, 0.6, 0.06, 1))
        self._brush = QBrush(gradient)
        self._brush.setStyle(Qt.RadialGradientPattern)
        self._pen = QPen()
        self._pen.setStyle(Qt.SolidLine)
        self._pen.setWidth(2)
        self._pen.setColor(self.theme().accent_color if self.theme() else QColor(104, 104, 104, 255))
        self._selected_pen = QPen()
        self._selected_pen.setStyle(Qt.SolidLine)
        self._selected_pen.setWidth(3)
        self._selected_pen.setColor(self.theme().accent_color_4 if self.theme() else QColor(67, 255, 163, 255))

        super(CurveNodeItem, self).__init__(parent)

        self._lock_x_pos = False
        self._snap = False
        self._current_pos = None
        self._new_pos = None
        self._line = None
        self._is_point1 = False
        self.set_rect(rect if rect else QRect(0, 0, 10, 10))

        self.setFlags(
            QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemSendsScenePositionChanges)
示例#3
0
    def paint(self, painter, option, widget):

        background_rect = self.boundingRect()
        if self.hovered:
            painter.setBrush(QBrush(self.color.lighter(160)))
        else:
            painter.setBrush(QBrush(self.color))
        painter.drawEllipse(background_rect)
示例#4
0
    def paintEvent(self, event):
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.HighQualityAntialiasing)

        gradient = QRadialGradient(self._bounds.center(),
                                   self._bounds.width() * 0.5,
                                   self._bounds.center())
        gradient.setFocalRadius(self._bounds.width() * 0.3)
        gradient.setCenterRadius(self._bounds.width() * 0.7)
        gradient.setColorAt(0, Qt.white)
        gradient.setColorAt(1, Qt.lightGray)

        painter.setPen(QPen(QBrush(Qt.gray), self._bounds.width() * 0.005))
        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(self._bounds)

        painter.setPen(QPen(QBrush(Qt.gray), self._bounds.width() * 0.005))
        painter.drawLine(
            QPointF(self._bounds.left(),
                    self._bounds.center().y()),
            QPointF(self._bounds.center().x() - self._bounds.width() * 0.35,
                    self._bounds.center().y()))
        painter.drawLine(
            QPointF(self._bounds.center().x() + self._bounds.width() * 0.35,
                    self._bounds.center().y()),
            QPointF(self._bounds.right(),
                    self._bounds.center().y()))
        painter.drawLine(
            QPointF(self._bounds.center().x(), self._bounds.top()),
            QPointF(self._bounds.center().x(),
                    self._bounds.center().y() - self._bounds.width() * 0.35))
        painter.drawLine(
            QPointF(self._bounds.center().x(),
                    self._bounds.center().y() + self._bounds.width() * 0.35),
            QPointF(self._bounds.center().x(), self._bounds.bottom()))

        if not self.isEnabled():
            return

        gradient = QRadialGradient(self._knop_bounds.center(),
                                   self._knop_bounds.width() * 0.5,
                                   self._knop_bounds.center())
        gradient.setFocalRadius(self._knop_bounds.width() * 0.2)
        gradient.setCenterRadius(self._knop_bounds.width() * 0.5)
        gradient.setColorAt(0, Qt.gray)
        gradient.setColorAt(1, Qt.darkGray)

        painter.setPen(QPen(QBrush(Qt.darkGray), self._bounds.width() * 0.005))
        painter.setBrush(QBrush(gradient))
        painter.drawEllipse(self._knop_bounds)
示例#5
0
    def setTextColor(self, text_color):
        """
        Sets the foreground color to the given color
        :param text_color: variant, QColor or str
        """

        if isinstance(text_color, QColor):
            text_color = color.Color.from_color(text_color)
        elif python.is_string(text_color):
            text_color = color.Color.from_string(text_color)
        self._settings['textColor'] = text_color.to_string()
        brush = QBrush()
        brush.setColor(text_color)
        self.setForeground(0, brush)
示例#6
0
    def drawSizeInfo(self):
        sizeInfoAreaWidth = 200
        sizeInfoAreaHeight = 30
        spacing = 5
        rect = self.selectedArea.normalized()
        sizeInfoArea = QRect(rect.left(),
                             rect.top() - spacing - sizeInfoAreaHeight,
                             sizeInfoAreaWidth, sizeInfoAreaHeight)

        if sizeInfoArea.top() < 0:
            sizeInfoArea.moveTopLeft(rect.topLeft() + QPoint(spacing, spacing))
        if sizeInfoArea.right() >= self.screenPixel.width():
            sizeInfoArea.moveTopLeft(rect.topLeft() -
                                     QPoint(spacing, spacing) -
                                     QPoint(sizeInfoAreaWidth, 0))
        if sizeInfoArea.left() < spacing:
            sizeInfoArea.moveLeft(spacing)
        if sizeInfoArea.top() < spacing:
            sizeInfoArea.moveTop(spacing)

        self.itemsToRemove.append(
            self.graphicsScene.addRect(QRectF(sizeInfoArea), QPen(Qt.white),
                                       QBrush(Qt.black)))

        sizeInfo = self.graphicsScene.addSimpleText('  {0} x {1}'.format(
            rect.width() * self.scale,
            rect.height() * self.scale))
        sizeInfo.setPos(sizeInfoArea.topLeft() + QPoint(0, 2))
        sizeInfo.setPen(QPen(QColor(255, 255, 255), 2))
        self.itemsToRemove.append(sizeInfo)
示例#7
0
    def paint_background(self, painter, option, index):
        """
        Overrides base paint_background icon function
        Draw the background for the item
        :param painter: QPainter
        :param option: QStyleOptionViewItem
        :param index: QModelIndex
        """

        super(GroupDataItemView, self).paint_background(painter, option, index)

        painter.setPen(QPen(Qt.NoPen))
        visual_rect = self.visualRect(option)
        text = self.name()
        metrics = QFontMetrics(self._font)
        text_width = metrics.width(text)
        padding = (25 * self.dpi())
        visual_rect.setX(text_width + padding)
        visual_rect.setY(visual_rect.y() + (visual_rect.height() / 2))
        visual_rect.setHeight(2 * self.dpi())
        visual_rect.setWidth(visual_rect.width() - padding)

        color = QColor(self.text_color().red(),
                       self.text_color().green(),
                       self.text_color().blue(), 10)
        painter.setBrush(QBrush(color))
        painter.drawRect(visual_rect)
示例#8
0
    def paint_blend_slider(self, painter, option, index):
        if not self.PAINT_SLIDER or not self.viewer().is_icon_view():
            return

        painter.setPen(QPen(Qt.NoPen))
        rect = self.visual_rect(option)
        color = self.viewer().background_color().toRgb()
        color.setAlpha(75)
        painter.setBrush(QBrush(color))
        height = rect.height()
        ratio = self.blend_value()
        if ratio < 0:
            width = 0
        elif ratio > 100:
            width = rect.width()
        else:
            width = rect.width() * (float(ratio) / 100)
        rect.setWidth(width)
        rect.setHeight(height)

        rect = self.visual_rect(option)
        rect.setY(rect.y() + (4 * self.dpi()))
        color = self.viewer().text_color().toRgb()
        color.setAlpha(220)
        pen = QPen(color)
        align = Qt.AlignTop | Qt.AlignHCenter
        painter.setPen(pen)
        painter.drawText(rect, align, str(self.blend_value()) + "%")
示例#9
0
    def paint_playhead(self, painter, option):
        """
        Pain the playhead if the item has an image sequence
        :param painter: QPainter
        :param option: QStyleOptionViewItem
        """

        image_sequence = self.image_sequence()
        if image_sequence and self.under_mouse():
            count = image_sequence.frame_count()
            current = image_sequence.current_frame_number()
            if count > 0:
                percent = float((count + current) + 1) / count - 1
            else:
                percent = 0

            icon_rect = self.icon_rect(option)
            playhead_color = self.playhead_color()

            painter.setPen(Qt.NoPen)
            painter.setBrush(QBrush(playhead_color))

            if percent <= 0:
                width = 0
            elif percent >= 1:
                width = icon_rect.width()
            else:
                width = (percent * icon_rect.width()) - 1

            height = 3 * self.dpi()
            y = icon_rect.y() + icon_rect.height() - (height - 1)

            painter.drawRect(icon_rect.x(), y, width, height)
示例#10
0
    def paint_background(self, painter, option, index):
        """
        Draw the background for the item
        :param painter: QPainter
        :param option: QStyleOptionViewItem
        :param index:QModelIndex
        """

        is_selected = option.state & QStyle.State_Selected
        is_mouse_over = option.state & QStyle.State_MouseOver
        painter.setPen(QPen(Qt.NoPen))
        visual_rect = self.visual_rect(option)
        if is_selected:
            color = self.background_selected_color()
        elif is_mouse_over:
            color = self.background_hover_color()
        else:
            color = self.backgroundColor()
        painter.setBrush(QBrush(color))

        if not self.viewer().is_icon_view():
            spacing = 1 * self.dpi()
            height = visual_rect.height() - spacing
            visual_rect.setHeight(height)

        painter.drawRect(visual_rect)
示例#11
0
    def __init__(self, parent=None):
        super(GridBackgroundImageView, self).__init__(parent=parent)

        self._background_image = None
        self._background_image_path = None
        self._fit_image_to_window = False

        self.setBackgroundBrush(QBrush(QColor(70, 70, 70, 255)))
示例#12
0
    def get_style(self, color, bold=False):
        brush = QBrush(QColor(*color))
        f = QTextCharFormat()
        if bold:
            f.setFontWeight(QFont.Bold)
        f.setForeground(brush)

        return f
示例#13
0
    def paintEvent(self, event):

        painter = QPainter(self)

        if self._is_expanded:
            rect2 = event.rect()
            rect2.setX(15)
            rect2.setWidth(1)
            painter.fillRect(rect2, QBrush(QColor(87, 87, 87)))
示例#14
0
 def __drawTriangle(self, painter, x, y):
     if self.rolloutStyle() == ExpanderStyles.Maya:
         brush = QBrush(QColor(255, 0, 0, 160), Qt.SolidPattern)
     else:
         brush = QBrush(QColor(255, 255, 255, 160), Qt.SolidPattern)
     if not self.isCollapsed():
         tl, tr, tp = QPoint(x + 9, y + 8), QPoint(x + 19, y + 8), QPoint(x + 14, y + 13)
         points = [tl, tr, tp]
         triangle = QPolygon(points)
     else:
         tl, tr, tp = QPoint(x + 11, y + 5), QPoint(x + 16, y + 10), QPoint(x + 11, y + 15)
         points = [tl, tr, tp]
         triangle = QPolygon(points)
     currentPen = painter.pen()
     currentBrush = painter.brush()
     painter.setPen(Qt.NoPen)
     painter.setBrush(brush)
     painter.drawPolygon(triangle)
     painter.setPen(currentPen)
     painter.setBrush(currentBrush)
示例#15
0
    def create_rubber_band(self):
        """
        Creates a new instance of the selection rubber band
        :return: QRubberBand
        """

        rubber_band = QRubberBand(QRubberBand.Rectangle, self)
        palette = QPalette()
        color = self.rubber_band_color()
        palette.setBrush(QPalette.Highlight, QBrush(color))
        rubber_band.setPalette(palette)

        return rubber_band
示例#16
0
    def _draw_triangle(self, painter, x, y):

        if self.rollout_style == AccordionStyle.MAYA:
            brush = QBrush(QColor(255, 0, 0, 160), Qt.SolidPattern)
        else:
            brush = QBrush(QColor(255, 255, 255, 160), Qt.SolidPattern)
        if not self.is_collapsed():
            tl, tr, tp = QPoint(x + 9, y + 8), QPoint(x + 19, y + 8), QPoint(x + 14, y + 13.0)
            points = [tl, tr, tp]
            triangle = QPolygon(points)
        else:
            tl, tr, tp = QPoint(x + 11, y + 6), QPoint(x + 16, y + 11), QPoint(x + 11, y + 16.0)
            points = [tl, tr, tp]
            triangle = QPolygon(points)

        current_pen = painter.pen()
        current_brush = painter.brush()
        painter.setPen(Qt.NoPen)
        painter.setBrush(brush)
        painter.drawPolygon(triangle)
        painter.setPen(current_pen)
        painter.setBrush(current_brush)
示例#17
0
    def __init__(self, parent, system):
        super(SystemTreeWidgetItem,
              self).__init__(parent,
                             [system.key(), system.type()])

        self._system = None
        self.setSystem(system)

        color = COLOR_BUILT if self._system.isBuilt() else COLOR_DEFAULT
        self.setForeground(0, QBrush(color))

        if system.settings()["location"] == "X":
            SubSystemTreeWidgetItem(self, system, location="L")
            SubSystemTreeWidgetItem(self, system, location="R")
示例#18
0
    def paintEvent(self, event):
        contents_y = self.editor.verticalScrollBar().value()
        page_bottom = contents_y + self.editor.viewport().height()
        font_metrics = self.fontMetrics()
        current_block = self.editor.document().findBlock(
            self.editor.textCursor().position())
        painter = QPainter(self)
        line_count = 0

        # Iterate over all text blocks in the document
        block = self.editor.document().begin()
        font_size = self.editor.font().pointSize()
        font = painter.font()
        font.setPixelSize(font_size)
        offset = font_metrics.ascent() + font_metrics.descent()
        color = painter.pen().color()
        painter.setFont(font)
        align = Qt.AlignRight
        while block.isValid():
            line_count += 1

            # Get top left position of the block in the document and check if the position of the block is
            # outside of the visible area
            position = self.editor.document().documentLayout(
            ).blockBoundingRect(block).topLeft()
            if position.y() == page_bottom:
                break

            rect = QRect(0,
                         round(position.y()) - contents_y,
                         self.width() - 5, font_size + offset)

            # Draw line rect
            if block == current_block:
                painter.setPen(Qt.NoPen)
                painter.setBrush(QBrush(self.bg))
                painter.drawRect(
                    QRect(0,
                          round(position.y()) - contents_y, self.width(),
                          font_size + (offset / 2)))
                painter.setPen(QPen(color))

            # Draw text
            painter.drawText(rect, align, str(line_count))
            block = block.next()

        self.highest_line = line_count
        painter.end()
        super(ScriptEditorNumberBar, self).paintEvent(event)
示例#19
0
    def __init__(self, parent, layer):
        super(LayerTreeWidgetItem, self).__init__(parent, [layer.name()])

        self._layer = layer
        self.setExpanded(self._layer.settings()["expanded"])

        sortedSubLayers = sorted(layer.layers().items(), key=lambda x: x[0])
        for subName, subLayer in sortedSubLayers:
            LayerTreeWidgetItem(self, subLayer)

        sortedSystems = sorted(layer.systems().items(), key=lambda x: x[0])
        for key, system in sortedSystems:
            item = SystemTreeWidgetItem(self, system)

        color = COLOR_BUILT if self.isBuilt() else COLOR_DEFAULT
        self.setForeground(0, QBrush(color))
 def paintEvent(self, event):
     super(CommandButton, self).paintEvent(event)
     if self.has_menu:
         painter = QPainter()
         painter.begin(self)
         brush = QBrush(QColor(self.theme().accent_color))
         painter.setRenderHint(painter.Antialiasing)
         painter.setBrush(brush)
         painter.setPen(Qt.NoPen)
         w = self.rect().width() - 1
         h = self.rect().height() - 1
         polygon = QPolygon()
         polygon.append(QPoint(w - 1, h - 8))
         polygon.append(QPoint(w - 8, h - 1))
         polygon.append(QPoint(w - 1, h - 1))
         painter.drawPolygon(polygon)
示例#21
0
    def _draw_triangle(self, painter, x, y):
        brush = QBrush(QColor(255, 255, 255, 160), Qt.SolidPattern)
        if not self.is_collapsed():
            tl, tr, tp = QPoint(x + 9, y + 8), QPoint(x + 19, y + 8), QPoint(
                x + 14, y + 13.0)
            points = [tl, tr, tp]
            triangle = QPolygon(points)
        else:
            tl, tr, tp = QPoint(x + 11, y + 6), QPoint(x + 16, y + 11), QPoint(
                x + 11, y + 16.0)
            points = [tl, tr, tp]
            triangle = QPolygon(points)

        current_brush = painter.brush()
        painter.setBrush(brush)
        painter.drawPolygon(triangle)
        painter.setBrush(current_brush)
示例#22
0
    def drawArrow(self, x1, x2, y1, y2, result):
        rect = self.selectedArea.normalized()
        if y1 <= rect.left():
            y1 = rect.left()
        elif y1 >= rect.right():
            y1 = rect.right()

        if y2 <= rect.top():
            y2 = rect.top()
        elif y2 >= rect.bottom():
            y2 = rect.bottom()

        tmp = [
            ACTION_ARROW, x1, x2, y1, y2,
            QPen(QColor(self.penColorNow), int(self.penSizeNow)),
            QBrush(QColor(self.penColorNow))
        ]
        if result:
            self.drawListResult.append(tmp)
        else:
            self.drawListProcess = tmp
示例#23
0
    def paintEvent(self, event):
        """
        Overrides base QToolButton paintEvent function
        Triggered on frame changed
        :param event: QEvent
        """

        super(ImageSequenceWidget, self).paintEvent(event)

        painter = QPainter()
        painter.begin(self)
        if self.current_filename() and self._image_sequence.frame_count() > 1:
            r = event.rect()
            playhead_height = self.playhead_height()
            playhead_pos = self._image_sequence.percent() * r.width() - 1
            x = r.x()
            y = self.height() - playhead_height
            painter.seten(Qt.NoPen)
            painter.setBrush(QBrush(self.DEFAULT_PLAYHEAD_COLOR))
            painter.drawRect(x, y, playhead_pos, playhead_height)

        painter.end()
示例#24
0
    def _paint_drop_indicator(self, painter):
        """
        Internal function used to paint the drop indicator manually
        :param painter: QPainter
        """

        if self.state() == QAbstractItemView.DraggingState:
            opt = QStyleOption()
            opt.initFrom(self)
            opt.rect = self._drop_indicator_rect
            rect = opt.rect

            color = Qt.black
            if dcc.is_maya():
                color = Qt.white

            brush = QBrush(QColor(color))
            pen = QPen(brush, 1, Qt.DotLine)
            painter.setPen(pen)
            if rect.height() == 0:
                painter.drawLine(rect.topLeft(), rect.topRight())
            else:
                painter.drawRect(rect)
示例#25
0
    def drawMagnifier(self):
        # First, calculate the magnifier position due to the mouse position
        watchAreaWidth = 16
        watchAreaHeight = 16
        watchAreaPixmap = QPixmap()

        cursor_pos = self.mousePoint

        watchArea = QRect(
            QPoint(cursor_pos.x() - watchAreaWidth / 2,
                   cursor_pos.y() - watchAreaHeight / 2),
            QPoint(cursor_pos.x() + watchAreaWidth / 2,
                   cursor_pos.y() + watchAreaHeight / 2))
        if watchArea.left() < 0:
            watchArea.moveLeft(0)
            watchArea.moveRight(watchAreaWidth)
        if self.mousePoint.x() + watchAreaWidth / 2 >= self.screenPixel.width(
        ):
            watchArea.moveRight(self.screenPixel.width() - 1)
            watchArea.moveLeft(watchArea.right() - watchAreaWidth)
        if self.mousePoint.y() - watchAreaHeight / 2 < 0:
            watchArea.moveTop(0)
            watchArea.moveBottom(watchAreaHeight)
        if self.mousePoint.y(
        ) + watchAreaHeight / 2 >= self.screenPixel.height():
            watchArea.moveBottom(self.screenPixel.height() - 1)
            watchArea.moveTop(watchArea.bottom() - watchAreaHeight)

        # tricks to solve the hidpi impact on QCursor.pos()
        watchArea.setTopLeft(
            QPoint(watchArea.topLeft().x() * self.scale,
                   watchArea.topLeft().y() * self.scale))
        watchArea.setBottomRight(
            QPoint(watchArea.bottomRight().x() * self.scale,
                   watchArea.bottomRight().y() * self.scale))
        watchAreaPixmap = self.screenPixel.copy(watchArea)

        # second, calculate the magnifier area
        magnifierAreaWidth = watchAreaWidth * 10
        magnifierAreaHeight = watchAreaHeight * 10
        fontAreaHeight = 40

        cursorSize = 24
        magnifierArea = QRectF(
            QPoint(QCursor.pos().x() + cursorSize,
                   QCursor.pos().y() + cursorSize),
            QPoint(QCursor.pos().x() + cursorSize + magnifierAreaWidth,
                   QCursor.pos().y() + cursorSize + magnifierAreaHeight))
        if magnifierArea.right() >= self.screenPixel.width():
            magnifierArea.moveLeft(QCursor.pos().x() - magnifierAreaWidth -
                                   cursorSize / 2)
        if magnifierArea.bottom() + fontAreaHeight >= self.screenPixel.height(
        ):
            magnifierArea.moveTop(QCursor.pos().y() - magnifierAreaHeight -
                                  cursorSize / 2 - fontAreaHeight)

        # third, draw the watch area to magnifier area
        watchAreaScaled = watchAreaPixmap.scaled(
            QSize(magnifierAreaWidth * self.scale,
                  magnifierAreaHeight * self.scale))
        magnifierPixmap = self.graphicsScene.addPixmap(watchAreaScaled)
        magnifierPixmap.setOffset(magnifierArea.topLeft())

        # then draw lines and text
        self.graphicsScene.addRect(QRectF(magnifierArea),
                                   QPen(QColor(255, 255, 255), 2))
        self.graphicsScene.addLine(
            QLineF(QPointF(magnifierArea.center().x(), magnifierArea.top()),
                   QPointF(magnifierArea.center().x(),
                           magnifierArea.bottom())),
            QPen(QColor(0, 255, 255), 2))
        self.graphicsScene.addLine(
            QLineF(QPointF(magnifierArea.left(),
                           magnifierArea.center().y()),
                   QPointF(magnifierArea.right(),
                           magnifierArea.center().y())),
            QPen(QColor(0, 255, 255), 2))

        # get the rgb of mouse point
        pointRgb = QColor(self.screenPixel.toImage().pixel(self.mousePoint))

        # draw information
        self.graphicsScene.addRect(
            QRectF(
                magnifierArea.bottomLeft(),
                magnifierArea.bottomRight() + QPoint(0, fontAreaHeight + 30)),
            QPen(Qt.black), QBrush(Qt.black))
        rgbInfo = self.graphicsScene.addSimpleText(
            ' Rgb: ({0}, {1}, {2})'.format(pointRgb.red(), pointRgb.green(),
                                           pointRgb.blue()))
        rgbInfo.setPos(magnifierArea.bottomLeft() + QPoint(0, 5))
        rgbInfo.setPen(QPen(QColor(255, 255, 255), 2))

        rect = self.selectedArea.normalized()
        sizeInfo = self.graphicsScene.addSimpleText(' Size: {0} x {1}'.format(
            rect.width() * self.scale,
            rect.height() * self.scale))
        sizeInfo.setPos(magnifierArea.bottomLeft() + QPoint(0, 15) +
                        QPoint(0, fontAreaHeight / 2))
        sizeInfo.setPen(QPen(QColor(255, 255, 255), 2))
示例#26
0
class BaseAnimObject(object):
    _glow_pens = {}
    for index in range(1, 11):
        _glow_pens[index] = [QPen(QColor(0, 255, 0, 12 * index), 1, Qt.SolidLine),
                             QPen(QColor(0, 255, 0, 5 * index), 3, Qt.SolidLine),
                             QPen(QColor(0, 255, 0, 2 * index), 5, Qt.SolidLine),
                             QPen(QColor(0, 255, 0, 25.5 * index), 1, Qt.SolidLine)]

    _pens_text = QPen(QColor(202, 207, 210), 1, Qt.SolidLine)
    _pens_shadow = QPen(QColor(9, 10, 12), 1, Qt.SolidLine)
    _pens_border = QPen(QColor(9, 10, 12), 2, Qt.SolidLine)
    _pens_clear = QPen(QColor(0, 0, 0, 0), 1, Qt.SolidLine)

    _pens_text_disabled = QPen(QColor(102, 107, 110), 1, Qt.SolidLine)
    _pens_shadow_disabled = QPen(QColor(0, 0, 0), 1, Qt.SolidLine)

    _brush_clear = QBrush(QColor(0, 0, 0, 0))
    _brush_border = QBrush(QColor(9, 10, 12))

    def __init__(self):
        font = QFont()
        font.setPointSize(8)
        font.setFamily("Calibri")
        self.setFont(font)

        self._hover = False
        self._glow_index = 0
        self._anim_timer = QTimer()
        self._anim_timer.timeout.connect(self._animate_glow)

    def enterEvent(self, event):
        super(self.__class__, self).enterEvent(event)

        if not self.isEnabled():
            return

        self._hover = True
        self._start_anim()

    def leaveEvent(self, event):
        super(self.__class__, self).leaveEvent(event)

        if not self.isEnabled():
            return

        self._hover = False
        self._start_anim()

    def _animate_glow(self):
        if self._hover:
            if self._glow_index >= 10:
                self._glow_index = 10
                self._anim_timer.stop()
            else:
                self._glow_index += 1

        else:
            if self._glow_index <= 0:
                self._glow_index = 0
                self._anim_timer.stop()
            else:
                self._glow_index -= 1

        dcc.execute_deferred(self.update)

    def _start_anim(self):
        if self._anim_timer.isActive():
            return

        self._anim_timer.start(20)
示例#27
0
 def __init__(self, name):
     super(RubberRect, self).__init__()
     self._name = name
     self.setZValue(2)
     self.setPen(QPen(self.DEFAULT_RUBBER_RECT_COLOR, 0.5, Qt.SolidLine))
     self.setBrush(QBrush(self.DEFAULT_RUBBER_RECT_COLOR))
class CurveNodeItem(QGraphicsItem, object):

    curveUpdated = Signal()
    WIDTH = 10

    def __init__(self, rect=None, parent=None):

        self.signals = CurveNodeItemSignals()
        gradient = QRadialGradient(
            self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75)
        gradient.setColorAt(0, self.theme().accent_color_6 if self.theme() else QColor.fromRgbF(1, 0.5, 0.01, 1))
        gradient.setColorAt(1, self.theme().accent_color_8 if self.theme() else QColor.fromRgbF(1, 0.6, 0.06, 1))
        self._brush = QBrush(gradient)
        self._brush.setStyle(Qt.RadialGradientPattern)
        self._pen = QPen()
        self._pen.setStyle(Qt.SolidLine)
        self._pen.setWidth(2)
        self._pen.setColor(self.theme().accent_color if self.theme() else QColor(104, 104, 104, 255))
        self._selected_pen = QPen()
        self._selected_pen.setStyle(Qt.SolidLine)
        self._selected_pen.setWidth(3)
        self._selected_pen.setColor(self.theme().accent_color_4 if self.theme() else QColor(67, 255, 163, 255))

        super(CurveNodeItem, self).__init__(parent)

        self._lock_x_pos = False
        self._snap = False
        self._current_pos = None
        self._new_pos = None
        self._line = None
        self._is_point1 = False
        self.set_rect(rect if rect else QRect(0, 0, 10, 10))

        self.setFlags(
            QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemSendsScenePositionChanges)

    @property
    def snap(self):
        return self._snap

    @snap.setter
    def snap(self, flag):
        self._snap = bool(flag)

    @property
    def lock_x_pos(self):
        return self._lock_x_pos

    @lock_x_pos.setter
    def lock_x_pos(self, value):
        self._lock_x_pos = value

    def boundingRect(self):
        return QRectF(0, 0, 20, 20)

    def paint(self, painter, option, widget):
        painter.setBrush(self._brush)
        painter.setPen(self._selected_pen if self.isSelected() else self._pen)
        painter.drawEllipse(self._rect)

    def mousePressEvent(self, event):
        self._current_pos = self.pos()
        super(CurveNodeItem, self).mousePressEvent(event)

    def mouseMoveEvent(self, event):
        super(CurveNodeItem, self).mouseMoveEvent(event)
        curve_offset = -self.WIDTH * 0.5
        scale_x = min(max(event.scenePos().x(), curve_offset), self.scene().base_size + curve_offset)
        scale_y = min(max(event.scenePos().y(), curve_offset), self.scene().base_size + curve_offset)
        if self._lock_x_pos:
            scale_x = self._lock_x_pos
        if self._snap is not False:
            scale_x = round((float(scale_x) / self._snap)) * self._snap
            scale_y = round((float(scale_y) / self._snap)) * self._snap
        self._new_pos = QPointF(scale_x, scale_y)
        self.setPos(self._new_pos)
        self.scene().update_curve()
        self.signals.curveUpdated.emit()

    def mouseReleaseEvent(self, event):
        super(CurveNodeItem, self).mouseReleaseEvent(event)

        if not self._new_pos:
            return

        self.scene().undo_stack.push(CurveNodeMoveUndoCommand(self.scene(), self, self._current_pos, self._new_pos))
        self._new_pos = None

    def itemChange(self, change, value):
        if change == self.ItemPositionChange and self.scene():
            new_pos = value
            self._move_line_to_center(new_pos)

        return super(CurveNodeItem, self).itemChange(change, value)

    def set_rect(self, rect):
        self._rect = rect
        self.update()

    def add_line(self, line, is_point1):
        self._line = line
        self._is_point1 = is_point1
        self._move_line_to_center(self.pos())

    def _move_line_to_center(self, new_pos):
        if not self._line:
            return

        x_offset = self._rect.x() - self._rect.width() / 2
        y_offset = self._rect.y() - self._rect.height() / 2
        new_center_pos = QPointF(new_pos.x() - x_offset, new_pos.y() - y_offset)
        p1 = new_center_pos if self._is_point1 else self._line.line().p1()
        p2 = self._line.line().p2() if self._is_point1 else new_center_pos
        self._line.setLine(QLineF(p1, p2))
示例#29
0
    def drawOneStep(self, step):
        """
        :type step: tuple
        """
        if step[0] == ACTION_RECT:
            self.graphicsScene.addRect(
                QRectF(QPointF(step[1], step[2]), QPointF(step[3], step[4])),
                step[5])
        elif step[0] == ACTION_ELLIPSE:
            self.graphicsScene.addEllipse(
                QRectF(QPointF(step[1], step[2]), QPointF(step[3], step[4])),
                step[5])
        elif step[0] == ACTION_ARROW:
            arrow = QPolygonF()

            linex = float(step[1] - step[3])
            liney = float(step[2] - step[4])
            line = sqrt(pow(linex, 2) + pow(liney, 2))

            # in case to divided by 0
            if line == 0:
                return

            sinAngel = liney / line
            cosAngel = linex / line

            # sideLength is the length of bottom side of the body of an arrow
            # arrowSize is the size of the head of an arrow, left and right
            # sides' size is arrowSize, and the bottom side's size is arrowSize / 2
            sideLength = step[5].width()
            arrowSize = 8
            bottomSize = arrowSize / 2

            tmpPoint = QPointF(step[3] + arrowSize * sideLength * cosAngel,
                               step[4] + arrowSize * sideLength * sinAngel)

            point1 = QPointF(step[1] + sideLength * sinAngel,
                             step[2] - sideLength * cosAngel)
            point2 = QPointF(step[1] - sideLength * sinAngel,
                             step[2] + sideLength * cosAngel)
            point3 = QPointF(tmpPoint.x() - sideLength * sinAngel,
                             tmpPoint.y() + sideLength * cosAngel)
            point4 = QPointF(tmpPoint.x() - bottomSize * sideLength * sinAngel,
                             tmpPoint.y() + bottomSize * sideLength * cosAngel)
            point5 = QPointF(step[3], step[4])
            point6 = QPointF(tmpPoint.x() + bottomSize * sideLength * sinAngel,
                             tmpPoint.y() - bottomSize * sideLength * cosAngel)
            point7 = QPointF(tmpPoint.x() + sideLength * sinAngel,
                             tmpPoint.y() - sideLength * cosAngel)

            arrow.append(point1)
            arrow.append(point2)
            arrow.append(point3)
            arrow.append(point4)
            arrow.append(point5)
            arrow.append(point6)
            arrow.append(point7)
            arrow.append(point1)

            self.graphicsScene.addPolygon(arrow, step[5], step[6])
        elif step[0] == ACTION_LINE:
            self.graphicsScene.addLine(
                QLineF(QPointF(step[1], step[2]), QPointF(step[3], step[4])),
                step[5])
        elif step[0] == ACTION_FREEPEN:
            self.graphicsScene.addPath(step[1], step[2])
        elif step[0] == ACTION_TEXT:
            textAdd = self.graphicsScene.addSimpleText(step[1], step[2])
            textAdd.setPos(step[3])
            textAdd.setBrush(QBrush(step[4]))
            self.textRect = textAdd.boundingRect()
示例#30
0
class BaseButtonStyle(object):
    _gradient = {NORMAL: {}, DOWN: {}, DISABLED: {}}
    inner_gradient = QLinearGradient(0, 3, 0, 24)
    inner_gradient.setColorAt(0, QColor(53, 57, 60))
    inner_gradient.setColorAt(1, QColor(33, 34, 36))
    _gradient[NORMAL][INNER] = QBrush(inner_gradient)
    outer_gradient = QLinearGradient(0, 2, 0, 25)
    outer_gradient.setColorAt(0, QColor(69, 73, 76))
    outer_gradient.setColorAt(1, QColor(17, 18, 20))
    _gradient[NORMAL][OUTER] = QBrush(outer_gradient)
    inner_gradient_down = QLinearGradient(0, 3, 0, 24)
    inner_gradient_down.setColorAt(0, QColor(20, 21, 23))
    inner_gradient_down.setColorAt(1, QColor(48, 49, 51))
    _gradient[DOWN][INNER] = QBrush(inner_gradient_down)
    outer_gradient_down = QLinearGradient(0, 2, 0, 25)
    outer_gradient_down.setColorAt(0, QColor(36, 37, 39))
    outer_gradient_down.setColorAt(1, QColor(32, 33, 35))
    _gradient[DOWN][OUTER] = QBrush(outer_gradient_down)
    inner_gradient_disabled = QLinearGradient(0, 3, 0, 24)
    inner_gradient_disabled.setColorAt(0, QColor(33, 37, 40))
    inner_gradient_disabled.setColorAt(1, QColor(13, 14, 16))
    _gradient[DISABLED][INNER] = QBrush(inner_gradient_disabled)
    outer_gradient_disabled = QLinearGradient(0, 2, 0, 25)
    outer_gradient_disabled.setColorAt(0, QColor(49, 53, 56))
    outer_gradient_disabled.setColorAt(1, QColor(9, 10, 12))
    _gradient[DISABLED][OUTER] = QBrush(outer_gradient_disabled)

    @staticmethod
    def paintEvent(base_button, event):
        painter = QStylePainter(base_button)
        painter.setRenderHint(QPainter.Antialiasing)

        option = QStyleOption()
        option.initFrom(base_button)
        x = option.rect.x()
        y = option.rect.y()
        height = option.rect.height() - 1
        width = option.rect.width() - 1

        radius = base_button._radius
        gradient = BaseButtonStyle._gradient[NORMAL]
        offset = 0
        if base_button.isDown():
            gradient = BaseButtonStyle._gradient[DOWN]
            offset = 1
        elif not base_button.isEnabled():
            gradient = BaseButtonStyle._gradient[DISABLED]

        painter.setBrush(base_button._brush_border)
        painter.setPen(base_button._pens_border)
        painter.drawRoundedRect(QRect(x + 1, y + 1, width - 1, height - 1),
                                radius, radius)

        painter.setPen(base_button._pens_clear)
        painter.setBrush(gradient[OUTER])
        painter.drawRoundedRect(QRect(x + 2, y + 2, width - 3, height - 3),
                                radius, radius)

        painter.setBrush(gradient[INNER])
        painter.drawRoundedRect(QRect(x + 3, y + 3, width - 5, height - 5),
                                radius - 1, radius - 1)
        painter.setBrush(base_button._brush_clear)

        text = base_button.text()
        font = base_button.font()
        text_width = base_button._font_metrics.width(text)
        text_height = font.pointSize()
        text_path = QPainterPath()
        text_path.addText((width - text_width) / 2,
                          height - ((height - text_height) / 2) - 1 + offset,
                          font, text)

        glow_index = base_button._glow_index
        glow_pens = base_button._glow_pens
        alignment = (Qt.AlignHCenter | Qt.AlignVCenter)
        if base_button.isEnabled():
            painter.setPen(base_button._pens_shadow)
            painter.drawPath(text_path)
            painter.setPen(base_button._pens_text)
            painter.drawText(x, y + offset, width, height, alignment, text)
            if glow_index > 0:
                for index in range(3):
                    painter.setPen(glow_pens[glow_index][index])
                    painter.drawPath(text_path)

                painter.setPen(glow_pens[glow_index][3])
                painter.drawText(x, y + offset, width, height, alignment, text)
        else:
            painter.setPen(base_button._pens_shadow_disabled)
            painter.drawPath(text_path)
            painter.setPen(base_button._pens_text_disabled)
            painter.drawText(x, y + offset, width, height, alignment, text)