Exemplo n.º 1
0
    def paintEvent(self, event):
        super(DragDoubleSpinBoxLine, self).paintEvent(event)
        p = QPainter()
        p.begin(self)

        try:
            v = float(self.text())
        except Exception:
            v = 0.0000001

        try:
            v /= self._max if v > 0 else (self._min * -1)
        except Exception:
            pass
        if self._sup:
            p.fillRect(QRect(0,
                             self.height() - 4, v * self.width(), 4),
                       self._color)
        else:
            p.fillRect(
                QRect(self.width() * 0.5,
                      self.height() - 4,
                      v * self.width() * 0.5, 4),
                self._color if v > 0 else QColor(255, 0, 0))
        p.end()
Exemplo n.º 2
0
    def invalidate(self) -> None:
        if self.width <= 0 or self.height <= 0:
            return

        ct = tileForCoordinate(self.latitude, self.longitude, self.zoom)
        tx = ct.x()
        ty = ct.y()

        # top-left corner of the center tile
        xp = self.width / 2 - (tx - math.floor(tx)) * tdim
        yp = self.height / 2 - (ty - math.floor(ty)) * tdim

        xa = (xp + tdim - 1) / tdim
        ya = (yp + tdim - 1) / tdim
        xs = int(tx) - xa
        ys = int(ty) - ya

        # offset for top-left tile
        self.m_offset = QPoint(xp - xa * tdim, yp - ya * tdim)

        # last tile vertical and horizontal
        xe = int(tx) + (self.width - xp - 1) / tdim
        ye = int(ty) + (self.height - yp - 1) / tdim

        # build a rect
        self.m_tilesRect = QRect(xs, ys, xe - xs + 1, ye - ys + 1)

        if self.m_url.isEmpty():
            self.download()

        self.updated.emit(QRect(0, 0, self.width, self.height))
Exemplo n.º 3
0
    def _drag_pixmap(self, item, items):
        """
        Internal function that shows the pixmap for the given item during drag operation
        :param item: LibraryItem
        :param items: list(LibraryItem)
        :return: QPixmap
        """

        rect = self.visualRect(self.index_from_item(item))
        pixmap = QPixmap()
        pixmap = pixmap.grabWidget(self, rect)
        if len(items) > 1:
            custom_width = 35
            custom_padding = 5
            custom_text = str(len(items))
            custom_x = pixmap.rect().center().x() - float(custom_width * 0.5)
            custom_y = pixmap.rect().top() + custom_padding
            custom_rect = QRect(custom_x, custom_y, custom_width, custom_width)
            painter = QPainter(pixmap)
            painter.setRenderHint(QPainter.Antialiasing)
            painter.setPen(Qt.NoPen)
            painter.setBrush(self.viewer().background_selected_color())
            painter.drawEllipse(custom_rect.center(),
                                float(custom_width * 0.5),
                                float(custom_width * 0.5))
            font = QFont('Serif', 12, QFont.Light)
            painter.setFont(font)
            painter.setPen(self.viewer().text_selected_color())
            painter.drawText(custom_rect, Qt.AlignCenter, str(custom_text))

        return pixmap
Exemplo n.º 4
0
    def _animate_expand(self, value):

        size_anim = QPropertyAnimation(self, 'geometry')
        geometry = self.geometry()
        width = geometry.width()
        x, y, _, _ = geometry.getCoords()
        size_start = QRect(x, y, width, int(not (value)) * 150)
        size_end = QRect(x, y, width, value * 150)
        size_anim.setStartValue(size_start)
        size_anim.setEndValue(size_end)
        size_anim.setDuration(300)
        size_anim_curve = QEasingCurve()
        if value:
            size_anim_curve.setType(QEasingCurve.InQuad)
        else:
            size_anim_curve.setType(QEasingCurve.OutQuad)
        size_anim.setEasingCurve(size_anim_curve)

        # =================================================== Animation Sequence

        self._animation = QSequentialAnimationGroup()
        self._animation.addAnimation(size_anim)
        size_anim.valueChanged.connect(self._force_resize)
        if not value:
            self._animation.finished.connect(self.delete_widget)
        self._animation.start(QAbstractAnimation.DeleteWhenStopped)
