Пример #1
1
    def paint(self, painter, option, index):
        option = QStyleOptionViewItem(option) # copy option
        self.initStyleOption(option, index)

        style = option.widget.style() if option.widget else QApplication.style()

        doc = QTextDocument()
        doc.setHtml(option.text)

        # painting item without text
        option.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, option, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        # Hilight text if item is selected
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option)
        painter.save()
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        doc.documentLayout().draw(painter, ctx)
        painter.restore()
    def paint(self, painter, option, index):
        options = QStyleOptionViewItem(option)
        item = index.data(Qt.UserRole)
        if isinstance(item, (CommentItem, ChangeItem)):
            options.decorationAlignment = Qt.AlignHCenter
        self.initStyleOption(options,index)

        if options.widget is None:
            style = QApplication.style()
        else:
            style = options.widget.style()
        
        doc = QTextDocument()
        doc.setHtml(options.text)
        
        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        # Highlighting text if item is selected
        #if (optionV4.state & QStyle::State_Selected)
            #ctx.palette.setColor(QPalette::Text, optionV4.palette.color(QPalette::Active, QPalette::HighlightedText))

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        doc.documentLayout().draw(painter, ctx)

        painter.restore()
Пример #3
0
    def paint(self, painter, option, index):
        if not index.isValid():
            return QStyledItemDelegate.paint(self, painter, option, index)
        else:
            item = index.internalPointer()

        d = item.data(index.column(), Qt.DisplayRole)
        if not d:
            d = 0

        lbl = self.mdlLabels.item(int(d), 0)
        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, self.mdlLabels.indexFromItem(lbl))

        qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)

        # Drop down indicator
        if index.isValid() and index.internalPointer().data(
                Outline.label) not in ["", None, "0", 0]:
            opt = QStyleOptionComboBox()
            opt.rect = option.rect
            r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt,
                                            QStyle.SC_ComboBoxArrow)
            option.rect = r
            qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option,
                                       painter)
Пример #4
0
 def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     for top, _, block in self._neditor.visible_blocks:
         if not self.is_foldable_block(block):
             continue
         branch_rect = QRect(0, top, self.sizeHint().width(),
                             self.sizeHint().height())
         opt = QStyleOptionViewItem()
         opt.rect = branch_rect
         opt.state = (QStyle.State_Active |
                      QStyle.State_Item |
                      QStyle.State_Children)
         folded = self.user_data(block).get("folded", default=False)
         if not folded:
             opt.state |= QStyle.State_Open
         # Draw item
         self.style().drawPrimitive(QStyle.PE_IndicatorBranch, opt,
                                    painter, self)
         # Draw folded region background
         if block == self.__mouse_over and not self.__timer.isActive():
             fm_height = self._neditor.fontMetrics().height()
             rect_height = 0
             color = self.palette().highlight().color()
             color.setAlpha(100)
             if not folded:
                 foldable_blocks = self.code_folding.foldable_blocks(block)
                 rect_height = (len(list(foldable_blocks))) * fm_height
             painter.fillRect(QRect(
                 0, top, self.sizeHint().width(),
                 rect_height + fm_height), color)
Пример #5
0
    def paint(self, painter, option, index):
        painter.save()
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)
        self.doc.setHtml(options.text)
        options.text = ""  # 原字符
        style = QApplication.style(
        ) if options.widget is None else options.widget.style()
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(
                QPalette.Text,
                option.palette.color(QPalette.Active,
                                     QPalette.HighlightedText))
        else:
            ctx.palette.setColor(
                QPalette.Text,
                option.palette.color(QPalette.Active, QPalette.Text))

        text_rect = style.subElementRect(QStyle.SE_ItemViewItemText, options)

        the_fuck_your_shit_up_constant = 3  #  ̄へ ̄ #
        margin = (option.rect.height() - options.fontMetrics.height()) // 2
        margin = margin - the_fuck_your_shit_up_constant
        text_rect.setTop(text_rect.top() + margin)

        painter.translate(text_rect.topLeft())
        painter.setClipRect(text_rect.translated(-text_rect.topLeft()))
        self.doc.documentLayout().draw(painter, ctx)

        painter.restore()
 def paintEvent(self, event):
     super().paintEvent(event)
     painter = QPainter(self)
     for top, _, block in self._neditor.visible_blocks:
         if not self.is_foldable_block(block):
             continue
         branch_rect = QRect(0, top,
                             self.sizeHint().width(),
                             self.sizeHint().height())
         opt = QStyleOptionViewItem()
         opt.rect = branch_rect
         opt.state = (QStyle.State_Active | QStyle.State_Item
                      | QStyle.State_Children)
         folded = self.user_data(block).get("folded", default=False)
         if not folded:
             opt.state |= QStyle.State_Open
         # Draw item
         self.style().drawPrimitive(QStyle.PE_IndicatorBranch, opt, painter,
                                    self)
         # Draw folded region background
         if block == self.__mouse_over and not self.__timer.isActive():
             fm_height = self._neditor.fontMetrics().height()
             rect_height = 0
             color = self.palette().highlight().color()
             color.setAlpha(100)
             if not folded:
                 foldable_blocks = self.code_folding.foldable_blocks(block)
                 rect_height = (len(list(foldable_blocks))) * fm_height
             painter.fillRect(
                 QRect(0, top,
                       self.sizeHint().width(), rect_height + fm_height),
                 color)
