File indexing completed on 2024-12-22 04:16:28
0001 # SPDX-License-Identifier: CC0-1.0 0002 0003 from PyQt5.QtCore import Qt 0004 from PyQt5.QtGui import QPixmap, QIcon 0005 from PyQt5.QtWidgets import (QDialogButtonBox, QLabel, QVBoxLayout, 0006 QHBoxLayout, QCheckBox) 0007 from . import tenbrushesdialog, dropbutton 0008 import krita 0009 0010 0011 class UITenBrushes(object): 0012 0013 def __init__(self): 0014 self.kritaInstance = krita.Krita.instance() 0015 self.mainDialog = tenbrushesdialog.TenBrushesDialog( 0016 self, self.kritaInstance.activeWindow().qwindow()) 0017 0018 self.buttonBox = QDialogButtonBox(self.mainDialog) 0019 self.vbox = QVBoxLayout(self.mainDialog) 0020 self.hbox = QHBoxLayout(self.mainDialog) 0021 0022 self.checkBoxActivatePrev = QCheckBox( 0023 i18n("&Activate previous brush preset when pressing the shortcut for the " 0024 "second time"), 0025 self.mainDialog) 0026 0027 self.checkBoxAutoBrush = QCheckBox( 0028 i18n("&Select freehand brush tool when pressing a shortcut"), 0029 self.mainDialog) 0030 0031 self.buttonBox.accepted.connect(self.mainDialog.accept) 0032 self.buttonBox.rejected.connect(self.mainDialog.reject) 0033 0034 self.buttonBox.setOrientation(Qt.Horizontal) 0035 self.buttonBox.setStandardButtons( 0036 QDialogButtonBox.Ok | QDialogButtonBox.Cancel) 0037 0038 self.presetChooser = krita.PresetChooser(self.mainDialog) 0039 0040 def initialize(self, tenbrushes): 0041 self.tenbrushes = tenbrushes 0042 0043 self.loadButtons() 0044 0045 self.vbox.addLayout(self.hbox) 0046 self.vbox.addWidget( 0047 QLabel(i18n("Select the brush preset, then click on the button " 0048 "you want to use to select the preset."))) 0049 self.vbox.addWidget( 0050 QLabel(i18n("Shortcuts are configurable through the <i>Keyboard Shortcuts</i> " 0051 "interface in Krita's settings."))) 0052 0053 self.vbox.addWidget(self.presetChooser) 0054 0055 self.checkBoxActivatePrev.setChecked(self.tenbrushes.activatePrev) 0056 self.checkBoxActivatePrev.toggled.connect(self.setActivatePrev) 0057 self.vbox.addWidget(self.checkBoxActivatePrev) 0058 0059 self.checkBoxAutoBrush.setChecked(self.tenbrushes.autoBrush) 0060 self.checkBoxAutoBrush.toggled.connect(self.setAutoBrush) 0061 self.vbox.addWidget(self.checkBoxAutoBrush) 0062 0063 self.vbox.addWidget(self.buttonBox) 0064 0065 self.mainDialog.show() 0066 self.mainDialog.activateWindow() 0067 self.mainDialog.exec_() 0068 0069 def setActivatePrev(self, checked): 0070 self.tenbrushes.activatePrev = checked 0071 0072 def setAutoBrush(self, checked): 0073 self.tenbrushes.autoBrush = checked 0074 0075 def loadButtons(self): 0076 self.tenbrushes.buttons = [] 0077 0078 allPresets = Application.resources("preset") 0079 0080 for index, item in enumerate(['1', '2', '3', '4', '5', 0081 '6', '7', '8', '9', '0']): 0082 buttonLayout = QVBoxLayout() 0083 button = dropbutton.DropButton(self.mainDialog) 0084 button.setObjectName(item) 0085 button.clicked.connect(button.selectPreset) 0086 button.presetChooser = self.presetChooser 0087 0088 action = Application.action("activate_preset_" + item) 0089 0090 preset = self.tenbrushes.selectedPresets[index] if index < len(self.tenbrushes.selectedPresets) else None 0091 0092 if action and preset and preset in allPresets: 0093 p = allPresets[preset] 0094 button.preset = p.name() 0095 button.setIcon(QIcon(QPixmap.fromImage(p.image()))) 0096 0097 buttonLayout.addWidget(button) 0098 0099 label = QLabel( 0100 action.shortcut().toString()) 0101 label.setAlignment(Qt.AlignHCenter) 0102 buttonLayout.addWidget(label) 0103 0104 self.hbox.addLayout(buttonLayout) 0105 self.tenbrushes.buttons.append(button)