Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
workflow_buttons, add iconMode
Timothée Giet2db78c648457
diff --git a/plugins/python/workflow_buttons/Manual.html b/plugins/python/workflow_buttons/Manual.htmlindex d24a10e74a..6dc81d641c 100644--- a/plugins/python/workflow_buttons/Manual.html+++ b/plugins/python/workflow_buttons/Manual.html@@ -21,6 +21,7 @@<p>You can see which button is selected in the list as it is "checked" (its background color is darker). If you add an icon which covers all of the button's background, you can still see which button is selected from the "Selected button" label which indicates the number of the selected button in the list.</p><p>After creating and selecting a button, you can now:</p><ul>+ <li>Select the icon mode for the button: custom icon, tool icon, or brush preset icon.</li><li>Select an icon for the button (svg or png files). Click on the button on the left to open a file selection dialog.</li><li>Enter a tooltip text to describe your button.</li><li>Select a tool in the list. If you don't want to select any tool, select the emtpy line at the beginning of the list.</li>diff --git a/plugins/python/workflow_buttons/buttons_settings_dialog.py b/plugins/python/workflow_buttons/buttons_settings_dialog.pyindex 420d9b575f..861b7cb3b9 100644--- a/plugins/python/workflow_buttons/buttons_settings_dialog.py+++ b/plugins/python/workflow_buttons/buttons_settings_dialog.py@@ -4,7 +4,7 @@# SPDX-License-Identifier: GPL-3.0-or-laterfrom PyQt5.QtCore import QSize-from PyQt5.QtGui import QIcon+from PyQt5.QtGui import QIcon, QPixmapfrom PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QWidget, QScrollArea, QPushButton,QToolButton, QLabel, QLineEdit, QComboBox, QDialogButtonBox,QFileDialog)@@ -54,16 +54,19 @@ LISTOFTOOLS = [LISTOFSIZES = [16, 22, 32, 48, 64]+LISTOFICONMODES = [i18n("Custom icon"), i18n("Tool icon"), i18n("Brush preset icon")]+class ButtonsSettingsDialog(QDialog):def __init__(self, parent=None, buttonsContentList=[], sizeIndex=2):super().__init__(parent)self.setWindowTitle(i18n("Workflow buttons settings"))self.kritaInstance = Krita.instance()+ self.allBrushPresets = self.kritaInstance.resources('preset')mainLayout = QVBoxLayout(self)self.buttonsContentList = copy.deepcopy(buttonsContentList)- self.defaultButtonContent = { "icon" : "", "tooltip": "", "toolIndex" : 0, "presetName" : "", "FGColorValues" : { "model":"","depth":"","components":[],"profile":"" }, "BGColorValues" : { "model":"","depth":"","components":[],"profile":"" }, "script" : "" }+ self.defaultButtonContent = { "iconMode": 0, "icon" : "", "tooltip": "", "toolIndex" : 0, "presetName" : "", "FGColorValues" : { "model":"","depth":"","components":[],"profile":"" }, "BGColorValues" : { "model":"","depth":"","components":[],"profile":"" }, "script" : "" }# button ID starts at 1, 0 is no button selected when list is emptyself.selectedButtonID = 0@@ -123,18 +126,29 @@ class ButtonsSettingsDialog(QDialog):layoutForSelectorControls.addWidget(deleteButtonButton)mainLayout.addLayout(layoutForSelectorControls)- # set selected button's icon+ # set selected button's icon mode+ layoutForIconMode = QHBoxLayout()+ iconModeLabel = QLabel(i18n("Select icon mode:"), self)+ layoutForIconMode.addWidget(iconModeLabel)+ self.iconModeSelector = QComboBox(self)+ self.populateIconModeList()+ self.iconModeSelector.activated.connect(self.iconModeChanged)+ layoutForIconMode.addWidget(self.iconModeSelector)++ mainLayout.addLayout(layoutForIconMode)++ # set selected button's custom iconlayoutForIconSelection = QHBoxLayout()- addIconLabel = QLabel(i18n("Select an icon:"), self)+ addIconLabel = QLabel(i18n("Select a custom icon:"), self)layoutForIconSelection.addWidget(addIconLabel)self.iconPathInput = QLineEdit(self)- self.iconPathInput.setToolTip(i18n("Icon path"))+ self.iconPathInput.setToolTip(i18n("Custom icon path"))self.iconPathInput.editingFinished.connect(self.iconPathChanged)layoutForIconSelection.addWidget(self.iconPathInput)iconPathDialogButton = QPushButton(i18n("..."), self)- iconPathDialogButton.setToolTip(i18n("Select the icon"))+ iconPathDialogButton.setToolTip(i18n("Select the custom icon"))iconPathDialogButton.clicked.connect(self.selectIcon)layoutForIconSelection.addWidget(iconPathDialogButton)@@ -257,6 +271,12 @@ class ButtonsSettingsDialog(QDialog):self.resize(640, 360)# end of __init__+ def populateIconModeList(self):+ listIndex = -1+ for mode in LISTOFICONMODES:+ listIndex += 1+ self.iconModeSelector.insertItem(listIndex,str(LISTOFICONMODES[listIndex]))+def populateToolList(self):toolNumber = -1for tool in LISTOFTOOLS:@@ -273,7 +293,15 @@ class ButtonsSettingsDialog(QDialog):def createButton(self, buttonToCreate, buttonID):# print("create button with buttonID: " + str(buttonID))- buttonIcon = QIcon(buttonToCreate["icon"])+ if buttonToCreate["iconMode"] == 0:+ buttonIcon = QIcon(buttonToCreate["icon"])+ elif buttonToCreate["iconMode"] == 1 and buttonToCreate["toolIndex"] != 0:+ buttonIcon = self.kritaInstance.icon(LISTOFTOOLS[buttonToCreate["toolIndex"]]["toolIcon"])+ elif buttonToCreate["iconMode"] == 2 and buttonToCreate["presetName"] != "":+ brushPreset = self.allBrushPresets[buttonToCreate["presetName"]]+ buttonIcon = QIcon(QPixmap.fromImage(brushPreset.image()))+ else:+ buttonIcon = QIcon()button = CustomButtonForSettings(self.buttonsWidget, buttonID)button.setIconSize(self.globalButtonSize)button.setIcon(buttonIcon)@@ -305,6 +333,7 @@ class ButtonsSettingsDialog(QDialog):self.selectedButtonIDLabel.setText(str(self.selectedButtonID))# add a line here for new dialog fields...if self.selectedButtonID > 0:+ self.iconModeSelector.setCurrentIndex(self.buttonsContentList[self.selectedButtonID - 1]["iconMode"])self.iconPathInput.setText(self.buttonsContentList[self.selectedButtonID - 1]["icon"])self.toolTipInput.setText(self.buttonsContentList[self.selectedButtonID - 1]["tooltip"])self.toolSelector.setCurrentIndex(self.buttonsContentList[self.selectedButtonID - 1]["toolIndex"])@@ -333,6 +362,12 @@ class ButtonsSettingsDialog(QDialog):self.createButton(self.defaultButtonContent, buttonID)self.refreshButtons()+ def iconModeChanged(self, iconModeIndex):+ if self.selectedButtonID < 1:+ return+ self.buttonsContentList[self.selectedButtonID - 1]["iconMode"] = iconModeIndex+ self.refreshButtons()+def selectIcon(self):# print("select icon dialog started")if self.selectedButtonID < 1:@@ -363,6 +398,8 @@ class ButtonsSettingsDialog(QDialog):if self.selectedButtonID < 1:returnself.buttonsContentList[self.selectedButtonID - 1]["toolIndex"] = toolIndex+ if self.iconModeSelector.currentIndex() == 1:+ self.refreshButtons()def selectPreset(self):# print("select preset dialog started")@@ -388,6 +425,8 @@ class ButtonsSettingsDialog(QDialog):if self.selectedButtonID < 1:returnself.buttonsContentList[self.selectedButtonID - 1]["presetName"] = self.presetSelectorInput.text()+ if self.iconModeSelector.currentIndex() == 2:+ self.refreshButtons()def setFGColorInfoLabel(self, values):colorInfoLabel = i18n("Color info: ")@@ -474,6 +513,7 @@ class ButtonsSettingsDialog(QDialog):def clearDialogFields(self):# print("clear all dialog fields...")# add a line here for new dialog fields...+ self.iconModeSelector.setCurrentIndex(0)self.selectedButtonIDLabel.setText("0")self.iconPathInput.setText("")self.toolTipInput.setText("")diff --git a/plugins/python/workflow_buttons/workflow_buttons.py b/plugins/python/workflow_buttons/workflow_buttons.pyindex 9818b8ac53..88fd5e6486 100644--- a/plugins/python/workflow_buttons/workflow_buttons.py+++ b/plugins/python/workflow_buttons/workflow_buttons.py@@ -4,7 +4,7 @@# SPDX-License-Identifier: GPL-3.0-or-laterfrom PyQt5.QtCore import QSize-from PyQt5.QtGui import QIcon, QKeySequence+from PyQt5.QtGui import QIcon, QPixmapfrom PyQt5.QtWidgets import QWidget, QVBoxLayout, QScrollArea, QToolButton, QShortcutfrom krita import Krita, DockWidget, DockWidgetFactory, DockWidgetFactoryBase, ManagedColorfrom .flow_layout import FlowLayout@@ -71,9 +71,18 @@ class WorkflowButtons(DockWidget):def populateButtons(self):buttonID = -1+ allBrushPresets = INSTANCE.resources('preset')for buttonToCreate in self.buttonsContentList:buttonID += 1- buttonIcon = QIcon(buttonToCreate["icon"])+ if buttonToCreate["iconMode"] == 0:+ buttonIcon = QIcon(buttonToCreate["icon"])+ elif buttonToCreate["iconMode"] == 1 and buttonToCreate["toolIndex"] != 0:+ buttonIcon = INSTANCE.icon(LISTOFTOOLS[buttonToCreate["toolIndex"]]["toolIcon"])+ elif buttonToCreate["iconMode"] == 2 and buttonToCreate["presetName"] != "":+ brushPreset = allBrushPresets[buttonToCreate["presetName"]]+ buttonIcon = QIcon(QPixmap.fromImage(brushPreset.image()))+ else:+ buttonIcon = QIcon()button = CustomButton(self.buttonsWidget, buttonID, buttonToCreate)button.setIconSize(self.globalButtonSize)button.setIcon(buttonIcon)