Exemple #1
0
 def paint(self, painter, option, index):
     item = index.data(Qt.UserRole).toPyObject()
     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()
Exemple #2
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     text, positions = index.data(Qt.UserRole).toPyObject()
     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()
Exemple #3
0
 def paint(self, painter, option, index):
     # If we are looking at a method then draw a button
     # http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview?p=128623#post128623
     if not hasattr(self, "blue_button"):
         self.blue_button = QPushButton()
         self.blue_button.setStyleSheet("color: rgb(0, 0, 196)")
     if index.isValid() and \
             isinstance(index.internalPointer().data, Method):
         item = index.internalPointer()
         opt = QStyleOptionButton()
         style = QApplication.style()
         # If method is running, draw sunken
         if item.argvalue:
             opt.state |= QStyle.State_Enabled
             opt.state |= QStyle.State_Sunken
         # if method is allowed, draw blue
         elif self.method_allowed(item):
             opt.state |= QStyle.State_Enabled
             style = self.blue_button.style()
         # if we are hovering, draw highlight
         if option.state & QStyle.State_MouseOver:
             opt.state |= QStyle.State_MouseOver
         opt.rect = option.rect
         opt.text = index.internalPointer().name
         style.drawControl(QStyle.CE_PushButton, opt, painter,
                           self.blue_button)
     else:
         if option.state & QStyle.State_Selected:
             # Don't show delegates as highlighted
             option.state = option.state ^ QStyle.State_Selected
         QStyledItemDelegate.paint(self, painter, option, index)
Exemple #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
 def __init__(self, parent, db, sep, items_func_name, col, space_before_sep=False):
     QStyledItemDelegate.__init__(self, parent)
     self.db = db
     self.sep = sep
     self.items_func_name = items_func_name
     self.col = col
     self.space_before_sep = space_before_sep
 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).toString())))
             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)
Exemple #7
0
 def paint(self, painter, option, index):
     item = index.data(Qt.UserRole).toPyObject()
     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()
Exemple #8
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     text, positions = index.data(Qt.UserRole).toPyObject()
     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()
Exemple #9
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()
 def paint(self, painter, option, index):
     # If we are looking at a method then draw a button
     # http://www.qtcentre.org/threads/26916-inserting-custom-Widget-to-listview?p=128623#post128623
     if self.is_method_button(index):
         item = index.internalPointer()
         opt = QStyleOptionButton()
         style = QApplication.style()
         # If method is running, draw sunken
         if item.get_state() == item.RUNNING:
             opt.state |= QStyle.State_Enabled
             opt.state |= QStyle.State_Sunken
         # if method is allowed, draw blue
         elif item.get_writeable():
             opt.state |= QStyle.State_Enabled
         # if we are hovering, draw highlight
         if option.state & QStyle.State_MouseOver:
             opt.state |= QStyle.State_MouseOver
         opt.rect = option.rect
         opt.text = item.get_label()
         style.drawControl(QStyle.CE_PushButton, opt, painter, QPushButton())
     else:
         if option.state & QStyle.State_Selected:
             # Don't show delegates as highlighted
             option.state = option.state ^ QStyle.State_Selected
         QStyledItemDelegate.paint(self, painter, option, index)
Exemple #11
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())
     painter.save()
     painter.setClipRect(QRectF(option.rect))
     painter.translate(option.rect.topLeft())
     self.to_doc(index, option).drawContents(painter)
     painter.restore()
Exemple #12
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
Exemple #13
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
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())
     painter.save()
     try:
         self.do_paint(painter, option, index)
     except:
         pass
     painter.restore()
Exemple #15
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
Exemple #16
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)
Exemple #17
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
Exemple #18
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
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())
     painter.save()
     try:
         self.do_paint(painter, option, index)
     except:
         pass
     painter.restore()
Exemple #20
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)
Exemple #21
0
 def editorEvent(self, event, model, option, index):
     if index.isValid() and isinstance(index.internalPointer().data, Method):
         # TODO: Drag seems to do the wrong thing here...
         if event.type() in [QEvent.MouseButtonPress,
                             QEvent.MouseButtonDblClick]:
             if self.method_allowed(index.internalPointer()):
                 model.setData(index, 0)
             return True
     QStyledItemDelegate.editorEvent(self, event, model, option, index)
Exemple #22
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     style = QApplication.style()
     waiting = self.timer.isActive() and index.data(Qt.UserRole).toBool()
     if waiting:
         rect = QRect(0, 0, self.spinner_width, self.spinner_width)
         rect.moveCenter(option.rect.center())
         self.draw_spinner(painter, rect)
     else:
         # Ensure the cover is rendered over any selection rect
         style.drawItemPixmap(painter, option.rect, Qt.AlignTop|Qt.AlignHCenter,
             QPixmap(index.data(Qt.DecorationRole)))