Пример #7
0
    def paint(self, painter, option, index):
        """Performs custom painting of value of data in the model and decorations.

         Performs custom painting of value of data in the model at the specified index
         plus any decorations used in that column.

         Args:
            painter - QPainter
            option - QStyleOptionViewItem
            index - QModelIndex
        """
        xOffset = 0
        # First added for #15, the painting of custom amount information.  This can
        # be used as a pattern for painting any column of information.
        value_painter = self._get_value_painter(index)
        self._display_text = value_painter is None
        QStyledItemDelegate.paint(self, painter, option, index)
        if value_painter is not None:
            value_option = QStyleOptionViewItem(option)
            rect = value_option.rect
            rect = QRect(rect.left(), rect.top(), rect.width() - xOffset, rect.height())
            value_option.rect = rect
            value_painter.paint(painter, value_option, index)

        decorations = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
        for dec in decorations:
            pixmap = dec.pixmap
            x = option.rect.right() - pixmap.width() - xOffset
            y = option.rect.center().y() - (pixmap.height() // 2)
            rect = QRect(x, y, pixmap.width(), pixmap.height())
            painter.drawPixmap(rect, pixmap)
            xOffset += pixmap.width()
Пример #8
0
    def paint(self, painter, option, index):
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        self.doc.setHtml(options.text)
        self.doc.setTextWidth(option.rect.width())

        options.text = ""
        style = QApplication.style() if options.widget is None else options.widget.style()
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(QPalette.Text, option.palette.color(
                    QPalette.Active, QPalette.HighlightedText))
        else:
            ctx.palette.setColor(QPalette.Text, option.palette.color(
                    QPalette.Active, QPalette.Text))

        text_rect = style.subElementRect(QStyle.SE_ItemViewItemText, options, None)

        painter.save()
        painter.translate(text_rect.topLeft())
        painter.setClipRect(text_rect.translated(-text_rect.topLeft()))
        self.doc.documentLayout().draw(painter, ctx)

        painter.restore()
Пример #9
0
    def paint(self, painter, option, index):
        """Performs custom painting of value of data in the model and decorations.

         Performs custom painting of value of data in the model at the specified index
         plus any decorations used in that column.

         Args:
            painter - QPainter
            option - QStyleOptionViewItem
            index - QModelIndex
        """
        xOffset = 0
        # First added for #15, the painting of custom amount information.  This can
        # be used as a pattern for painting any column of information.
        value_painter = self._get_value_painter(index)
        self._display_text = value_painter is None
        QStyledItemDelegate.paint(self, painter, option, index)
        if value_painter is not None:
            value_option = QStyleOptionViewItem(option)
            rect = value_option.rect
            rect = QRect(rect.left(), rect.top(), rect.width() - xOffset, rect.height())
            value_option.rect = rect
            value_painter.paint(painter, value_option, index)

        decorations = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
        for dec in decorations:
            pixmap = dec.pixmap
            x = option.rect.right() - pixmap.width() - xOffset
            y = option.rect.center().y() - (pixmap.height() // 2)
            rect = QRect(x, y, pixmap.width(), pixmap.height())
            painter.drawPixmap(rect, pixmap)
            xOffset += pixmap.width()
Пример #10
0
    def paint(self, painter, option, index):
        ##option.rect.setWidth(option.rect.width() - 18)
        # QStyledItemDelegate.paint(self, painter, option, index)
        ##option.rect.setWidth(option.rect.width() + 18)

        itemIndex = QModelIndex()
        character = self.mdlCharacter.getCharacterByID(index.data())
        if character:
            itemIndex = character.index(Character.name)

        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, itemIndex)

        qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)

        # if index.isValid() and index.internalPointer().data(Outline.POV) not in ["", None]:
        if itemIndex.isValid() and self.mdlCharacter.data(itemIndex) not in [
                "", None
        ]:
            opt = QStyleOptionComboBox()
            opt.rect = option.rect
            r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt,
                                            QStyle.SC_ComboBoxArrow)
            option.rect = r
            qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option,
                                       painter)
Пример #11
0
 def paint(self, painter: QPainter, option: QStyleOptionViewItem,
           index: QModelIndex):
     """
     Reposition the icon to the right side.
     """
     option.decorationPosition = QStyleOptionViewItem.Right
     option.decorationAlignment = Qt.AlignRight | Qt.AlignVCenter
     super(EditorDelegate, self).paint(painter, option, index)
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              index: QModelIndex):
        if self._decoration_position is not None:
            option.decorationPosition = self._decoration_position

        if self._decoration_alignment is not None:
            option.decorationAlignment = self._decoration_alignment

        super(StyleOptionModifyingDelegate, self).paint(painter, option, index)
    def paint(self, painter: QPainter, option: QStyleOptionViewItem,
              model_index: QModelIndex):
        column = model_index.column()
        new_rect = QRect(option.rect)
        if column == NAME_COL:  # Part Name
            option.displayAlignment = Qt.AlignVCenter
            QStyledItemDelegate.paint(self, painter, option, model_index)
        if column == LOCKED_COL:  # Visibility
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionButton()
            styleoption.rect = new_rect
            checked = model_index.model().data(model_index, Qt.EditRole)
            styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
            # make the check box look a little more active by changing the pallete
            styleoption.palette.setBrush(QPalette.Button, Qt.white)
            styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
            if checked:
                # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                # _QCOMMONSTYLE.drawItemText(painter, new_rect, Qt.AlignCenter, styleoption.palette, True, 'L')
                icon = QPixmap(":/outlinericons/lock")
                _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter,
                                             icon)
        if column == VISIBLE_COL:  # Visibility
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionButton()
            styleoption.rect = new_rect
            checked = model_index.model().data(model_index, Qt.EditRole)
            styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
            # make the check box look a little more active by changing the pallete
            styleoption.palette.setBrush(QPalette.Button, Qt.white)
            styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
            if checked:
                # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                icon = QPixmap(":/outlinericons/eye")
                _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter,
                                             icon)
        elif column == COLOR_COL:  # Color

            # Alternate way to get color
            # outline_tw = self.parent()
            # item = outline_tw.itemFromIndex(model_index)
            # color = item.getColor()
            # print("COLOR_COL", item)

            color = model_index.model().data(model_index, Qt.EditRole)
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionViewItem()
            brush = getBrushObj(color)
            styleoption.palette.setBrush(QPalette.Button, brush)
            styleoption.rect = new_rect
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, model_index)
Пример #14
0
    def paint(self, painter, option, index):
        hasValue = True
        if (self.m_editorPrivate):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property):
                hasValue = property.hasValue()

        opt = QStyleOptionViewItem(option)
        if ((self.m_editorPrivate and index.column() == 0) or not hasValue):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property and property.isModified()):
                opt.font.setBold(True)
                opt.fontMetrics = QFontMetrics(opt.font)

        c = QColor()
        if (not hasValue
                and self.m_editorPrivate.markPropertiesWithoutValue()):
            c = opt.palette.color(QPalette.Dark)
            opt.palette.setColor(QPalette.Text,
                                 opt.palette.color(QPalette.BrightText))
        else:
            c = self.m_editorPrivate.calculatedBackgroundColor(
                self.m_editorPrivate.indexToBrowserItem(index))
            if (c.isValid()
                    and (opt.features & QStyleOptionViewItem.Alternate)):
                c = c.lighter(112)

        if (c.isValid()):
            painter.fillRect(option.rect, c)
        opt.state &= ~QStyle.State_HasFocus

        if (index.column() == 1):
            item = self.m_editorPrivate.indexToItem(index)
            if (self.m_editedItem and (self.m_editedItem == item)):
                self.m_disablePainting = True

        super(QtPropertyEditorDelegate, self).paint(painter, opt, index)
        if (option.type):
            self.m_disablePainting = False

        opt.palette.setCurrentColorGroup(QPalette.Active)
        color = QApplication.style().styleHint(QStyle.SH_Table_GridLineColor,
                                               opt)
        painter.save()
        painter.setPen(QPen(color))
        if (not self.m_editorPrivate
                or (not self.m_editorPrivate.lastColumn(index.column())
                    and hasValue)):
            if option.direction == Qt.LeftToRight:
                right = option.rect.right()
            else:
                right = option.rect.left()
            painter.drawLine(right, option.rect.y(), right,
                             option.rect.bottom())

        painter.restore()