Exemplo n.º 5
0
    def paint(self, painter, option, index):

        painter.setRenderHints(QPainter.Antialiasing
                               | QPainter.SmoothPixmapTransform)
        model = index.model()
        view = self.parent()

        if view.hasFocus() and option.state & QStyle.State_MouseOver:
            painter.setPen(Qt.NoPen)
            painter.setBrush(Qt.gray)
            painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1),
                                    self._ICON_MARGIN, self._ICON_MARGIN)

        pixmap = model.data(index, Qt.DecorationRole).pixmap(view.iconSize())
        pm_rect = QRect(
            option.rect.topLeft() +
            QPoint(self._ICON_MARGIN + 1, self._ICON_MARGIN + 1),
            view.iconSize() -
            QSize(self._ICON_MARGIN * 2, self._ICON_MARGIN * 2))
        painter.drawPixmap(pm_rect, pixmap)
        if option.state & QStyle.State_Selected:
            painter.setPen(
                QPen(Qt.red, 1.0, Qt.SolidLine, Qt.SquareCap, Qt.RoundJoin))
            painter.setBrush(Qt.NoBrush)
            painter.drawRect(option.rect.adjusted(2, 2, -2, -2))

        font = view.font()
        fm = QFontMetrics(font)
        text = os.path.splitext(
            os.path.basename(model.data(index, Qt.DisplayRole)))[0]
        text = fm.elidedText(text, Qt.ElideRight, view.iconSize().width() - 4)
        text_opt = QTextOption()
        text_opt.setAlignment(Qt.AlignHCenter)
        txt_rect = QRectF(QPointF(pm_rect.bottomLeft() + QPoint(0, 1)),
                          QPointF(option.rect.bottomRight() - QPoint(4, 3)))

        painter.save()
        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(22, 22, 22, 220))
        painter.drawRoundedRect(txt_rect.adjusted(-2, -2, 2, 2), 2, 2)
        painter.restore()
        painter.setPen(self.parent().palette().color(QPalette.WindowText))
        painter.drawText(txt_rect, text, text_opt)

        font.setPointSize(8)
        fm = QFontMetrics(font)
        item = model.itemFromIndex(index)
        size_text = '%d x %d' % (item.size.width(), item.size.height())
        size_rect = fm.boundingRect(option.rect, Qt.AlignLeft | Qt.AlignTop,
                                    size_text)
        size_rect.translate(4, 4)

        painter.save()
        painter.setPen(Qt.NoPen)
        painter.setBrush(QColor(22, 22, 22, 220))
        painter.drawRoundedRect(size_rect.adjusted(-2, -2, 2, 2), 2, 2)
        painter.restore()
        painter.setFont(font)
        painter.drawText(size_rect, size_text)
Exemplo n.º 6
0
    def rubber_band_move_event(self, event):
        """
        Triggered when the user moves the mouse over the current viewport
        :param event: QMouseEvent
        """

        if self.rubber_band() and self._rubber_band_start_pos:
            rect = QRect(self._rubber_band_start_pos, event.pos())
            rect = rect.normalized()
            self.rubber_band().setGeometry(rect)
