Exemplo n.º 1
0
    def eventFilter(self, widget, event):
        """Using  the custom event filter to paint the background."""
        if event.type() == QtCore.QEvent.Paint:
            painter = QtGui.QPainter()
            painter.begin(self)
            font = common.font_db.secondary_font(
                font_size=common.MEDIUM_FONT_SIZE())[0]
            painter.setFont(font)
            painter.setRenderHints(QtGui.QPainter.Antialiasing)

            o = common.INDICATOR_WIDTH()
            rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
            painter.setBrush(QtGui.QColor(250, 250, 250, 255))
            painter.setPen(QtCore.Qt.NoPen)
            painter.drawRoundedRect(rect, o * 2, o * 2)

            center = rect.center()
            rect.setWidth(rect.width() - common.MARGIN())
            rect.setHeight(rect.height() - common.MARGIN())
            rect.moveCenter(center)

            text = u'Click the plus icon on the top to add a note'
            text = text if not len(self.todoeditors_widget.items) else u''
            common.draw_aliased_text(painter, font, rect, text,
                                     QtCore.Qt.AlignCenter,
                                     common.SECONDARY_BACKGROUND)
            painter.end()
        return False
Exemplo n.º 2
0
 def paintEvent(self, event):
     painter = QtGui.QPainter()
     painter.begin(self)
     common.draw_aliased_text(
         painter,
         common.font_db.primary_font(common.SMALL_FONT_SIZE())[0],
         self.rect(), self.text(), QtCore.Qt.AlignCenter, common.ADD)
     painter.end()
Exemplo n.º 3
0
    def paintEvent(self, event):
        """Drawing a rounded background help to identify that the widget
        is in standalone mode."""
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)

        rect = QtCore.QRect(self.rect())
        pen = QtGui.QPen(QtGui.QColor(35, 35, 35, 255))
        pen.setWidth(1.0)
        painter.setPen(pen)
        painter.setBrush(common.SEPARATOR.darker(110))

        if self._frameless is True:
            o = common.INDICATOR_WIDTH()
            rect = rect.marginsRemoved(QtCore.QMargins(o, o, o, o))
            painter.drawRoundedRect(rect, o * 3, o * 3)
        else:
            painter.drawRect(rect)

        if not self._initialized:
            font, metrics = common.font_db.primary_font(
                common.MEDIUM_FONT_SIZE())
            rect = QtCore.QRect(self.rect())
            align = QtCore.Qt.AlignCenter
            color = QtGui.QColor(255, 255, 255, 80)

            pixmaprect = QtCore.QRect(rect)
            center = pixmaprect.center()
            s = common.ASSET_ROW_HEIGHT() * 1.5
            o = common.MARGIN()

            pixmaprect.setWidth(s)
            pixmaprect.setHeight(s)
            pixmaprect.moveCenter(center)

            painter.setBrush(QtGui.QColor(0, 0, 0, 20))
            pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 20))
            painter.setPen(pen)

            painter.drawRoundedRect(
                pixmaprect.marginsAdded(
                    QtCore.QMargins(o * 3, o * 3, o * 3, o * 3)), o, o)

            pixmap = images.ImageCache.get_rsc_pixmap(u'icon_bw', None, s)
            painter.setOpacity(0.5)
            painter.drawPixmap(pixmaprect, pixmap, pixmap.rect())
            painter.setOpacity(1.0)

            rect.setTop(pixmaprect.bottom() + (o * 0.5))
            rect.setHeight(metrics.height())
            common.draw_aliased_text(painter, font, rect, self.init_progress,
                                     align, color)

        painter.end()
Exemplo n.º 4
0
 def paintEvent(self, event):
     """Custom paint event to use the aliased paint method."""
     painter = QtGui.QPainter()
     painter.begin(self)
     common.draw_aliased_text(
         painter,
         common.font_db.primary_font(font_size=self._size)[0],
         self.rect(),
         self.text(),
         QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft,
         self._color
     )
     painter.end()
