1 /*
2 * Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
3 * Copyright (c) 2008 Cyrille Berger <cberger@cberger.net>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20 #include "kis_dlg_adjustment_layer.h"
21 #include <klocalizedstring.h>
22
23 #include <QGroupBox>
24 #include <QLabel>
25 #include <QLayout>
26 #include <QGridLayout>
27 #include <QTimer>
28 #include <QIcon>
29 #include <QImage>
30 #include <QPixmap>
31 #include <QPushButton>
32 #include <QDialogButtonBox>
33
34 #include "filter/kis_filter.h"
35 #include "kis_config_widget.h"
36 #include "filter/kis_filter_configuration.h"
37 #include "kis_paint_device.h"
38 #include "kis_transaction.h"
39 #include "kis_node.h"
40 #include "kis_node_filter_interface.h"
41 #include <kis_config.h>
42 #include "KisViewManager.h"
43
44
KisDlgAdjustmentLayer(KisNodeSP node,KisNodeFilterInterface * nfi,KisPaintDeviceSP paintDevice,const QString & layerName,const QString & caption,KisViewManager * view,QWidget * parent)45 KisDlgAdjustmentLayer::KisDlgAdjustmentLayer(KisNodeSP node,
46 KisNodeFilterInterface* nfi,
47 KisPaintDeviceSP paintDevice,
48 const QString &layerName,
49 const QString &caption,
50 KisViewManager *view, QWidget *parent)
51 : KoDialog(parent, Qt::Dialog)
52 , m_node(node)
53 , m_nodeFilterInterface(nfi)
54 , m_currentFilter(0)
55 , m_customName(false)
56 , m_layerName(layerName)
57 {
58 setCaption(caption);
59 setButtons(None);
60
61 QWidget * page = new QWidget(this);
62 wdgFilterNodeCreation.setupUi(page);
63 setMainWidget(page);
64
65 wdgFilterNodeCreation.filterGalleryToggle->setChecked(wdgFilterNodeCreation.filterSelector->isFilterGalleryVisible());
66 wdgFilterNodeCreation.filterGalleryToggle->setIcon(QPixmap(":/pics/sidebaricon.png"));
67 wdgFilterNodeCreation.filterGalleryToggle->setMaximumWidth(wdgFilterNodeCreation.filterGalleryToggle->height());
68 connect(wdgFilterNodeCreation.filterSelector, SIGNAL(sigFilterGalleryToggled(bool)), wdgFilterNodeCreation.filterGalleryToggle, SLOT(setChecked(bool)));
69 connect(wdgFilterNodeCreation.filterGalleryToggle, SIGNAL(toggled(bool)), wdgFilterNodeCreation.filterSelector, SLOT(showFilterGallery(bool)));
70 connect(wdgFilterNodeCreation.filterSelector, SIGNAL(sigSizeChanged()), this, SLOT(slotFilterWidgetSizeChanged()));
71
72 connect(wdgFilterNodeCreation.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
73 connect(wdgFilterNodeCreation.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
74
75 wdgFilterNodeCreation.filterSelector->setView(view);
76 wdgFilterNodeCreation.filterSelector->showFilterGallery(KisConfig(true).showFilterGalleryLayerMaskDialog());
77
78 wdgFilterNodeCreation.filterSelector->setPaintDevice(false, paintDevice);
79 wdgFilterNodeCreation.layerName->setText(layerName);
80
81 connect(wdgFilterNodeCreation.filterSelector, SIGNAL(configurationChanged()), SLOT(slotConfigChanged()));
82 connect(wdgFilterNodeCreation.layerName, SIGNAL(textChanged(QString)), SLOT(slotNameChanged(QString)));
83
84 slotConfigChanged();
85 }
86
~KisDlgAdjustmentLayer()87 KisDlgAdjustmentLayer::~KisDlgAdjustmentLayer()
88 {
89 KisConfig(true).setShowFilterGalleryLayerMaskDialog(wdgFilterNodeCreation.filterSelector->isFilterGalleryVisible());
90 }
91
slotNameChanged(const QString & text)92 void KisDlgAdjustmentLayer::slotNameChanged(const QString &text)
93 {
94 Q_UNUSED(text);
95 m_customName = !text.isEmpty();
96 enableButtonOk(m_currentFilter);
97 }
98
filterConfiguration() const99 KisFilterConfigurationSP KisDlgAdjustmentLayer::filterConfiguration() const
100 {
101 KisFilterConfigurationSP config = wdgFilterNodeCreation.filterSelector->configuration();
102
103 Q_ASSERT(config);
104
105 return config;
106 }
107
layerName() const108 QString KisDlgAdjustmentLayer::layerName() const
109 {
110 return wdgFilterNodeCreation.layerName->text();
111 }
112
slotConfigChanged()113 void KisDlgAdjustmentLayer::slotConfigChanged()
114 {
115 m_currentFilter = filterConfiguration();
116
117 enableButtonOk(m_currentFilter);
118
119 if (m_currentFilter) {
120 m_nodeFilterInterface->setFilter(m_currentFilter);
121 if (!m_customName) {
122 wdgFilterNodeCreation.layerName->blockSignals(true);
123 wdgFilterNodeCreation.layerName->setText(m_layerName + " (" + wdgFilterNodeCreation.filterSelector->currentFilter()->name() + ")");
124 wdgFilterNodeCreation.layerName->blockSignals(false);
125 }
126 }
127
128 m_node->setDirty();
129 }
130
adjustSize()131 void KisDlgAdjustmentLayer::adjustSize()
132 {
133 QWidget::adjustSize();
134 }
135
slotFilterWidgetSizeChanged()136 void KisDlgAdjustmentLayer::slotFilterWidgetSizeChanged()
137 {
138 QMetaObject::invokeMethod(this, "adjustSize", Qt::QueuedConnection);
139 }
140
141