Beispiel #1
0
    def __init__(self, parent):
        super(DragFilter, self).__init__(parent)

        self.dragSensitivity = 5  #pixels for one step
        self.startSensitivity = 10  #pixel move to start the dragging
        self.cursorLock = False
        self.wrapBoundary = 10  #wrap when within boundary of screen edge
        self.dragCursor = self.CURSOR_ARROWS
        self.dragButton = Qt.MiddleButton

        # The QSpinbox has an option where, if you hold down the mouse button
        # it will continually increment. This flag enables a workaround
        # for that problem
        self.isSpinbox = False

        self.fastModifier = Qt.ControlModifier
        self.slowModifier = Qt.ShiftModifier

        self.fastMultiplier = 5.0
        self.slowDivisor = 5.0

        # private vars
        self._lastPos = QPoint()
        self._leftover = 0
        self._dragStart = None
        self._firstDrag = False
        self._dragType = self.DRAG_NONE
        self._overridden = False
        self._screen = None
        self._isDragging = False
Beispiel #2
0
    def mousePressEvent(self, event):
        """
        Override the behaviour when the mouse is pressed
        """

        self._drag_initiated = False
        self._drag_dropped_pos = QPoint()

        if event.button() == Qt.LeftButton and event.modifiers(
        ) == Qt.ControlModifier:
            self._drag_start_pos = event.pos()

            # Get mouse position and store the area rectangle of the selected tab
            pos = event.pos()
            self._select_tab_index = self.tabAt(pos)
            rect = self.tabRect(self._select_tab_index)

            # Store a pixmap of the selected tab and a pixmap of the close hand cursor image
            # After that we draw the tab and also the hand cursor in the middle of the tab
            pixmap = QPixmap.grabWidget(self, rect)
            painter = QPainter(pixmap)
            cursor_pm = QPixmap(':/icons/close_hand_cursor.png')
            cursor_pos = QPoint(*map(lambda x, y: (x - y) * 0.5,
                                     rect.size().toTuple(),
                                     cursor_pm.size().toTuple()))
            painter.drawPixmap(cursor_pos, cursor_pm)
            painter.end()

            # Update cursor
            cursor = QCursor(pixmap)
            self.setCursor(cursor)

        super(TearOffTabBar, self).mousePressEvent(event)
    def _create_controls(self):
        self._control_points = list()
        points = [
            QPoint(0, 0),
            QPoint(self._base_size / 4.0, 0),
            QPoint(self._base_size - (self._base_size / 4.0), self._base_size),
            QPoint(self._base_size, self._base_size)]
        for point in points:
            control_point = CurveNodeItem()
            self.addItem(control_point)
            control_point.setPos(point - QPoint(5, 5))
            self._control_points.append(control_point)
            self._point_objects.append(control_point)
            control_point.signals.curveUpdated.connect(self.curveUpdated.emit)

        self._control_points[0].lock_x_pos = -5.0
        self._control_points[-1].lock_x_pos = (self._base_size - 5.0)
        self._bezier_curve = BezierCurveItem()
        self._bezier_curve.update_path(points)
        self.addItem(self._bezier_curve)

        start_connector = self.addLine(
            QLineF(40, 40, 80, 80), QPen(Qt.white, 1, Qt.DashLine))
        start_connector.setZValue(-2)
        end_connector = self.addLine(
            QLineF(40, 40, 80, 80), QPen(Qt.white, 1, Qt.DashLine))
        end_connector.setZValue(-2)

        self._control_points[0].add_line(start_connector, is_point1=True)
        self._control_points[1].add_line(start_connector, is_point1=False)
        self._control_points[-1].add_line(end_connector, is_point1=False)
        self._control_points[-2].add_line(end_connector, is_point1=True)
Beispiel #4
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)
Beispiel #5
0
def slide_window(start=-100, end=0, duration=300, object=None, on_finished=None):
    """
    Slide animation for windows
    :param start: int, animation start value
    :param end: int, animation end value
    :param duration: int, duration of the effect
    :param object: variant, QDialog || QMainWindow
    :param on_finished: variant, function to call when the animation is finished
    :return: QPropertyAnimation
    """

    pos = object.pos()
    animation = QPropertyAnimation(object, b'pos', object)
    animation.setDuration(duration)
    anim_curve = QEasingCurve()
    if start >= end:
        anim_curve.setType(QEasingCurve.OutExpo)
    else:
        anim_curve.setType(QEasingCurve.InOutExpo)
    animation.setEasingCurve(anim_curve)
    animation.setStartValue(QPoint(pos.x(), pos.y() + start))
    animation.setEndValue(QPoint(pos.x(), pos.y() + end))
    animation.start()

    if on_finished:
        animation.finished.connect(on_finished)

    return animation