Пример #15
0
    def paint(self, painter, option, model_index):
        """Summary

        Args:
            painter (TYPE): Description
            option (TYPE): Description
            model_index (TYPE): Description

        Returns:
            TYPE: Description
        """
        # row = model_index.row()
        column = model_index.column()
        if column == 0:  # Part Name
            option.displayAlignment = Qt.AlignVCenter
            QStyledItemDelegate.paint(self, painter, option, model_index)
        if column == 1:  # Visibility
            value = model_index.model().data(model_index, Qt.EditRole)
            data_type = type(value)
            if data_type is str:
                # print("val", value)
                if COLOR_PATTERN.search(value):
                    # print("found color")
                    element = _QCOMMONSTYLE.PE_IndicatorCheckBox
                    styleoption = QStyleOptionViewItem()
                    styleoption.palette.setBrush(QPalette.Button,
                                                 getBrushObj(value))
                    styleoption.rect = QRect(option.rect)
                    _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                option.displayAlignment = Qt.AlignVCenter
                QStyledItemDelegate.paint(self, painter, option, model_index)
            elif data_type is int:
                option.displayAlignment = Qt.AlignVCenter
                QStyledItemDelegate.paint(self, painter, option, model_index)
            elif data_type is float:
                option.displayAlignment = Qt.AlignVCenter
                QStyledItemDelegate.paint(self, painter, option, model_index)
            elif data_type is bool:
                element = _QCOMMONSTYLE.PE_IndicatorCheckBox
                styleoption = QStyleOptionButton()
                styleoption.rect = QRect(option.rect)
                checked = value
                styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
                styleoption.palette.setBrush(QPalette.Button, Qt.white)
                styleoption.palette.setBrush(QPalette.HighlightedText,
                                             Qt.black)
                _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                if checked:
                    element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                    _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, model_index)
Пример #16
0
    def paint(self, painter, option, index):
        painter.save()

        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        self.doc.setPlainText(options.text)

        column = index.column()
        if column in self.disasm_columns:
            options.font.setWeight(QFont.Bold)
            self.highlight(self.doc, self.disasm_rules)
        elif column in self.value_columns:
            options.font.setWeight(QFont.Bold)
            self.highlight(self.doc, self.value_rules)

        self.doc.setDefaultFont(options.font)

        options.text = ""

        style = (QApplication.style()
                 if options.widget is None else options.widget.style())
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(
                QPalette.Text,
                option.palette.color(QPalette.Active,
                                     QPalette.HighlightedText),
            )
        else:
            ctx.palette.setColor(
                QPalette.Text,
                option.palette.color(QPalette.Active, QPalette.Text),
            )

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)

        if index.column() != 0:
            textRect.adjust(5, 0, 0, 0)

        the_constant = 4
        margin = (option.rect.height() - options.fontMetrics.height()) // 2
        margin = margin - the_constant
        textRect.setTop(textRect.top() + margin)

        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        self.doc.documentLayout().draw(painter, ctx)

        painter.restore()
Пример #17
0
    def paint(self, painter, opt: QtWidgets.QStyleOptionViewItem, index):
        self.drawBackground(painter, opt, index)
        self.drawFocus(painter, opt, opt.rect)
        try:
            opt.text = '{0:%d %b %H:%M}'.format(
                datetime.strptime(index.model().data(index),
                                  '%Y-%m-%d %H:%M:%S.%f'))
        except TypeError:
            pass

        opt.font.setItalic(True)
        opt.backgroundBrush = QtCore.Qt.yellow

        QtWidgets.QApplication.style().drawControl(
            QtWidgets.QStyle.CE_ItemViewItem, opt, painter)
    def paint(self, painter, option, index):
        hasValue = True
        if (self.m_editorPrivate):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property):
                hasValue = property.hasValue()

        opt = QStyleOptionViewItem(option)
        if ((self.m_editorPrivate and index.column() == 0) or not hasValue):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property and property.isModified()):
                opt.font.setBold(True)
                opt.fontMetrics = QFontMetrics(opt.font)

        c = QColor()
        if (not hasValue and self.m_editorPrivate.markPropertiesWithoutValue()):
            c = opt.palette.color(QPalette.Dark)
            opt.palette.setColor(QPalette.Text, opt.palette.color(QPalette.BrightText))
        else:
            c = self.m_editorPrivate.calculatedBackgroundColor(self.m_editorPrivate.indexToBrowserItem(index))
            if (c.isValid() and (opt.features & QStyleOptionViewItem.Alternate)):
                c = c.lighter(112)

        if (c.isValid()):
            painter.fillRect(option.rect, c)
        opt.state &= ~QStyle.State_HasFocus

        if (index.column() == 1):
            item = self.m_editorPrivate.indexToItem(index)
            if (self.m_editedItem and (self.m_editedItem == item)):
                self.m_disablePainting = True

        super(QtPropertyEditorDelegate, self).paint(painter, opt, index)
        if (option.type):
            self.m_disablePainting = False

        opt.palette.setCurrentColorGroup(QPalette.Active)
        color = QApplication.style().styleHint(QStyle.SH_Table_GridLineColor, opt)
        painter.save()
        painter.setPen(QPen(color))
        if (not self.m_editorPrivate or (not self.m_editorPrivate.lastColumn(index.column()) and hasValue)):
            if option.direction == Qt.LeftToRight:
                right = option.rect.right()
            else:
                right = option.rect.left()
            painter.drawLine(right, option.rect.y(), right, option.rect.bottom())

        painter.restore()
Пример #19
0
    def paint(self, painter, option, index):
        """Paints the amount within the bounding box provided in the option parameter.

        Draws the currency left aligned and the value of the model amount right aligned.
        Some spacing between with left and right padding is also utilized.

        Args:
            painter - QPainter
            option - QStyleOptionViewItem
            index - QModelIndex in the model
        """
        column_data = self._getDataFromIndex(index)
        if column_data is None:
            return
        option = QStyleOptionViewItem(option)
        painter.setFont(option.font)
        cur_width, val_width = self._getAmountTextWidths(column_data, option)
        font_height = option.fontMetrics.height()
        do_paint_currency = cur_width > 0
        is_selected = bool(option.state & QStyle.State_Selected)
        is_active = bool(option.state & QStyle.State_Active)
        palette_active = QPalette.Active if is_active else QPalette.Inactive
        palette_text = QPalette.HighlightedText if is_selected else QPalette.Text
        pen_color = option.palette.color(palette_active, palette_text)
        painter.setPen(pen_color)

        if do_paint_currency:
            painter.drawText(
                QRectF(4 + option.rect.left(), option.rect.top(), cur_width,
                       font_height), column_data.currency,
                QTextOption(Qt.AlignVCenter))
        painter.drawText(
            QRectF(option.rect.right() - val_width - 5, option.rect.top(),
                   val_width, font_height), column_data.value,
            QTextOption(Qt.AlignVCenter))
Пример #20
0
    def drawRow(self, painter, option, index):
        opt = QStyleOptionViewItem(option)
        hasValue = True
        if (self.m_editorPrivate):
            property = self.m_editorPrivate.indexToProperty(index)
            if (property):
                hasValue = property.hasValue()

        if (not hasValue
                and self.m_editorPrivate.markPropertiesWithoutValue()):
            c = option.palette.color(QPalette.Dark)
            painter.fillRect(option.rect, c)
            opt.palette.setColor(QPalette.AlternateBase, c)
        else:
            c = self.m_editorPrivate.calculatedBackgroundColor(
                self.m_editorPrivate.indexToBrowserItem(index))
            if (c.isValid()):
                painter.fillRect(option.rect, c)
                opt.palette.setColor(QPalette.AlternateBase, c.lighter(112))

        super(QtPropertyEditorView, self).drawRow(painter, opt, index)
        color = QApplication.style().styleHint(QStyle.SH_Table_GridLineColor,
                                               opt)
        painter.save()
        painter.setPen(QPen(QColor(color)))
        painter.drawLine(opt.rect.x(), opt.rect.bottom(), opt.rect.right(),
                         opt.rect.bottom())
        painter.restore()
