예제 #1
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, self.dummy_index)
     painter.save()
     painter.setClipRect(QRectF(option.rect))
     painter.translate(option.rect.topLeft())
     self.to_doc(index, option).drawContents(painter)
     painter.restore()
예제 #2
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     text, positions = index.data(Qt.ItemDataRole.UserRole)
     self.initStyleOption(option, index)
     painter.save()
     painter.setFont(option.font)
     p = option.palette
     c = QPalette.ColorRole.HighlightedText if option.state & QStyle.StateFlag.State_Selected else QPalette.ColorRole.Text
     group = (QPalette.ColorGroup.Active if option.state & QStyle.StateFlag.State_Active else QPalette.ColorGroup.Inactive)
     c = p.color(group, c)
     painter.setClipRect(option.rect)
     if positions is None or -1 in positions:
         painter.setPen(c)
         painter.drawText(option.rect, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter | Qt.TextFlag.TextSingleLine, text)
     else:
         to = QTextOption()
         to.setWrapMode(QTextOption.WrapMode.NoWrap)
         to.setAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
         positions = sorted(set(positions) - {-1}, reverse=True)
         text = '<body>%s</body>' % make_highlighted_text(emphasis_style(), text, positions)
         doc = QTextDocument()
         c = 'rgb(%d, %d, %d)'%c.getRgb()[:3]
         doc.setDefaultStyleSheet(' body { color: %s }'%c)
         doc.setHtml(text)
         doc.setDefaultFont(option.font)
         doc.setDocumentMargin(0.0)
         doc.setDefaultTextOption(to)
         height = doc.size().height()
         painter.translate(option.rect.left(), option.rect.top() + (max(0, option.rect.height() - height) // 2))
         doc.drawContents(painter)
     painter.restore()
예제 #3
0
 def __init__(self, parent):
     '''
     Delegate for custom_column bool data.
     '''
     QStyledItemDelegate.__init__(self, parent)
     self.disallow_edit = gprefs[
         'edit_metadata_templates_only_F2_on_booklist']
예제 #4
0
    def paint(self, painter, option, index):
        QStyledItemDelegate.paint(
            self, painter, option,
            empty_index)  # draw the hover and selection highlights
        name = str(index.data(Qt.ItemDataRole.DisplayRole) or '')
        cover = self.cover_cache.get(name, None)
        if cover is None:
            cover = self.cover_cache[name] = QPixmap()
            try:
                raw = current_container().raw_data(name, decode=False)
            except:
                pass
            else:
                try:
                    dpr = painter.device().devicePixelRatioF()
                except AttributeError:
                    dpr = painter.device().devicePixelRatio()
                cover.loadFromData(raw)
                cover.setDevicePixelRatio(dpr)
                if not cover.isNull():
                    scaled, width, height = fit_image(cover.width(),
                                                      cover.height(),
                                                      self.cover_size.width(),
                                                      self.cover_size.height())
                    if scaled:
                        cover = self.cover_cache[name] = cover.scaled(
                            int(dpr * width),
                            int(dpr * height),
                            transformMode=Qt.TransformationMode.
                            SmoothTransformation)

        painter.save()
        try:
            rect = option.rect
            rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
            trect = QRect(rect)
            rect.setBottom(rect.bottom() - self.title_height)
            if not cover.isNull():
                dx = max(
                    0,
                    int((rect.width() -
                         int(cover.width() / cover.devicePixelRatio())) / 2.0))
                dy = max(
                    0,
                    rect.height() -
                    int(cover.height() / cover.devicePixelRatio()))
                rect.adjust(dx, dy, -dx, 0)
                painter.drawPixmap(rect, cover)
            rect = trect
            rect.setTop(rect.bottom() - self.title_height + 5)
            painter.setRenderHint(QPainter.RenderHint.TextAntialiasing, True)
            metrics = painter.fontMetrics()
            painter.drawText(
                rect,
                Qt.AlignmentFlag.AlignCenter | Qt.TextFlag.TextSingleLine,
                metrics.elidedText(name, Qt.TextElideMode.ElideLeft,
                                   rect.width()))
        finally:
            painter.restore()
예제 #5
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     pal = option.palette
     color = pal.color(QPalette.ColorRole.HighlightedText if option.state & QStyle.StateFlag.State_Selected else QPalette.ColorRole.Text).name()
     text = '<div style="color:%s">%s</div>' % (color, index.data(RENDER_ROLE))
     st = QStaticText(text)
     st.setTextWidth(option.rect.width())
     painter.drawStaticText(option.rect.left() + self.MARGIN // 2, option.rect.top() + self.MARGIN // 2, st)
예제 #6
0
 def __init__(self, parent, tweak_name='gui_timestamp_display_format',
         default_format='dd MMM yyyy'):
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
     self.tweak_name = tweak_name
     self.format = tweaks[self.tweak_name]
     if self.format is None:
         self.format = default_format
예제 #7
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     painter.save()
     try:
         self.do_paint(painter, option, index)
     except:
         pass
     painter.restore()
예제 #8
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     painter.save()
     try:
         self.do_paint(painter, option, index)
     except:
         import traceback
         traceback.print_exc()
     painter.restore()
예제 #9
0
 def __init__(self, parent):
     '''
     Delegate for text data. If auto_complete_function needs to return a list
     of text items to auto-complete with. If the function is None no
     auto-complete will be used.
     '''
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
     self.auto_complete_function = None
예제 #10
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     result = index.data(Qt.ItemDataRole.UserRole)
     is_hidden, result_before, result_text, result_after, show_leading_dot = self.result_data(
         result)
     if result_text is None:
         return
     painter.save()
     try:
         p = option.palette
         c = QPalette.ColorRole.HighlightedText if option.state & QStyle.StateFlag.State_Selected else QPalette.ColorRole.Text
         group = (QPalette.ColorGroup.Active if option.state
                  & QStyle.StateFlag.State_Active else
                  QPalette.ColorGroup.Inactive)
         c = p.color(group, c)
         painter.setPen(c)
         font = option.font
         if self.emphasize_text:
             emphasis_font = QFont(font)
             emphasis_font.setBold(True)
         else:
             emphasis_font = font
         flags = Qt.AlignmentFlag.AlignTop | Qt.TextFlag.TextSingleLine | Qt.TextFlag.TextIncludeTrailingSpaces
         rect = option.rect.adjusted(
             option.decorationSize.width() + 4 if is_hidden else 0, 0, 0, 0)
         painter.setClipRect(rect)
         before = re.sub(r'\s+', ' ', result_before)
         if show_leading_dot:
             before = '•' + before
         before_width = 0
         if before:
             before_width = painter.boundingRect(rect, flags,
                                                 before).width()
         after = re.sub(r'\s+', ' ', result_after.rstrip())
         after_width = 0
         if after:
             after_width = painter.boundingRect(rect, flags, after).width()
         ellipsis_width = painter.boundingRect(rect, flags, '...').width()
         painter.setFont(emphasis_font)
         text = re.sub(r'\s+', ' ', result_text)
         match_width = painter.boundingRect(rect, flags, text).width()
         if match_width >= rect.width() - 3 * ellipsis_width:
             efm = QFontMetrics(emphasis_font)
             if show_leading_dot:
                 text = '•' + text
             text = efm.elidedText(text, Qt.TextElideMode.ElideRight,
                                   rect.width())
             painter.drawText(rect, flags, text)
         else:
             self.draw_match(painter, flags, before, text, after, rect,
                             before_width, match_width, after_width,
                             ellipsis_width, emphasis_font, font)
     except Exception:
         import traceback
         traceback.print_exc()
     painter.restore()
예제 #11
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args)
     self.is_half_star = kwargs.get('is_half_star', False)
     self.table_widget = args[0]
     self.rf = QFont(rating_font())
     self.em = Qt.TextElideMode.ElideMiddle
     delta = 0
     if iswindows and sys.getwindowsversion().major >= 6:
         delta = 2
     self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
예제 #12
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     style = QApplication.style()
     waiting = self.animator.is_running() and bool(index.data(Qt.ItemDataRole.UserRole))
     if waiting:
         rect = QRect(0, 0, self.spinner_width, self.spinner_width)
         rect.moveCenter(option.rect.center())
         self.animator.draw(painter, rect, self.color)
     else:
         # Ensure the cover is rendered over any selection rect
         style.drawItemPixmap(painter, option.rect, Qt.AlignmentFlag.AlignTop|Qt.AlignmentFlag.AlignHCenter,
             QPixmap(index.data(Qt.ItemDataRole.DecorationRole)))
예제 #13
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     try:
         charcode = int(index.data(Qt.ItemDataRole.UserRole))
     except (TypeError, ValueError):
         return
     painter.save()
     try:
         if charcode in non_printing:
             self.paint_non_printing(painter, option, charcode)
         else:
             self.paint_normal(painter, option, charcode)
     finally:
         painter.restore()
예제 #14
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     img = index.data(Qt.ItemDataRole.DecorationRole)
     if img:
         h = option.rect.height() - 4
         w = option.rect.width()
         if isinstance(img, QIcon):
             img = img.pixmap(h - 4, h - 4)
             dpr = img.devicePixelRatio()
         else:
             dpr = img.devicePixelRatio()
             scaled, nw, nh = fit_image(img.width(), img.height(), w, h)
             if scaled:
                 img = img.scaled(int(nw*dpr), int(nh*dpr), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
         iw, ih = int(img.width()/dpr), int(img.height()/dpr)
         dx, dy = (option.rect.width() - iw) // 2, (option.rect.height() - ih) // 2
         painter.drawPixmap(option.rect.adjusted(dx, dy, -dx, -dy), img)
예제 #15
0
 def helpEvent(self, ev, view, option, index):
     # Show a tooltip only if the item is truncated
     if not ev or not view:
         return False
     if ev.type() == QEvent.Type.ToolTip:
         rect = view.visualRect(index)
         size = self.sizeHint(option, index)
         if rect.width() < size.width():
             tooltip = index.data(Qt.ItemDataRole.DisplayRole)
             QToolTip.showText(ev.globalPos(), tooltip, view)
             return True
     return QStyledItemDelegate.helpEvent(self, ev, view, option, index)
예제 #16
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     theme = index.data(Qt.ItemDataRole.UserRole)
     if not theme:
         return
     painter.save()
     pixmap = index.data(Qt.ItemDataRole.DecorationRole)
     if pixmap and not pixmap.isNull():
         rect = option.rect.adjusted(0, self.SPACING,
                                     COVER_SIZE[0] - option.rect.width(),
                                     -self.SPACING)
         painter.drawPixmap(rect, pixmap)
     if option.state & QStyle.StateFlag.State_Selected:
         painter.setPen(
             QPen(QApplication.instance().palette().highlightedText().color(
             )))
     bottom = option.rect.bottom() - 2
     painter.drawLine(0, bottom, option.rect.right(), bottom)
     if 'static-text' not in theme:
         theme['static-text'] = QStaticText(
             _('''
         <h1>{title}</h1>
         <p>by <i>{author}</i> with <b>{number}</b> icons [{size}]</p>
         <p>{description}</p>
         <p>Version: {version} Number of users: {usage}</p>
         <p><i>Right click to visit theme homepage</i></p>
         '''.format(
                 title=theme.get('title', _('Unknown')),
                 author=theme.get('author', _('Unknown')),
                 number=theme.get('number', 0),
                 description=theme.get('description', ''),
                 size=human_readable(theme.get('compressed-size', 0)),
                 version=theme.get('version', 1),
                 usage=theme.get('usage', 0),
             )))
     painter.drawStaticText(COVER_SIZE[0] + self.SPACING,
                            option.rect.top() + self.SPACING,
                            theme['static-text'])
     painter.restore()
예제 #17
0
 def __init__(self, parent):
     '''
     Delegate for custom_column bool data.
     '''
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
예제 #18
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.document = QTextDocument()
예제 #19
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
     self.longest_text = ''
예제 #20
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
예제 #21
0
 def setModelData(self, editor, model, index):
     if isinstance(editor, EditWithComplete):
         val = editor.lineEdit().text()
         model.setData(index, (val), Qt.ItemDataRole.EditRole)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
예제 #22
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.format = tweaks['gui_pubdate_display_format']
     self.table_widget = args[0]
     if self.format is None:
         self.format = 'MMM yyyy'
예제 #23
0
 def sizeHint(self, *args):
     ans = QStyledItemDelegate.sizeHint(self, *args)
     ans.setHeight(ans.height() + 4)
     return ans
예제 #24
0
 def __init__(self, parent, sep, items_func_name, space_before_sep=False):
     QStyledItemDelegate.__init__(self, parent)
     self.sep = sep
     self.items_func_name = items_func_name
     self.space_before_sep = space_before_sep
     self.table_widget = parent