Пример #1
0
 def drawControl(self, element, option, painter, widget=None):
     if element == QStyle.CE_PushButtonLabel:
         icon = QIcon(option.icon)
         option.icon = QIcon()
     super(ProxyStyle, self).drawControl(element, option, painter, widget)
     if element == QStyle.CE_PushButtonLabel:
         if not icon.isNull():
             iconSpacing = 4
             mode = (QIcon.Normal if option.state
                     & QStyle.State_Enabled else QIcon.Disabled)
             if (mode == QIcon.Normal
                     and option.state & QStyle.State_HasFocus):
                 mode = QIcon.Active
             state = QIcon.Off
             if option.state & QStyle.State_On:
                 state = QIcon.On
             window = widget.window().windowHandle(
             ) if widget is not None else None
             pixmap = icon.pixmap(window, option.iconSize, mode, state)
             pixmapWidth = pixmap.width() / pixmap.devicePixelRatio()
             pixmapHeight = pixmap.height() / pixmap.devicePixelRatio()
             iconRect = QRect(QPoint(), QSize(pixmapWidth, pixmapHeight))
             iconRect.moveCenter(option.rect.center())
             iconRect.moveLeft(option.rect.left() + iconSpacing)
             iconRect = self.visualRect(option.direction, option.rect,
                                        iconRect)
             iconRect.translate(
                 self.proxy().pixelMetric(QStyle.PM_ButtonShiftHorizontal,
                                          option, widget),
                 self.proxy().pixelMetric(QStyle.PM_ButtonShiftVertical,
                                          option, widget),
             )
             painter.drawPixmap(iconRect, pixmap)
Пример #2
0
    def paintEvent(self, event):

        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setAttribute(Qt.WA_TranslucentBackground)
        self.setStyleSheet("background:transparent;")

        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        drawingRect = QRect(
            QtCore.QPoint(),
            self.rect().size() - 2 * self.width * QtCore.QSize(1, 1))
        drawingRect.moveCenter(self.rect().center())

        gradient = QtGui.QConicalGradient()
        gradient.setCenter(drawingRect.center())
        gradient.setAngle(90)
        gradient.setColorAt(1, QtGui.QColor(0, 0, 0))
        gradient.setColorAt(
            0, QtGui.QColor(self.color[0], self.color[1], self.color[2]))

        arcLengthApproximation = self.width + self.width / 3
        pen = QtGui.QPen(QtGui.QBrush(gradient), self.width)
        pen.setCapStyle(QtCore.Qt.RoundCap)
        painter.setPen(pen)
        painter.drawArc(drawingRect, 90 * 16 - arcLengthApproximation,
                        -self._loading_angle * 16)
Пример #3
0
 def _set_screen_size(self):  # should also be responsibility of the UI!
     screen_geometry = QGuiApplication.primaryScreen().availableGeometry()
     geometry = QRect(0, 0,
                      screen_geometry.width() * 3 / 4,
                      screen_geometry.height() * 3 / 4)
     geometry.moveCenter(screen_geometry.center())
     self.setGeometry(geometry)
Пример #4
0
def decorate_welcome_icon(icon, background_color):
    """Return a `QIcon` with a circle shaped background.
    """
    welcome_icon = QIcon()
    sizes = [32, 48, 64, 80]
    background_color = NAMED_COLORS.get(background_color, background_color)
    background_color = QColor(background_color)
    grad = radial_gradient(background_color)
    for size in sizes:
        icon_pixmap = icon.pixmap(5 * size / 8, 5 * size / 8)
        icon_size = icon_pixmap.size()
        icon_rect = QRect(QPoint(0, 0), icon_size)

        pixmap = QPixmap(size, size)
        pixmap.fill(QColor(0, 0, 0, 0))
        p = QPainter(pixmap)
        p.setRenderHint(QPainter.Antialiasing, True)
        p.setBrush(QBrush(grad))
        p.setPen(Qt.NoPen)
        ellipse_rect = QRect(0, 0, size, size)
        p.drawEllipse(ellipse_rect)
        icon_rect.moveCenter(ellipse_rect.center())
        p.drawPixmap(icon_rect.topLeft(), icon_pixmap)
        p.end()

        welcome_icon.addPixmap(pixmap)

    return welcome_icon
Пример #5
0
    def paintEvent(self, theEvent):
        """Custom implementation of the label painter that rotates the
        label 90 degrees.
        """
        pObj = QStylePainter(self)
        oObj = QStyleOptionTab()

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

            oSize = oObj.rect.size()
            oSize.transpose()
            oRect = QRect(QPoint(), oSize)
            oRect.moveCenter(oObj.rect.center())
            oObj.rect = oRect

            oCenter = self.tabRect(i).center()
            pObj.translate(oCenter)
            pObj.rotate(90)
            pObj.translate(-oCenter)
            pObj.drawControl(QStyle.CE_TabBarTabLabel, oObj)
            pObj.restore()

        return