Пример #21
0
    def sizeHint(self, option, index):
        """Override sizeHint of QStyledItemDelegate.

        Return the cell size based on the QTextDocument size, but might not
        work correctly yet.

        Args:
            option: const QStyleOptionViewItem & option
            index: const QModelIndex & index

        Return:
            A QSize with the recommended size.
        """
        value = index.data(Qt.SizeHintRole)
        if value is not None:
            return value
        self._opt = QStyleOptionViewItem(option)
        self.initStyleOption(self._opt, index)
        self._style = self._opt.widget.style()
        self._get_textdoc(index)
        docsize = self._doc.size().toSize()
        size = self._style.sizeFromContents(QStyle.CT_ItemViewItem, self._opt,
                                            docsize, self._opt.widget)
        qtutils.ensure_valid(size)
        return size + QSize(10, 3)
Пример #22
0
def export_tv_graph(graph_filename, scene):

    # define the bounding rectangle for pixmap for painter to paint in
    w = int(scene.width()) + 40
    h = int(scene.height()) + 40
    pixmap = QPixmap(w, h)
    painter = QPainter(pixmap)
    painter.fillRect(0,0,w,h, QColor("#f0f0f0"))

    # get a default option object.  It is neither a QStyleOptionViewItem
    # nor a QStyleOptionGraphicsItem and we don't use it, but we need something.
    option = QStyleOptionViewItem()

    # paint the annotation, texture graphs, and similarity lines
    painter.translate(20,12)
    scene.tv_g_annotation.paint(painter, option, None)
    painter.translate(0,scene.tv_g_annotation.boundingRect().height()+35)
    scene.tv_g_texture1.paint(painter, option, None)
    painter.translate(0,100)
    scene.tv_g_lines.paint(painter, option, None)
    painter.translate(0,200)
    scene.tv_g_texture2.paint(painter, option, None)
    painter.translate(0,140)
    scene.tv_g_histogram.paint(painter, option, None)
    painter.end()

    # export
    try:
        pixmap.save(graph_filename)

    except Exception as e:
        status = "Error exporting TV graph image file '%s': %s" % (
                                         graph_filename, str(e))
Пример #23
0
    def sizeHint(self, option, index):
        """
        Public method to get a size hint for the specified list item.
        
        @param option style option used for painting (QStyleOptionViewItem)
        @param index model index of the item (QModelIndex)
        @return size hint (QSize)
        """
        if not self.__rowHeight:
            opt = QStyleOptionViewItem(option)
            self.initStyleOption(opt, index)

            widget = opt.widget
            style = widget.style() if widget is not None \
                else QApplication.style()
            padding = style.pixelMetric(QStyle.PM_FocusFrameHMargin) + 1

            titleFont = opt.font
            titleFont.setBold(True)
            titleFont.setPointSize(titleFont.pointSize() + 1)

            self.__padding = padding \
                if padding > GreaseMonkeyConfigurationListDelegate.MinPadding \
                else GreaseMonkeyConfigurationListDelegate.MinPadding

            titleMetrics = QFontMetrics(titleFont)

            self.__rowHeight = 2 * self.__padding + \
                opt.fontMetrics.leading() + \
                opt.fontMetrics.height() + \
                titleMetrics.height()

        return QSize(GreaseMonkeyConfigurationListDelegate.ItemWidth,
                     self.__rowHeight)
Пример #24
0
    def paint(self, painter: QPainter, option, index):
        # reference following link
        # https://stackoverflow.com/questions/53353450/how-to-highlight-a-words-in-qtablewidget-from-a-searchlist
        # https://stackoverflow.com/questions/34623036/implementing-a-delegate-for-wordwrap-in-a-qtreeview-qt-pyside-pyqt
        painter.save()
        doc = QTextDocument(self)
        # option.palette.setColor(QPalette.HighlightedText, QColor.fromRgb(30, 136, 200))
        # remove dotted border in table
        if option.state & QStyle.State_HasFocus:
            option.state = option.state ^ QStyle.State_HasFocus
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)
        doc.setPlainText(options.text)
        # keyword = index.data(Qt.UserRole)
        # if self.keywords:
        self.keywordHighlight(doc)
        options.text = ""
        # print(dir(options.palette))

        # print(options.palette.Highlight)
        style = QApplication.style() if options.widget is None \
            else options.widget.style()
        style.drawControl(QStyle.CE_ItemViewItem, options, painter,
                          options.widget)  # for selection highlight

        ctx = QAbstractTextDocumentLayout.PaintContext()

        if index.data(Qt.UserRole) == 'reserved':
            ctx.palette.setColor(QPalette.Text, QColor.fromRgb(100, 100, 100))
            doc.setDefaultFont(
                QFont(option.font.family(),
                      option.font.pointSize() * 2 // 3))

        else:
            ctx.palette.setColor(QPalette.Text, QColor.fromRgb(217, 217, 217))
            doc.setDefaultFont(option.font)

        textRect = option.rect
        # margin = 4
        # textRect.setTop(textRect.top() + margin)
        textRect.setTop(textRect.top())
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))

        doc.setTextWidth(option.rect.width())
        doc.documentLayout().draw(painter, ctx)
        painter.restore()
Пример #25
0
    def sizeHint(self, option, index):
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        self.doc.setHtml(options.text)
        self.doc.setTextWidth(option.rect.width())

        return QSize(self.doc.idealWidth(), self.doc.size().height())
Пример #26
0
    def sizeHint(self, option, index):
        option = QStyleOptionViewItem(option)
        self.initStyleOption(option, index)
        size = QStyledItemDelegate.sizeHint(self, option, index)

        # TODO: get the default QMenu item height from the current style.
        size.setHeight(max(size.height(), 25))
        return size
Пример #27
0
 def paint(
         self,
         painter: QtGui.QPainter,
         item: QtWidgets.QStyleOptionViewItem,
         ix: QtCore.QModelIndex,
 ):
     if item.state & QtWidgets.QStyle.State_HasFocus:
         item.state = item.state ^ QtWidgets.QStyle.State_HasFocus
     super().paint(painter, item, ix)
Пример #28
0
    def sizeHint(self, option, index):
        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        doc = QtGui.QTextDocument()
        doc.setHtml(options.text)
        doc.setTextWidth(options.rect.width())

        return QtCore.QSize(doc.idealWidth() + 5, option.fontMetrics.height())
 def paint(self, painter, option, index):
     view_option = QStyleOptionViewItem(option)
     view_option.decorationAlignment |= Qt.AlignHCenter
     # Even though we told Qt that we don't want any selection on our
     # list, it still adds a blue rectangle on focused items.
     # So we just get rid of focus.
     if option.state & QStyle.State_HasFocus:
         view_option.state &= ~QStyle.State_HasFocus
     super().paint(painter, view_option, index)