Beispiel #6
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))
Beispiel #7
0
    def saveScreenshot(self,
                       clipboard=False,
                       fileName='screenshot.png',
                       picType='png'):
        fullWindow = QRect(0, 0, self.width() - 1, self.height() - 1)
        selected = QRect(self.selectedArea)
        if selected.left() < 0:
            selected.setLeft(0)
        if selected.right() >= self.width():
            selected.setRight(self.width() - 1)
        if selected.top() < 0:
            selected.setTop(0)
        if selected.bottom() >= self.height():
            selected.setBottom(self.height() - 1)

        source = (fullWindow & selected)
        source.setTopLeft(
            QPoint(source.topLeft().x() * self.scale,
                   source.topLeft().y() * self.scale))
        source.setBottomRight(
            QPoint(source.bottomRight().x() * self.scale,
                   source.bottomRight().y() * self.scale))
        image = self.screenPixel.copy(source)
        image = self.grab().copy(source)
        image = image.toImage()
        # if clipboard:
        #     QApplication.clipboard().setImage(image, QClipboard.Mode.Clipboard)
        # else:
        #     image.save(fileName)
        self.target_img = image
        self.screen_shot_grabed.emit(QImage(image))
Beispiel #8
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)
Beispiel #9
0
 def IsInRect(self, btn, rect):
     topLeft = QPoint(btn.x(), btn.y())
     bottomLeft = QPoint(btn.x(), btn.y() + btn.height())
     topRight = QPoint(btn.x() + btn.width(), btn.y())
     bottomRight = QPoint(btn.x() + btn.width(), btn.y() + btn.height())
     if (self.PointInRect(topLeft, rect) or self.PointInRect(bottomLeft, rect) or \
           self.PointInRect(topRight, rect) or self.PointInRect(bottomRight, rect)):
           return True
Beispiel #10
0
    def mouseMoveEvent(self, event):
        """
        Override the behaviour when the mouse is moved
        Doing this we avoid that the tab is moved when tearing off the tab
        """

        if self._select_tab_index < -1:
            pass
        else:
            if event.modifiers() == Qt.ControlModifier:
                self.setCursor(Qt.OpenHandCursor)
            else:
                self.setCursor(Qt.ArrowCursor)

        if not event.buttons() == Qt.LeftButton:
            return

        if not self._drag_start_pos.isNull() and (
                event.pos() - self._drag_start_pos
        ).manhattanLength() < QApplication.startDragDistance():
            self._drag_initiated = True

        if (event.buttons() == Qt.LeftButton
            ) and self._drag_initiated and not self.geometry().contains(
                event.pos()):
            finish_move_event = QMouseEvent(QEvent.MouseMove, event.pos(),
                                            Qt.NoButton, Qt.NoButton,
                                            Qt.NoModifier)
            super(TearOffTabBar, self).mouseMoveEvent(finish_move_event)

            drag = QDrag(self)
            mime_data = QMimeData()
            mime_data.setData('action', 'application/tab-detach')
            drag.setMimeData(mime_data)

            rect = self.tabRect(self.tabAt(event.pos()))
            pixmap_big = QPixmap.grabWidget(
                self.parentWidget().currentWidget()).scaled(
                    640, 480, Qt.KeepAspectRatio)
            drag.setPixmap(pixmap_big)
            drag.setDragCursor(QPixmap(), Qt.LinkAction)

            dragged = drag.exec_(Qt.MoveAction)
            if dragged == Qt.IgnoreAction:
                # moved outside of tab widget
                event.accept()
                self.tabDetached.emit(self.tabAt(self._drag_start_pos),
                                      QCursor.pos())
            elif dragged == Qt.MoveAction:
                # moved inside of tab widget
                if not self._drag_dropped_pos.isNull():
                    event.accept()
                    self.tabMoved.emit(self.tabAt(self._drag_start_pos),
                                       self.tabAt(self._drag_dropped_pos))
                    self._drag_dropped_pos = QPoint()
        else:
            super(TearOffTabBar, self).mouseMoveEvent(event)