Exemple #23
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     style = QApplication.style()
     waiting = self.timer.isActive() and index.data(Qt.UserRole).toBool()
     if waiting:
         rect = QRect(0, 0, self.spinner_width, self.spinner_width)
         rect.moveCenter(option.rect.center())
         self.draw_spinner(painter, rect)
     else:
         # Ensure the cover is rendered over any selection rect
         style.drawItemPixmap(painter, option.rect, Qt.AlignTop|Qt.AlignHCenter,
             QPixmap(index.data(Qt.DecorationRole)))
Exemple #24
0
 def __init__(self,
              parent,
              db,
              sep,
              items_func_name,
              col,
              space_before_sep=False):
     QStyledItemDelegate.__init__(self, parent)
     self.db = db
     self.sep = sep
     self.items_func_name = items_func_name
     self.col = col
     self.space_before_sep = space_before_sep
Exemple #25
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     charcode, ok = index.data(Qt.UserRole).toInt()
     if not ok:
         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()
Exemple #26
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, index)
     charcode, ok = index.data(Qt.UserRole).toInt()
     if not ok:
         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()
Exemple #27
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())  # 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()
     db = db.new_api
     cdata = self.cover_cache[book_id]
     painter.save()
     try:
         rect = option.rect
         rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
         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:
                 orect = 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)
             dx = max(0, int((rect.width() - cdata.width())/2.0))
             dy = max(0, rect.height() - cdata.height())
             rect.adjust(dx, dy, -dx, 0)
             painter.drawPixmap(rect, cdata)
             if self.title_height != 0:
                 rect = orect
                 rect.setTop(rect.bottom() - self.title_height + 5)
                 painter.setRenderHint(QPainter.TextAntialiasing, True)
                 title = db.field_for('title', book_id, default_value='')
                 metrics = painter.fontMetrics()
                 painter.drawText(rect, Qt.AlignCenter|Qt.TextSingleLine,
                                  metrics.elidedText(title, Qt.ElideRight, rect.width()))
     finally:
         painter.restore()
Exemple #28
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
 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
 def editorEvent(self, event, model, option, index):
     if self.is_method_button(index):
         # TODO: Drag seems to do the wrong thing here...
         if event.type() in [QEvent.MouseButtonPress,
                             QEvent.MouseButtonDblClick]:
             return model.setData(index, None)
     return QStyledItemDelegate.editorEvent(self, event, model, option, index)
Exemple #31
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).toString())
        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:
                cover.loadFromData(raw)
                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(
                            width,
                            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() - cover.width()) / 2.0))
                dy = max(0, rect.height() - cover.height())
                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()
Exemple #32
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:
             suffix = NBSP + human_readable(current_container().filesize(unicode(index.data(NAME_ROLE).toString())))
         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)
Exemple #33
0
 def setEditorData(self, editor, index):
     if isinstance(editor, QComboBox):
         i = editor.findText(index.data(Qt.EditRole).toString())
         if i > -1:
             editor.setCurrentIndex(i)
         else:
             editor.setEditText(index.data(Qt.EditRole).toString())
         editor.lineEdit().selectAll()
     else:
         return QStyledItemDelegate.setEditorData(self, editor, index)
 def setEditorData(self, editor, index):
     if isinstance(editor, QComboBox):
         i = editor.findText(index.data(Qt.EditRole).toString())
         if i > -1:
             editor.setCurrentIndex(i)
         else:
             editor.setEditText(index.data(Qt.EditRole).toString())
         editor.lineEdit().selectAll()
     else:
         return QStyledItemDelegate.setEditorData(self, editor, 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).toString())
        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:
                cover.loadFromData(raw)
                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(
                            width, 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() - cover.width()) / 2.0))
                dy = max(0, rect.height() - cover.height())
                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()
Exemple #36
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
Exemple #37
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(
         self, painter, option,
         QModelIndex())  # 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)
     painter.save()
     right_adjust = 0
     try:
         rect = option.rect
         rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
         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)
             dx = max(0, int((rect.width() - cdata.width()) / 2.0))
             dy = max(0, rect.height() - cdata.height())
             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 = self.render_field(db, book_id)
                 metrics = painter.fontMetrics()
                 painter.setPen(self.highlight_color)
                 painter.drawText(
                     rect, Qt.AlignCenter | Qt.TextSingleLine,
                     metrics.elidedText(title, Qt.ElideRight, rect.width()))
         if marked:
             try:
                 p = self.marked_emblem
             except AttributeError:
                 p = self.marked_emblem = m.marked_icon.pixmap(48, 48)
             drect = QRect(orect)
             drect.setLeft(drect.left() + right_adjust)
             drect.setRight(drect.left() + p.width())
             drect.setBottom(drect.bottom() - self.title_height)
             drect.setTop(drect.bottom() - p.height())
             painter.drawPixmap(drect, p)
         if on_device:
             try:
                 p = self.on_device_emblem
             except AttributeError:
                 p = self.on_device_emblem = QPixmap(I('ok.png')).scaled(
                     48, 48, transformMode=Qt.SmoothTransformation)
             drect = QRect(orect)
             drect.setRight(drect.right() - right_adjust)
             drect.setBottom(drect.bottom() - self.title_height)
             drect.setTop(drect.bottom() - p.height() + 1)
             drect.setLeft(drect.right() - p.width() + 1)
             painter.drawPixmap(drect, p)
     finally:
         painter.restore()