Пример #30
0
 def paint(self, painter, option, index):
     view_option = QStyleOptionViewItem(option)
     view_option.decorationAlignment |= Qt.AlignHCenter
     # Qt tries to be nice and adds a lovely background color
     # on the focused item. Since we select items by rows and not
     # individually, we don't want that, so we remove the focus
     if option.state & QStyle.State_HasFocus:
         view_option.state &= ~QStyle.State_HasFocus
     super().paint(painter, view_option, index)
    def paint(self, painter: QtGui.QPainter, option: QStyleOptionViewItem,
              index: QtCore.QModelIndex) -> None:
        item_size = option.rect.size()
        custom_decoration_w, custom_decoration_h = index.data(
            SlideListModel.DecorationSizeOrRatioRole)
        if option.decorationPosition == QStyleOptionViewItem.Left:
            text_x, text_y = custom_decoration_w + self.icon_and_text_spacing, 0
            text_width = item_size.width(
            ) - custom_decoration_w - self.icon_and_text_spacing
            text_height = custom_decoration_h
        elif option.decorationPosition == QStyleOptionViewItem.Top:
            text_size = super().sizeHint(option, index)
            custom_decoration_h = custom_decoration_h - text_size.height()
            text_x, text_y = 0, custom_decoration_h + self.icon_and_text_spacing
            text_width = custom_decoration_w
            text_height = item_size.height(
            ) - custom_decoration_h - self.icon_and_text_spacing

        slide_view_params: SlideViewParams = index.data(
            SlideListModel.SlideViewParamsRole)
        scene_rect = QRectF(*slide_view_params.level_rect)
        img_key = "{}_{}_{}".format(custom_decoration_w, custom_decoration_h,
                                    slide_view_params.cache_key())
        icon_pixmap = QPixmapCache.find(img_key)
        if icon_pixmap is None:
            slide_helper = SlideHelper(slide_view_params.slide_path)
            # print("read", img_key)
            scene = QGraphicsScene()
            # t1 = elapsed()
            # print("before slide_graphics", t1)
            slide_graphics = SlideGraphicsGroup(slide_view_params)
            # t2 = elapsed()
            # print("slide_graphics", t2 - t1)
            scene.clear()
            scene.invalidate()
            scene.addItem(slide_graphics)
            slide_graphics.update_visible_level(slide_view_params.level)
            scene.setSceneRect(
                slide_helper.get_rect_for_level(slide_view_params.level))
            image = build_screenshot_image(
                scene, QSize(custom_decoration_w, custom_decoration_h),
                scene_rect)
            # t3 = elapsed()
            # print("build_screenshot_image", t3 - t2)
            icon_pixmap = QtGui.QPixmap.fromImage(image)
            QPixmapCache.insert(img_key, icon_pixmap)
        # t4 = elapsed()
        painter.fillRect(option.rect, painter.background())
        painter.drawPixmap(option.rect.topLeft(), icon_pixmap)
        # painter.drawRect(option.rect)
        painter.drawRect(option.rect.topLeft().x(),
                         option.rect.topLeft().y(), icon_pixmap.width(),
                         icon_pixmap.height())

        option.rect = option.rect.translated(text_x, text_y)
        option.rect.setSize(QSize(text_width, text_height))
        super().paint(painter, option, index)
Пример #32
0
    def paint(self, painter: QtGui.QPainter, option: 'QStyleOptionViewItem',
              index: QtCore.QModelIndex) -> None:
        viewOption = QStyleOptionViewItem(option)
        self.initStyleOption(viewOption, index)
        QStyledItemDelegate.paint(self, painter, viewOption, index)

        item = index.model().data(index, Qt.UserRole)
        if isinstance(item, QVariant):
            return

        value = item['value']
        type = item['type']
        if type == 'checkbox':
            # 数据转换
            value = True if value == 1 else 0
            # 绘制单选框
            checkBoxStyle = QStyleOptionButton()
            checkBoxStyle.state = QStyle.State_On if value else QStyle.State_Off
            checkBoxStyle.state |= QStyle.State_Enabled
            # 计算位置
            size = item['size']
            rect = calculate_middle_rect(option.rect, size, size)
            checkBoxStyle.rect = rect
            checkBox = QCheckBox()
            QApplication.style().drawPrimitive(QStyle.PE_IndicatorCheckBox,
                                               checkBoxStyle, painter,
                                               checkBox)
        if type == 'tag':
            painter.setRenderHint(QPainter.Antialiasing, True)
            painter.setRenderHints(QPainter.SmoothPixmapTransform)
            path = QPainterPath()

            # 绘制文本
            self.font = ResourceLoader().qt_font_text_tag
            text_color = item['text_color']
            border_color = item['border_color']
            text = value
            padding_v = 2
            padding_h = 4
            border_radius = 2
            border_width = 1
            painter.setFont(item['font'])
            painter.setPen(text_color)
            fm = QFontMetrics(painter.font())
            w = fm.width(text)
            h = fm.height()
            # 计算位置
            rect = calculate_middle_rect(option.rect, w + padding_h * 2,
                                         h + padding_v * 2)
            rectf = QRectF(rect.x(), rect.y(), rect.width(), rect.height())
            painter.drawText(
                QRect(rectf.x() + padding_h,
                      rectf.y() + padding_v, w, h), Qt.TextWordWrap, text)
            # 绘制边框
            path.addRoundedRect(rectf, border_radius, border_radius)
            painter.strokePath(path, QPen(border_color, border_width))
Пример #33
0
    def paint(self, painter: QPainter,
                    option: QStyleOptionViewItem,
                    model_index: QModelIndex):
        column = model_index.column()
        new_rect = QRect(option.rect)
        if column == NAME_COL:  # Part Name
            option.displayAlignment = Qt.AlignVCenter
            QStyledItemDelegate.paint(self, painter, option, model_index)
        if column == LOCKED_COL:  # Visibility
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionButton()
            styleoption.rect = new_rect
            checked = model_index.model().data(model_index, Qt.EditRole)
            styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
            # make the check box look a little more active by changing the pallete
            styleoption.palette.setBrush(QPalette.Button, Qt.white)
            styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
            if checked:
                # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                # _QCOMMONSTYLE.drawItemText(painter, new_rect, Qt.AlignCenter, styleoption.palette, True, 'L')
                icon = QPixmap(":/outlinericons/lock")
                _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon)
        if column == VISIBLE_COL:  # Visibility
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionButton()
            styleoption.rect = new_rect
            checked = model_index.model().data(model_index, Qt.EditRole)
            styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
            # make the check box look a little more active by changing the pallete
            styleoption.palette.setBrush(QPalette.Button, Qt.white)
            styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
            if checked:
                # element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                # _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
                icon = QPixmap(":/outlinericons/eye")
                _QCOMMONSTYLE.drawItemPixmap(painter, new_rect, Qt.AlignCenter, icon)
        elif column == COLOR_COL:  # Color

            # Alternate way to get color
            # outline_tw = self.parent()
            # item = outline_tw.itemFromIndex(model_index)
            # color = item.getColor()
            # print("COLOR_COL", item)

            color = model_index.model().data(model_index, Qt.EditRole)
            element = _QCOMMONSTYLE.PE_IndicatorCheckBox
            styleoption = QStyleOptionViewItem()
            brush = getBrushObj(color)
            styleoption.palette.setBrush(QPalette.Button, brush)
            styleoption.rect = new_rect
            _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
        else:
            QStyledItemDelegate.paint(self, painter, option, model_index)