Exemplo n.º 7
0
    def paintEvent(self, event):
        painter = QStylePainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        painter.setRenderHint(QPainter.TextAntialiasing)
        option = QStyleOption()
        option.initFrom(self)

        x = option.rect.x()
        y = option.rect.y()
        height = option.rect.height() - 1
        width = option.rect.width() - 1
        font = self.font()
        text = self.text()
        alignment = (Qt.AlignLeft | Qt.AlignVCenter)

        painter.setPen(self._pens_border)
        painter.setBrush(self._brush_border)
        painter.drawRoundedRect(QRect(x + 2, y + 2, 13, 13), 3, 3)

        if self.isEnabled():
            painter.setPen(self._pens_shadow)
            painter.drawText(21, y + 2, width, height, alignment, text)

            painter.setPen(self._pens_text)
            painter.drawText(20, y + 1, width, height, alignment, text)

        else:
            painter.setPen(self._pens_shadow_disabled)
            painter.drawText(21, y + 2, width, height, alignment, text)

            painter.setPen(self._pens_text_disabled)
            painter.drawText(20, y + 1, width, height, alignment, text)

        painter.setPen(self._pens_clear)

        if self.isEnabled():
            glow_brushes = self._glow_brushes
        else:
            glow_brushes = self._disabled_glow_brushes

        if self.checkState():
            for index, pos, size, corner in zip(range(4), (2, 3, 4, 5),
                                                (13, 11, 9, 7), (4, 3, 3, 2)):
                painter.setBrush(glow_brushes[10][index])
                painter.drawRoundedRect(QRect(x + pos, y + pos, size, size),
                                        corner, corner)

        glow_index = self._glow_index
        if glow_index > 0:
            for index, pos, size, corner in zip(range(4), (3, 4, 5, 6),
                                                (11, 9, 7, 5), (3, 3, 2, 2)):
                painter.setBrush(glow_brushes[glow_index][index])
                painter.drawRoundedRect(QRect(x + pos, y + pos, size, size),
                                        corner, corner)
Exemplo n.º 8
0
 def undoOperation(self):
     if len(self.drawListResult) == 0:
         self.action = ACTION_SELECT
         self.selectedArea = QRect()
         self.selectedAreaRaw = QRect()
         self.tooBar.hide()
         if self.penSetBar is not None:
             self.penSetBar.hide()
     else:
         self.drawListResult.pop()
     self.redraw()
Exemplo n.º 9
0
    def _generate_layout(self, rect, test_only=True):
        """
        Generates layout with proper flow
        :param rect: QRect
        :param test_only: bool
        :return: int
        """

        x = rect.x()
        y = rect.y()
        line_height = 0
        orientation = self.orientation()

        for item in self._item_list:
            widget = item.widget()
            if widget.isHidden():
                continue

            space_x = self._spacing_x
            space_y = self._spacing_y

            if orientation == Qt.Horizontal:
                next_x = x + item.sizeHint().width() + space_x
                if next_x - space_x > rect.right() and line_height > 0:
                    if not self._overflow:
                        x = rect.x()
                        y = y + line_height + (space_y * 2)
                        next_x = x + item.sizeHint().width() + space_x
                        line_height = 0
                if not test_only:
                    item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
                x = next_x
                line_height = max(line_height, item.sizeHint().height())
            else:
                next_y = y + item.sizeHint().height() + space_y
                if next_y - space_y > rect.bottom() and line_height > 0:
                    if not self._overflow:
                        y = rect.y()
                        x = x + line_height + (space_x * 2)
                        next_y = y + item.sizeHint().height() + space_y
                        line_height = 0
                if not test_only:
                    item.setGeometry(QRect(QPoint(x, y), item.sizeHint()))
                x = next_y
                line_height = max(line_height, item.sizeHint().height())

        if orientation == Qt.Horizontal:
            return y + line_height - rect.y()
        else:
            return x + line_height - rect.x()
Exemplo n.º 10
0
    def __init__(self, title='', parent=None):
        super(ExpandableGroup, self).__init__(title, parent)

        self.close_btn = QPushButton('-', self)
        self.close_btn.clicked.connect(self.toggle)

        self.setMouseTracking(True)

        self.setFont(QFont('Verdana', 10, QFont.Bold))
        self.setTitle('     ' + self.title())

        self.expanded = True

        self.hitbox = QRect(0, 0, self.width(), 18)