Exemple #38
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)
Exemple #39
0
 def sizeHint(self, option, index):
     option.font = self.rf
     option.textElideMode = self.em
     return QStyledItemDelegate.sizeHint(self, option, index)
Exemple #40
0
 def initStyleOption(self, option, index):
     QStyledItemDelegate.initStyleOption(self, option, index)
     top_level = not index.parent().isValid()
     if top_level:
         option.decorationSize = QSize(TOP_ICON_SIZE, TOP_ICON_SIZE)
 def setModelData(self, editor, model, index):
     if isinstance(editor, MultiCompleteComboBox):
         val = editor.lineEdit().text()
         model.setData(index, QVariant(val), Qt.EditRole)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Exemple #42
0
 def __init__(self, parent=None, max_width=160):
     QStyledItemDelegate.__init__(self, parent)
     self.max_width = max_width
Exemple #43
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
 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
Exemple #45
0
 def __init__(self, parent):
     QStyledItemDelegate.__init__(self, parent)
     self.document = QTextDocument()
Exemple #46
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
Exemple #47
0
 def sizeHint(self, *args):
     ans = QStyledItemDelegate.sizeHint(self, *args)
     ans.setHeight(ans.height() + 4)
     return ans
Exemple #48
0
 def sizeHint(self, *args):
     ans = QStyledItemDelegate.sizeHint(self, *args)
     ans.setHeight(ans.height() + 4)
     return ans
Exemple #49
0
 def paint(self, painter, option, index):
     QStyledItemDelegate.paint(self, painter, option, QModelIndex())  # 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)
     painter.save()
     right_adjust = 0
     try:
         rect = option.rect
         rect.adjust(self.MARGIN, self.MARGIN, -self.MARGIN, -self.MARGIN)
         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)
             dx = max(0, int((rect.width() - cdata.width())/2.0))
             dy = max(0, rect.height() - cdata.height())
             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 = db.field_for('title', book_id, default_value='')
                 metrics = painter.fontMetrics()
                 painter.drawText(rect, Qt.AlignCenter|Qt.TextSingleLine,
                                  metrics.elidedText(title, Qt.ElideRight, rect.width()))
         if marked:
             try:
                 p = self.marked_emblem
             except AttributeError:
                 p = self.marked_emblem = QPixmap(I('rating.png')).scaled(48, 48, transformMode=Qt.SmoothTransformation)
             drect = QRect(orect)
             drect.setLeft(drect.left() + right_adjust)
             drect.setRight(drect.left() + p.width())
             drect.setBottom(drect.bottom() - self.title_height)
             drect.setTop(drect.bottom() - p.height())
             painter.drawPixmap(drect, p)
         if on_device:
             try:
                 p = self.on_device_emblem
             except AttributeError:
                 p = self.on_device_emblem = QPixmap(I('ok.png')).scaled(48, 48, transformMode=Qt.SmoothTransformation)
             drect = QRect(orect)
             drect.setRight(drect.right() - right_adjust)
             drect.setBottom(drect.bottom() - self.title_height)
             drect.setTop(drect.bottom() - p.height() + 1)
             drect.setLeft(drect.right() - p.width() + 1)
             painter.drawPixmap(drect, p)
     finally:
         painter.restore()
Exemple #50
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.old_look = gprefs['tag_browser_old_look']
Exemple #51
0
 def __init__(self, parent):
     '''
     Delegate for custom_column bool data.
     '''
     QStyledItemDelegate.__init__(self, parent)
Exemple #52
0
 def setModelData(self, editor, model, index):
     if isinstance(editor, MultiCompleteComboBox):
         val = editor.lineEdit().text()
         model.setData(index, QVariant(val), Qt.EditRole)
     else:
         QStyledItemDelegate.setModelData(self, editor, model, index)
Exemple #53
0
 def __init__(self, *args, **kwargs):
     QStyledItemDelegate.__init__(self, *args, **kwargs)
     self.format = tweaks['gui_pubdate_display_format']
     if self.format is None:
         self.format = 'MMM yyyy'
Exemple #54
0
 def __init__(self, parent=None):
     QStyledItemDelegate.__init__(self, parent)
     self.editing_index = None
     self.closeEditor.connect(self.editing_done)
 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
Exemple #56
0
 def sizeHint(self, option, index):
     ans = QStyledItemDelegate.sizeHint(self, option, index)
     ans.setHeight(ans.height() + 10)
     return ans
Exemple #57
0
 def sizeHint(self, *args):
     ans = QStyledItemDelegate.sizeHint(self, *args)
     return ans + QSize(0, 10)
Exemple #58
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)