Пример #6
0
 def paintVerticalCell(self, painter: QPainter, hv: QHeaderView,
                       cellIndex: QModelIndex, leafIndex: QModelIndex,
                       logicalLeafIndex: int,
                       styleOptions: QStyleOptionHeader,
                       sectionRect: QRect, left: int):
     uniopt = QStyleOptionHeader(styleOptions)
     self.setForegroundBrush(uniopt, cellIndex)
     self.setBackgroundBrush(uniopt, cellIndex)
     width = self.cellSize(cellIndex, hv, uniopt).width()
     if cellIndex == leafIndex:
         width = sectionRect.width() - left
     top = self.currentCellLeft(cellIndex, leafIndex, logicalLeafIndex,
                                sectionRect.top(), hv)
     height = self.currentCellWidth(cellIndex, leafIndex,
                                    logicalLeafIndex, hv)
     r = QRect(left, top, width, height)
     uniopt.text = cellIndex.data(Qt.DisplayRole)
     painter.save()
     uniopt.rect = r
     if cellIndex.data(Qt.UserRole):
         hv.style().drawControl(QStyle.CE_HeaderSection, uniopt,
                                painter, hv)
         m = QTransform()
         m.rotate(-90)
         painter.setWorldMatrix(m, True)
         new_r = QRect(0, 0, r.height(), r.width())
         new_r.moveCenter(QPoint(-r.center().y(), r.center().x()))
         uniopt.rect = new_r
         hv.style().drawControl(QStyle.CE_HeaderLabel, uniopt, painter,
                                hv)
     else:
         hv.style().drawControl(QStyle.CE_Header, uniopt, painter, hv)
     painter.restore()
     return left + width
Пример #7
0
    def centerMultiScreen(self):
        mouse_pointer_position = QApplication.desktop().cursor().pos()
        screen = QApplication.desktop().screenNumber(mouse_pointer_position)
        print("current screen " + str(screen))

        self.window_one = QRect(QApplication.desktop().screenGeometry(0))
        self.window_two = QRect(QApplication.desktop().screenGeometry(1))

        if screen == 0:
            window_geometry = QRect(QApplication.desktop().screenGeometry(1))
            self.resize(window_geometry.width(), window_geometry.height())
            center_point = QApplication.desktop().screenGeometry(1).center()
            self.arrowsSet.height_k = (self.window_two.height() / self.window_one.height())
            self.arrowsSet.width_k = (self.window_two.width() / self.window_one.width())
        elif screen == 1:
            window_geometry = QRect(QApplication.desktop().screenGeometry(0))
            self.resize(window_geometry.width(), window_geometry.height())
            center_point = QApplication.desktop().screenGeometry(0).center()
            self.arrowsSet.height_k = (self.window_one.height() / self.window_two.height())
            self.arrowsSet.width_k = (self.window_one.width() / self.window_two.width())
        else:
            window_geometry = self.frameGeometry()
            center_point = QDesktopWidget.availableGeometry().center()
        window_geometry.moveCenter(center_point)
        self.move(window_geometry.topLeft())
Пример #8
0
 def paintEvent(self, ev):
     """Called when paint is needed, finds out which page to magnify."""
     layout = self.parent().surface().pageLayout()
     pos = self.geometry().center() - self.parent().surface().pos()
     page = layout.pageAt(pos)
     if not page:
         return
     pagePos = pos - page.pos()
     
     max_zoom = self.parent().surface().view().MAX_ZOOM * self.MAX_EXTRA_ZOOM
     newPage = Page(page, min(max_zoom, self._scale * page.scale()))
     if not newPage.same_page(self._page):
         if self._page:
             self._page.magnifier = None
         self._page = newPage
         self._page.magnifier = self
     
     relx = pagePos.x() / float(page.width())
     rely = pagePos.y() / float(page.height())
     
     image = cache.image(self._page)
     img_rect = QRect(self.rect())
     if not image:
         cache.generate(self._page)
         image = cache.image(self._page, False)
         if image:
             img_rect.setWidth(self.width() * image.width() / self._page.width())
             img_rect.setHeight(self.height() * image.height() / self._page.height())
     if image:
         img_rect.moveCenter(QPoint(relx * image.width(), rely * image.height()))
         p = QPainter(self)
         p.drawImage(self.rect(), image, img_rect)
         p.setRenderHint(QPainter.Antialiasing, True)
         p.setPen(QPen(QColor(192, 192, 192, 128), 6))
         p.drawEllipse(self.rect().adjusted(2, 2, -2, -2))