Exemplo n.º 11
0
    def animate_expand(self, value):

        size_animation = QPropertyAnimation(self, b'geometry')
        geometry = self.geometry()
        width = geometry.width()
        x, y, _, _ = geometry.getCoords()
        size_start = QRect(x, y, width, int(not value) * self.INTERP_HEIGHT)
        size_end = QRect(x, y, width, value * 150)
        size_animation.setStartValue(size_start)
        size_animation.setEndValue(size_end)
        size_animation.setDuration(200)
        size_anim_curve = QEasingCurve()
        size_anim_curve.setType(
            QEasingCurve.InQuad) if value else size_anim_curve.setType(
                QEasingCurve.OutQuad)
        size_animation.setEasingCurve(size_anim_curve)

        opacity_animation = QPropertyAnimation(self._main_widget_proxy,
                                               b'opacity')
        opacity_animation.setStartValue(not (value))
        opacity_animation.setEndValue(value)
        opacity_animation.setDuration(100)
        opacity_anim_curve = QEasingCurve()
        opacity_anim_curve.setType(
            QEasingCurve.InQuad) if value else opacity_anim_curve.setType(
                QEasingCurve.OutQuad)
        opacity_animation.setEasingCurve(opacity_anim_curve)

        # We must store the animation objects as a member variables. Otherwise the animation object could be deleted
        # once the function is completed. In that case, the animation will not work.
        self._animation = QSequentialAnimationGroup()
        if value:
            self._main_widget_proxy.setOpacity(0)
            self._animation.addAnimation(size_animation)
            self._animation.addAnimation(opacity_animation)
        else:
            self._main_widget_proxy.setOpacity(1)
            self._animation.addAnimation(opacity_animation)
            self._animation.addAnimation(size_animation)

        # When animating geometry property, the parent layout is not updated automatically.
        # We force the resize of the layout by calling a signal each time the size animation value changes.
        size_animation.valueChanged.connect(self._on_force_resize)
        self._animation.finished.connect(self._animation.clear)

        if not value:
            self._animation.finished.connect(self._on_delete_widget)

        self._animation.start(QAbstractAnimation.DeleteWhenStopped)
Exemplo n.º 12
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)
Exemplo n.º 13
0
    def initUI(self):
        self.setFixedSize(400, 400)
        self.setWindowTitle('Colours')
        self.btnPaint = QPushButton("Paint", self)
        self.btnMove = QPushButton("Move x+1 y+1", self)
        self.rect = QRect()

        self.btnPaint.clicked.connect(self.onPaint)
        self.btnMove.clicked.connect(self.onMove)

        self.hlayout = QHBoxLayout(self)
        self.hlayout.addWidget(self.btnPaint)
        self.hlayout.addWidget(self.btnMove)
        self.hlayout.addStretch(1)
        self.show()
    def ui(self):
        super(FallofCurveWidget, self).ui()

        base_rect = QRect(0, 0, self._base_size, self._base_size)

        self._scene = CurveNodeScene(base_rect)
        self._scene.base_size = self._base_size
        self._view = CurveNodeView(parent=self)
        self._view.setScene(self._scene)
        self._view.setGeometry(base_rect)

        self._menu_bar = QMenuBar(self)
        self._menu_bar.addAction(self._scene.undo_action)
        self._menu_bar.addAction(self._scene.redo_action)

        bottom_layout = layouts.HorizontalLayout(spacing=2, margins=(2, 2, 2, 2))
        self._bezier_type_combo = combobox.BaseComboBox(parent=self)
        self._snap_cbx = checkbox.BaseCheckBox('Snap', parent=self)
        bottom_layout.addWidget(self._bezier_type_combo)
        bottom_layout.addWidget(self._snap_cbx)

        self.main_layout.addWidget(self._menu_bar)
        self.main_layout.addWidget(dividers.Divider(parent=self))
        self.main_layout.addWidget(self._view)
        self.main_layout.addWidget(dividers.Divider(parent=self))
        self.main_layout.addLayout(bottom_layout)
    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)