Beispiel #11
0
    def myendDrag(self, o, e):
        #Only end dragging if it's *not* the first mouse release. See @longClickFix
        if self._firstDrag and self.isSpinbox:
            self._firstDrag = False

        elif self._dragType:
            self.restoreOverrideCursor()
            self._dragType = self.DRAG_NONE
            self._lastPos = QPoint()
            self._dragStart = None
            self._screen = None
            self.dragReleased.emit()
Beispiel #12
0
    def slide_in_index(self, next, force=False):
        """
        Slides to the given widget index
        :param next: int, index of the widget to slide
        """

        now = self.currentIndex()
        if (self._active_state or next == now) and not force:
            return

        self._active_state = True
        width, height = self.frameRect().width(), self.frameRect().height()
        next %= self.count()
        if next > now:
            if self._vertical:
                offset_x, offset_y = 0, height
            else:
                offset_x, offset_y = width, 0
        else:
            if self._vertical:
                offset_x, offset_y = 0, -height
            else:
                offset_x, offset_y = -width, 0
        self.widget(next).setGeometry(0, 0, width, height)
        pnow, pnext = self.widget(now).pos(), self.widget(next).pos()
        self._point_now = pnow

        self.widget(next).move(pnext.x() + offset_x, pnext.y() + offset_y)
        self.widget(next).show()
        self.widget(next).raise_()
        self._current_widget = self.widget(next)

        anim_now = QPropertyAnimation(self.widget(now), b'pos')
        anim_now.setDuration(self._speed)
        anim_now.setStartValue(pnow)
        anim_now.setEndValue(QPoint(pnow.x() - offset_x, pnow.y() - offset_y))
        anim_now.setEasingCurve(self._animation_type)

        anim_next = QPropertyAnimation(self.widget(next), b'pos')
        anim_next.setDuration(self._speed)
        anim_next.setStartValue(
            QPoint(offset_x + pnext.x(), offset_y + pnext.y()))
        anim_next.setEndValue(pnext)
        anim_next.setEasingCurve(self._animation_type)

        self._anim_group = QParallelAnimationGroup()
        self._anim_group.addAnimation(anim_now)
        self._anim_group.addAnimation(anim_next)
        self._anim_group.finished.connect(self._animation_done_slot)
        self._anim_group.start()

        self._next = next
        self._now = now
Beispiel #13
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
Beispiel #14
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()
Beispiel #15
0
    def _center_below(self, rect, screen):
        """
        Internal function that returns a position for the tooltip ensuring that:
            1) The content is fully visible
            2) The content is not drawn inside rect
        :param rect: QRect
        :param screen: QScreen
        :return: QPoint
        """

        size = self.sizeHint()
        margin = self.style().pixelMetric(QStyle.PM_ToolTipLabelFrameWidth)
        screen_geometry = screen.geometry()

        has_room_to_left = (rect.left() - size.width() - margin >=
                            screen_geometry.left())
        has_room_to_right = (rect.right() + size.width() + margin <=
                             screen_geometry.right())
        has_room_above = (rect.top() - size.height() - margin >=
                          screen_geometry.top())
        has_room_below = (rect.bottom() + size.height() + margin <=
                          screen_geometry.bottom())
        if not has_room_above and not has_room_below and not has_room_to_left and not has_room_to_right:
            return QPoint()

        x = 0
        y = 0
        if has_room_below or has_room_above:
            x = max(screen_geometry.left(),
                    rect.center().x() - size.width() / 2)
            if x + size.width() >= screen_geometry.right():
                x = screen_geometry.right() - size.width() + 1
            assert x >= 0
            if has_room_below:
                y = rect.bottom() + margin
            else:
                y = rect.top() - size.height() - margin + 1
        else:
            assert has_room_to_left or has_room_to_right
            if has_room_to_right:
                x = rect.right() + margin
            else:
                x = rect.left() - size.width() - margin + 1

            # Put tooltip at the bottom of the screen. The x-coordinate has already been adjusted,
            # so no overlapping with rect occurs
            y = screen_geometry.bottom() - size.height() + 1

        return QPoint(x, y)
Beispiel #16
0
    def eventFilter(self, obj, event):
        if event.type() == QEvent.MouseButtonPress:
            if event.button() == Qt.MiddleButton:
                if not self._draggers:
                    self._draggers = SliderDraggers(self, self._is_float, dragger_steps=self._dragger_steps)
                    self._draggers.increment.connect(self._on_value_incremented)
                self._draggers.show()
                if self._is_float:
                    self._draggers.move(
                        self.mapToGlobal(QPoint(event.pos().x() - 1, event.pos().y() - self._draggers.height() / 2)))
                else:
                    self._draggers.move(
                        self.mapToGlobal(QPoint(event.pos().x() - 1, event.pos().y() - self._draggers.height() + 15)))

        return False