Пример #34
0
    def paint(self, painter, option, index):
        if index.column() == 2:
            value = index.model().data(index, Qt.UserRole)
            if not self.isSupportedType(value):
                myOption = QStyleOptionViewItem(option)
                myOption.state &= ~QStyle.State_Enabled
                super(VariantDelegate, self).paint(painter, myOption, index)
                return

        super(VariantDelegate, self).paint(painter, option, index)
Пример #35
0
        def paint(self, painter, option, index):
            if option.widget is not None:
                style = option.widget.style()
            else:
                style = QApplication.style()

            option = QStyleOptionViewItem(option)
            option.showDecorationSelected = True

            # option.state &= ~QStyle.State_HasFocus & ~QStyle.State_MouseOver
            if self.isSeparator(index):
                opt = QStyleOption()
                opt.rect = QRect(option.rect)
                if isinstance(option.widget, QAbstractItemView):
                    opt.rect.setWidth(option.widget.viewport().width())
                style.drawPrimitive(QStyle.PE_IndicatorToolBarSeparator,
                                    opt, painter, option.widget)
            else:
                super(CheckComboBox.ComboItemDelegate, self).paint(painter, option, index)
Пример #36
0
    def paint(self, painter, option, index):
        ##option.rect.setWidth(option.rect.width() - 18)
        # QStyledItemDelegate.paint(self, painter, option, index)
        ##option.rect.setWidth(option.rect.width() + 18)

        itemIndex = QModelIndex()
        character = self.mdlCharacter.getCharacterByID(index.data())
        if character:
            itemIndex = character.index(Character.name.value)

        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, itemIndex)

        qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)

        # if index.isValid() and index.internalPointer().data(Outline.POV.value) not in ["", None]:
        if itemIndex.isValid() and self.mdlCharacter.data(itemIndex) not in ["", None]:
            opt = QStyleOptionComboBox()
            opt.rect = option.rect
            r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
            option.rect = r
            qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
Пример #37
0
    def paint(self, painter, option, index):
        ##option.rect.setWidth(option.rect.width() - 18)
        # QStyledItemDelegate.paint(self, painter, option, index)
        ##option.rect.setWidth(option.rect.width() + 18)

        item = QModelIndex()
        for i in range(self.mdlPersos.rowCount()):
            if self.mdlPersos.ID(i) == index.data():
                item = self.mdlPersos.index(i, Perso.name.value)

        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, item)

        qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)

        # if index.isValid() and index.internalPointer().data(Outline.POV.value) not in ["", None]:
        if index.isValid() and self.mdlPersos.data(index) not in ["", None]:
            opt = QStyleOptionComboBox()
            opt.rect = option.rect
            r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
            option.rect = r
            qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
Пример #38
0
 def paint(self, painter: QPainter,
                 option: QStyleOptionViewItem,
                 model_index: QModelIndex):
     """
     Args:
         painter: Description
         option: Description
         model_index: Description
     """
     # row = model_index.row()
     column = model_index.column()
     if column == 0:  # Part Name
         option.displayAlignment = Qt.AlignVCenter
         QStyledItemDelegate.paint(self, painter, option, model_index)
     if column == 1:  # Visibility
         value = model_index.model().data(model_index, Qt.EditRole)
         data_type = type(value)
         if data_type is str:
             # print("val", value)
             if COLOR_PATTERN.search(value):
                 # print("found color")
                 element = _QCOMMONSTYLE.PE_IndicatorCheckBox
                 styleoption = QStyleOptionViewItem()
                 styleoption.palette.setBrush(QPalette.Button, getBrushObj(value))
                 styleoption.rect = QRect(option.rect)
                 _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
             option.displayAlignment = Qt.AlignVCenter
             QStyledItemDelegate.paint(self, painter, option, model_index)
         elif data_type is int:
             option.displayAlignment = Qt.AlignVCenter
             QStyledItemDelegate.paint(self, painter, option, model_index)
         elif data_type is float:
             option.displayAlignment = Qt.AlignVCenter
             QStyledItemDelegate.paint(self, painter, option, model_index)
         elif data_type is bool:
             element = _QCOMMONSTYLE.PE_IndicatorCheckBox
             styleoption = QStyleOptionButton()
             styleoption.rect = QRect(option.rect)
             checked = value
             styleoption.state |= QStyle.State_On if checked else QStyle.State_Off
             styleoption.palette.setBrush(QPalette.Button, Qt.white)
             styleoption.palette.setBrush(QPalette.HighlightedText, Qt.black)
             _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
             if checked:
                 element = _QCOMMONSTYLE.PE_IndicatorMenuCheckMark
                 _QCOMMONSTYLE.drawPrimitive(element, styleoption, painter)
     else:
         QStyledItemDelegate.paint(self, painter, option, model_index)
Пример #39
0
    def paint(self, painter, option, index):
        if not index.isValid():
            return QStyledItemDelegate.paint(self, painter, option, index)
        else:
            item = index.internalPointer()

        d = item.data(index.column(), Qt.DisplayRole)
        if not d:
            d = 0

        lbl = self.mdlLabels.item(int(d), 0)
        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, self.mdlLabels.indexFromItem(lbl))

        qApp.style().drawControl(QStyle.CE_ItemViewItem, opt, painter)

        # Drop down indicator
        if index.isValid() and index.internalPointer().data(Outline.label.value) not in ["", None, "0", 0]:
            opt = QStyleOptionComboBox()
            opt.rect = option.rect
            r = qApp.style().subControlRect(QStyle.CC_ComboBox, opt, QStyle.SC_ComboBoxArrow)
            option.rect = r
            qApp.style().drawPrimitive(QStyle.PE_IndicatorArrowDown, option, painter)
Пример #40
0
    def paint(self, painter, option, index):
        """QStyledItemDelegate.paint implementation
        """
        option.state &= ~QStyle.State_HasFocus  # never draw focus rect

        option.state |= QStyle.State_Active  # draw fuzzy-open completion as focused, even if focus is on the line edit

        options = QStyleOptionViewItem(option)
        self.initStyleOption(options, index)

        style = QApplication.style() if options.widget is None else options.widget.style()

        doc = QTextDocument()
        if self._font is not None:
            doc.setDefaultFont(self._font)

        doc.setDocumentMargin(1)
        doc.setHtml(options.text)
        #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())

        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter)

        ctx = QAbstractTextDocumentLayout.PaintContext()

        # Highlighting text if item is selected
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.Text))

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        painter.setClipRect(textRect.translated(-textRect.topLeft()))
        doc.documentLayout().draw(painter, ctx)

        painter.restore()
