chalk

kis_dlg_adjustment_layer.cpp
1/*
2 * Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
3 * Copyright (c) 2007 Benjamin Schleimer <bensch128@yahoo.com>
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#include <tdelocale.h>
20
21#include <tqgroupbox.h>
22#include <tqlabel.h>
23#include <tqlayout.h>
24
25#include <klineedit.h>
26#include <tdelocale.h>
27
28#include "kis_filter_config_widget.h"
29#include "kis_transaction.h"
30#include "kis_filter.h"
31#include "kis_filter_configuration.h"
32#include "kis_dlg_adjustment_layer.h"
33#include "kis_filters_listview.h"
34#include "kis_image.h"
35#include "kis_previewwidget.h"
36#include "kis_layer.h"
37#include "kis_paint_device.h"
38#include "kis_paint_layer.h"
39#include "kis_group_layer.h"
40#include "kis_adjustment_layer.h"
41#include "kis_filter.h"
42#include "kis_filter_configuration.h"
43
45 const TQString & /*layerName*/,
46 const TQString & caption,
47 TQWidget *parent,
48 const char *name)
49 : KDialogBase(parent, name, true, "", Ok | Cancel)
50 , m_image(img)
51 , m_currentFilter(0)
52 , m_customName(false)
53 , m_freezeName(false)
54{
55 Q_ASSERT(img);
56
57 KisLayerSP activeLayer = img->activeLayer();
58 m_dev = 0;
59
60 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(activeLayer.data());
61 if (pl) {
62 m_dev = pl->paintDevice();
63 }
64 else {
65 KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(activeLayer.data());
66 if (gl) {
67 m_dev = gl->projection(img->bounds());
68 }
69 else {
70 KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(activeLayer.data());
71 if (al) {
72 m_dev = al->cachedPaintDevice();
73 }
74 }
75 }
76
77 setCaption(caption);
78 TQWidget * page = new TQWidget(this, "page widget");
79 TQGridLayout * grid = new TQGridLayout(page, 3, 2, 0, 6);
80 setMainWidget(page);
81
82 TQLabel * lblName = new TQLabel(i18n("Layer name:"), page, "lblName");
83 grid->addWidget(lblName, 0, 0);
84
85 m_layerName = new KLineEdit(page, "m_layerName");
86 grid->addWidget(m_layerName, 0, 1);
87 connect( m_layerName, TQ_SIGNAL( textChanged ( const TQString & ) ), this, TQ_SLOT( slotNameChanged( const TQString & ) ) );
88
89 m_filtersList = new KisFiltersListView(m_dev, page, true, "dlgadjustment.filtersList");
90 connect(m_filtersList , TQ_SIGNAL(selectionChanged(TQIconViewItem*)), this, TQ_SLOT(selectionHasChanged(TQIconViewItem* )));
91 grid->addMultiCellWidget(m_filtersList, 1, 2, 0, 0);
92
93 m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
94 m_preview->slotSetDevice( m_dev );
95
96 connect( m_preview, TQ_SIGNAL(updated()), this, TQ_SLOT(refreshPreview()));
97 grid->addWidget(m_preview, 1, 1);
98
99 m_configWidgetHolder = new TQGroupBox(i18n("Configuration"), page, "currentConfigWidget");
100 m_configWidgetHolder->setColumnLayout(0, TQt::Horizontal);
101 grid->addWidget(m_configWidgetHolder, 2, 1);
102
103 m_labelNoConfigWidget = new TQLabel(i18n("No configuration options are available for this filter"),
104 m_configWidgetHolder);
105 m_configWidgetHolder->layout()->add(m_labelNoConfigWidget);
106 m_labelNoConfigWidget->hide();
107
108 resize( TQSize(600, 480).expandedTo(minimumSizeHint()) );
109
110 m_currentConfigWidget = 0;
111
112 enableButtonOK(0);
113}
114
115void KisDlgAdjustmentLayer::slotNameChanged( const TQString & text )
116{
117 if (m_freezeName)
118 return;
119
120 m_customName = !text.isEmpty();
121 enableButtonOK( m_currentFilter && m_customName );
122}
123
124KisFilterConfiguration * KisDlgAdjustmentLayer::filterConfiguration() const
125{
126 return m_currentFilter->configuration(m_currentConfigWidget);
127}
128
129TQString KisDlgAdjustmentLayer::layerName() const
130{
131 return m_layerName->text();
132}
133
134void KisDlgAdjustmentLayer::slotConfigChanged()
135{
136 if(m_preview->getAutoUpdate())
137 {
138 refreshPreview();
139 } else {
140 m_preview->needUpdate();
141 }
142}
143
144void KisDlgAdjustmentLayer::refreshPreview()
145{
146 KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);
147
148 m_preview->runFilter(m_currentFilter, config);
149}
150
151void KisDlgAdjustmentLayer::selectionHasChanged ( TQIconViewItem * item )
152{
153 KisFiltersIconViewItem* kisitem = (KisFiltersIconViewItem*) item;
154
155 m_currentFilter = kisitem->filter();
156
157 if ( m_currentConfigWidget != 0 )
158 {
159 m_configWidgetHolder->layout()->remove(m_currentConfigWidget);
160
161 delete m_currentConfigWidget;
162 m_currentConfigWidget = 0;
163
164 } else {
165
166 m_labelNoConfigWidget->hide();
167 }
168
169 if (m_dev) {
170 m_currentConfigWidget = m_currentFilter->createConfigurationWidget(m_configWidgetHolder,
171 m_dev);
172 }
173
174 if (m_currentConfigWidget != 0)
175 {
176 m_configWidgetHolder->layout()->add(m_currentConfigWidget);
177 m_currentConfigWidget->show();
178 connect(m_currentConfigWidget, TQ_SIGNAL(sigPleaseUpdatePreview()), this, TQ_SLOT(slotConfigChanged()));
179 } else {
180 m_labelNoConfigWidget->show();
181 }
182
183 if (!m_customName) {
184 m_freezeName = true;
185 m_layerName->setText(m_currentFilter->id().name());
186 m_freezeName = false;
187 }
188
189 enableButtonOK( !m_layerName->text().isEmpty() );
190 refreshPreview();
191}
192
193#include "kis_dlg_adjustment_layer.moc"
Class that contains a KisFilter and optionally a KisSelection.
KisDlgAdjustmentLayer(KisImage *img, const TQString &layerName, const TQString &caption, TQWidget *parent=0, const char *name=0)
Create a new adjustmentlayer dialog.
A KisFilterConfiguration is the serializable representation of the filter parameters.
A KisLayer that bundles child layers into a single layer.
virtual KisPaintDeviceSP projection(const TQRect &rect)
will copy from to, if !0, CoW!!
This layer is of a type that can be painted on.
A widget that can be used by plugins to show a preview of the effect of the plugin to the user.