Beispiel #17
0
    def startDrag(self, event):
        """
        Overrides bae QListView startDrag function
        :param event: QEvent
        """

        if not self.dragEnabled():
            return

        if self._drag_start_pos and hasattr(event, 'pos'):
            item = self.item_at(event.pos())
            if item and item.drag_enabled():
                self._drag_start_index = self.indexAt(event.pos())
                point = self._drag_start_pos - event.pos()
                dt = self.drag_threshold()
                if point.x() > dt or point.y() > dt or point.x(
                ) < -dt or point.y() < -dt:
                    items = self.selected_items()
                    mime_data = self.mime_data(items)
                    pixmap = self._drag_pixmap(item, items)
                    hotspot = QPoint(pixmap.width() * 0.5,
                                     pixmap.height() * 0.5)
                    self._drag = QDrag(self)
                    self._drag.setPixmap(pixmap)
                    self._drag.setHotSpot(hotspot)
                    self._drag.setMimeData(mime_data)
                    self._drag.start(Qt.MoveAction)
    def move_completer(self):
        """
        Moves completer to a proper position
        """

        rect = self.cursorRect()
        pt = self.mapToGlobal(rect.bottomRight())
        x = 0
        y = 0
        if self._completer.isVisible() and self._desktop:
            current_screen = self._desktop.screenGeometry(
                self.mapToGlobal(rect.bottomRight()))
            future_comp_geo = self.completer.geometry()
            future_comp_geo.moveTo(pt)
            if not current_screen.contains(future_comp_geo):
                try:
                    i = current_screen.intersect(future_comp_geo)
                except Exception:
                    i = current_screen.intersected(future_comp_geo)
                x = future_comp_geo.width() - i.width()
                y = future_comp_geo.height() + self.completer.line_height \
                    if (future_comp_geo.height() - i.height()) > 0 else 0

        pt = self.mapToGlobal(rect.bottomRight()) + QPoint(10 - x, -y)
        self._completer.move(pt)
    def __init__(self, parent=None):
        self._base_size = 300
        self._bezier_dict = {
            'bezier': [
                QPoint(0, 0), QPoint(75, 0),
                QPoint(225, 300), QPoint(300, 300)],
            'linear': [
                QPointF(0.000000, 0.000000), QPointF(75.000000, 75.000000),
                QPointF(225.000000, 225.000000), QPointF(300.000000, 300.000000)]
        }

        super(FallofCurveWidget, self).__init__(parent=parent)
        self.setObjectName('Falloff Curve')
        self.show()

        self.refresh()
Beispiel #20
0
    def __init__(self, parent: QWidget = None) -> None:
        super().__init__(parent)

        self.m_normalMap = SlippyMap(self)
        self.m_largeMap = SlippyMap(self)
        self.m_normalMap.updated.connect(self.updateMap)
        self.m_largeMap.updated.connect(self.update)
        self.pressed = False
        self.snapped = False
        self.pressPos = QPoint()
        self.dragPos = QPoint()
        self.tapTimer = QBasicTimer()
        self.zoomed = False
        self.zoomPixmap = QPixmap()
        self.maskPixmap = QPixmap()
        self.invert = False
Beispiel #21
0
    def __init__(self, parent=None):
        super(JoyPad, self).__init__(parent=parent)

        self._x = 0
        self._y = 0
        self._bounds = QRectF()
        self._knop_bounds = QRectF()
        self._last_pos = QPoint()
        self._knop_pressed = False

        self._return_animation = QParallelAnimationGroup(self)
        self._x_anim = QPropertyAnimation(self, 'x')
        self._y_anim = QPropertyAnimation(self, 'y')
        self._alignment = Qt.AlignTop | Qt.AlignLeft

        self._x_anim.setEndValue(0.0)
        self._x_anim.setDuration(400)
        self._x_anim.setEasingCurve(QEasingCurve.OutSine)

        self._y_anim.setEndValue(0.0)
        self._y_anim.setDuration(400)
        self._y_anim.setEasingCurve(QEasingCurve.OutSine)

        self._return_animation.addAnimation(self._x_anim)
        self._return_animation.addAnimation(self._y_anim)