Пример #41
0
    def paint(self, painter, option, index):
        """QStyledItemDelegate.paint implementation
        """
        option.state &= ~QStyle.State_HasFocus  # never draw focus rect

        options = QStyleOptionViewItem(option)
        self.initStyleOption(options,index)

        style = QApplication.style() if options.widget is None else options.widget.style()

        doc = QTextDocument()
        doc.setDocumentMargin(1)
        doc.setHtml(options.text)
        if options.widget is not None:
            doc.setDefaultFont(options.widget.font())
        #  bad long (multiline) strings processing doc.setTextWidth(options.rect.width())

        options.text = ""
        style.drawControl(QStyle.CE_ItemViewItem, options, painter);

        ctx = QAbstractTextDocumentLayout.PaintContext()

        # Highlighting text if item is selected
        if option.state & QStyle.State_Selected:
            ctx.palette.setColor(QPalette.Text, option.palette.color(QPalette.Active, QPalette.HighlightedText))

        textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
        painter.save()
        painter.translate(textRect.topLeft())
        """Original example contained line
            painter.setClipRect(textRect.translated(-textRect.topLeft()))
        but text is drawn clipped with it on kubuntu 12.04
        """
        doc.documentLayout().draw(painter, ctx)

        painter.restore()
Пример #42
0
    def printImage(self):
        if self.model.rowCount(QModelIndex()) * self.model.columnCount(QModelIndex()) > 90000:
            answer = QMessageBox.question(self, "Large Image Size",
                    "The printed image may be very large. Are you sure that "
                    "you want to print it?",
                    QMessageBox.Yes | QMessageBox.No)
            if answer == QMessageBox.No:
                return

        printer = QPrinter(QPrinter.HighResolution)

        dlg = QPrintDialog(printer, self)
        dlg.setWindowTitle("Print Image")

        if dlg.exec_() != QDialog.Accepted:
            return

        painter = QPainter()
        painter.begin(printer)

        rows = self.model.rowCount(QModelIndex())
        columns = self.model.columnCount(QModelIndex())
        sourceWidth = (columns+1) * ItemSize
        sourceHeight = (rows+1) * ItemSize

        painter.save()

        xscale = printer.pageRect().width() / float(sourceWidth)
        yscale = printer.pageRect().height() / float(sourceHeight)
        scale = min(xscale, yscale)

        painter.translate(printer.pageRect().x()+printer.pageRect().width()/2,
                          printer.pageRect().y()+printer.pageRect().height()/2)
        painter.scale(scale, scale)
        painter.translate(-sourceWidt/2, -sourceHeight/2)

        option = QStyleOptionViewItem()
        parent = QModelIndex()

        progress = QProgressDialog("Printing...", "Cancel", 0, rows, self)
        y = ItemSize / 2.0

        for row in range(rows):
            progress.setValue(row)
            QApplication.processEvents()
            if progress.wasCanceled():
                break

            x = ItemSize / 2.0

            for col in range(columns):
                option.rect = QRect(x, y, ItemSize, ItemSize)
                self.view.itemDelegate.paint(painter, option,
                        self.model.index(row, column, parent))
                x = x + ItemSize

            y = y + ItemSize

        progress.setValue(rows)

        painter.restore()
        painter.end()

        if progress.wasCanceled():
            QMessageBox.information(self, "Printing canceled",
                    "The printing process was canceled.", QMessageBox.Cancel)
    def paint(self, painter, option, index):
        """
        Public method to paint the specified list item.
        
        @param painter painter object to paint to (QPainter)
        @param option style option used for painting (QStyleOptionViewItem)
        @param index model index of the item (QModelIndex)
        """
        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, index)

        widget = opt.widget
        style = widget.style() if widget is not None else QApplication.style()
        height = opt.rect.height()
        center = height // 2 + opt.rect.top()

        # Prepare title font
        titleFont = QFont(opt.font)
        titleFont.setBold(True)
        titleFont.setPointSize(titleFont.pointSize() + 1)

        titleMetrics = QFontMetrics(titleFont)
        if Globals.isWindowsPlatform():
            colorRole = QPalette.Text
        else:
            colorRole = QPalette.HighlightedText if opt.state & QStyle.State_Selected else QPalette.Text

        leftPos = self.__padding
        rightPos = opt.rect.right() - self.__padding - GreaseMonkeyConfigurationListDelegate.RemoveIconSize

        # Draw background
        style.drawPrimitive(QStyle.PE_PanelItemViewItem, opt, painter, widget)

        # Draw checkbox
        checkBoxYPos = center - GreaseMonkeyConfigurationListDelegate.CheckBoxSize // 2
        opt2 = QStyleOptionViewItem(opt)
        if opt2.checkState == Qt.Checked:
            opt2.state |= QStyle.State_On
        else:
            opt2.state |= QStyle.State_Off
        styleCheckBoxRect = style.subElementRect(QStyle.SE_ViewItemCheckIndicator, opt2, widget)
        opt2.rect = QRect(leftPos, checkBoxYPos, styleCheckBoxRect.width(), styleCheckBoxRect.height())
        style.drawPrimitive(QStyle.PE_IndicatorViewItemCheck, opt2, painter, widget)
        leftPos = opt2.rect.right() + self.__padding

        # Draw icon
        iconYPos = center - GreaseMonkeyConfigurationListDelegate.IconSize // 2
        iconRect = QRect(
            leftPos,
            iconYPos,
            GreaseMonkeyConfigurationListDelegate.IconSize,
            GreaseMonkeyConfigurationListDelegate.IconSize,
        )
        pixmap = index.data(Qt.DecorationRole).pixmap(GreaseMonkeyConfigurationListDelegate.IconSize)
        painter.drawPixmap(iconRect, pixmap)
        leftPos = iconRect.right() + self.__padding

        # Draw script name
        name = index.data(Qt.DisplayRole)
        leftTitleEdge = leftPos + 2
        rightTitleEdge = rightPos - self.__padding
        leftPosForVersion = titleMetrics.width(name) + self.__padding
        nameRect = QRect(
            leftTitleEdge, opt.rect.top() + self.__padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()
        )
        painter.setFont(titleFont)
        style.drawItemText(painter, nameRect, Qt.AlignLeft, opt.palette, True, name, colorRole)

        # Draw version
        version = index.data(Qt.UserRole)
        versionRect = QRect(
            nameRect.x() + leftPosForVersion, nameRect.y(), rightTitleEdge - leftTitleEdge, titleMetrics.height()
        )
        versionFont = titleFont
        painter.setFont(versionFont)
        style.drawItemText(painter, versionRect, Qt.AlignLeft, opt.palette, True, version, colorRole)

        # Draw description
        infoYPos = nameRect.bottom() + opt.fontMetrics.leading()
        infoRect = QRect(nameRect.x(), infoYPos, nameRect.width(), opt.fontMetrics.height())
        info = opt.fontMetrics.elidedText(index.data(Qt.UserRole + 1), Qt.ElideRight, infoRect.width())
        painter.setFont(opt.font)
        style.drawItemText(painter, infoRect, Qt.AlignLeft | Qt.TextSingleLine, opt.palette, True, info, colorRole)

        # Draw remove button
        removeIconYPos = center - GreaseMonkeyConfigurationListDelegate.RemoveIconSize // 2
        removeIconRect = QRect(
            rightPos,
            removeIconYPos,
            GreaseMonkeyConfigurationListDelegate.RemoveIconSize,
            GreaseMonkeyConfigurationListDelegate.RemoveIconSize,
        )
        painter.drawPixmap(removeIconRect, self.__removePixmap)