Exemplo n.º 5
0
    def paintEvent(self, event):
        painter = QtGui.QPainter()
        painter.begin(self)

        font, metrics = common.font_db.secondary_font(common.SMALL_FONT_SIZE())
        common.draw_aliased_text(
            painter, font,
            self.rect().marginsRemoved(
                QtCore.QMargins(common.INDICATOR_WIDTH(), 0,
                                common.INDICATOR_WIDTH(),
                                0)), u'  {}  '.format(self.currentMessage()),
            QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft, common.TEXT)
        painter.end()
Exemplo n.º 6
0
    def paintEvent(self, event):
        """Paint event for smooth font display."""
        painter = QtGui.QPainter()
        painter.begin(self)

        option = QtWidgets.QStyleOption()
        option.initFrom(self)
        hover = option.state & QtWidgets.QStyle.State_MouseOver
        pressed = option.state & QtWidgets.QStyle.State_Sunken
        focus = option.state & QtWidgets.QStyle.State_HasFocus

        color = common.TEXT if self.isEnabled() else common.SECONDARY_TEXT
        color = common.TEXT_SELECTED if hover else color

        bg_color = common.SECONDARY_TEXT if self.isEnabled(
        ) else common.SECONDARY_BACKGROUND.darker(110)
        bg_color = common.TEXT if hover else bg_color
        bg_color = common.SEPARATOR if pressed else bg_color

        if focus:
            pen = QtGui.QPen(common.FAVOURITE)
        else:
            pen = QtGui.QPen(bg_color)
            pen.setWidthF(common.ROW_SEPARATOR())

        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setBrush(bg_color)
        painter.setPen(pen)
        o = common.ROW_SEPARATOR()
        rect = self.rect().marginsRemoved(QtCore.QMargins(o, o, o, o))
        o = common.INDICATOR_WIDTH() * 0.7
        painter.drawRoundedRect(rect, o, o)

        rect = QtCore.QRect(self.rect())
        center = rect.center()
        rect.setWidth(rect.width() - (common.INDICATOR_WIDTH() * 2))
        rect.moveCenter(center)
        common.draw_aliased_text(
            painter,
            common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0],
            rect,
            self.text(),
            QtCore.Qt.AlignCenter,
            color
        )

        painter.end()
Exemplo n.º 7
0
 def paintEvent(self, event):
     """Paints the indicator area."""
     painter = QtGui.QPainter()
     painter.begin(self)
     pen = QtGui.QPen(common.FAVOURITE)
     pen.setWidth(common.INDICATOR_WIDTH())
     painter.setPen(pen)
     painter.setBrush(common.FAVOURITE)
     painter.setOpacity(0.35)
     painter.drawRect(self.rect())
     painter.setOpacity(1.0)
     common.draw_aliased_text(
         painter,
         common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0],
         self.rect(), u'Drop to add bookmark', QtCore.Qt.AlignCenter,
         common.FAVOURITE)
     painter.end()
Exemplo n.º 8
0
    def paintEvent(self, event):
        painter = QtGui.QPainter()
        painter.begin(self)

        painter.setPen(QtCore.Qt.NoPen)
        painter.setBrush(common.SECONDARY_BACKGROUND)
        painter.setOpacity(0.6)
        painter.drawRoundedRect(self.rect(), 4, 4)
        painter.setOpacity(1.0)

        pixmap_rect = QtCore.QRect(0, 0, self.height(), self.height())
        painter.drawPixmap(pixmap_rect, self._pixmap, self._pixmap.rect())

        width = self._text_width + common.INDICATOR_WIDTH()
        width = 640 if width > 640 else width
        rect = QtCore.QRect(
            self._pixmap.rect().width() + common.INDICATOR_WIDTH(), 0, width,
            self.height())
        common.draw_aliased_text(
            painter,
            common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0], rect,
            self._text, QtCore.Qt.AlignCenter, common.TEXT_SELECTED)
        painter.end()