Exemplo n.º 16
0
    def setupUi(self, Form):
        if not Form.objectName():
            Form.setObjectName(u"Form")
        Form.resize(412, 548)
        self.verticalLayout = QVBoxLayout(Form)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.start_button = QPushButton(Form)
        self.start_button.setObjectName(u"start_button")

        self.verticalLayout.addWidget(self.start_button)

        self.ScrollArea = QScrollArea(Form)
        self.ScrollArea.setObjectName(u"ScrollArea")
        self.ScrollArea.setWidgetResizable(True)
        self.scrollAreaWidgetContents = QWidget()
        self.scrollAreaWidgetContents.setObjectName(
            u"scrollAreaWidgetContents")
        self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 392, 499))
        self.verticalLayout_2 = QVBoxLayout(self.scrollAreaWidgetContents)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.ScrollArea.setWidget(self.scrollAreaWidgetContents)

        self.verticalLayout.addWidget(self.ScrollArea)

        self.retranslateUi(Form)

        QMetaObject.connectSlotsByName(Form)
Exemplo n.º 17
0
    def __init__(self, parent=None):
        super(TreeWidget, self).__init__(parent)

        self._auto_add_sub_items = True
        self._title_text_index = 0
        self._text_edit = True
        self._edit_state = None
        self._current_name = None
        self._old_name = None
        self._current_item = None
        self._last_item = None
        self._drop_indicator_rect = QRect()
        self._drop_indicator_position = None
        self._name_filter = None

        self.setIndentation(25)
        self.setExpandsOnDoubleClick(False)
        self.setSortingEnabled(True)
        self.sortByColumn(0, Qt.AscendingOrder)

        if dcc.is_maya():
            self.setAlternatingRowColors(dcc.get_version() < 2016)
        if not dcc.is_maya() and not not dcc.is_nuke():
            palette = QPalette()
            palette.setColor(palette.Highlight, Qt.gray)
            self.setPalette(palette)

        self.itemActivated.connect(self._on_item_activated)
        self.itemChanged.connect(self._on_item_changed)
        self.itemSelectionChanged.connect(self._on_item_selection_changed)
        self.itemClicked.connect(self._on_item_clicked)
        self.itemExpanded.connect(self._on_item_expanded)
        self.itemCollapsed.connect(self._on_item_collapsed)
Exemplo n.º 18
0
    def paintEvent(self, event):
        if self.isVisible() and self.paintLineNum > 0:

            # NOTE 更新绘制
            self.viewport().update()

            block = self.firstVisibleBlock()
            height = self.lineNumberArea.fontMetrics().height()
            number = block.blockNumber()
            painter = QPainter(self.viewport())

            condition = True
            while block.isValid() and condition:
                block_geometry = self.blockBoundingGeometry(block)
                offset = self.contentOffset()
                block_top = block_geometry.translated(offset).top()
                number += 1

                block_rect = QRect(0, block_top, self.width(), height)

                if number == self.paintLineNum:
                    lineColor = QColor(LINE_COLOR).lighter(100)
                    painter.fillRect(block_rect, lineColor)
                    painter.drawRect(block_rect)
                    condition = False

                if block_top > event.rect().bottom():
                    condition = False

                block = block.next()

            painter.end()
        return super(CodeEditor, self).paintEvent(event)
Exemplo n.º 19
0
    def visual_rect(self, option):
        """
        Returns the visual rect for the item
        :param option: QStyleOptionViewItem
        :return: QRect
        """

        return QRect(option.rect)
