Exemple #1
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)
 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)
    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()
 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)
    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)
    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)
Exemple #7
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)
Exemple #8
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()
    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)
    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)
    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)
    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)
Exemple #13
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(-sourceWidth / 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 column 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)
Exemple #14
0
    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)
    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)
Exemple #16
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)