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()
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()
def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) style = QApplication.style() # Ensure the cover is rendered over any selection rect style.drawItemPixmap(painter, option.rect, Qt.AlignTop | Qt.AlignHCenter, QPixmap(index.data(Qt.DecorationRole)))
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, empty_index) 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()
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)
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()
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()
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()
def paint(self, painter, option, index): QStyledItemDelegate.paint( self, painter, option, empty_index) # draw the hover and selection highlights name = unicode_type(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()
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 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)
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()
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()
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 = p.HighlightedText if option.state & QStyle.StateFlag.State_Selected else p.Text group = (p.Active if option.state & QStyle.StateFlag.State_Active else p.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()
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)))
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)))
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()
def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) result = index.data(Qt.UserRole) painter.save() 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) painter.setPen(c) try: painter.drawStaticText(option.rect.topLeft(), result.static_text) except Exception: import traceback traceback.print_exc() painter.restore()
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)
def paint(self, painter, option, index): icon = index.data(Qt.ItemDataRole.DecorationRole) if icon and not icon.isNull(): QStyledItemDelegate.paint(self, painter, option, QModelIndex()) pw, ph = option.rect.width(), option.rect.height() scaled, w, h = fit_image(option.decorationSize.width(), option.decorationSize.height(), pw, ph) r = option.rect if pw > w: x = (pw - w) // 2 r = r.adjusted(x, 0, -x, 0) if ph > h: y = (ph - h) // 2 r = r.adjusted(0, y, 0, -y) painter.drawPixmap(r, icon.pixmap(w, h)) else: QStyledItemDelegate.paint(self, painter, option, index)
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()
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)
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)
def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) result = index.data(Qt.UserRole) painter.save() 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) painter.setPen(c) height = result.static_text.size().height() tl = option.rect.topLeft() x, y = tl.x(), tl.y() y += (option.rect.height() - height) // 2 if result.is_hidden: x += option.decorationSize.width() + 4 try: painter.drawStaticText(x, y, result.static_text) except Exception: import traceback traceback.print_exc() painter.restore()
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()
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()
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) trect = QRect(rect) if self.title_height != 0: rect.setBottom(rect.bottom() - self.title_height) trect.setTop(trect.bottom() - self.title_height + 5) 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) if self.title_height != 0: self.paint_title(painter, trect, db, book_id) else: 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: self.paint_title(painter, trect, db, book_id) 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()
def paint(self, painter, option, index): option.font = self.rf option.textElideMode = self.em return QStyledItemDelegate.paint(self, painter, option, index)
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)
def paint(self, painter, option, index): QStyledItemDelegate.paint(self, painter, option, index) style = QApplication.style() # Ensure the cover is rendered over any selection rect style.drawItemPixmap(painter, option.rect, Qt.AlignTop|Qt.AlignHCenter, QPixmap(index.data(Qt.DecorationRole)))
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()