Exemplo n.º 20
0
    def paintEvent(self, event):
        if self.isVisible():
            block = self.editor.firstVisibleBlock()
            height = self.fontMetrics().height()
            number = block.blockNumber()
            painter = QPainter(self)
            painter.fillRect(event.rect(), LINEBAR_COLOR)
            painter.drawRect(event.rect().width() - 1, 0,
                             event.rect().width(),
                             event.rect().height() - 1)
            font = painter.font()
            current_block = self.editor.textCursor().block().blockNumber() + 1

            condition = True
            while block.isValid() and condition:
                block_geometry = self.editor.blockBoundingGeometry(block)
                offset = self.editor.contentOffset()
                block_top = block_geometry.translated(offset).top()
                number += 1

                # NOTE set the linebar breakpoint color
                if self.paintLineNum > 0 and number == self.paintLineNum:
                    font.setBold(True)
                    block_rect = QRect(LINE_MARGIN, block_top,
                                       self.width() - LINE_MARGIN * 2, height)
                    painter.fillRect(block_rect, LINEBAR_BP_COLOR)
                # NOTE set the current line color
                elif number == current_block:
                    font.setBold(True)
                    block_rect = QRect(LINE_MARGIN, block_top,
                                       self.width() - LINE_MARGIN * 2, height)
                    painter.fillRect(block_rect, LINEBAR_NUM_COLOR)
                else:
                    font.setBold(False)

                painter.setFont(font)
                rect = QRect(0, block_top, self.width() - 5, height)
                painter.drawText(rect, Qt.AlignRight, '%i' % number)

                if block_top > event.rect().bottom():
                    condition = False

                block = block.next()

            painter.end()
Exemplo n.º 21
0
 def setText(self, text):
     self.m_text = text
     metrics = QFontMetrics(self.m_font)
     self.m_textRect = QRectF(
         metrics.boundingRect(QRect(0, 0, 150, 150), Qt.AlignLeft,
                              self.m_text))
     self.m_textRect.translate(5, 5)
     self.prepareGeometryChange()
     self.m_rect = self.m_textRect.adjusted(-5, -5, 5, 5)
Exemplo n.º 22
0
 def render(self, painter: QPainter, rect: QRect) -> None:
     for x in range(self.m_tilesRect.width() + 1):
         for y in range(self.m_tilesRect.height() + 1):
             tp = QPoint(x + self.m_tilesRect.left(),
                         y + self.m_tilesRect.top())
             box = self.tileRect(tp)
             if rect.intersects(box):
                 painter.drawPixmap(
                     box,
                     self.m_tilePixmaps.get(QPointH(tp), self.m_emptyTile))
Exemplo n.º 23
0
    def mousePressEvent(self, event):
        """
        :type event: QMouseEvent
        :param event:
        :return:
        """
        if event.button() != Qt.LeftButton:
            return

        if self.action is None:
            self.action = ACTION_SELECT

        self.startX, self.startY = event.x(), event.y()

        if self.action == ACTION_SELECT:
            if self.mousePosition == MousePosition.OUTSIDE_AREA:
                self.mousePressed = True
                self.selectedArea = QRect()
                self.selectedArea.setTopLeft(QPoint(event.x(), event.y()))
                self.selectedArea.setBottomRight(QPoint(event.x(), event.y()))
                self.redraw()
            elif self.mousePosition == MousePosition.INSIDE_AREA:
                self.mousePressed = True
            else:
                pass
        elif self.action == ACTION_MOVE_SELECTED:
            if self.mousePosition == MousePosition.OUTSIDE_AREA:
                self.action = ACTION_SELECT
                self.selectedArea = QRect()
                self.selectedArea.setTopLeft(QPoint(event.x(), event.y()))
                self.selectedArea.setBottomRight(QPoint(event.x(), event.y()))
                self.redraw()
            self.mousePressed = True
        elif self.action in DRAW_ACTION:
            self.mousePressed = True
            if self.action == ACTION_FREEPEN:
                self.pointPath = QPainterPath()
                self.pointPath.moveTo(QPoint(event.x(), event.y()))
            elif self.action == ACTION_TEXT:
                if self.textPosition is None:
                    self.textPosition = QPoint(event.x(), event.y())
                    self.textRect = None
                    self.redraw()
Exemplo n.º 24
0
    def button_rect(self):
        r = self.tabBar().tabRect(self.count() - 1)

        if dcc.is_maya() and dcc.get_version() > 2015:
            rect = QRect(2, 0, 30, 31)
        else:
            rect = QRect(6, 3, 26, 17)
        if r.isValid():
            if dcc.is_maya() and dcc.get_version() > 2015:
                rect.moveBottomLeft(r.bottomRight() + QPoint(1, 1))
            else:
                rect.moveBottomLeft(r.bottomRight() + QPoint(3, -1))
        return rect
