Esempio n. 1
0
 def draw_text(self, style, painter, option, widget, index, item):
     tr = style.subElementRect(style.SE_ItemViewItemText, option, widget)
     text = index.data(Qt.DisplayRole)
     hover = option.state & style.State_MouseOver
     if hover or gprefs['tag_browser_show_counts']:
         count = unicode_type(index.data(COUNT_ROLE))
         width = painter.fontMetrics().boundingRect(count).width()
         r = QRect(tr)
         r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4)
         self.paint_text(painter, r, Qt.AlignCenter | Qt.TextSingleLine, count, hover)
         tr.setRight(r.left() - 1)
     else:
         tr.setRight(tr.right() - 1)
     is_rating = item.type == TagTreeItem.TAG and not self.rating_pat.sub('', text)
     if is_rating:
         painter.setFont(self.rating_font)
     flags = Qt.AlignVCenter | Qt.AlignLeft | Qt.TextSingleLine
     lr = QRect(tr)
     lr.setRight(lr.right() * 2)
     br = painter.boundingRect(lr, flags, text)
     if br.width() > tr.width():
         g = QLinearGradient(tr.topLeft(), tr.topRight())
         c = option.palette.color(QPalette.WindowText)
         g.setColorAt(0, c), g.setColorAt(0.8, c)
         c = QColor(c)
         c.setAlpha(0)
         g.setColorAt(1, c)
         pen = QPen()
         pen.setBrush(QBrush(g))
         painter.setPen(pen)
     self.paint_text(painter, tr, flags, text, hover)
Esempio n. 2
0
 def draw_text(self, style, painter, option, widget, index, item):
     tr = style.subElementRect(style.SE_ItemViewItemText, option, widget)
     text = index.data(Qt.DisplayRole)
     hover = option.state & style.State_MouseOver
     if hover or gprefs['tag_browser_show_counts']:
         count = unicode_type(index.data(COUNT_ROLE))
         width = painter.fontMetrics().boundingRect(count).width()
         r = QRect(tr)
         r.setRight(r.right() - 1), r.setLeft(r.right() - width - 4)
         painter.drawText(r, Qt.AlignCenter | Qt.TextSingleLine, count)
         tr.setRight(r.left() - 1)
     else:
         tr.setRight(tr.right() - 1)
     is_rating = item.type == TagTreeItem.TAG and not self.rating_pat.sub('', text)
     if is_rating:
         painter.setFont(self.rating_font)
     flags = Qt.AlignVCenter | Qt.AlignLeft | Qt.TextSingleLine
     lr = QRect(tr)
     lr.setRight(lr.right() * 2)
     br = painter.boundingRect(lr, flags, text)
     if br.width() > tr.width():
         g = QLinearGradient(tr.topLeft(), tr.topRight())
         c = option.palette.color(QPalette.WindowText)
         g.setColorAt(0, c), g.setColorAt(0.8, c)
         c = QColor(c)
         c.setAlpha(0)
         g.setColorAt(1, c)
         pen = QPen()
         pen.setBrush(QBrush(g))
         painter.setPen(pen)
     painter.drawText(tr, flags, text)
