File indexing completed on 2024-12-22 04:15:06
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "dlg_layersplit.h" 0008 0009 #include <klocalizedstring.h> 0010 0011 #include <KoResourceServerProvider.h> 0012 #include <kis_debug.h> 0013 0014 #include <KisViewManager.h> 0015 #include <kis_image.h> 0016 #include <kis_paint_device.h> 0017 0018 #include "kis_slider_spin_box.h" 0019 #include <QCheckBox> 0020 #include <QSpinBox> 0021 0022 #include <kis_config.h> 0023 #include <KisDialogStateSaver.h> 0024 0025 DlgLayerSplit::DlgLayerSplit() 0026 : KoDialog() 0027 { 0028 m_page = new WdgLayerSplit(this); 0029 0030 setCaption(i18n("Split Layer")); 0031 setButtons(Apply | Cancel); 0032 setDefaultButton(Apply); 0033 0034 m_page->intFuzziness->setRange(0, 200); 0035 m_page->intFuzziness->setSingleStep(1); 0036 0037 m_colorSetChooser = new KisPaletteChooser(); 0038 m_page->paletteChooser->setPopupWidget(m_colorSetChooser); 0039 connect(m_colorSetChooser, SIGNAL(sigPaletteSelected(KoColorSetSP)), this, SLOT(slotSetPalette(KoColorSetSP))); 0040 0041 QMap<QString, QVariant> defaults; 0042 defaults[ m_page->intFuzziness->objectName() ] = QVariant::fromValue<int>(20); 0043 defaults[ m_page->chkCreateGroupLayer->objectName() ] = QVariant::fromValue<bool>(true); 0044 defaults[ m_page->chkSeparateGroupLayers->objectName() ] = QVariant::fromValue<bool>(false); 0045 defaults[ m_page->chkAlphaLock->objectName() ] = QVariant::fromValue<bool>(true); 0046 defaults[ m_page->chkHideOriginal->objectName() ] = QVariant::fromValue<bool>(false); 0047 defaults[ m_page->chkSortLayers->objectName() ] = QVariant::fromValue<bool>(true); 0048 defaults[ m_page->chkDisregardOpacity->objectName() ] = QVariant::fromValue<bool>(true); 0049 0050 KisDialogStateSaver::restoreState(m_page, "krita/layer_split", defaults); 0051 0052 connect(m_page->cmbMode, SIGNAL(currentIndexChanged(int)), this, SLOT(slotChangeMode(int))); 0053 0054 KisConfig cfg(true); 0055 QString paletteName = cfg.readEntry<QString>("layersplit/paletteName", "Default"); // resource names are not translatable by design 0056 KoResourceServer<KoColorSet> *pserver = KoResourceServerProvider::instance()->paletteServer(); 0057 KoColorSetSP pal = pserver->resource("", "", paletteName); 0058 m_modeToMask = m_page->cmbMode->currentIndex(); 0059 slotChangeMode(m_modeToMask); 0060 0061 if (pal) { 0062 m_palette = pal; 0063 m_page->paletteChooser->setText(pal->name()); 0064 QIcon icon(QPixmap::fromImage(pal->image())); 0065 m_page->paletteChooser->setIcon(icon); 0066 } 0067 0068 0069 connect(this, SIGNAL(applyClicked()), this, SLOT(slotApplyClicked())); 0070 0071 setMainWidget(m_page); 0072 } 0073 0074 DlgLayerSplit::~DlgLayerSplit() 0075 { 0076 } 0077 0078 void DlgLayerSplit::slotApplyClicked() 0079 { 0080 0081 KisDialogStateSaver::saveState(m_page, "krita/layer_split"); 0082 0083 KisConfig cfg(false); 0084 if (m_palette) { 0085 cfg.writeEntry("layersplit/paletteName", m_palette->name()); 0086 } 0087 0088 accept(); 0089 } 0090 0091 bool DlgLayerSplit::createBaseGroup() const 0092 { 0093 return m_page->chkCreateGroupLayer->isChecked(); 0094 } 0095 0096 bool DlgLayerSplit::createSeparateGroups() const 0097 { 0098 return m_page->chkSeparateGroupLayers->isChecked(); 0099 } 0100 0101 bool DlgLayerSplit::lockAlpha() const 0102 { 0103 return m_page->chkAlphaLock->isChecked(); 0104 } 0105 0106 bool DlgLayerSplit::hideOriginal() const 0107 { 0108 return m_page->chkHideOriginal->isChecked(); 0109 } 0110 0111 bool DlgLayerSplit::sortLayers() const 0112 { 0113 return m_page->chkSortLayers->isChecked(); 0114 } 0115 0116 bool DlgLayerSplit::disregardOpacity() const 0117 { 0118 return m_page->chkDisregardOpacity->isChecked(); 0119 } 0120 0121 int DlgLayerSplit::fuzziness() const 0122 { 0123 return m_page->intFuzziness->value(); 0124 0125 } 0126 0127 KoColorSetSP DlgLayerSplit::palette() const 0128 { 0129 return m_palette; 0130 } 0131 0132 void DlgLayerSplit::slotSetPalette(KoColorSetSP pal) 0133 { 0134 if (pal) { 0135 m_palette = pal; 0136 m_page->paletteChooser->setText(pal->name()); 0137 QIcon icon(QPixmap::fromImage(pal->image())); 0138 m_page->paletteChooser->setIcon(icon); 0139 } 0140 } 0141 0142 void DlgLayerSplit::slotChangeMode(int idx){ 0143 m_modeToMask = idx; 0144 if( m_modeToMask){ 0145 m_page->chkCreateGroupLayer->hide(); 0146 m_page->chkSeparateGroupLayers->hide(); 0147 m_page->chkAlphaLock->hide(); 0148 m_page->chkHideOriginal->hide(); 0149 } 0150 else{ 0151 m_page->chkCreateGroupLayer->show(); 0152 m_page->chkSeparateGroupLayers->show(); 0153 m_page->chkAlphaLock->show(); 0154 m_page->chkHideOriginal->show(); 0155 } 0156 }