Beispiel #22
0
 def drawEllipse(self, x1, x2, y1, y2, result):
     rect = self.selectedArea.normalized()
     tmpRect = QRect(QPoint(x1, x2), QPoint(y1, y2)).normalized()
     resultRect = rect & tmpRect
     tmp = [
         ACTION_ELLIPSE,
         resultRect.topLeft().x(),
         resultRect.topLeft().y(),
         resultRect.bottomRight().x(),
         resultRect.bottomRight().y(),
         QPen(QColor(self.penColorNow), int(self.penSizeNow))
     ]
     if result:
         self.drawListResult.append(tmp)
     else:
         self.drawListProcess = tmp
 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)
Beispiel #24
0
    def present(self, newNotification):
        if self.notification:
            self.notification.close()
            sip.delete(self.notification)
            self.notification = None

        self.notification = newNotification

        self.m_title.setText(f"<b>{self.notification.title()}</b>")
        self.m_message.setText(self.notification.message())
        self.m_icon.setPixmap(
            QPixmap.fromImage(self.notification.icon()).scaledToHeight(
                self.m_icon.height()))

        self.show()
        self.notification.show()

        self.notification.closed.connect(self.onClosed)
        QTimer.singleShot(
            10000, lambda: self.onClosed()
            if self.notification is not None else None)

        # position our popup in the right corner of its parent widget
        self.move(self.parentWidget().mapToGlobal(
            self.parentWidget().rect().bottomRight() -
            QPoint(self.width() + 10,
                   self.height() + 10)))
Beispiel #25
0
    def resizeEvent(self, event):
        """
        Overrides base QDialog resizeEvent function
        :param event: QResizeEvent
        """

        r = self.rect()
        ss = self.styleSheet()
        # ss.replace(str(QRegExp("\\s*margin-top\\s*:\\s*.+?;")), "")
        self.setStyleSheet('{} margin-top: {}px;'.format(
            ss, self.FIXED_HEIGHT))

        poly = QPolygon()
        poly.append(QPoint(r.x(), r.y() + self.FIXED_HEIGHT))
        poly.append(
            QPoint(r.x() + r.width() / 2 - self.FIXED_WIDTH / 2,
                   r.y() + self.FIXED_HEIGHT))
        poly.append(QPoint(r.x() + r.width() / 2, r.y()))
        poly.append(
            QPoint(r.x() + r.width() / 2 + self.FIXED_WIDTH / 2,
                   r.y() + self.FIXED_HEIGHT))
        poly.append(QPoint(r.x() + r.width(), r.y() + self.FIXED_HEIGHT))
        poly.append(QPoint(r.x() + r.width(), r.y() + r.height()))
        poly.append(QPoint(r.x(), r.y() + r.height()))

        new_mask = QRegion(poly)
        self.setMask(new_mask)
Beispiel #26
0
def point_by_dpi(point):
    """
    Scales given QPoint by the current DPI scaling
    :param QPoint point: point to scale by current DPI scaling
    :return: Newly scaled QPoint
    :rtype: QPoint
    """

    return QPoint(dpi_scale(point.x()), dpi_scale(point.y()))
Beispiel #27
0
    def mousePressEvent(self, event):
        super(GuideTreeWidget, self).mousePressEvent(event)

        if event.button() == Qt.RightButton:
            # We add a little offset, otherwise we might click the first action accidentally
            pos = self.mapToGlobal(event.pos() + QPoint(-25, 15))
            self._menu.filterActions()
            self._menu.exec_(pos)

        event.accept()
Beispiel #28
0
    def menu_pos(self, widget=None, align=Qt.AlignLeft):
        """
        Returns menu position based on the current widget position and size
        :param widget: QWidget, widget to culculate the width based off
        :param align:  Qt.Alignleft or Qt.AlignRight, whether to align menu left or right
        :return:
        """

        pos = 0

        if align == Qt.AlignLeft:
            point = self.rect().bottomLeft() - QPoint(0, -self._menu_padding)
            pos = self.mapToGlobal(point)
        elif align == Qt.AlignRight:
            point = self.rect().bottomRight() - QPoint(
                widget.sizeHint().width(), -self._menu_padding)
            pos = self.mapToGlobal(point)

        return pos
Beispiel #29
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))
Beispiel #30
0
    def showPopup(self):
        """
        Overrides base showPopup function.
        If we have a custom menu, we make sure that we show it.
        """

        if self._has_custom_view or self._root_menu is None:
            super(BaseComboBox, self).showPopup()
        else:
            QComboBox.hidePopup(self)
            self._root_menu.popup(self.mapToGlobal(QPoint(0, self.height())))