Exemplo n.º 1
0
    def paintEvent(self, event):
        '''
        @param: event QPaintEvent
        '''
        super().paintEvent(event)

        # Draw drop indicator
        if self._dropRow != -1:
            # BookmarksToolbarButton
            button = self._buttonAt(self._dropPos)
            if button:
                if button.bookmark().isFolder():
                    return
                tmpRect = QRect(button.x(), 0, button.width(), self.height())
                rect = QRect()

                if self._dropRow == self._layout.indexOf(button):
                    rect = QRect(max(0,
                                     tmpRect.left() - 2), tmpRect.top(), 3,
                                 tmpRect.height())
                else:
                    rect = QRect(tmpRect.right() + 0, tmpRect.top(), 3,
                                 tmpRect.height())

                gVar.appTools.paintDropIndicator(self, rect)
Exemplo n.º 2
0
 def calculate_rects(self):
     rect = self.rect()
     self.spinner_rect = r = QRect(0, 0, 96, 96)
     r.moveCenter(rect.center() - QPoint(0, r.height() // 2))
     r = QRect(r)
     r.moveTop(r.center().y() + 20 + r.height() // 2)
     r.setLeft(0), r.setRight(self.width())
     self.label.setGeometry(r)
Exemplo n.º 3
0
 def __call__(self, painter, rect, color_theme, title_block, subtitle_block, footer_block):
     painter.fillRect(rect, self.color1)
     r = QRect(0, int(title_block.position.y), rect.width(),
               title_block.height + subtitle_block.height + subtitle_block.line_spacing // 2 + title_block.leading)
     painter.save()
     p = QPainterPath()
     p.addRoundedRect(QRectF(r), 10, 10 * r.width()/r.height(), Qt.RelativeSize)
     painter.setClipPath(p)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.fillRect(r, self.color2)
     painter.restore()
     r = QRect(0, 0, int(title_block.position.x), rect.height())
     painter.fillRect(r, self.color2)
     return self.ccolor2, self.ccolor2, self.ccolor1
Exemplo n.º 4
0
 def __call__(self, painter, rect, color_theme, title_block, subtitle_block, footer_block):
     painter.fillRect(rect, self.color1)
     r = QRect(0, int(title_block.position.y), rect.width(),
               title_block.height + subtitle_block.height + subtitle_block.line_spacing // 2 + title_block.leading)
     painter.save()
     p = QPainterPath()
     p.addRoundedRect(QRectF(r), 10, 10 * r.width()/r.height(), Qt.RelativeSize)
     painter.setClipPath(p)
     painter.setRenderHint(QPainter.Antialiasing)
     painter.fillRect(r, self.color2)
     painter.restore()
     r = QRect(0, 0, int(title_block.position.x), rect.height())
     painter.fillRect(r, self.color2)
     return self.ccolor2, self.ccolor2, self.ccolor1
Exemplo n.º 5
0
    def _paintGroupBox(self, rect, title):
        painter = QPainter(self)
        qDrawShadeRect(painter, rect, self.palette(), True)

        if len(title) > 0:
            fnt = self.font()
            fnt.setPointSize(fnt.pointSize() - 1)
            offset = 5
            asterix = ' *'
            twidth = QFontMetrics(fnt).width(title)
            awidth = QFontMetrics(fnt).width(asterix)
            width = twidth + awidth + 2 * offset
            height = QFontMetrics(fnt).height()
            rect = QRect(rect.left() + 2 * offset,
                         rect.top() - height / 2 + 1, width, height)
            painter.fillRect(rect, self.palette().color(self.backgroundRole()))
            painter.setFont(fnt)
            painter.drawText(
                QRect(rect.left() + offset, rect.top(), twidth, rect.height()),
                Qt.AlignLeft, title)
            painter.setPen(Qt.red)
            painter.drawText(
                QRect(rect.left() + offset + twidth, rect.top(), awidth,
                      rect.height()), Qt.AlignRight, asterix)
Exemplo n.º 6
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     hovering = index.data(HOVER_ROLE) is True
     painter.save()
     rect = option.rect
     is_current = index.data(Qt.FontRole) is not None
     if not hovering and is_current:
         qpp = QPainterPath()
         qpp.addRoundedRect(QRectF(rect), 6, 6)
         painter.fillPath(qpp, self.current_background)
     icon_rect = QRect(rect.left() + self.MARGIN, rect.top() + self.MARGIN, ICON_SIZE, ICON_SIZE)
     left = icon_rect.right() + 2 * self.MARGIN
     text_rect = QRect(left, icon_rect.top(), rect.width() - left + rect.left(), icon_rect.height())
     mark = index.data(MARK_ROLE)
     if hovering or mark:
         text_rect.adjust(0, 0, -text_rect.height(), 0)
     text = index.data(DISPLAY_ROLE) or ''
     font = index.data(Qt.FontRole)
     if font:
         painter.setFont(font)
     text_flags = Qt.AlignVCenter | Qt.AlignLeft | Qt.TextSingleLine
     text = elided_text(text, font, text_rect.width(), 'right')
     if option.state & QStyle.State_Selected:
         painter.setPen(QPen(self.highlighted_text))
     painter.drawText(text_rect, text_flags, text)
     if mark:
         hrect = QRect(text_rect.right(), text_rect.top(), text_rect.height(), text_rect.height())
         painter.fillRect(hrect, QColor('#ffffaa'))
         painter.drawText(hrect, Qt.AlignCenter, mark)
     elif hovering:
         hrect = QRect(text_rect.right(), text_rect.top(), text_rect.height(), text_rect.height())
         close_hover = index.data(CLOSE_HOVER_ROLE) is True
         if close_hover:
             pen = painter.pen()
             pen.setColor(QColor('red'))
             painter.setPen(pen)
         painter.drawText(hrect, Qt.AlignCenter, '✖ ')
     if index.data(LOADING_ROLE):
         if not self.errored_out:
             angle = index.data(ANGLE_ROLE)
             try:
                 draw_snake_spinner(painter, icon_rect, angle, self.light, self.dark)
             except Exception:
                 import traceback
                 traceback.print_exc()
                 self.errored_out = True
     else:
         icurl = index.data(URL_ROLE)
         if icurl == WELCOME_URL:
             icon = welcome_icon()
         elif icurl == DOWNLOADS_URL:
             icon = downloads_icon()
         else:
             icon = index.data(DECORATION_ROLE)
         icon.paint(painter, icon_rect)
     painter.restore()
Exemplo n.º 7
0
    def paintEvent(self, event):
        '''
        @param event QPaintEvent
        '''
        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        size = 16
        pixmapSize = round(size *
                           self.data().animationPixmap.devicePixelRatioF())

        # Center the pixmap in rect
        r = QRect(self.rect())
        r.setX((r.width() - size) / 2)
        r.setY((r.height() - size) / 2)
        r.setWidth(size)
        r.setHeight(size)

        if self._animationRunning:
            p.drawPixmap(
                r,
                self.data().animationPixmap,
                QRect(self._currentFrame * pixmapSize, 0, pixmapSize,
                      pixmapSize))
        elif self._audioIconDisplayed and not self._tab.isPinned():
            self._audioIconRect = QRect(r)
            p.drawPixmap(
                r,
                self._tab.isMuted() and self.data().audioMutedPixmap
                or self.data().audioPlayingPixmap)
        elif not self._sitePixmap.isNull():
            p.drawPixmap(r, self._sitePixmap)
        elif self._tab and self._tab.isPinned():
            p.drawPixmap(r, IconProvider.emptyWebIcon().pixmap(size))

        # Draw audio icon on top of site icon for pinned tabs
        if not self._animationRunning and self._audioIconDisplayed and self._tab.isPinned(
        ):
            s = size - 4
            r0 = QRect(self.width() - 4, 0, s, s)
            self._audioIconRect = r0
            c = self.palette().color(QPalette.Window)
            c.setAlpha(180)
            p.setPen(c)
            p.setBrush(c)
            p.drawEllipse(r)
            p.drawPixmap(
                r,
                self._tab.isMuted() and self.data().audioMutedPixmap
                or self.data().audioPlayingPixmap)

        # Draw background activity indicator
        if self._tab and self._tab.isPinned() and self._tab.webView(
        ).backgroundActivity():
            s = 5
            # Background
            r1 = QRect(self.width() - s - 2,
                       self.height() - s - 2, s + 2, s + 2)
            c1 = self.palette().color(QPalette.Window)
            c1.setAlpha(180)
            p.setPen(Qt.transparent)
            p.setBrush(c1)
            p.drawEllipse(r1)
            # Forground
            r2 = QRect(self.width() - s - 1, self.height() - s - 1, s, s)
            c2 = self.palette().color(QPalette.Text)
            p.setPen(Qt.transparent)
            p.setBrush(c2)
            p.drawEllipse(r2)
Exemplo n.º 8
0
    def drawControl(self, element, option, painter, widget):
        '''
        @param: element ControlElement
        @param: option QStyleOption
        @param: painter QPainter
        @param: widget QWidget
        '''
        v_opt = option

        if element != self.CE_TabBarTab or not isinstance(
                v_opt, QStyleOptionTab):
            QProxyStyle.drawControl(element, option, painter, widget)
            return

        rect = v_opt.rect
        selected = v_opt.state & self.State_Selected
        vertical_tabs = v_opt.shape == QTabBar.RoundedWest
        text = v_opt.text

        if selected:
            # background
            painter.save()
            grad = QLinearGradient(rect.topLeft(), rect.topRight())
            grad.setColorAt(0, QColor(255, 255, 255, 140))
            grad.setColorAt(0, QColor(255, 255, 255, 210))
            painter.fillRect(rect.adjusted(0, 0, 0, -1), grad)
            painter.restore()

            # shadows
            painter.setPen(QColor(0, 0, 0, 110))
            painter.drawLine(rect.topLeft() + QPoint(1, -1),
                             rect.topRight() - QPoint(0, 1))
            painter.drawLine(rect.bottomLeft(), rect.bottomRight())
            painter.setPen(QColor(0, 0, 0, 40))
            painter.drawLine(rect.topLeft(), rect.bottomLeft())

            # highlights
            painter.setPen(QColor(255, 255, 255, 50))
            painter.drawLine(rect.topLeft() + QPoint(0, -2),
                             rect.topRight() - QPoint(0, 2))
            painter.drawLine(rect.bottomLeft() + QPoint(0, 1),
                             rect.bottomRight() + QPoint(0, 1))
            painter.setPen(QColor(255, 255, 255, 40))
            painter.drawLine(rect.topLeft() + QPoint(0, 0), rect.topRight())
            painter.drawLine(rect.topRight() + QPoint(0, 1),
                             rect.bottomRight() - QPoint(0, 1))
            painter.drawLine(rect.bottomLeft() + QPoint(0, -1),
                             rect.bottomRight() - QPoint(0, 1))

        m = QTransform()
        if vertical_tabs:
            m = QTransform.fromTranslate(rect.left(), rect.bottom())
            m.rotate(-90)
        else:
            m = QTransform.fromTranslate(rect.left(), rect.top())

        draw_rect = QRect(QPoint(0, 0), m.mapRect(rect).size())

        painter.save()
        painter.setTransform(m)

        icon_rect = QRect(QPoint(8, 0), v_opt.iconSize)
        text_rect = QRect(icon_rect.topRight() + QPoint(4, 0),
                          draw_rect.size())
        text_rect.setRight(draw_rect.width())
        icon_rect.translate(0, (draw_rect.height() - icon_rect.height()) / 2)

        boldFont = QFont(painter.font())
        boldFont.setPointSizeF(styleHelper.sidebarFontSize())
        boldFont.setBold(True)
        painter.setFont(boldFont)
        painter.setPen(selected and QColor(255, 255, 255, 160)
                       or QColor(0, 0, 0, 110))
        textFlags = Qt.AlignHCenter | Qt.AlignVCenter
        painter.drawText(text_rect, textFlags, text)
        painter.setPen(selected and QColor(60, 60, 60)
                       or styleHelper.panelTextColor())
        if widget:
            fader_key = 'tab_' + text + '_fader'
            animation_key = 'tab_' + text + '_animation'

            tab_hover = widget.property('tab_hover')
            # int
            fader = widget.property(fader_key)
            # QPropertyAnimation
            animation = widget.property(animation_key)

            if not animation:
                mut_widget = widget
                fader = 0
                mut_widget.setProperty(fader_key, fader)
                animation = QPropertyAnimation(mut_widget, fader_key,
                                               mut_widget)
                animation.valueChanged.connect(mut_widget.update)
                mut_widget.setProperty(animation_key, animation)

            if text == tab_hover:
                if animation.state(
                ) != QAbstractAnimation.Running and fader != 40:
                    animation.stop()
                    animation.setDuration(80)
                    animation.setEndValue(40)
                    animation.start()
            else:
                if animation.state(
                ) != QAbstractAnimation.Running and fader != 0:
                    animation.stop()
                    animation.setDuration(160)
                    animation.setEndValue(0)
                    animation.start()

            if not selected:
                painter.save()
                painter.fillRect(draw_rect, QColor(255, 255, 255, fader))
                painter.setPen(QPen(QColor(255, 255, 255, fader), 1.0))
                painter.drawLine(
                    draw_rect.topLeft(),
                    vertical_tabs and draw_rect.bottomLeft()
                    or draw_rect.topRight())
                painter.drawLine(
                    draw_rect.bottomRight(),
                    vertical_tabs and draw_rect.topRight()
                    or draw_rect.bottomLeft())
                painter.restore()

        if selected:
            iconMode = QIcon.Selected
        else:
            iconMode = QIcon.Normal
        styleHelper.drawIconWithShadow(v_opt.icon, icon_rect, painter,
                                       iconMode)

        painter.drawText(text_rect.translated(0, -1), textFlags, text)

        painter.restore()