Пример #44
0
    def paint(self, painter, option, index):

        item = index.internalPointer()
        colors = outlineItemColors(item)

        style = qApp.style()

        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, index)

        iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt)
        textRect = style.subElementRect(style.SE_ItemViewItemText, opt)

        # Background
        style.drawPrimitive(style.PE_PanelItemViewItem, opt, painter)

        if settings.viewSettings["Outline"]["Background"] != "Nothing" and not opt.state & QStyle.State_Selected:

            col = colors[settings.viewSettings["Outline"]["Background"]]

            if col != QColor(Qt.transparent):
                col2 = QColor(Qt.white)
                if opt.state & QStyle.State_Selected:
                    col2 = opt.palette.brush(QPalette.Normal, QPalette.Highlight).color()
                col = mixColors(col, col2, .2)

            painter.save()
            painter.setBrush(col)
            painter.setPen(Qt.NoPen)

            rect = opt.rect
            if self._view:
                r2 = self._view.visualRect(index)
                rect = self._view.viewport().rect()
                rect.setLeft(r2.left())
                rect.setTop(r2.top())
                rect.setBottom(r2.bottom())

            painter.drawRoundedRect(rect, 5, 5)
            painter.restore()

        # Icon
        mode = QIcon.Normal
        if not opt.state & QStyle.State_Enabled:
            mode = QIcon.Disabled
        elif opt.state & QStyle.State_Selected:
            mode = QIcon.Selected
        state = QIcon.On if opt.state & QStyle.State_Open else QIcon.Off
        icon = opt.icon.pixmap(iconRect.size(), mode=mode, state=state)
        if opt.icon and settings.viewSettings["Outline"]["Icon"] != "Nothing":
            color = colors[settings.viewSettings["Outline"]["Icon"]]
            colorifyPixmap(icon, color)
        opt.icon = QIcon(icon)
        opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state)

        # Text
        if opt.text:
            painter.save()
            if settings.viewSettings["Outline"]["Text"] != "Nothing":
                col = colors[settings.viewSettings["Outline"]["Text"]]
                if col == Qt.transparent:
                    col = Qt.black
                painter.setPen(col)
            f = QFont(opt.font)
            painter.setFont(f)
            fm = QFontMetrics(f)
            elidedText = fm.elidedText(opt.text, Qt.ElideRight, textRect.width())
            painter.drawText(textRect, Qt.AlignLeft, elidedText)

            painter.restore()
Пример #45
0
    def paint(self, painter, option, index):

        item = index.internalPointer()
        colors = outlineItemColors(item)

        style = qApp.style()

        opt = QStyleOptionViewItem(option)
        self.initStyleOption(opt, index)

        iconRect = style.subElementRect(style.SE_ItemViewItemDecoration, opt)
        textRect = style.subElementRect(style.SE_ItemViewItemText, opt)

        # Background
        style.drawPrimitive(style.PE_PanelItemViewItem, opt, painter)

        if settings.viewSettings["Tree"]["Background"] != "Nothing" and not opt.state & QStyle.State_Selected:

            col = colors[settings.viewSettings["Tree"]["Background"]]

            if col != QColor(Qt.transparent):
                col2 = QColor(Qt.white)
                if opt.state & QStyle.State_Selected:
                    col2 = opt.palette.brush(QPalette.Normal, QPalette.Highlight).color()
                col = mixColors(col, col2, .2)

            painter.save()
            painter.setBrush(col)
            painter.setPen(Qt.NoPen)

            rect = opt.rect
            if self._view:
                r2 = self._view.visualRect(index)
                rect = self._view.viewport().rect()
                rect.setLeft(r2.left())
                rect.setTop(r2.top())
                rect.setBottom(r2.bottom())

            painter.drawRoundedRect(rect, 5, 5)
            painter.restore()

        # Icon
        mode = QIcon.Normal
        if not opt.state & QStyle.State_Enabled:
            mode = QIcon.Disabled
        elif opt.state & QStyle.State_Selected:
            mode = QIcon.Selected
        state = QIcon.On if opt.state & QStyle.State_Open else QIcon.Off
        icon = opt.icon.pixmap(iconRect.size(), mode=mode, state=state)
        if opt.icon and settings.viewSettings["Tree"]["Icon"] != "Nothing":
            color = colors[settings.viewSettings["Tree"]["Icon"]]
            colorifyPixmap(icon, color)
        opt.icon = QIcon(icon)
        opt.icon.paint(painter, iconRect, opt.decorationAlignment, mode, state)

        # Text
        if opt.text:
            painter.save()
            if settings.viewSettings["Tree"]["Text"] != "Nothing":
                col = colors[settings.viewSettings["Tree"]["Text"]]
                if col == Qt.transparent:
                    col = Qt.black
                painter.setPen(col)
            f = QFont(opt.font)
            painter.setFont(f)
            fm = QFontMetrics(f)
            elidedText = fm.elidedText(opt.text, Qt.ElideRight, textRect.width())
            painter.drawText(textRect, Qt.AlignLeft, elidedText)

            extraText = ""
            if item.isFolder() and settings.viewSettings["Tree"]["InfoFolder"] != "Nothing":
                if settings.viewSettings["Tree"]["InfoFolder"] == "Count":
                    extraText = item.childCount()
                    extraText = " [{}]".format(extraText)
                elif settings.viewSettings["Tree"]["InfoFolder"] == "WC":
                    extraText = item.data(Outline.wordCount.value)
                    extraText = " ({})".format(extraText)
                elif settings.viewSettings["Tree"]["InfoFolder"] == "Progress":
                    extraText = int(toFloat(item.data(Outline.goalPercentage.value)) * 100)
                    if extraText:
                        extraText = " ({}%)".format(extraText)
                elif settings.viewSettings["Tree"]["InfoFolder"] == "Summary":
                    extraText = item.data(Outline.summarySentance.value)
                    if extraText:
                        extraText = " - {}".format(extraText)

            if item.isText() and settings.viewSettings["Tree"]["InfoText"] != "Nothing":
                if settings.viewSettings["Tree"]["InfoText"] == "WC":
                    extraText = item.data(Outline.wordCount.value)
                    extraText = " ({})".format(extraText)
                elif settings.viewSettings["Tree"]["InfoText"] == "Progress":
                    extraText = int(toFloat(item.data(Outline.goalPercentage.value)) * 100)
                    if extraText:
                        extraText = " ({}%)".format(extraText)
                elif settings.viewSettings["Tree"]["InfoText"] == "Summary":
                    extraText = item.data(Outline.summarySentance.value)
                    if extraText:
                        extraText = " - {}".format(extraText)


            if extraText:
                r = QRect(textRect)
                r.setLeft(r.left() + fm.width(opt.text + " "))

                painter.save()
                f = painter.font()
                f.setWeight(QFont.Normal)
                painter.setFont(f)
                painter.setPen(Qt.darkGray)
                painter.drawText(r, Qt.AlignLeft | Qt.AlignBottom, extraText)
                painter.restore()

            painter.restore()