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, move settings button to the bottom of the docker
Timothée Giet08da195a4b78
diff --git a/plugins/python/workflow_buttons/Manual.html b/plugins/python/workflow_buttons/Manual.htmlindex 6dc81d641c..65c2105794 100644--- a/plugins/python/workflow_buttons/Manual.html+++ b/plugins/python/workflow_buttons/Manual.html@@ -30,7 +30,7 @@<li>Select a background color. Same as for the foreground color...</li><li>Select a script file. Click on the button on the left to open a file selection dialog. To deselect the script, erase the content of the corresponding text field.</li></ul>-<p>There is also an option to select the buttons size. By default it is set to 32 pixels, but you can set it smaller or bigger.</p>+<p>There are also two global options. The first one is to select the buttons size. By default it is set to 32 pixels, but you can set it smaller or bigger. The second option is to selecte the settings button position. By default it is placed separately in the bottom bar of the docker, but you can instead make it appear at the start of the main buttons list (this can be useful to optimize the docker size as it removes the extra height of the bottom bar).</p><p>Finally, to save all your changes, click on the OK button. If you want to discard all your changes, click on the Cancel button.</p></body></html>diff --git a/plugins/python/workflow_buttons/buttons_settings_dialog.py b/plugins/python/workflow_buttons/buttons_settings_dialog.pyindex 861b7cb3b9..83df3072af 100644--- a/plugins/python/workflow_buttons/buttons_settings_dialog.py+++ b/plugins/python/workflow_buttons/buttons_settings_dialog.py@@ -7,7 +7,7 @@ from PyQt5.QtCore import QSizefrom PyQt5.QtGui import QIcon, QPixmapfrom PyQt5.QtWidgets import (QDialog, QVBoxLayout, QHBoxLayout, QWidget, QScrollArea, QPushButton,QToolButton, QLabel, QLineEdit, QComboBox, QDialogButtonBox,- QFileDialog)+ QFileDialog, QFrame)from krita import Krita, PresetChooserfrom .flow_layout import FlowLayoutimport copy@@ -57,7 +57,7 @@ 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):+ def __init__(self, parent=None, buttonsContentList=[], sizeIndex=2, settingsButtonPosition=0):super().__init__(parent)self.setWindowTitle(i18n("Workflow buttons settings"))self.kritaInstance = Krita.instance()@@ -86,6 +86,8 @@ class ButtonsSettingsDialog(QDialog):self.sizeIndex = sizeIndexself.globalButtonSize = QSize(LISTOFSIZES[self.sizeIndex], LISTOFSIZES[self.sizeIndex])+ self.settingsButtonPosition = settingsButtonPosition+layoutForSelectorControls = QHBoxLayout()controlsSize = QSize(22,22)@@ -247,19 +249,37 @@ class ButtonsSettingsDialog(QDialog):mainLayout.addLayout(layoutForScriptSelection)- # add bottom buttons- layoutForBottom = QHBoxLayout()+ # spacer for global controls+ spacerLine = QFrame(self)+ spacerLine.setFrameShape(QFrame.HLine)+ spacerLine.setFrameShadow(QFrame.Sunken)+ mainLayout.addWidget(spacerLine)# button's size selector+ layoutForButtonsSize = QHBoxLayout()buttonsSizeLabel = QLabel(i18n("Buttons size:"), self)self.buttonsSizeSelector = QComboBox(self)self.populateSizeList()self.buttonsSizeSelector.setCurrentIndex(self.sizeIndex)self.buttonsSizeSelector.activated.connect(self.buttonsSizeChanged)- layoutForBottom.addWidget(buttonsSizeLabel)- layoutForBottom.addWidget(self.buttonsSizeSelector)+ layoutForButtonsSize.addWidget(buttonsSizeLabel)+ layoutForButtonsSize.addWidget(self.buttonsSizeSelector)+ mainLayout.addLayout(layoutForButtonsSize)++ # layout for settings button position option+ layoutForSettingsButtonOption = QHBoxLayout()+ settingsButtonOptionLabel = QLabel(i18n("Settings button position:"), self)+ self.settingsButtonPositionSelector = QComboBox(self)+ self.settingsButtonPositionSelector.insertItem(0, i18n("Bottom bar"))+ self.settingsButtonPositionSelector.insertItem(1, i18n("Inline"))+ self.settingsButtonPositionSelector.setCurrentIndex(self.settingsButtonPosition)+ self.settingsButtonPositionSelector.activated.connect(self.settingsButtonPositionChanged)+ layoutForSettingsButtonOption.addWidget(settingsButtonOptionLabel)+ layoutForSettingsButtonOption.addWidget(self.settingsButtonPositionSelector)+ mainLayout.addLayout(layoutForSettingsButtonOption)# main dialog's default buttons+ layoutForBottom = QHBoxLayout()buttonBox = QDialogButtonBox(self)buttonBox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel)buttonBox.accepted.connect(self.accept)@@ -561,6 +581,11 @@ class ButtonsSettingsDialog(QDialog):if self.selectedButtonID > 0:self.refreshButtons()+ def settingsButtonPositionChanged(self, position):+ # print("settings button position changed")+ self.settingsButtonPosition = position++class CustomButtonForSettings(QToolButton):# Class to define the custom buttons inside the dialogdef __init__(self, parent=None, buttonID=-1):diff --git a/plugins/python/workflow_buttons/workflow_buttons.py b/plugins/python/workflow_buttons/workflow_buttons.pyindex 88fd5e6486..0383f5120e 100644--- a/plugins/python/workflow_buttons/workflow_buttons.py+++ b/plugins/python/workflow_buttons/workflow_buttons.py@@ -5,7 +5,7 @@from PyQt5.QtCore import QSizefrom PyQt5.QtGui import QIcon, QPixmap-from PyQt5.QtWidgets import QWidget, QVBoxLayout, QScrollArea, QToolButton, QShortcut+from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QScrollArea, QToolButton, QPushButton, QToolBar, QAction, QSizePolicyfrom krita import Krita, DockWidget, DockWidgetFactory, DockWidgetFactoryBase, ManagedColorfrom .flow_layout import FlowLayoutfrom .buttons_settings_dialog import LISTOFTOOLS, LISTOFSIZES, ButtonsSettingsDialog@@ -21,11 +21,14 @@ class WorkflowButtons(DockWidget):self.setWindowTitle(DOCKER_NAME)self.sizeIndex = 2self.globalButtonSize = QSize(LISTOFSIZES[self.sizeIndex], LISTOFSIZES[self.sizeIndex])+ self.settingsButtonPosition = 0# all widget and layout setup of the dockermainWidget = QWidget(self)self.setWidget(mainWidget)mainLayout = QVBoxLayout(mainWidget)+ mainLayout.setSpacing(2)+ mainLayout.setContentsMargins(0, 0, 0, 0)buttonsScrollArea = QScrollArea(mainWidget)buttonsScrollArea.setMinimumSize(self.globalButtonSize)@@ -34,18 +37,39 @@ class WorkflowButtons(DockWidget):buttonsScrollArea.setWidget(self.buttonsWidget)mainLayout.addWidget(buttonsScrollArea)- self.buttonsLayout = FlowLayout(self.buttonsWidget)- # Edit button setup+ self.buttonsLayout = FlowLayout(self.buttonsWidget)+ self.buttonsLayout.setSpacing(2)+ self.buttonsLayout.setContentsMargins(0, 0, 0, 0)++ self.bottomLayout = QHBoxLayout()+ self.bottomLayout.setSpacing(2)+ self.bottomLayout.setContentsMargins(0, 0, 0, 0)+ mainLayout.addLayout(self.bottomLayout)++ self.bottomBar = QToolBar(self)+ self.bottomBar.setIconSize(QSize(22,22))+ self.bottomBar.setStyleSheet("QToolBar{spacing:0px; margins:0px;}")+ barSpacer = QWidget(self.bottomBar)+ barSpacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)+ self.bottomBar.addWidget(barSpacer)+ self.bottomLayout.addWidget(self.bottomBar)++ self.settingsAction = QAction(self)+ self.settingsAction.setIcon(INSTANCE.icon('view-choose-22'))+ self.settingsAction.setToolTip(i18n("Open workflow buttons settings dialog"))+ self.settingsAction.triggered.connect(self.openSettingsDialog)+ self.bottomBar.addAction(self.settingsAction)++ # Inline edit button setupself.editButton = QToolButton(self.buttonsWidget)self.editButton.setIconSize(self.globalButtonSize)- self.editButton.setIcon(INSTANCE.icon('properties'))- self.editButton.setToolTip(i18n("Open workflow buttons settings dialog"))- self.editButton.clicked.connect(self.openSettingsDialog)+ self.editButton.setDefaultAction(self.settingsAction)self.buttonsLayout.addWidget(self.editButton)self.buttonsContentList = []self.readSettings()+ self.refreshSettingsButtonPosition()self.populateButtons()def canvasChanged(self, canvas):@@ -59,10 +83,22 @@ class WorkflowButtons(DockWidget):savedList = Application.readSetting("workflowbuttons", "buttons", "")if savedList:self.buttonsContentList = ast.literal_eval(savedList)+ savedSettingsButtonPosition = Application.readSetting("workflowbuttons", "settingsButtonPosition", "")+ if savedSettingsButtonPosition:+ self.settingsButtonPosition = int(savedSettingsButtonPosition)def writeSettings(self):Application.writeSetting("workflowbuttons", "buttonsSize", str(self.sizeIndex))Application.writeSetting("workflowbuttons", "buttons", str(self.buttonsContentList))+ Application.writeSetting("workflowbuttons", "settingsButtonPosition", str(self.settingsButtonPosition))++ def refreshSettingsButtonPosition(self):+ if self.settingsButtonPosition == 0:+ self.bottomBar.setVisible(True)+ self.editButton.setVisible(False)+ elif self.settingsButtonPosition == 1:+ self.bottomBar.setVisible(False)+ self.editButton.setVisible(True)def clearButtons(self):for widget in self.buttonsWidget.children():@@ -93,11 +129,13 @@ class WorkflowButtons(DockWidget):self.populateButtons()def openSettingsDialog(self):- newDialog = ButtonsSettingsDialog(self, self.buttonsContentList, self.sizeIndex)+ newDialog = ButtonsSettingsDialog(self, self.buttonsContentList, self.sizeIndex, self.settingsButtonPosition)newDialog.exec_()if newDialog.result() == 1:self.buttonsContentList = newDialog.buttonsContentListself.sizeIndex = newDialog.sizeIndex+ self.settingsButtonPosition = newDialog.settingsButtonPosition+ self.refreshSettingsButtonPosition()self.refreshButtonsSize()self.writeSettings()self.refreshButtons()