Esempio n. 3
0
 def paintEvent(self, ev):
     if not self.static_text or not self.static_text.text():
         return
     p = QPainter(self)
     p.setRenderHint(p.TextAntialiasing)
     # If text is too long too fit, fade it out at the end
     self.static_text.setTextWidth(self.rect().width())
     sz = self.static_text.size()
     r = self.rect()
     p.drawStaticText(0, (r.height() - sz.height()) // 2, self.static_text)
     if sz.width() > r.width():
         g = QLinearGradient(self.rect().topLeft(), self.rect().topRight())
         c = QColor(self.sb_background)
         c.setAlpha(0)
         g.setColorAt(0, c)
         g.setColorAt(0.8, c)
         g.setColorAt(1.0, self.sb_background)
         p.fillRect(self.rect(), QBrush(g))
     p.end()
Esempio n. 4
0
 def paintEvent(self, ev):
     if not self.static_text or not self.static_text.text():
         return
     p = QPainter(self)
     p.setRenderHint(p.TextAntialiasing)
     # If text is too long too fit, fade it out at the end
     self.static_text.setTextWidth(self.rect().width())
     sz = self.static_text.size()
     r = self.rect()
     p.drawStaticText(0, (r.height() - sz.height()) // 2, self.static_text)
     if sz.width() > r.width():
         g = QLinearGradient(self.rect().topLeft(), self.rect().topRight())
         c = QColor(self.sb_background)
         c.setAlpha(0)
         g.setColorAt(0, c)
         g.setColorAt(0.8, c)
         g.setColorAt(1.0, self.sb_background)
         p.fillRect(self.rect(), QBrush(g))
     p.end()
Esempio n. 5
0
    def _draw_column_data(self, painter, color,
                        xcol, ycol, xmin, xmax, ymin, ymax):
                            
        painter.setPen( QPen(QColor(color), 2,
                        Qt.SolidLine, Qt.RoundCap))

        color = QColor(color)
        color.setAlpha(40)
        painter.setBrush(color)

        path = QPainterPath()
        path.moveTo(xmin, ymax)
        for row in self.data.rows:
            x, y = self._xy_from_data(row[xcol], row[ycol],
                                    xmin, xmax, ymin, ymax)
            path.lineTo(x, y)
        path.lineTo(xmax, ymax)
        path.moveTo(xmin, ymax)
        painter.drawPath(path)
Esempio n. 6
0
    def search_log_area(self):
        """ Search a word in log area.
        Keep last cursor and word used for iteration
        in the document.
        """

        cursor: QTextCursor
        doc: QTextDocument
        text: str
        search_format: QTextCharFormat

        text = self.log_filters.filter_line.text()
        doc = self.log_area.document()

        search_format = QTextCharFormat()
        color = QColor("yellow")
        color.setAlpha(255)
        search_format.setBackground(color)

        # remove the previous search highlight
        if not self.last_search_cursor.isNull():
            self.last_search_cursor.setCharFormat(QTextCharFormat())

        # if search word changed or erased, reset cursor and last_search
        if len(text) == 0 or text != self.last_search:
            self.last_search_cursor = QTextCursor()
            self.last_search = text
            self.log_area.unsetCursor()
        # if has no word to search, just return
        if len(text) == 0:
            return

        cursor = self.last_search_cursor if not self.last_search_cursor.isNull(
        ) else QTextCursor(doc)
        cursor = doc.find(text, cursor)
        if not cursor.isNull():
            self.log_area.setTextCursor(cursor)
            cursor.setCharFormat(search_format)
        else:
            self.log_area.unsetCursor()
        self.last_search_cursor = cursor
Esempio n. 7
0
class Pointer(QWidget):
    def __init__(self, gui):
        QWidget.__init__(self, gui)
        self.setObjectName('jobs_pointer')
        self.setVisible(False)
        self.resize(100, 80)
        self.animation = QPropertyAnimation(self, "geometry", self)
        self.animation.setDuration(750)
        self.animation.setLoopCount(2)
        self.animation.setEasingCurve(QEasingCurve.Linear)
        self.animation.finished.connect(self.hide)

        taily, heady = 0, 55
        self.arrow_path = QPainterPath(QPointF(40, taily))
        self.arrow_path.lineTo(40, heady)
        self.arrow_path.lineTo(20, heady)
        self.arrow_path.lineTo(50, self.height())
        self.arrow_path.lineTo(80, heady)
        self.arrow_path.lineTo(60, heady)
        self.arrow_path.lineTo(60, taily)
        self.arrow_path.closeSubpath()

        c = self.palette().color(QPalette.Active, QPalette.WindowText)
        self.color = QColor(c)
        self.color.setAlpha(100)
        self.brush = QBrush(self.color, Qt.SolidPattern)

        # from PyQt5.Qt import QTimer
        # QTimer.singleShot(1000, self.start)

    @property
    def gui(self):
        return self.parent()

    def point_at(self, frac):
        return (self.path.pointAtPercent(frac).toPoint() -
                QPoint(self.rect().center().x(), self.height()))

    def rect_at(self, frac):
        return QRect(self.point_at(frac), self.size())

    def abspos(self, widget):
        pos = widget.pos()
        parent = widget.parent()
        while parent is not self.gui:
            pos += parent.pos()
            parent = parent.parent()
        return pos

    def start(self):
        if config['disable_animations']:
            return
        self.setVisible(True)
        self.raise_()
        end = self.abspos(self.gui.jobs_button)
        end = QPointF(end.x() + self.gui.jobs_button.width() / 3.0,
                      end.y() + 20)
        start = QPointF(end.x(), end.y() - 0.5 * self.height())
        self.path = QPainterPath(QPointF(start))
        self.path.lineTo(end)
        self.path.closeSubpath()
        self.animation.setStartValue(self.rect_at(0.0))
        self.animation.setEndValue(self.rect_at(1.0))
        self.animation.setDirection(self.animation.Backward)
        num_keys = 100
        for i in xrange(1, num_keys):
            i /= num_keys
            self.animation.setKeyValueAt(i, self.rect_at(i))
        self.animation.start()

    def paintEvent(self, ev):
        p = QPainter(self)
        p.setRenderHints(p.Antialiasing)
        p.setBrush(self.brush)
        p.setPen(Qt.NoPen)
        p.drawPath(self.arrow_path)
        p.end()
Esempio n. 8
0
class Pointer(QWidget):

    def __init__(self, gui):
        QWidget.__init__(self, gui)
        self.setObjectName('jobs_pointer')
        self.setVisible(False)
        self.resize(100, 80)
        self.animation = QPropertyAnimation(self, "geometry", self)
        self.animation.setDuration(750)
        self.animation.setLoopCount(2)
        self.animation.setEasingCurve(QEasingCurve.Linear)
        self.animation.finished.connect(self.hide)

        taily, heady = 0, 55
        self.arrow_path = QPainterPath(QPointF(40, taily))
        self.arrow_path.lineTo(40, heady)
        self.arrow_path.lineTo(20, heady)
        self.arrow_path.lineTo(50, self.height())
        self.arrow_path.lineTo(80, heady)
        self.arrow_path.lineTo(60, heady)
        self.arrow_path.lineTo(60, taily)
        self.arrow_path.closeSubpath()

        c = self.palette().color(QPalette.Active, QPalette.WindowText)
        self.color = QColor(c)
        self.color.setAlpha(100)
        self.brush = QBrush(self.color, Qt.SolidPattern)

        # from PyQt5.Qt import QTimer
        # QTimer.singleShot(1000, self.start)

    @property
    def gui(self):
        return self.parent()

    def point_at(self, frac):
        return (self.path.pointAtPercent(frac).toPoint() -
                QPoint(self.rect().center().x(), self.height()))

    def rect_at(self, frac):
        return QRect(self.point_at(frac), self.size())

    def abspos(self, widget):
        pos = widget.pos()
        parent = widget.parent()
        while parent is not self.gui:
            pos += parent.pos()
            parent = parent.parent()
        return pos

    def start(self):
        if config['disable_animations']:
            return
        self.setVisible(True)
        self.raise_()
        end = self.abspos(self.gui.jobs_button)
        end = QPointF( end.x() + self.gui.jobs_button.width()/3.0, end.y()+20)
        start = QPointF(end.x(), end.y() - 0.5*self.height())
        self.path = QPainterPath(QPointF(start))
        self.path.lineTo(end)
        self.path.closeSubpath()
        self.animation.setStartValue(self.rect_at(0.0))
        self.animation.setEndValue(self.rect_at(1.0))
        self.animation.setDirection(self.animation.Backward)
        num_keys = 100
        for i in xrange(1, num_keys):
            i /= num_keys
            self.animation.setKeyValueAt(i, self.rect_at(i))
        self.animation.start()

    def paintEvent(self, ev):
        p = QPainter(self)
        p.setRenderHints(p.Antialiasing)
        p.setBrush(self.brush)
        p.setPen(Qt.NoPen)
        p.drawPath(self.arrow_path)
        p.end()