Пример #9
0
    def paintTab(self, painter: QPainter, index: int):
        if not self.isValidIndex(index):
            return
        painter.save()

        tab = self._tabs[index]
        rect = self._tabRect(index)
        selected = index == self._currentIndex
        enabled = self._enabled and tab.enabled

        if selected:
            painter.fillRect(rect, FancyToolButtonSelectedColor)

        tabText = tab.text
        tabTextRect = QRect(rect)
        drawIcon = rect.height() > 36
        tabIconRect = QRect(rect)

        tabTextRect.translate(0, -2 if drawIcon else 1)
        boldFont = QFont(painter.font())
        boldFont.setPointSizeF(SIDEBAR_FONT_SIZE)
        boldFont.setBold(True)
        painter.setFont(boldFont)
        #painter.setPen(QColor(255, 255, 255, 160) if selected else QColor(0, 0, 0, 110))
        textFlags = Qt.AlignCenter | (Qt.AlignBottom if drawIcon else
                                      Qt.AlignVCenter) | Qt.TextWordWrap

        fader = tab.fader
        if fader > 0 and not selected and enabled:
            painter.save()
            painter.setOpacity(fader)
            painter.fillRect(rect, FancyToolButtonHoverColor)
            painter.restore()

        if not enabled:
            painter.setOpacity(0.7)

        if drawIcon:
            textHeight = (painter.fontMetrics().boundingRect(
                QRect(0, 0, self.width(), self.height()), Qt.TextWordWrap,
                tabText).height())
            tabIconRect.adjust(0, 4, 0, -textHeight - 4)
            iconMode = (QIcon.Active if selected else
                        QIcon.Normal) if enabled else QIcon.Disabled
            iconRect = QRect(0, 0, MODEBAR_ICON_SIZE, MODEBAR_ICON_SIZE)
            iconRect.moveCenter(tabIconRect.center())
            iconRect = iconRect.intersected(tabIconRect)
            drawIconWithShadow(tab.icon, iconRect, painter, iconMode)

        if enabled:
            penColor = FancyTabWidgetEnabledSelectedTextColor if selected else FancyTabWidgetEnabledUnselectedTextColor
        else:
            penColor = FancyTabWidgetDisabledSelectedTextColor if selected else FancyTabWidgetDisabledUnselectedTextColor
        painter.setPen(penColor)
        painter.translate(0, -1)
        painter.drawText(tabTextRect, textFlags, tabText)

        painter.restore()
Пример #10
0
 def draw_setpoint(self, qp, event, w):
     w *= 0.6
     center = event.rect().center()
     rad = w / 2
     rect = QRect(0, 0, 8, 8)
     p = self._setpoint * rad
     p += center
     rect.moveCenter(p.toPoint())
     qp.fillRect(rect, QColor(Qt.yellow))
Пример #11
0
 def setGeometry(self, oldRect):
     # assuming that the minimum size is 50 pixel, find the minimum possible
     # "extent" based on the geometry provided
     minSize = max(50 * 8, min(oldRect.width(), oldRect.height()))
     # create a new squared rectangle based on that size
     newRect = QRect(0, 0, minSize, minSize)
     # move it to the center of the old one
     newRect.moveCenter(oldRect.center())
     super().setGeometry(newRect)
Пример #12
0
 def __get_pen_cursor(self) -> QCursor:
     image = QImage(32, 32, QImage.Format_ARGB32_Premultiplied)
     image.fill(Qt.transparent)
     pen_diam = self.__image_widget.get_pen_width()
     pen_rect = QRect(0, 0, pen_diam, pen_diam)
     pen_rect.moveCenter(image.rect().center())
     painter = QPainter(image)
     painter.drawEllipse(pen_rect)
     painter.end()
     return QCursor(QPixmap.fromImage(image))
Пример #13
0
 def draw_zones(self, qp, event, w):
     segment1 = -45
     span1 = ((self._max_value - self._threshold) * 270) / self._max_value
     segment2 = span1 - 45
     span2 = 270 - span1
     rect = QRect()
     rect.setSize(QSize(w / 2, w / 2))
     rect.moveCenter(event.rect().center())
     qp.setPen(QPen(self._zone1_color, self.arc_width, cap=Qt.FlatCap))
     qp.drawArc(rect, segment1 * 16, span1 * 16)
     qp.setPen(QPen(self._zone2_color, self.arc_width, cap=Qt.FlatCap))
     qp.drawArc(rect, segment2 * 16, span2 * 16)
Пример #14
0
 def paintEvent(self, ev):
     image = self.viewer.image()
     painter = QPainter(self)
     if self.size() == image.size():
         painter.drawImage(ev.rect(), image, ev.rect())
     else:
         s = image.size()
         s.scale(self.size(), Qt.KeepAspectRatio)
         r = QRect()
         r.setSize(s)
         r.moveCenter(self.rect().center())
         painter.drawPixmap(r, self.viewer.pixmap(s))
Пример #15
0
 def draw_center(self, qp, event, w):
     w *= 0.2
     rect = QRect()
     rect.setSize(QSize(w, w))
     rect.moveCenter(event.rect().center())
     rad = rect.width() / 2
     cap = QRadialGradient(rect.center(), rad)
     cap.setColorAt(0, Qt.white)
     cap.setColorAt(1, Qt.gray)
     qp.setPen(QPen(Qt.black, 1))
     qp.setBrush(QBrush(cap))
     qp.drawEllipse(rect)
