File indexing completed on 2024-12-22 04:12:17
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "kis_dlg_brush_hud_config.h" 0008 #include "ui_kis_dlg_brush_hud_config.h" 0009 0010 #include "kis_paintop_preset.h" 0011 #include "kis_paintop_settings.h" 0012 0013 #include "kis_brush_hud_properties_config.h" 0014 0015 #include <kstandardguiitem.h> 0016 0017 0018 struct KisDlgConfigureBrushHud::Private 0019 { 0020 KisPaintOpPresetSP preset; 0021 QList<KisUniformPaintOpPropertySP> properties; 0022 }; 0023 0024 KisDlgConfigureBrushHud::KisDlgConfigureBrushHud(KisPaintOpPresetSP preset, QWidget *parent) : 0025 QDialog(parent), 0026 ui(new Ui::KisDlgConfigureBrushHud), 0027 m_d(new Private) 0028 { 0029 ui->setupUi(this); 0030 0031 KGuiItem::assign(ui->btnBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok()); 0032 KGuiItem::assign(ui->btnBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); 0033 0034 m_d->preset = preset; 0035 m_d->properties = preset->uniformProperties(); 0036 0037 QList<KisUniformPaintOpPropertySP> available; 0038 QList<KisUniformPaintOpPropertySP> chosen; 0039 0040 KisBrushHudPropertiesConfig cfg; 0041 cfg.filterProperties(preset->paintOp().id(), 0042 m_d->properties, &chosen, &available); 0043 0044 ui->lstAvailable->addProperties(available); 0045 ui->lstCurrent->addProperties(chosen); 0046 0047 connect(this, SIGNAL(accepted()), SLOT(slotConfigAccepted())); 0048 0049 connect(ui->btnAdd, SIGNAL(clicked()), SLOT(slotMoveRight())); 0050 connect(ui->btnRemove, SIGNAL(clicked()), SLOT(slotMoveLeft())); 0051 0052 connect(ui->btnDown, SIGNAL(clicked()), SLOT(slotMoveDown())); 0053 connect(ui->btnUp, SIGNAL(clicked()), SLOT(slotMoveUp())); 0054 } 0055 0056 KisDlgConfigureBrushHud::~KisDlgConfigureBrushHud() 0057 { 0058 delete ui; 0059 } 0060 0061 void KisDlgConfigureBrushHud::slotConfigAccepted() 0062 { 0063 KisBrushHudPropertiesConfig cfg; 0064 cfg.setSelectedProperties(m_d->preset->paintOp().id(), ui->lstCurrent->selectedPropertiesIds()); 0065 } 0066 0067 void KisDlgConfigureBrushHud::slotMoveRight() 0068 { 0069 QListWidgetItem *item = ui->lstAvailable->currentItem(); 0070 if (!item) return; 0071 0072 const int prevPosition = ui->lstAvailable->row(item) - 1; 0073 const int newPosition = ui->lstCurrent->currentRow() + 1; 0074 0075 ui->lstAvailable->takeItem(ui->lstAvailable->row(item)); 0076 ui->lstAvailable->setCurrentRow(qMax(0, prevPosition)); 0077 ui->lstCurrent->insertItem(newPosition, item); 0078 ui->lstCurrent->setCurrentItem(item); 0079 } 0080 0081 void KisDlgConfigureBrushHud::slotMoveLeft() 0082 { 0083 QListWidgetItem *item = ui->lstCurrent->currentItem(); 0084 if (!item) return; 0085 0086 const int prevPosition = ui->lstCurrent->row(item) - 1; 0087 const int newPosition = ui->lstAvailable->currentRow() + 1; 0088 0089 ui->lstCurrent->takeItem(ui->lstCurrent->row(item)); 0090 ui->lstCurrent->setCurrentRow(qMax(0, prevPosition)); 0091 ui->lstAvailable->insertItem(newPosition, item); 0092 ui->lstAvailable->setCurrentItem(item); 0093 } 0094 0095 void KisDlgConfigureBrushHud::slotMoveUp() 0096 { 0097 QListWidgetItem *item = ui->lstCurrent->currentItem(); 0098 if (!item) return; 0099 0100 int position = ui->lstCurrent->row(item); 0101 0102 if (position <= 0) return; 0103 0104 ui->lstCurrent->takeItem(ui->lstCurrent->row(item)); 0105 ui->lstCurrent->insertItem(position - 1, item); 0106 ui->lstCurrent->setCurrentItem(item); 0107 } 0108 0109 void KisDlgConfigureBrushHud::slotMoveDown() 0110 { 0111 QListWidgetItem *item = ui->lstCurrent->currentItem(); 0112 if (!item) return; 0113 0114 int position = ui->lstCurrent->row(item); 0115 0116 if (position >= ui->lstCurrent->count() - 1) return; 0117 0118 ui->lstCurrent->takeItem(ui->lstCurrent->row(item)); 0119 ui->lstCurrent->insertItem(position + 1, item); 0120 ui->lstCurrent->setCurrentItem(item); 0121 } 0122