Пример #1
1
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     text, positions = index.data(Qt.UserRole)
     self.initStyleOption(option, index)
     painter.save()
     painter.setFont(option.font)
     p = option.palette
     c = p.HighlightedText if option.state & QStyle.State_Selected else p.Text
     group = (p.Active if option.state & QStyle.State_Active else p.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.AlignLeft | Qt.AlignVCenter | Qt.TextSingleLine, text)
     else:
         to = QTextOption()
         to.setWrapMode(to.NoWrap)
         to.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
         positions = sorted(set(positions) - {-1}, reverse=True)
         text = '<body>%s</body>' % make_highlighted_text(Results.EMPH, 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()
Пример #2
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())
     theme = index.data(Qt.UserRole)
     if not theme:
         return
     painter.save()
     pixmap = index.data(Qt.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.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>
         '''.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()
Пример #3
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()
Пример #4
0
 def __init__(self, parent, tweak_name='gui_timestamp_display_format',
         default_format='dd MMM yyyy'):
     QStyledItemDelegate.__init__(self, parent)
     self.tweak_name = tweak_name
     self.format = tweaks[self.tweak_name]
     if self.format is None:
         self.format = default_format
Пример #5
0
 def paint(self, painter, option, index):
     item = index.data(Qt.UserRole)
     QStyledItemDelegate.paint(self, painter, option, index)
     widget = self.parent()
     style = QApplication.style() if widget is None else widget.style()
     self.initStyleOption(option, index)
     if item.boxed:
         r = style.subElementRect(style.SE_ItemViewItemFocusRect, option, widget)
         painter.save()
         painter.drawLine(r.bottomLeft(), r.bottomRight())
         painter.restore()
     if item.type != TagTreeItem.TAG:
         return
     if item.tag.state == 0 and config["show_avg_rating"] and item.tag.avg_rating is not None:
         r = style.subElementRect(style.SE_ItemViewItemDecoration, option, widget)
         icon = option.icon
         painter.save()
         rating = item.tag.avg_rating
         nr = r.adjusted(0, 0, 0, 0)
         nr.setBottom(r.bottom() - int(r.height() * (rating / 5.0)))
         painter.setClipRect(nr)
         bg = option.palette.window()
         if self.old_look:
             bg = option.palette.alternateBase() if option.features & option.Alternate else option.palette.base()
         painter.fillRect(r, bg)
         style.proxy().drawPrimitive(style.PE_PanelItemViewItem, option, painter, widget)
         painter.setOpacity(0.3)
         icon.paint(painter, r, option.decorationAlignment, icon.Normal, icon.On)
         painter.restore()
Пример #6
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.auto_complete_function = None
Пример #7
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.rf = QFont(rating_font())
     self.em = Qt.ElideMiddle
     delta = 0
     if iswindows and sys.getwindowsversion().major >= 6:
         delta = 2
     self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
Пример #8
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     pal = option.palette
     color = pal.color(pal.HighlightedText if option.state & QStyle.State_Selected else pal.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)
Пример #9
0
    def __init__(self, parent):
        QStyledItemDelegate.__init__(self, parent)

        self.angle = 0
        self.timer = QTimer(self)
        self.timer.timeout.connect(self.frame_changed)
        self.color = parent.palette().color(QPalette.WindowText)
        self.spinner_width = 64
Пример #10
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()
 def __init__(self, parent, db, sep, items_func_name, space_before_sep=False,
              col=None, col_fn=None):
     QStyledItemDelegate.__init__(self, parent)
     self.db = db
     self.sep = sep
     self.items_func_name = items_func_name
     self.col = col
     self.col_fn = col_fn
     self.space_before_sep = space_before_sep
Пример #12
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, self._m.index(1))
     painter.save()
     parent = self.parent() or QApplication.instance()
     style = parent.style()
     try:
         index.data(Qt.UserRole).draw_item(painter, style, option)
     finally:
         painter.restore()
Пример #13
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.is_half_star = kwargs.get('is_half_star', False)
     self.table_widget = args[0]
     self.rf = QFont(rating_font())
     self.em = Qt.ElideMiddle
     delta = 0
     if iswindows and sys.getwindowsversion().major >= 6:
         delta = 2
     self.rf.setPointSize(QFontInfo(QApplication.font()).pointSize()+delta)
Пример #14
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     style = QApplication.style()
     waiting = self.timer.isActive() and bool(index.data(Qt.UserRole))
     if waiting:
         rect = QRect(0, 0, self.spinner_width, self.spinner_width)
         rect.moveCenter(option.rect.center())
         draw_snake_spinner(painter, rect, self.angle, self.light_color, self.dark_color)
     else:
         # Ensure the cover is rendered over any selection rect
         style.drawItemPixmap(painter, option.rect, Qt.AlignTop|Qt.AlignHCenter,
             QPixmap(index.data(Qt.DecorationRole)))
Пример #15
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     try:
         charcode = int(index.data(Qt.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()
Пример #16
0
 def createEditor(self, parent, option, index):
     qde = QStyledItemDelegate.createEditor(self, parent, option, index)
     qde.setDisplayFormat(self.format)
     qde.setMinimumDateTime(UNDEFINED_QDATETIME)
     qde.setSpecialValueText(_('Undefined'))
     qde.setCalendarPopup(True)
     return qde
Пример #17
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     widget = self.parent()
     style = QApplication.style() if widget is None else widget.style()
     self.initStyleOption(option, index)
     item = index.data(Qt.UserRole)
     self.draw_icon(style, painter, option, widget)
     painter.save()
     self.draw_text(style, painter, option, widget, index, item)
     painter.restore()
     if item.boxed:
         r = style.subElementRect(style.SE_ItemViewItemFocusRect, option,
                 widget)
         painter.drawLine(r.bottomLeft(), r.bottomRight())
     if item.type == TagTreeItem.TAG and item.tag.state == 0 and config['show_avg_rating']:
         self.draw_average_rating(item, style, painter, option, widget)
Пример #18
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, empty_index)
     img = index.data(Qt.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(nw*dpr, nh*dpr, Qt.IgnoreAspectRatio, Qt.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)
Пример #19
0
    def paint(self, painter, option, index):
        QStyledItemDelegate.paint(self, painter, option, QModelIndex())  # draw the hover and selection highlights
        name = unicode(index.data(Qt.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.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.TextAntialiasing, True)
            metrics = painter.fontMetrics()
            painter.drawText(
                rect, Qt.AlignCenter | Qt.TextSingleLine, metrics.elidedText(name, Qt.ElideLeft, rect.width())
            )
        finally:
            painter.restore()
Пример #20
0
 def sizeHint(self, option, index):
     ans = QStyledItemDelegate.sizeHint(self, option, index)
     entry = index.data(Qt.UserRole)
     if entry is None:
         return ans
     th = self.parent().thumbnail_height
     width, height = min(th, entry.width), min(th, entry.height)
     m = self.MARGIN * 2
     return QSize(max(width + m, ans.width()), height + m + self.MARGIN + ans.height())
Пример #21
0
 def createEditor(self, parent, option, index):
     m = index.model()
     col = m.column_map[index.column()]
     key = m.db.field_metadata.key_to_label(col)
     if m.db.field_metadata[col]['datatype'] != 'comments':
         editor = EditWithComplete(parent)
         editor.set_separator(None)
         complete_items = sorted(list(m.db.all_custom(label=key)), key=sort_key)
         editor.update_items_cache(complete_items)
     else:
         editor = QStyledItemDelegate.createEditor(self, parent, option, index)
     return editor
Пример #22
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() == ev.ToolTip:
         rect = view.visualRect(index)
         size = self.sizeHint(option, index)
         if rect.width() < size.width():
             tooltip = index.data(Qt.DisplayRole)
             QToolTip.showText(ev.globalPos(), tooltip, view)
             return True
     return QStyledItemDelegate.helpEvent(self, ev, view, option, index)
Пример #23
0
 def paint(self, painter, option, index):
     top_level = not index.parent().isValid()
     hover = option.state & QStyle.State_MouseOver
     if hover:
         if top_level:
             suffix = '%s(%d)' % (NBSP, index.model().rowCount(index))
         else:
             try:
                 suffix = NBSP + human_readable(current_container().filesize(unicode(index.data(NAME_ROLE) or '')))
             except EnvironmentError:
                 suffix = NBSP + human_readable(0)
         br = painter.boundingRect(option.rect, Qt.AlignRight|Qt.AlignVCenter, suffix)
     if top_level and index.row() > 0:
         option.rect.adjust(0, 5, 0, 0)
         painter.drawLine(option.rect.topLeft(), option.rect.topRight())
         option.rect.adjust(0, 1, 0, 0)
     if hover:
         option.rect.adjust(0, 0, -br.width(), 0)
     QStyledItemDelegate.paint(self, painter, option, index)
     if hover:
         option.rect.adjust(0, 0, br.width(), 0)
         painter.drawText(option.rect, Qt.AlignRight|Qt.AlignVCenter, suffix)
Пример #24
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, ROOT)
     entry = index.data(Qt.UserRole)
     if entry is None:
         return
     painter.save()
     th = self.parent().thumbnail_height
     k = (th, entry.name)
     pmap = self.cache.get(k)
     if pmap is None:
         pmap = self.cache[k] = self.pixmap(th, entry)
     if pmap.isNull():
         bottom = option.rect.top()
     else:
         m = 2 * self.MARGIN
         x = option.rect.left() + (option.rect.width() - m - pmap.width()) // 2
         painter.drawPixmap(x, option.rect.top() + self.MARGIN, pmap)
         bottom = m + pmap.height() + option.rect.top()
     rect = QRect(option.rect.left(), bottom, option.rect.width(), option.rect.bottom() - bottom)
     if option.state & QStyle.State_Selected:
         painter.setPen(self.parent().palette().color(QPalette.HighlightedText))
     painter.drawText(rect, Qt.AlignHCenter | Qt.AlignVCenter, entry.basename)
     painter.restore()
Пример #25
0
 def paint(self, painter, option, index):
     name = index.data(Qt.DisplayRole)
     sz = human_readable(index.data(Qt.UserRole))
     pmap = index.data(Qt.UserRole+1)
     irect = option.rect.adjusted(0, 5, 0, -5)
     irect.setRight(irect.left() + 70)
     if pmap is None:
         pmap = QPixmap(current_container().get_file_path_for_processing(name))
         scaled, nwidth, nheight = fit_image(pmap.width(), pmap.height(), irect.width(), irect.height())
         if scaled:
             pmap = pmap.scaled(nwidth, nheight, transformMode=Qt.SmoothTransformation)
         index.model().setData(index, pmap, Qt.UserRole+1)
     x, y = (irect.width() - pmap.width())//2, (irect.height() - pmap.height())//2
     r = irect.adjusted(x, y, -x, -y)
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())
     painter.drawPixmap(r, pmap)
     trect = irect.adjusted(irect.width() + 10, 0, 0, 0)
     trect.setRight(option.rect.right())
     painter.save()
     if option.state & QStyle.State_Selected:
         painter.setPen(QPen(option.palette.color(option.palette.HighlightedText)))
     painter.drawText(trect, Qt.AlignVCenter | Qt.AlignLeft, name + '\n' + sz)
     painter.restore()
Пример #26
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
Пример #27
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
     self.longest_text = ''
Пример #28
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.document = QTextDocument()
Пример #29
0
 def sizeHint(self, *args):
     ans = QStyledItemDelegate.sizeHint(self, *args)
     ans.setHeight(ans.height() + 4)
     return ans
Пример #30
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
Пример #31
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self.item_size = QSize(32, 32)
     self.np_pat = re.compile(r'(sp|j|nj|ss|fs|ds)$')
Пример #32
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'
Пример #33
0
 def createEditor(self, parent, option, index):
     sb = QStyledItemDelegate.createEditor(self, parent, option, index)
     sb.setMinimum(0)
     sb.setMaximum(5)
     sb.setSuffix(' ' + _('stars'))
     return sb
Пример #34
0
 def __init__(self, parent=None, max_width=160):
     QStyledItemDelegate.__init__(self, parent)
     self.max_width = max_width
     self.dummy_model = QStringListModel([' '], self)
     self.dummy_index = self.dummy_model.index(0)
Пример #35
0
 def sizeHint(self, option, index):
     ans = QStyledItemDelegate.sizeHint(self, option, index)
     top_level = not index.parent().isValid()
     ans += QSize(0, 20 if top_level else 10)
     return ans
Пример #36
0
 def __init__(self, view):
     QStyledItemDelegate.__init__(self, view)
     self.view = view
Пример #37
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.document = QTextDocument()
Пример #38
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
Пример #39
0
 def sizeHint(self, option, index):
     option.font = self.rf
     option.textElideMode = self.em
     return QStyledItemDelegate.sizeHint(self, option, index)
Пример #40
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self.editing_indices = {}
     self.closeEditor.connect(self.editing_done)
Пример #41
0
 def __init__(self, all_authors, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.all_authors = all_authors
Пример #42
0
 def paint(self, painter, option, index):
     option.font = self.rf
     option.textElideMode = self.em
     return QStyledItemDelegate.paint(self, painter, option, index)
Пример #43
0
 def initStyleOption(self, option, index):
     QStyledItemDelegate.initStyleOption(self, option, index)
     option.font = QApplication.instance().font(
     ) if index.row() <= 0 else self.parent().rating_font
     option.fontMetrics = QFontMetrics(option.font)
Пример #44
0
 def sizeHint(self, option, index):
     ans = QStyledItemDelegate.sizeHint(self, option, index)
     ans.setHeight(ans.height() + 10)
     return ans
Пример #45
0
 def sizeHint(self, *args):
     ans = QStyledItemDelegate.sizeHint(self, *args)
     return ans + QSize(0, 10)
Пример #46
0
 def sizeHint(self, option, index):
     ans = QStyledItemDelegate.sizeHint(self, option, index)
     if not index.parent().isValid():
         ans += QSize(0, 6)
     return ans
Пример #47
0
 def __init__(self, parent):
     '''
     Delegate for custom_column bool data.
     '''
     QStyledItemDelegate.__init__(self, parent)
Пример #48
0
 def sizeHint(self, *args):
     return QStyledItemDelegate.sizeHint(self, *args) + QSize(0, 15)
Пример #49
0
 def paint(self, p, opt, idx):
     copy = QStyleOptionViewItem(opt)
     copy.showDecorationSelected = True
     if self.view.currentIndex() == idx:
         copy.state |= QStyle.State_HasFocus
     QStyledItemDelegate.paint(self, p, copy, idx)
Пример #50
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.old_look = False
     self.rating_pat = re.compile(r'[%s]' % rating_to_stars(3, True))
     self.rating_font = QFont(rating_font())
Пример #51
0
 def __init__(self, parent, fmt='dd MMM yyyy', default_to_today=True):
     QStyledItemDelegate.__init__(self, parent)
     self.format = fmt
     self.default_to_today = default_to_today
Пример #52
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.table_widget = parent
     self.longest_text = ''
Пример #53
0
 def setModelData(self, editor, model, index):
     if isinstance(editor, EditWithComplete):
         val = editor.lineEdit().text()
         model.setData(index, val, Qt.EditRole)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Пример #54
0
 def __init__(self, parent):
     '''
     Delegate for custom_column bool data.
     '''
     QStyledItemDelegate.__init__(self, parent)
Пример #55
0
    def paint(self, painter, option, index):
        QStyledItemDelegate.paint(
            self, painter, option,
            empty_index)  # draw the hover and selection highlights
        m = index.model()
        db = m.db
        try:
            book_id = db.id(index.row())
        except (ValueError, IndexError, KeyError):
            return
        if book_id in m.ids_to_highlight_set:
            painter.save()
            try:
                painter.setPen(self.highlight_color)
                painter.setRenderHint(QPainter.Antialiasing, True)
                painter.drawRoundedRect(option.rect, 10, 10, Qt.RelativeSize)
            finally:
                painter.restore()
        marked = db.data.get_marked(book_id)
        db = db.new_api
        cdata = self.cover_cache[book_id]
        device_connected = self.parent().gui.device_connected is not None
        on_device = device_connected and db.field_for('ondevice', book_id)

        emblem_rules = db.pref('cover_grid_icon_rules', default=())
        emblems = []
        if self.emblem_size > 0:
            mi = None
            for i, (kind, column, rule) in enumerate(emblem_rules):
                icon_name, mi = self.render_emblem(book_id, rule, i,
                                                   m.cover_grid_emblem_cache,
                                                   mi, db, m.formatter,
                                                   m.cover_grid_template_cache)
                if icon_name is not None:
                    pixmap = self.cached_emblem(m.cover_grid_bitmap_cache,
                                                icon_name)
                    if pixmap is not None:
                        emblems.append(pixmap)
            if marked:
                emblems.insert(
                    0,
                    self.cached_emblem(m.cover_grid_bitmap_cache, ':marked',
                                       m.marked_icon))
            if on_device:
                emblems.insert(
                    0,
                    self.cached_emblem(m.cover_grid_bitmap_cache, ':ondevice'))

        painter.save()
        right_adjust = 0
        try:
            rect = option.rect
            rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
            if self.emblem_size > 0:
                self.paint_emblems(painter, rect, emblems)
            orect = QRect(rect)
            if cdata is None or cdata is False:
                title = db.field_for('title', book_id, default_value='')
                authors = ' & '.join(
                    db.field_for('authors', book_id, default_value=()))
                painter.setRenderHint(QPainter.TextAntialiasing, True)
                painter.drawText(rect, Qt.AlignCenter | Qt.TextWordWrap,
                                 '%s\n\n%s' % (title, authors))
                if cdata is False:
                    self.render_queue.put(book_id)
            else:
                if self.title_height != 0:
                    trect = QRect(rect)
                    rect.setBottom(rect.bottom() - self.title_height)
                if self.animating is not None and self.animating.row(
                ) == index.row():
                    cdata = cdata.scaled(cdata.size() * self._animated_size)
                dpr = cdata.devicePixelRatio()
                cw, ch = int(cdata.width() / dpr), int(cdata.height() / dpr)
                dx = max(0, int((rect.width() - cw) / 2.0))
                dy = max(0, rect.height() - ch)
                right_adjust = dx
                rect.adjust(dx, dy, -dx, 0)
                painter.drawPixmap(rect, cdata)
                if self.title_height != 0:
                    rect = trect
                    rect.setTop(rect.bottom() - self.title_height + 5)
                    painter.setRenderHint(QPainter.TextAntialiasing, True)
                    title, is_stars = self.render_field(db, book_id)
                    if is_stars:
                        painter.setFont(self.rating_font)
                    metrics = painter.fontMetrics()
                    painter.setPen(self.highlight_color)
                    painter.drawText(
                        rect, Qt.AlignCenter | Qt.TextSingleLine,
                        metrics.elidedText(title, Qt.ElideRight, rect.width()))
            if self.emblem_size > 0:
                return  # We dont draw embossed emblems as the ondevice/marked emblems are drawn in the gutter
            if marked:
                try:
                    p = self.marked_emblem
                except AttributeError:
                    p = self.marked_emblem = m.marked_icon.pixmap(48, 48)
                self.paint_embossed_emblem(p, painter, orect, right_adjust)

            if on_device:
                try:
                    p = self.on_device_emblem
                except AttributeError:
                    p = self.on_device_emblem = QIcon(I('ok.png')).pixmap(
                        48, 48)
                self.paint_embossed_emblem(p,
                                           painter,
                                           orect,
                                           right_adjust,
                                           left=False)
        finally:
            painter.restore()
Пример #56
0
 def sizeHint(self, option, index):
     ans = QStyledItemDelegate.sizeHint(self, option, index)
     ans.setHeight(ans.height() + 10)
     return ans
Пример #57
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.format = 'dd MMM yyyy'
Пример #58
0
    def paint(self, painter, option, index):
        QStyledItemDelegate.paint(self, painter, option, empty_index)  # draw the hover and selection highlights
        m = index.model()
        db = m.db
        try:
            book_id = db.id(index.row())
        except (ValueError, IndexError, KeyError):
            return
        if book_id in m.ids_to_highlight_set:
            painter.save()
            try:
                painter.setPen(self.highlight_color)
                painter.setRenderHint(QPainter.Antialiasing, True)
                painter.drawRoundedRect(option.rect, 10, 10, Qt.RelativeSize)
            finally:
                painter.restore()
        marked = db.data.get_marked(book_id)
        db = db.new_api
        cdata = self.cover_cache[book_id]
        device_connected = self.parent().gui.device_connected is not None
        on_device = device_connected and db.field_for('ondevice', book_id)

        emblem_rules = db.pref('cover_grid_icon_rules', default=())
        emblems = []
        if self.emblem_size > 0:
            mi = None
            for i, (kind, column, rule) in enumerate(emblem_rules):
                icon_name, mi = self.render_emblem(book_id, rule, i, m.cover_grid_emblem_cache, mi, db, m.formatter, m.cover_grid_template_cache)
                if icon_name is not None:
                    pixmap = self.cached_emblem(m.cover_grid_bitmap_cache, icon_name)
                    if pixmap is not None:
                        emblems.append(pixmap)
            if marked:
                emblems.insert(0, self.cached_emblem(m.cover_grid_bitmap_cache, ':marked', m.marked_icon))
            if on_device:
                emblems.insert(0, self.cached_emblem(m.cover_grid_bitmap_cache, ':ondevice'))

        painter.save()
        right_adjust = 0
        try:
            rect = option.rect
            rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
            if self.emblem_size > 0:
                self.paint_emblems(painter, rect, emblems)
            orect = QRect(rect)
            if cdata is None or cdata is False:
                title = db.field_for('title', book_id, default_value='')
                authors = ' & '.join(db.field_for('authors', book_id, default_value=()))
                painter.setRenderHint(QPainter.TextAntialiasing, True)
                painter.drawText(rect, Qt.AlignCenter|Qt.TextWordWrap, '%s\n\n%s' % (title, authors))
                if cdata is False:
                    self.render_queue.put(book_id)
            else:
                if self.title_height != 0:
                    trect = QRect(rect)
                    rect.setBottom(rect.bottom() - self.title_height)
                if self.animating is not None and self.animating.row() == index.row():
                    cdata = cdata.scaled(cdata.size() * self._animated_size)
                dpr = cdata.devicePixelRatio()
                cw, ch = int(cdata.width() / dpr), int(cdata.height() / dpr)
                dx = max(0, int((rect.width() - cw)/2.0))
                dy = max(0, rect.height() - ch)
                right_adjust = dx
                rect.adjust(dx, dy, -dx, 0)
                painter.drawPixmap(rect, cdata)
                if self.title_height != 0:
                    rect = trect
                    rect.setTop(rect.bottom() - self.title_height + 5)
                    painter.setRenderHint(QPainter.TextAntialiasing, True)
                    title, is_stars = self.render_field(db, book_id)
                    if is_stars:
                        painter.setFont(self.rating_font)
                    metrics = painter.fontMetrics()
                    painter.setPen(self.highlight_color)
                    painter.drawText(rect, Qt.AlignCenter|Qt.TextSingleLine,
                                     metrics.elidedText(title, Qt.ElideRight, rect.width()))
            if self.emblem_size > 0:
                return  # We dont draw embossed emblems as the ondevice/marked emblems are drawn in the gutter
            if marked:
                try:
                    p = self.marked_emblem
                except AttributeError:
                    p = self.marked_emblem = m.marked_icon.pixmap(48, 48)
                self.paint_embossed_emblem(p, painter, orect, right_adjust)

            if on_device:
                try:
                    p = self.on_device_emblem
                except AttributeError:
                    p = self.on_device_emblem = QIcon(I('ok.png')).pixmap(48, 48)
                self.paint_embossed_emblem(p, painter, orect, right_adjust, left=False)
        finally:
            painter.restore()
Пример #59
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.animator = SpinAnimator(self)
     self.animator.updated.connect(self.needs_redraw)
     self.color = parent.palette().color(QPalette.ColorRole.WindowText)
     self.spinner_width = 64