chalk

kis_dlg_adj_layer_props.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_filters_listview.h"
33#include "kis_image.h"
34#include "kis_previewwidget.h"
35#include "kis_layer.h"
36#include "kis_adjustment_layer.h"
37#include "kis_paint_device.h"
38#include "kis_paint_layer.h"
39#include "kis_group_layer.h"
40#include "kis_dlg_adj_layer_props.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{
51 Q_ASSERT( layer );
52 m_layer = layer;
53
54 KisLayerSP next = layer->nextSibling();
55 Q_ASSERT( next );
56
57 m_currentConfiguration = layer->filter();
58 m_currentFilter = KisFilterRegistry::instance()->get(m_currentConfiguration->name());
59 if (!m_currentFilter) {
60 kdWarning() << "No filter specified!\n";
61 }
62
63 KisPaintDeviceSP dev = 0;
64
65 if( next )
66 {
67 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(next.data());
68 if (pl) {
69 dev = pl->paintDevice();
70 }
71 else {
72 KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(next.data());
73 if (gl) {
74 dev = gl->projection(gl->extent());
75 }
76 else {
77 KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(next.data());
78 if (al) {
79 dev = al->cachedPaintDevice();
80 }
81 }
82 }
83 } else {
84 dev = new KisPaintDevice(m_layer->image()->colorSpace());
85 }
86 setCaption(caption);
87 TQWidget * page = new TQWidget(this, "page widget");
88 TQHBoxLayout * layout = new TQHBoxLayout(page, 0, 6);
89 setMainWidget(page);
90
91 m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
92 m_preview->slotSetDevice( dev );
93
94 connect( m_preview, TQ_SIGNAL(updated()), this, TQ_SLOT(refreshPreview()));
95 layout->addWidget(m_preview, 1, 1);
96
97 TQVBoxLayout *v1 = new TQVBoxLayout( layout );
98 TQHBoxLayout *hl = new TQHBoxLayout( v1 );
99
100 TQLabel * lblName = new TQLabel(i18n("Layer name:"), page, "lblName");
101 hl->addWidget(lblName, 0, 0);
102
103 m_layerName = new KLineEdit(page, "m_layerName");
104 m_layerName->setText(layerName);
105 m_layerName->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed);
106 hl->addWidget(m_layerName, 0, 1);
107 connect( m_layerName, TQ_SIGNAL( textChanged ( const TQString & ) ), this, TQ_SLOT( slotNameChanged( const TQString & ) ) );
108
109 if ( m_currentFilter ) {
110 m_currentConfigWidget = m_currentFilter->createConfigurationWidget(page, dev);
111 if (m_currentConfigWidget) {
112 m_currentConfigWidget->setConfiguration( m_currentConfiguration );
113 }
114 }
115 if ( m_currentFilter == 0 || m_currentConfigWidget == 0 ) {
116 TQLabel * labelNoConfigWidget = new TQLabel( i18n("No configuration options are available for this filter"), page );
117 v1->addWidget( labelNoConfigWidget );
118 }
119 else {
120 v1->addWidget( m_currentConfigWidget );
121 connect(m_currentConfigWidget, TQ_SIGNAL(sigPleaseUpdatePreview()), this, TQ_SLOT(slotConfigChanged()));
122 }
123
124 refreshPreview();
125 enableButtonOK( !m_layerName->text().isEmpty() );
126}
127
128void KisDlgAdjLayerProps::slotNameChanged( const TQString & text )
129{
130 enableButtonOK( !text.isEmpty() );
131}
132
133KisFilterConfiguration * KisDlgAdjLayerProps::filterConfiguration() const
134{
135 return m_currentFilter->configuration(m_currentConfigWidget);
136}
137
138TQString KisDlgAdjLayerProps::layerName() const
139{
140 return m_layerName->text();
141}
142
143void KisDlgAdjLayerProps::slotConfigChanged()
144{
145 if(m_preview->getAutoUpdate())
146 {
147 refreshPreview();
148 } else {
149 m_preview->needUpdate();
150 }
151}
152
153void KisDlgAdjLayerProps::refreshPreview()
154{
155 if (!m_preview) {
156 kdDebug() << "no preview!\n";
157 return;
158 }
159
160 if (!m_currentFilter) {
161 return;
162 }
163 KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);
164
165 m_preview->runFilter(m_currentFilter, config);
166}
167
168#include "kis_dlg_adj_layer_props.moc"
Class that contains a KisFilter and optionally a KisSelection.
KisDlgAdjLayerProps(KisAdjustmentLayerSP layer, 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!!
virtual TQRect extent() const
Returns an approximation of where the bounds on actual data are in this layer.
A paint device contains the actual pixel data and offers methods to read and write pixels.
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.