Пример #16
0
 def draw_readout(self, qp, event, w):
     center = event.rect().center()
     rect = QRect()
     rect.setSize(QSize(w / 4, w / 8))
     rect.moveCenter(QPoint(center.x(), center.y() + w / 4))
     text = "{}".format(self.value)
     qp.setPen(QPen(Qt.white, 4))
     qp.setFont(QFont('Lato Heavy', self._value_font_size))
     qp.drawText(rect, Qt.AlignCenter, text)
     rect.moveCenter(QPoint(center.x(), center.y() + w / 3))
     text = self._gauge_label
     qp.setFont(QFont('Lato Heavy', self._label_font_size))
     qp.drawText(rect, Qt.AlignCenter, text)
Пример #17
0
 def draw_background(self, qp, event, w):
     w -= 6
     center = event.rect().center()
     rect = QRect()
     rect.setSize(QSize(w, w))
     rect.moveCenter(center)
     fp = QPoint(center.x() - w / 4, center.y() - w / 4)
     bg = QRadialGradient(center, w / 2, fp)
     bg.setColorAt(0, QColor(180, 180, 180))
     bg.setColorAt(1, QColor(40, 40, 40))
     qp.setPen(QPen(self._bezel_color, 6))
     qp.setBrush(QBrush(bg))
     qp.drawEllipse(rect)
     qp.drawArc(rect, 0, 360 * 16)
Пример #18
0
    def drawBackground(self, painter, rect):
        QGraphicsView.drawBackground(self, painter, rect)

        if not self.__backgroundIcon.isNull():
            painter.setClipRect(rect)
            vrect = QRect(QPoint(0, 0), self.viewport().size())
            vrect = self.mapToScene(vrect).boundingRect()

            pm = self.__backgroundIcon.pixmap(
                vrect.size().toSize().boundedTo(QSize(200, 200))
            )
            pmrect = QRect(QPoint(0, 0), pm.size())
            pmrect.moveCenter(vrect.center().toPoint())
            if rect.toRect().intersects(pmrect):
                painter.drawPixmap(pmrect, pm)
Пример #19
0
  def setupPainter(self,painter,rect,backgroundColor,textColor,text,fontSize):

      painter.save()
      # painter.fillRect(rect, QColor("#D3D3D3"))
      painter.setPen(Qt.NoPen)
      painter.setBrush(QColor(backgroundColor))
      r = QRect(QPoint(), min(rect.width(), rect.height()) * QSize(1, 1))
      r.moveCenter(rect.center())
      painter.drawEllipse(r)
      painter.setPen(QPen(QColor(textColor)))
      # font = painter.font() #设置字体
      # font.setPixelSize(12)
      painter.setFont(QFont('Arial', fontSize))
      painter.drawText(rect, Qt.AlignCenter, text)  # str(date.day())
      painter.restore()
Пример #20
0
 def countWwindowRect(self):
     #获取系统桌面尺寸大小
     desktop = QApplication.desktop()
     screenRect = desktop.screenGeometry(desktop.primaryScreen())
     #窗口默认尺寸
     windowRect = QRect(0, 0,colors.CONFIGFILE.getint('Properties',"WindowWidth"), colors.CONFIGFILE.getint('Properties',"WindowHeight"))
     #如果系统桌面宽小于默认值,窗口宽度将被设为系统桌面的宽度
     if screenRect.width() < colors.CONFIGFILE.getint('Properties',"WindowWidth"):
         windowRect.setWidth(screenRect.width())
     #如果系统桌面高小于默认值,窗口高度将被设为系统桌面的高度
     if screenRect.height() < colors.CONFIGFILE.getint('Properties',"WindowHeight"):
         windowRect.setHeight(screenRect.height())
     #移动中心点为系统中心点
     windowRect.moveCenter(screenRect.center())
     self.windowRect = windowRect
Пример #21
0
 def draw_digits(self, qp, event, w):
     w *= 0.8
     center = event.rect().center()
     rect = QRect()
     rect.setSize(QSize(40, 18))
     qp.setPen(QPen(Qt.white, self.tick_width))
     qp.setFont(QFont('Lato Heavy', self._dial_font_size))
     rad = w / 2
     inc = 270 / (self._num_ticks - 1)
     for i in range(self._num_ticks):
         angle = -225 + (inc * i)
         text = str(i * self._max_reading / (self._num_ticks - 1))
         x = int(rad * math.cos(math.radians(angle)) + center.x())
         y = int(rad * math.sin(math.radians(angle)) + center.y())
         rect.moveCenter(QPoint(x, y))
         qp.drawText(rect, Qt.AlignCenter, text)
