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 __init__(self, item, *args): QtWidgets.QWidget.__init__(self, *args) studioqt.loadUi(self) self._item = item pixmap = studioqt.Pixmap(item.thumbnailPath()) pixmap.setColor('rgb(255,255,255,20)') self.ui.thumbnailLabel.setPixmap(pixmap) self._infoWidget = studiolibrary.widgets.OptionsWidget(self) self._infoWidget.setTitle("INFO") self._infoWidget.setTitleVisible(True) self._infoWidget.setOptions(item.info()) self._infoWidget.stateChanged.connect(self._stateChanged) self.ui.infoFrame.layout().addWidget(self._infoWidget) self._optionsWidget = studiolibrary.widgets.OptionsWidget(self) self._optionsWidget.setTitle("OPTIONS") self._optionsWidget.stateChanged.connect(self._stateChanged) options = item.loadOptions() if options: self._optionsWidget.setOptions(options) self._optionsWidget.setTitleVisible(True) self.ui.optionsFrame.layout().addWidget(self._optionsWidget) self.ui.acceptButton.hide() self.ui.acceptButton.setText("Load") self.ui.acceptButton.clicked.connect(self.accept) self.loadSettings()
def pixmap(self, name, scope='icons', extension='png', color=None): """ :type name: str :type extension: str :rtype: QtGui.QPixmap """ path = self.get(scope, name + '.' + extension) pixmap = studioqt.Pixmap(path) if color: pixmap.setColor(color) return pixmap
def pixmap(self): """ :rtype: QtGui.QPixmap """ if not self.isIconVisible(): return studiolibrary.resource().pixmap('') color = self.color() iconPath = self.iconPath() self._pixmap = studioqt.Pixmap(iconPath) if color: self._pixmap.setColor(color) return self._pixmap
def __init__(self, item, *args): QtWidgets.QWidget.__init__(self, *args) studioqt.loadUi(self) pixmap = studioqt.Pixmap(item.thumbnailPath()) pixmap.setColor('rgb(255,255,255,20)') self.ui.thumbnailLabel.setPixmap(pixmap) self._optionsWidget = studiolibrary.widgets.OptionsWidget(self) self.ui.optionsFrame.layout().addWidget(self._optionsWidget) self._optionsWidget.setOptions(item.options())
def pixmap(self, name, scope="icons", extension="png", color=None): """ :type name: str :type extension: str :rtype: QtWidgets.QPixmap """ path = self.get(scope, name + "." + extension) pixmap = studioqt.Pixmap(path) if color: pixmap.setColor(color) return pixmap
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 updateIcon(self): """ Force the icon to update. :rtype: None """ path = self.iconPath() if not path: if self.isExpanded(): path = self.expandedIconPath() else: path = self.collapsedIconPath() color = self.iconColor() pixmap = studioqt.Pixmap(path) pixmap.setColor(color) self.setIcon(0, pixmap)
def fa(cls, path, **kwargs): """ Create a new icon with the given path, options and state. Example: icon = studioqt.Icon.fa( path, color="rgb(255,255,255)" color_disabled="rgb(0,200,200,20)", ) :type path: str :type kwargs: dict :rtype: studioqt.Icon """ color = kwargs.get('color', QtGui.QColor(0, 0, 0)) pixmap = studioqt.Pixmap(path) pixmap.setColor(color) valid_options = [ 'active', 'selected', 'disabled', 'on', 'off', 'on_active', 'on_selected', 'on_disabled', 'off_active', 'off_selected', 'off_disabled', 'color', 'color_on', 'color_off', 'color_active', 'color_selected', 'color_disabled', 'color_on_selected', 'color_on_active', 'color_on_disabled', 'color_off_selected', 'color_off_active', 'color_off_disabled', ] default = { "on_active": kwargs.get("active", studioqt.Pixmap(path)), "off_active": kwargs.get("active", studioqt.Pixmap(path)), "on_disabled": kwargs.get("disabled", studioqt.Pixmap(path)), "off_disabled": kwargs.get("disabled", studioqt.Pixmap(path)), "on_selected": kwargs.get("selected", studioqt.Pixmap(path)), "off_selected": kwargs.get("selected", studioqt.Pixmap(path)), "color_on_active": kwargs.get("color_active", color), "color_off_active": kwargs.get("color_active", color), "color_on_disabled": kwargs.get("color_disabled", color), "color_off_disabled": kwargs.get("color_disabled", color), "color_on_selected": kwargs.get("color_selected", color), "color_off_selected": kwargs.get("color_selected", color), } default.update(kwargs) kwargs = copy.copy(default) for option in valid_options: if 'color' in option: kwargs[option] = kwargs.get(option, color) else: svg_path = kwargs.get(option, path) kwargs[option] = studioqt.Pixmap(svg_path) options = { QtGui.QIcon.On: { QtGui.QIcon.Normal: (kwargs['color_on'], kwargs['on']), QtGui.QIcon.Active: (kwargs['color_on_active'], kwargs['on_active']), QtGui.QIcon.Disabled: (kwargs['color_on_disabled'], kwargs['on_disabled']), QtGui.QIcon.Selected: (kwargs['color_on_selected'], kwargs['on_selected']) }, QtGui.QIcon.Off: { QtGui.QIcon.Normal: (kwargs['color_off'], kwargs['off']), QtGui.QIcon.Active: (kwargs['color_off_active'], kwargs['off_active']), QtGui.QIcon.Disabled: (kwargs['color_off_disabled'], kwargs['off_disabled']), QtGui.QIcon.Selected: (kwargs['color_off_selected'], kwargs['off_selected']) } } icon = cls(pixmap) for state in options: for mode in options[state]: color, pixmap = options[state][mode] pixmap = studioqt.Pixmap(pixmap) pixmap.setColor(color) icon.addPixmap(pixmap, mode, state) return icon