Пример #1
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()
Пример #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()
Пример #3
0
 def copy_to_clipboard(self, *args):
     d = QTextDocument()
     d.setHtml(self.msg_label.text())
     QApplication.clipboard().setText(
         u'calibre, version %s (%s, isfrozen: %s)\n%s: %s\n\n%s' %
         (__version__, sys.platform, isfrozen, unicode(self.windowTitle()),
          unicode(d.toPlainText()), unicode(self.det_msg.toPlainText())))
     if hasattr(self, 'ctc_button'):
         self.ctc_button.setText(_('Copied'))
Пример #4
0
 def copy_to_clipboard(self, *args):
     d = QTextDocument()
     d.setHtml(self.msg_label.text())
     QApplication.clipboard().setText(
             u'calibre, version %s (%s, isfrozen: %s)\n%s: %s\n\n%s' %
             (__version__, sys.platform, isfrozen,
                 unicode(self.windowTitle()), unicode(d.toPlainText()),
                 unicode(self.det_msg.toPlainText())))
     if hasattr(self, 'ctc_button'):
         self.ctc_button.setText(_('Copied'))
Пример #5
0
 def to_doc(self, index, option=None):
     doc = QTextDocument()
     if option is not None and option.state & QStyle.State_Selected:
         p = option.palette
         group = p.Active if option.state & QStyle.State_Active else p.Inactive
         c = p.color(group, p.HighlightedText)
         c = "rgb(%d, %d, %d)" % c.getRgb()[:3]
         doc.setDefaultStyleSheet(" * { color: %s }" % c)
     doc.setHtml(index.data().toString())
     return doc
Пример #6
0
 def to_doc(self, index, option=None):
     doc = QTextDocument()
     if option is not None and option.state & QStyle.State_Selected:
         p = option.palette
         group = (p.Active if option.state
                  & QStyle.State_Active else p.Inactive)
         c = p.color(group, p.HighlightedText)
         c = 'rgb(%d, %d, %d)' % c.getRgb()[:3]
         doc.setDefaultStyleSheet(' * { color: %s }' % c)
     doc.setHtml(index.data().toString())
     return doc
Пример #7
0
 def to_doc(self, index):
     data = index.data(Qt.UserRole).toPyObject()
     if data is None:
         html = _('<b>This shortcut no longer exists</b>')
     elif data.is_shortcut:
         shortcut = data.data
         # Shortcut
         keys = [unicode(k.toString(k.NativeText)) for k in shortcut['keys']]
         if not keys:
             keys = _('None')
         else:
             keys = ', '.join(keys)
         html = '<b>%s</b><br>%s: %s'%(shortcut['name'], _('Shortcuts'), keys)
     else:
         # Group
         html = '<h3>%s</h3>'%data.data
     doc =  QTextDocument()
     doc.setHtml(html)
     return doc
Пример #8
0
 def to_doc(self, index):
     data = index.data(Qt.UserRole).toPyObject()
     if data is None:
         html = _("<b>This shortcut no longer exists</b>")
     elif data.is_shortcut:
         shortcut = data.data
         # Shortcut
         keys = [unicode(k.toString(k.NativeText)) for k in shortcut["keys"]]
         if not keys:
             keys = _("None")
         else:
             keys = ", ".join(keys)
         html = "<b>%s</b><br>%s: %s" % (shortcut["name"], _("Shortcuts"), keys)
     else:
         # Group
         html = "<h3>%s</h3>" % data.data
     doc = QTextDocument()
     doc.setHtml(html)
     return doc
Пример #9
0
class CcCommentsDelegate(QStyledItemDelegate):  # {{{
    '''
    Delegate for comments data.
    '''
    def __init__(self, parent):
        QStyledItemDelegate.__init__(self, parent)
        self.document = QTextDocument()

    def paint(self, painter, option, index):
        self.initStyleOption(option, index)
        style = QApplication.style() if option.widget is None \
                                                else option.widget.style()
        self.document.setHtml(option.text)
        option.text = u''
        if hasattr(QStyle, 'CE_ItemViewItem'):
            style.drawControl(QStyle.CE_ItemViewItem, option, painter)
        ctx = QAbstractTextDocumentLayout.PaintContext()
        ctx.palette = option.palette  # .setColor(QPalette.Text, QColor("red"));
        if hasattr(QStyle, 'SE_ItemViewItemText'):
            textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
            painter.save()
            painter.translate(textRect.topLeft())
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
            self.document.documentLayout().draw(painter, ctx)
            painter.restore()

    def createEditor(self, parent, option, index):
        m = index.model()
        col = m.column_map[index.column()]
        text = m.db.data[index.row()][m.custom_columns[col]['rec_index']]
        editor = CommentsDialog(parent,
                                text,
                                column_name=m.custom_columns[col]['name'])
        d = editor.exec_()
        if d:
            m.setData(index, QVariant(editor.textbox.html), Qt.EditRole)
        return None

    def setModelData(self, editor, model, index):
        model.setData(index, QVariant(editor.textbox.html), Qt.EditRole)
Пример #10
0
class CcCommentsDelegate(QStyledItemDelegate):  # {{{
    '''
    Delegate for comments data.
    '''

    def __init__(self, parent):
        QStyledItemDelegate.__init__(self, parent)
        self.document = QTextDocument()

    def paint(self, painter, option, index):
        self.initStyleOption(option, index)
        style = QApplication.style() if option.widget is None \
                                                else option.widget.style()
        self.document.setHtml(option.text)
        option.text = u''
        if hasattr(QStyle, 'CE_ItemViewItem'):
            style.drawControl(QStyle.CE_ItemViewItem, option, painter)
        ctx = QAbstractTextDocumentLayout.PaintContext()
        ctx.palette = option.palette  # .setColor(QPalette.Text, QColor("red"));
        if hasattr(QStyle, 'SE_ItemViewItemText'):
            textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
            painter.save()
            painter.translate(textRect.topLeft())
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
            self.document.documentLayout().draw(painter, ctx)
            painter.restore()

    def createEditor(self, parent, option, index):
        m = index.model()
        col = m.column_map[index.column()]
        text = m.db.data[index.row()][m.custom_columns[col]['rec_index']]
        editor = CommentsDialog(parent, text)
        d = editor.exec_()
        if d:
            m.setData(index, QVariant(editor.textbox.html), Qt.EditRole)
        return None

    def setModelData(self, editor, model, index):
        model.setData(index, QVariant(editor.textbox.html), Qt.EditRole)
Пример #11
0
 def to_doc(self, index):
     data = index.data(Qt.UserRole).toPyObject()
     if data is None:
         html = _('<b>This shortcut no longer exists</b>')
     elif data.is_shortcut:
         shortcut = data.data
         # Shortcut
         keys = [
             unicode(k.toString(k.NativeText)) for k in shortcut['keys']
         ]
         if not keys:
             keys = _('None')
         else:
             keys = ', '.join(keys)
         html = '<b>%s</b><br>%s: %s' % (shortcut['name'], _('Shortcuts'),
                                         keys)
     else:
         # Group
         html = '<h3>%s</h3>' % data.data
     doc = QTextDocument()
     doc.setHtml(html)
     return doc
Пример #12
0
 def to_doc(self, index):
     doc = QTextDocument()
     doc.setHtml(index.data().toString())
     return doc