Пример #22
0
 def draw_icons(self, qp, event):
     rect = QRect()
     rect.setSize(
         QSize(int(self.rect1.width() * 0.4),
               int(self.rect1.height() * 0.4)))
     center = event.rect().center()
     qp.setPen(QPen(self._text_color, 2))
     qp.setFont(self._font)
     # left button
     rect.moveCenter(
         QPoint(int(center.x() - self.rect2.width() / 3), center.y()))
     if isinstance(self.left_image, QPixmap):
         pix = self.left_image
         qp.drawPixmap(rect, pix, pix.rect())
     elif isinstance(self.left_image, str):
         qp.drawText(rect, Qt.AlignCenter, self.left_image)
     # right button
     rect.moveCenter(
         QPoint(int(center.x() + self.rect2.width() / 3), center.y()))
     if isinstance(self.right_image, QPixmap):
         pix = self.right_image
         qp.drawPixmap(rect, pix, pix.rect())
     elif isinstance(self.right_image, str):
         qp.drawText(rect, Qt.AlignCenter, self.right_image)
     # bottom button
     rect.moveCenter(
         QPoint(center.x(), int(center.y() + self.rect2.width() / 3)))
     if isinstance(self.bottom_image, QPixmap):
         pix = self.bottom_image
         qp.drawPixmap(rect, pix, pix.rect())
     elif isinstance(self.bottom_image, str):
         qp.drawText(rect, Qt.AlignCenter, self.bottom_image)
     # top button
     rect.moveCenter(
         QPoint(center.x(), int(center.y() - self.rect2.width() / 3)))
     if isinstance(self.top_image, QPixmap):
         pix = self.top_image
         qp.drawPixmap(rect, pix, pix.rect())
     elif isinstance(self.top_image, str):
         qp.drawText(rect, Qt.AlignCenter, self.top_image)
     # center button
     rect.moveCenter(QPoint(center.x(), center.y()))
     if isinstance(self.center_image, QPixmap):
         pix = self.center_image
         qp.drawPixmap(rect, pix, pix.rect())
     elif isinstance(self.center_image, str):
         qp.drawText(rect, Qt.AlignCenter, self.center_image)
Пример #23
0
def generateRandomRectangle(imageRect, patchSize=(32, 32)):
    while (True):
        x = np.random.uniform()
        y = np.random.uniform()

        halfRectX = patchSize[0] / (2.0 * imageRect[0])
        halfRectY = patchSize[1] / (2.0 * imageRect[1])
        normRect = [(x - halfRectX, y - halfRectY),
                    (x + halfRectX, y + halfRectY),
                    (x - halfRectX, y + halfRectY),
                    (x + halfRectX, y - halfRectY)]

        if rectangleInsideValidArea(normRect):
            rect = QRect(QPoint(0, 0), QSize(patchSize[0], patchSize[1]))
            rect.moveCenter(QPoint(x * imageRect[0], y * imageRect[1]))

            return rect
Пример #24
0
 def draw_gauge(self, qp, event, w):
     w *= 0.6
     rect = QRect()
     rect.setSize(QSize(w, w))
     rect.moveCenter(event.rect().center())
     center = rect.center()
     qp.setPen(QPen(Qt.white, self.tick_width, cap=Qt.FlatCap))
     qp.drawArc(rect, (-45 * 16), (270 * 16))
     rad = rect.width() / 2
     inc = 270.0 / (self._num_ticks - 1)
     for i in range(self._num_ticks):
         p1 = self.qpa[i] * rad
         p1 += center
         p2 = self.qpa[i] * (rad + 10)
         p2 += center
         line = QLine(p1.toPoint(), p2.toPoint())
         qp.drawLine(line)
Пример #25
0
    def paintEvent(self, ev):
        """Called when paint is needed, finds out which page to magnify."""
        view = self.parent().parent()
        layout = view.pageLayout()

        scale = max(
            min(self._scale,
                view.MAX_ZOOM * self.MAX_EXTRA_ZOOM / layout.zoomFactor),
            view.MIN_ZOOM / layout.zoomFactor)

        # the position of our center on the layout
        c = self.rect().center() + self.pos() - view.layoutPosition()

        # make a region scaling back to the view scale
        rect = QRect(0, 0, self.width() / scale, self.height() / scale)
        rect.moveCenter(c)
        region = QRegion(rect,
                         QRegion.Ellipse)  # touches the Pages we need to draw

        # our rect on the enlarged pages
        our_rect = self.rect()
        our_rect.moveCenter(QPoint(c.x() * scale, c.y() * scale))

        # the virtual position of the whole scaled-up layout
        ev_rect = ev.rect().translated(our_rect.topLeft())

        painter = QPainter(self)
        for p in layout.pagesAt(region):
            # reuse the copy of the page if still existing
            try:
                page = self._pages[p]
            except KeyError:
                page = self._pages[p] = p.copy()
            page.x = p.x * scale
            page.y = p.y * scale
            page.width = p.width * scale
            page.height = p.height * scale
            # now paint it
            rect = (page.rect() & ev_rect).translated(-page.pos())
            painter.save()
            painter.translate(page.pos() - our_rect.topLeft())
            page.paint(painter, rect, self.repaintPage)
            painter.restore()

        self.drawBorder(painter)
Пример #26
0
 def draw(self, rect, indicator, depth, new_depth):
     p = self.p
     if depth:
         p.drawLine(rect.center(), QPoint(rect.center().x(), rect.y()))
     if new_depth:
         p.drawLine(rect.center(), QPoint(rect.center().x(), rect.bottom()))
     if new_depth < depth and not indicator:
         p.drawLine(rect.center(), QPoint(rect.right()-1, rect.center().y()))
     if indicator:
         square = QRect(0, 0, 8, 8)
         square.moveCenter(rect.center() - QPoint(1, 1))
         p.fillRect(square, self.w.palette().color(QPalette.Base))
         p.drawRect(square)
         x = rect.center().x()
         y = rect.center().y()
         p.drawLine(QPoint(x-2, y), QPoint(x+2, y))
         if indicator == OPEN:
             p.drawLine(QPoint(x, y-2), QPoint(x, y+2))