Exemplo n.º 9
0
    def paintEvent(self, event):
        """Indicating the visibility of the TaskFolderWidget."""
        if not self.view().isHidden():
            painter = QtGui.QPainter()
            painter.begin(self)

            painter.setRenderHint(QtGui.QPainter.Antialiasing)
            painter.setRenderHint(QtGui.QPainter.SmoothPixmapTransform)
            painter.setPen(QtCore.Qt.NoPen)
            painter.setBrush(QtGui.QColor(0, 0, 0, 30))
            painter.drawRect(self.rect())

            rect = self.rect()
            rect.setHeight(common.ROW_SEPARATOR() * 2.0)
            painter.setBrush(common.ADD)
            painter.drawRect(rect)

            common.draw_aliased_text(
                painter,
                common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0],
                self.rect(), u'...', QtCore.Qt.AlignCenter, common.BACKGROUND)
            painter.end()
        else:
            super(FilesTabButton, self).paintEvent(event)
Exemplo n.º 10
0
    def paint_name(self, *args):
        """Paints the name and the number of files available for the given data-key."""
        rectangles, painter, option, index, selected, focused, active, archived, favourite, hover, font, metrics, cursor_position = args
        if not index.data(QtCore.Qt.DisplayRole):
            return

        if index.data(common.TodoCountRole):
            color = common.TEXT_SELECTED if hover else common.TEXT
        else:
            color = common.TEXT if hover else common.BACKGROUND_SELECTED
        color = common.TEXT_SELECTED if selected else color

        font = common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0]

        o = common.MARGIN()
        rect = QtCore.QRect(option.rect)
        if selected:
            pixmap = images.ImageCache.get_rsc_pixmap(u'check', common.ADD, o)
            _rect = QtCore.QRect(option.rect)
            _rect.setSize(pixmap.size())
            _rect.moveCenter(option.rect.center())
            _rect.moveLeft(option.rect.left() +
                           ((o + common.INDICATOR_WIDTH()) * 0.5))
            painter.drawPixmap(_rect, pixmap, pixmap.rect())
            rect = rect.marginsRemoved(QtCore.QMargins(o * 2, 0, o, 0))
        else:
            rect = rect.marginsRemoved(QtCore.QMargins(o, 0, o, 0))

        text = index.data(QtCore.Qt.DisplayRole).upper()
        width = 0
        width = common.draw_aliased_text(
            painter, font, rect, text,
            QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft, color)
        rect.setLeft(rect.left() + width)

        items = []
        # Adding an indicator for the number of items in the folder
        if index.data(common.TodoCountRole):
            if index.data(common.TodoCountRole) >= 999:
                text = u'999+ items'
            else:
                text = u'{} items'.format(index.data(common.TodoCountRole))
            color = common.TEXT_SELECTED if selected else common.FAVOURITE
            color = common.TEXT_SELECTED if hover else color
            items.append((text, color))
        else:
            color = common.TEXT if selected else common.BACKGROUND
            color = common.TEXT if hover else color
            items.append((u'n/a', color))

        if index.data(QtCore.Qt.ToolTipRole):
            color = common.TEXT_SELECTED if selected else common.TEXT
            color = common.TEXT_SELECTED if hover else color
            items.append((index.data(QtCore.Qt.ToolTipRole), color))

        for idx, val in enumerate(items):
            text, color = val
            if idx == 0:
                align = QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft
            else:
                align = QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight

            width = common.draw_aliased_text(
                painter,
                common.font_db.secondary_font(common.SMALL_FONT_SIZE())[0],
                rect, u'    |    ', align, common.SEPARATOR)
            rect.setLeft(rect.left() + width)

            width = common.draw_aliased_text(
                painter,
                common.font_db.primary_font(common.MEDIUM_FONT_SIZE())[0],
                rect, text, align, color)
            rect.setLeft(rect.left() + width)