Exemplo n.º 1
0
    def paint(self, painter, option, index):
        """
        Paint performs low-level painting for the item.

        :type painter: QtWidgets.QPainter
        :type option: QtWidgets.QStyleOptionViewItem
        :type index: QtCore.QModelIndex
        :rtype: None
        """
        self.setRect(QtCore.QRect(option.rect))

        painter.save()

        try:
            self.paintBackground(painter, option, index)

            if self.isTextVisible():
                self.paintText(painter, option, index)

            self.paintIcon(painter, option, index)

            if index.column() == 0:
                if self.imageSequence():
                    self.paintPlayhead(painter, option)
        finally:
            painter.restore()
Exemplo n.º 2
0
 def dragPixmap(self, item, items):
     """
     Show the drag pixmap for the given item.
     
     :type item: recordwidgetitem.RecordWidgetItem
     :rtype: QtGui.QPixmap
     """
     rect = self.visualRect(self.indexFromItem(item))
     pixmap = QtGui.QPixmap()
     pixmap = pixmap.grabWidget(self, rect)
     if len(items) > 1:
         cWidth = 35
         cPadding = 5
         cText = str(len(items))
         cX = pixmap.rect().center().x() - float(cWidth / 2)
         cY = pixmap.rect().top() + cPadding
         cRect = QtCore.QRect(cX, cY, cWidth, cWidth)
         painter = QtGui.QPainter(pixmap)
         painter.setRenderHint(QtGui.QPainter.Antialiasing)
         painter.setPen(QtCore.Qt.NoPen)
         painter.setBrush(self.combinedWidget().backgroundSelectedColor())
         painter.drawEllipse(cRect.center(), float(cWidth / 2), float(cWidth / 2))
         font = QtGui.QFont('Serif', 12, QtGui.QFont.Light)
         painter.setFont(font)
         painter.setPen(self.combinedWidget().textSelectedColor())
         painter.drawText(cRect, QtCore.Qt.AlignCenter, str(cText))
     return pixmap
Exemplo n.º 3
0
 def paintIcon(self, painter, option, index, align=None):
     """
     Draw the icon for the item.
     
     :type painter: QtWidgets.QPainter
     :type option: QtWidgets.QStyleOptionViewItem
     :rtype: None
     """
     column = index.column()
     pixmap = self.pixmap(column)
     if not pixmap:
         return
     rect = self.iconRect(option)
     pixmap = pixmap.scaled(rect.width(), rect.height(),
                            QtCore.Qt.KeepAspectRatio,
                            QtCore.Qt.SmoothTransformation)
     pixmapRect = QtCore.QRect(rect)
     pixmapRect.setWidth(pixmap.width())
     pixmapRect.setHeight(pixmap.height())
     align = QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter
     x, y = (0, 0)
     isAlignBottom = align == QtCore.Qt.AlignBottom | QtCore.Qt.AlignLeft or align == QtCore.Qt.AlignBottom | QtCore.Qt.AlignHCenter or align == QtCore.Qt.AlignBottom | QtCore.Qt.AlignRight
     isAlignHCenter = align == QtCore.Qt.AlignHCenter or align == QtCore.Qt.AlignCenter or align == QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom or align == QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop
     isAlignVCenter = align == QtCore.Qt.AlignVCenter or align == QtCore.Qt.AlignCenter or align == QtCore.Qt.AlignVCenter | QtCore.Qt.AlignLeft or align == QtCore.Qt.AlignVCenter | QtCore.Qt.AlignRight
     if isAlignHCenter:
         x += float(rect.width() - pixmap.width()) / 2
     if isAlignVCenter:
         y += float(rect.height() - pixmap.height()) / 2
     elif isAlignBottom:
         y += float(rect.height() - pixmap.height())
     pixmapRect.translate(x, y)
     painter.drawPixmap(pixmapRect, pixmap)
Exemplo n.º 4
0
    def visualRect(self, option):
        """
        Return the visual rect for the item.

        :type option: QtWidgets.QStyleOptionViewItem
        :rtype: QtCore.QRect
        """
        rect = QtCore.QRect(option.rect)
        return rect
Exemplo n.º 5
0
 def typeIconRect(self, option):
     """
     :rtype: QtGui.QRect
     """
     padding = 2 * self.dpi()
     r = self.iconRect(option)
     x = r.x() + padding
     y = r.y() + padding
     rect = QtCore.QRect(x, y, 13 * self.dpi(), 13 * self.dpi())
     return rect
Exemplo n.º 6
0
    def visualRect(self, option):
        """
        Return the visual rect for the item.

        :type option: QtWidgets.QStyleOptionViewItem
        :rtype: QtCore.QRect
        """
        rect = QtCore.QRect(option.rect)
        rect.setX(10 * self.dpi())
        rect.setWidth(self.sizeHint().width())
        return rect
Exemplo n.º 7
0
 def visualRect(self, option):
     """
     Return the visual rect for the item.
     
     :type option: QtWidgets.QStyleOptionViewItem
     :rtype: QtCore.QRect
     """
     width = self.combinedWidget().width() - 20
     rect = QtCore.QRect(option.rect)
     rect.setWidth(width)
     return rect
Exemplo n.º 8
0
    def rubberBandMoveEvent(self, event):
        """
        Triggered when the user moves the mouse over the current viewport.

        :type event: QtWidgets.QMouseEvent
        :rtype: None
        """
        if self.rubberBand() and self._rubberBandStartPos:
            rect = QtCore.QRect(self._rubberBandStartPos, event.pos())
            rect = rect.normalized()
            self.rubberBand().setGeometry(rect)
Exemplo n.º 9
0
 def rubberBandStartEvent(self, event):
     """
     Triggered when the user presses an empty area.
     
     :type event: QtWidgets.QMouseEvent
     :rtype: None
     """
     self._rubberBandStartPos = event.pos()
     rect = QtCore.QRect(self._rubberBandStartPos, QtCore.QSize())
     rubberBand = self.rubberBand()
     rubberBand.setGeometry(rect)
     rubberBand.show()
Exemplo n.º 10
0
Arquivo: icon.py Projeto: jonntd/mira
 def setColor(self, color, size = None):
     """
     :type color: QtGui.QColor
     :rtype: None
     """
     icon = self
     size = size or icon.actualSize(QtCore.QSize(256, 256))
     pixmap = icon.pixmap(size)
     rect = QtCore.QRect(0, 0, size.width(), size.height())
     if not self.isNull():
         painter = QtGui.QPainter(pixmap)
         painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceIn)
         painter.setBrush(color)
         painter.setPen(color)
         painter.drawRect(pixmap.rect())
         painter.end()
     icon = QtGui.QIcon(pixmap)
     self.swap(icon)
Exemplo n.º 11
0
    def drawIconBorder(self, painter, pixmapRect):
        """
        Draw a border around the icon.

        :type painter: QtWidgets.QPainter
        :type pixmapRect: QtWidgets.QRect
        :rtype: None
        """
        pixmapRect = QtCore.QRect(pixmapRect)
        pixmapRect.setX(pixmapRect.x() - 5)
        pixmapRect.setY(pixmapRect.y() - 5)
        pixmapRect.setWidth(pixmapRect.width() + 5)
        pixmapRect.setHeight(pixmapRect.height() + 5)

        color = QtGui.QColor(255, 255, 255, 10)
        painter.setPen(QtGui.QPen(QtCore.Qt.NoPen))
        painter.setBrush(QtGui.QBrush(color))

        painter.drawRect(pixmapRect)