Пример #27
0
 def draw(self, rect, indicator, depth, new_depth):
     p = self.p
     if depth:
         p.drawLine(rect.center(), QPoint(rect.center().x(), rect.y()))
     if new_depth:
         p.drawLine(rect.center(), QPoint(rect.center().x(), rect.bottom()))
     if new_depth < depth and not indicator:
         p.drawLine(rect.center(), QPoint(rect.right()-1, rect.center().y()))
     if indicator:
         square = QRect(0, 0, 8, 8)
         square.moveCenter(rect.center() - QPoint(1, 1))
         p.fillRect(square, self.w.palette().color(QPalette.Base))
         p.drawRect(square)
         x = rect.center().x()
         y = rect.center().y()
         p.drawLine(QPoint(x-2, y), QPoint(x+2, y))
         if indicator == OPEN:
             p.drawLine(QPoint(x, y-2), QPoint(x, y+2))
Пример #28
0
    def mouseMoveEvent(self, event):

        if (event.buttons() & Qt.LeftButton) and self.rect().contains(event.pos()):
            self.painter.setOpacity(0.9)
            currentPoint = event.pos()
            currentPoint.setX(currentPoint.x() - self.pointerOffsetX)
            currentPoint.setY(currentPoint.y() - self.pointerOffsetY)

            # drawing annotation
            if self.drawing:
                self.painter.setPen(QPen(self.brushColor, self.brushSize, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
                self.painter.drawLine(self.lastPoint, currentPoint)

            # erasing the annotation
            elif self.erase_flag:
                r = QRect(QPoint(), self.clear_size * QSize())
                r.moveCenter(currentPoint)
                self.painter.save()

                self.painter.setCompositionMode(QtGui.QPainter.CompositionMode_Clear)
                self.painter.eraseRect(r)
                self.painter.restore()

            # set drawn annotation to the label and save last point
            self.annotation_label.setPixmap(self.draw_pixmap)
            self.lastPoint = currentPoint

            # update the paint in both screens
            scaled_pixmap = self.draw_pixmap.scaled(self.secondaryWindow_final.secWidth,
                                                    self.secondaryWindow_final.secHeight,
                                                    Qt.IgnoreAspectRatio, Qt.FastTransformation)

            # apply homography transform
            # numpyImage = self.pixmapToArray(QPixmap(scaled_pixmap))
            # H = self.getHomography()
            # hImage = self.getHomographyTransform(H, numpyImage)
            #
            # # display the image
            # # secImage = QPixmap.fromImage(hTransformed)
            # image = QtGui.QImage(hImage, hImage.shape[1], hImage.shape[0], hImage.shape[1] * 3,QtGui.QImage.Format_RGB888)
            # pix = QtGui.QPixmap(image)
            self.secondaryWindow_final.label.setPixmap(scaled_pixmap)
            # self.secondaryWindow_final.label.resize(self.secondaryWindow_final.width(), self.secondaryWindow_final.height())
            self.update()
Пример #29
0
    def paintEvent(self, event):

        painter = QtGui.QPainter(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        drawingRect = QRect(
            QtCore.QPoint(),
            self.rect().size() - 2 * self.width * QtCore.QSize(1, 1))

        if drawingRect.width() == 520:
            painter.rotate(90)
            painter.translate(0, -drawingRect.height())
        elif drawingRect.width() == 470:
            painter.rotate(60)
            painter.translate(drawingRect.width() * (6 / 9),
                              -drawingRect.height() * (6 / 9))
        elif drawingRect.width() == 420:
            painter.rotate(40)
            painter.translate(drawingRect.width() * (4 / 9),
                              -drawingRect.height() * (4 / 9))
        elif drawingRect.width() == 370:
            painter.rotate(20)
            painter.translate(drawingRect.width() * (2 / 9),
                              -drawingRect.height() * (2 / 9))
        elif drawingRect.width() == 320:
            pass
        drawingRect.moveCenter(self.rect().center())

        gradient = QtGui.QConicalGradient()
        gradient.setCenter(drawingRect.center())
        gradient.setAngle(90)
        gradient.setColorAt(1, QtGui.QColor(0, 0, 0))
        gradient.setColorAt(
            0, QtGui.QColor(self.color[0], self.color[1], self.color[2]))

        arcLengthApproximation = self.width + self.width / 3
        pen = QtGui.QPen(QtGui.QBrush(gradient), self.width)
        pen.setCapStyle(QtCore.Qt.RoundCap)
        painter.setPen(pen)
        if self.side == "L":
            painter.drawLine(0, 0, self.NextStep, self.NextStep)
        else:
            painter.drawLine(drawingRect.width(), 0,
                             drawingRect.width() - self.NextStep,
                             self.NextStep)
Пример #30
0
    def paintEvent(self, event):
        painter = QPainter(self)
        if self.isEnabled() and not self.isDown() and not self.isChecked():
            painter.save()
            hover_color = QColor("#424242")
            faded_hover_color = QColor(hover_color)
            faded_hover_color.setAlpha(int(self._fader * hover_color.alpha()))
            painter.fillRect(event.rect(), faded_hover_color)
            painter.restore()
        elif self.isDown() or self.isChecked():
            painter.save()
            selected_color = QColor("#161719")
            painter.fillRect(event.rect(), selected_color)
            painter.restore()

        is_titled = bool(self.defaultAction().property("titled"))
        icon_rect = QRect(0, 0, 32, 32)
        icon_rect.moveCenter(event.rect().center())

        if is_titled:
            font = painter.font()
            center_rect = event.rect()
            font.setPointSizeF(6)
            fm = QFontMetrics(font)
            line_height = fm.height()
            text_flags = Qt.AlignHCenter | Qt.AlignTop
            project_name = self.defaultAction().property("heading")
            if project_name is not None:
                center_rect.adjust(0, line_height, 0, 0)
                icon_rect.moveTop(center_rect.top())
            else:
                icon_rect.moveCenter(center_rect.center())
            self.icon().paint(painter, icon_rect, Qt.AlignCenter)
            painter.setFont(font)
            r = QRect(0, 5, self.rect().width(), line_height)
            painter.setPen(Qt.white)
            margin = 5
            available_width = r.width() - margin
            ellided_project_name = fm.elidedText(
                project_name, Qt.ElideMiddle, available_width)
            painter.drawText(r, text_flags, ellided_project_name)
        else:
            self.icon().paint(painter, icon_rect, Qt.AlignCenter)
Пример #31
0
    def initUI(self):

        # initiating the UI layout
        self.hbox = QHBoxLayout(self)
        self.setWindowTitle('Art Screen')

        qtRectangle = QRect(0, 0, self.size[1], self.size[0])
        centerPoint = QDesktopWidget().availableGeometry().center()
        qtRectangle.moveCenter(centerPoint)
        self.move(qtRectangle.topLeft())

        pixmap = QPixmap()
        self.imageLabel = QLabel(self)
        self.imageLabel.setPixmap(pixmap)
        self.hbox.addWidget(self.imageLabel)
        self.setBaseSize(self.size[0], self.size[1])
        self.setLayout(self.hbox)
        self.raise_()
        self.show()
Пример #32
0
    def paintEvent(self, event):
        painter = QPainter(self)
        if self.isEnabled() and not self.isDown() and not self.isChecked():
            painter.save()
            hover_color = QColor("#424242")
            faded_hover_color = QColor(hover_color)
            faded_hover_color.setAlpha(int(self._fader * hover_color.alpha()))
            painter.fillRect(event.rect(), faded_hover_color)
            painter.restore()
        elif self.isDown() or self.isChecked():
            painter.save()
            selected_color = QColor("#161719")
            painter.fillRect(event.rect(), selected_color)
            painter.restore()

        is_titled = bool(self.defaultAction().property("titled"))
        icon_rect = QRect(0, 0, 32, 32)
        icon_rect.moveCenter(event.rect().center())

        if is_titled:
            font = painter.font()
            center_rect = event.rect()
            font.setPointSizeF(6)
            fm = QFontMetrics(font)
            line_height = fm.height()
            text_flags = Qt.AlignHCenter | Qt.AlignTop
            project_name = self.defaultAction().property("heading")
            if project_name is not None:
                center_rect.adjust(0, line_height, 0, 0)
                icon_rect.moveTop(center_rect.top())
            else:
                icon_rect.moveCenter(center_rect.center())
            self.icon().paint(painter, icon_rect, Qt.AlignCenter)
            painter.setFont(font)
            r = QRect(0, 5, self.rect().width(), line_height)
            painter.setPen(Qt.white)
            margin = 5
            available_width = r.width() - margin
            ellided_project_name = fm.elidedText(project_name, Qt.ElideMiddle,
                                                 available_width)
            painter.drawText(r, text_flags, ellided_project_name)
        else:
            self.icon().paint(painter, icon_rect, Qt.AlignCenter)
Пример #33
0
 def paintEvent(self, ev):
     """Called when paint is needed, finds out which page to magnify."""
     view = self.parent().parent()
     layout = view.pageLayout()
     
     scale = max(min(self._scale, view.MAX_ZOOM * self.MAX_EXTRA_ZOOM / layout.zoomFactor), view.MIN_ZOOM / layout.zoomFactor)
     
     # the position of our center on the layout
     c = self.rect().center() + self.pos() - view.layoutPosition()
     
     # make a region scaling back to the view scale
     rect = QRect(0, 0, self.width() / scale, self.height() / scale)
     rect.moveCenter(c)
     region = QRegion(rect, QRegion.Ellipse) # touches the Pages we need to draw
     
     # our rect on the enlarged pages
     our_rect = self.rect()
     our_rect.moveCenter(QPoint(c.x() * scale, c.y() * scale))
     
     # the virtual position of the whole scaled-up layout
     ev_rect = ev.rect().translated(our_rect.topLeft())
     
     painter = QPainter(self)
     for p in layout.pagesAt(region):
         # reuse the copy of the page if still existing
         try:
             page = self._pages[p]
         except KeyError:
             page = self._pages[p] = p.copy()
         page.x = p.x * scale
         page.y = p.y * scale
         page.width = p.width * scale
         page.height = p.height * scale
         # now paint it
         rect = (page.rect() & ev_rect).translated(-page.pos())
         painter.save()
         painter.translate(page.pos() - our_rect.topLeft())
         page.paint(painter, rect, self.repaintPage)
         painter.restore()
         
     self.drawBorder(painter)
Пример #34
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(270)
            painter.translate(-c)
            painter.drawControl(QStyle.CE_TabBarTabLabel, opt)
            painter.restore()
Пример #35
0
    def setupWidget(self):
        desktop = QApplication.desktop()
        screenRect = desktop.screenGeometry(desktop.primaryScreen())
        windowRect = QRect(0, 0, 800, 600)

        if screenRect.width() < 800:
            windowRect.setWidth(screenRect.width())

        if screenRect.height() < 600:
            windowRect.setHeight(screenRect.height())

        windowRect.moveCenter(screenRect.center())
        self.setGeometry(windowRect)
        self.setMinimumSize(80, 60)

        self.setWindowTitle("PyQt Examples")
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setFrameStyle(QFrame.NoFrame)
        self.setRenderingSystem()
        self.updateTimer.timeout.connect(self.tick)
Пример #36
0
    def _paint_tab(self, painter, index):
        if not self._is_valid_index(index):
            return

        painter.save()
        tab = self.__tabs[index]
        rect = self._tab_rect(index)
        selected = index == self.__current_index
        enabled = self._is_enabled(index)

        if selected:
            painter.fillRect(rect, QColor("#161719"))

        tab_icon_rect = QRect(rect)
        if selected:
            color = QColor(255, 255, 255, 160)
        else:
            color = QColor(0, 0, 0, 110)
        painter.setPen(color)

        fader = self.__tabs[index].fader
        if fader > 0 and not selected and enabled:
            painter.save()
            painter.setOpacity(fader)
            painter.fillRect(rect, QColor("#424242"))
            painter.restore()

        if tab.icon is not None:
            icon_rect = QRect(0, 0, 20, 20)
            icon_rect.moveCenter(tab_icon_rect.center())
            tab.icon.paint(painter, rect)

        painter.setOpacity(1.0)
        if enabled:
            painter.setPen(QColor("#ffffff"))
        else:
            painter.setPen(QColor("blue"))
        painter.translate(0, -1)

        painter.restore()
Пример #37
0
    def _paint_crop(self, painter, option, index):
        """Paints the crop
        """
        source_rect = index.data(RectRole)
        crop_rect = self.crop_rect.translated(option.rect.topLeft())
        angle = index.data(RotationRole)

        # Target rect with same aspect ratio as source
        source_aspect = float(source_rect.width()) / source_rect.height()
        crop_aspect = float(crop_rect.width()) / crop_rect.height()

        # True if the item has been rotated by a multiple of 90 degrees
        perpendicular = 1 == (angle / 90) % 2

        # Some nasty logic to compute the target rect
        if perpendicular:
            crop_aspect = 1.0 / crop_aspect

        if source_aspect > 1.0:
            # Crop is wider than is is tall
            if crop_aspect > source_aspect:
                fit_to = 'height'
                f = 1.0 / source_aspect
            else:
                fit_to = 'width'
                f = source_aspect
        else:
            # Crop is taller than is is wide
            if crop_aspect < source_aspect:
                fit_to = 'width'
                f = source_aspect
            else:
                fit_to = 'height'
                f = 1.0 / source_aspect

        if perpendicular:
            if 'width' == fit_to:
                size = QSize(crop_rect.height(),
                             crop_rect.height() / f)
            else:
                size = QSize(crop_rect.width() / f,
                             crop_rect.width())
        else:
            if 'width' == fit_to:
                size = QSize(crop_rect.width(),
                             crop_rect.width() / f)
            else:
                size = QSize(crop_rect.height() / f,
                             crop_rect.height())

        target_rect = QRect(crop_rect.topLeft(), size)
        target_rect.moveCenter(option.rect.center())

        # Draw rotated
        if angle:
            t = QTransform()
            t.translate(option.rect.width() / 2 + option.rect.left(),
                        option.rect.height() / 2 + option.rect.top())
            t.rotate(angle)
            t.translate(-option.rect.width() / 2 - option.rect.left(),
                        -option.rect.height() / 2 - option.rect.top())

        with painter_state(painter):
            if angle:
                painter.setTransform(t)
            painter.drawPixmap(target_rect, index.data(PixmapRole), source_rect)

            if QStyle.State_Selected & option.state:
                painter.setPen(QPen(Qt.white, 1, Qt.SolidLine))
                painter.drawRect(target_rect)