Exemplo n.º 25
0
    def rubber_band_start_event(self, event):
        """
        Triggered when the user presses an empty area
        :param event: QMouseEvent
        """

        self._rubber_band_start_pos = event.pos()
        rect = QRect(self._rubber_band_start_pos, QSize())
        rubber_band = self.rubber_band()
        rubber_band.setGeometry(rect)
        rubber_band.show()
Exemplo n.º 26
0
    def mouseReleaseEvent(self, event):
        """
        :type event: QMouseEvent
        :param event:
        :return:
        """
        if event.button() != Qt.LeftButton:
            return

        if self.mousePressed:
            self.mousePressed = False
            self.endX, self.endY = event.x(), event.y()

            if self.action == ACTION_SELECT:
                self.selectedArea.setBottomRight(QPoint(event.x(), event.y()))
                self.selectedAreaRaw = QRect(self.selectedArea)
                self.action = ACTION_MOVE_SELECTED
                self.redraw()
            elif self.action == ACTION_MOVE_SELECTED:
                self.selectedAreaRaw = QRect(self.selectedArea)
                self.redraw()
                # self.action = None
            elif self.action == ACTION_RECT:
                self.drawRect(self.startX, self.startY, event.x(), event.y(),
                              True)
                self.redraw()
            elif self.action == ACTION_ELLIPSE:
                self.drawEllipse(self.startX, self.startY, event.x(),
                                 event.y(), True)
                self.redraw()
            elif self.action == ACTION_ARROW:
                self.drawArrow(self.startX, self.startY, event.x(), event.y(),
                               True)
                self.redraw()
            elif self.action == ACTION_LINE:
                self.drawLine(self.startX, self.startY, event.x(), event.y(),
                              True)
                self.redraw()
            elif self.action == ACTION_FREEPEN:
                self.drawFreeLine(self.pointPath, True)
                self.redraw()
Exemplo n.º 27
0
    def paintEvent(self, event):
        painter = QStylePainter(self)
        opt = QStyleOptionTab()

        for i in range(self.count()):
            self.initStyleOption(opt, i)
            painter.drawControl(QStyle.CE_TabBarTabShape, opt)
            painter.save()

            s = opt.rect.size()
            s.transpose()
            r = QRect(QPoint(), s)
            r.moveCenter(opt.rect.center())
            opt.rect = r

            c = self.tabRect(i).center()
            painter.translate(c)
            painter.rotate(90)
            painter.translate(-c)
            painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
            painter.restore()
Exemplo n.º 28
0
    def hide_drop_overlay(self):
        self.hide()
        self._full_area_drop = False

        # Check if Qt Version > 5.0.0 -> If True:
        # self._target.clear
        # else
        # self._target = 0

        self._target = 0
        self._target_rect = QRect()
        self._last_location = DropArea.InvalidDropArea
Exemplo n.º 29
0
    def heightForWidth(self, width):
        """
        Returns the preferred heights a layout item with given width
        Overrides base QLayout heightForWidth function
        :param width: int
        :return: int
        """

        height = self._generate_layout(QRect(0, 0, width, 0), True)
        self._size_hint_layout = QSize(width, height)

        return height
Exemplo n.º 30
0
    def snapshot(self):
        """
        Takes snapshot
        """

        if not self._save_path:
            LOGGER.error('Path not specificed for snapshot.')
            return

        rect = QRect(self._snap_widget.rect())
        pos = self._snap_widget.mapToGlobal(QPoint(0, 0))
        rect.translate(pos.x(), pos.y())
        self.setWindowOpacity(0)
        self._snapshot_pixmap = qtutils.desktop_pixmap_from_rect(rect)
        dir_path = os.path.dirname(self._save_path)
        if not os.path.exists(os.path.dirname(dir_path)):
            os.makedirs(dir_path)

        self.save(self._save_path, self._image_type)

        self.close()