def setBadge(self, x, y, w, h, color=None): """ Set a for the icon. :type x: int :type y: int :type w: int :type h: int :type color: QtGui.QColor or None """ color = color or QtGui.QColor(240, 100, 100) size = self.actualSize(QtCore.QSize(256, 256)) pixmap = self.pixmap(size) painter = QtGui.QPainter(pixmap) pen = QtGui.QPen(color) pen.setWidth(0) painter.setPen(pen) painter.setBrush(color) painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.drawEllipse(x, y, w, h) painter.end() icon = QtGui.QIcon(pixmap) self.swap(icon)
def paintEvent(self, event): """ Triggered on frame changed. :type event: QtCore.QEvent :rtype: None """ QtWidgets.QToolButton.paintEvent(self, event) painter = QtGui.QPainter() painter.begin(self) if self.currentFilename() and self._imageSequence.frameCount() > 1: r = event.rect() playheadHeight = self.playheadHeight() playheadPosition = self._imageSequence.percent() * r.width()-1 x = r.x() y = self.height() - playheadHeight painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtGui.QBrush(self.DEFAULT_PLAYHEAD_COLOR)) painter.drawRect(x, y, playheadPosition, playheadHeight) painter.end()
def thumbnailIcon(self): """ Overriding this method add support for dynamic icon colors. :rtype: QtGui.QIcon """ customPath = self.customIconPath() if customPath and "/" not in customPath and "\\" not in customPath: customPath = studiolibrary.resource.get("icons", customPath) color = self.iconColor() if not color: color = self.DEFAULT_ICON_COLOR key = customPath + color icon = self._THUMBNAIL_ICON_CACHE.get(key) if not icon: color1 = studioqt.Color.fromString(color) pixmap1 = studioqt.Pixmap(self.THUMBNAIL_PATH) pixmap1.setColor(color1) pixmap1 = pixmap1.scaled( 128, 128, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation ) color2 = studioqt.Color.fromString("rgb(255,255,255,150)") pixmap2 = studioqt.Pixmap(customPath) pixmap2.setColor(color2) pixmap2 = pixmap2.scaled( 64, 64, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation ) x = (128 - pixmap2.width()) / 2 y = (128 - pixmap2.height()) / 2 painter = QtGui.QPainter(pixmap1) painter.drawPixmap(x, y+5, pixmap2) painter.end() icon = studioqt.Icon(pixmap1) self._THUMBNAIL_ICON_CACHE[key] = icon return self._THUMBNAIL_ICON_CACHE.get(key)
def setColor(self, color): """ :type color: QtGui.QColor :rtype: None """ if isinstance(color, basestring): color = studioqt.Color.fromString(color) if not self.isNull(): painter = QtGui.QPainter(self) painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceIn) painter.setBrush(color) painter.setPen(color) painter.drawRect(self.rect()) painter.end()
def createPixmap(self, path, color): """ Create a new Pixmap from the given path. :type path: str :type color: str or QtCore.QColor :rtype: QtCore.QPixmap """ dpi = self.treeWidget().dpi() key = path + color + "DPI-" + str(dpi) pixmap = self.PIXMAP_CACHE.get(key) if not pixmap: width = 20 * dpi height = 18 * dpi if "/" not in path and "\\" not in path: path = studiolibrary.resource.get("icons", path) if not os.path.exists(path): path = self.defaultIconPath() pixmap2 = studioqt.Pixmap(path) pixmap2.setColor(color) pixmap2 = pixmap2.scaled( 16 * dpi, 16 * dpi, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation ) x = (width - pixmap2.width()) / 2 y = (height - pixmap2.height()) / 2 pixmap = QtGui.QPixmap(QtCore.QSize(width, height)) pixmap.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pixmap) painter.drawPixmap(x, y, pixmap2) painter.end() self.PIXMAP_CACHE[key] = pixmap return pixmap
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) 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)
def dragPixmap(self, item, items): """ Show the drag pixmap for the given item. :type item: studioqt.Item :type items: list[studioqt.Item] :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.itemsWidget().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.itemsWidget().textSelectedColor()) painter.drawText(cRect, QtCore.Qt.AlignCenter, str(cText)) return pixmap