krita

kis_dlg_adjustment_layer.cc

00001 /*
00002  *  Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
00003  *  Copyright (c) 2007 Benjamin Schleimer <bensch128@yahoo.com>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018  */
00019 #include <klocale.h>
00020 
00021 #include <qgroupbox.h>
00022 #include <qlabel.h>
00023 #include <qlayout.h>
00024 
00025 #include <klineedit.h>
00026 #include <klocale.h>
00027 
00028 #include "kis_filter_config_widget.h"
00029 #include "kis_transaction.h"
00030 #include "kis_filter.h"
00031 #include "kis_filter_configuration.h"
00032 #include "kis_dlg_adjustment_layer.h"
00033 #include "kis_filters_listview.h"
00034 #include "kis_image.h"
00035 #include "kis_previewwidget.h"
00036 #include "kis_layer.h"
00037 #include "kis_paint_device.h"
00038 #include "kis_paint_layer.h"
00039 #include "kis_group_layer.h"
00040 #include "kis_adjustment_layer.h"
00041 #include "kis_filter.h"
00042 #include "kis_filter_configuration.h"
00043 
00044 KisDlgAdjustmentLayer::KisDlgAdjustmentLayer(KisImage * img,
00045                                              const QString & /*layerName*/,
00046                                              const QString & caption,
00047                                              QWidget *parent,
00048                                              const char *name)
00049     : KDialogBase(parent, name, true, "", Ok | Cancel)
00050     , m_image(img)
00051     , m_currentFilter(0)
00052     , m_customName(false)
00053     , m_freezeName(false)
00054 {
00055     Q_ASSERT(img);
00056 
00057     KisLayerSP activeLayer = img->activeLayer();
00058     m_dev = 0;
00059 
00060     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(activeLayer.data());
00061     if (pl) {
00062         m_dev = pl->paintDevice();
00063     }
00064     else {
00065         KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(activeLayer.data());
00066         if (gl) {
00067             m_dev = gl->projection(img->bounds());
00068         }
00069         else {
00070             KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(activeLayer.data());
00071             if (al) {
00072                 m_dev = al->cachedPaintDevice();
00073             }
00074         }
00075     }
00076 
00077     setCaption(caption);
00078     QWidget * page = new QWidget(this, "page widget");
00079     QGridLayout * grid = new QGridLayout(page, 3, 2, 0, 6);
00080     setMainWidget(page);
00081 
00082     QLabel * lblName = new QLabel(i18n("Layer name:"), page, "lblName");
00083     grid->addWidget(lblName, 0, 0);
00084 
00085     m_layerName = new KLineEdit(page, "m_layerName");
00086     grid->addWidget(m_layerName, 0, 1);
00087     connect( m_layerName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) );
00088 
00089     m_filtersList = new KisFiltersListView(m_dev,  page, true, "dlgadjustment.filtersList");
00090     connect(m_filtersList , SIGNAL(selectionChanged(QIconViewItem*)), this, SLOT(selectionHasChanged(QIconViewItem* )));
00091     grid->addMultiCellWidget(m_filtersList, 1, 2, 0, 0);
00092 
00093     m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
00094     m_preview->slotSetDevice( m_dev );
00095 
00096     connect( m_preview, SIGNAL(updated()), this, SLOT(refreshPreview()));
00097     grid->addWidget(m_preview, 1, 1);
00098 
00099     m_configWidgetHolder = new QGroupBox(i18n("Configuration"), page, "currentConfigWidget");
00100     m_configWidgetHolder->setColumnLayout(0, Qt::Horizontal);
00101     grid->addWidget(m_configWidgetHolder, 2, 1);
00102 
00103     m_labelNoConfigWidget = new QLabel(i18n("No configuration options are available for this filter"),
00104                                         m_configWidgetHolder);
00105     m_configWidgetHolder->layout()->add(m_labelNoConfigWidget);
00106     m_labelNoConfigWidget->hide();
00107 
00108     resize( QSize(600, 480).expandedTo(minimumSizeHint()) );
00109 
00110     m_currentConfigWidget = 0;
00111 
00112     enableButtonOK(0);
00113 }
00114 
00115 void KisDlgAdjustmentLayer::slotNameChanged( const QString & text )
00116 {
00117     if (m_freezeName)
00118         return;
00119 
00120     m_customName = !text.isEmpty();
00121     enableButtonOK( m_currentFilter && m_customName );
00122 }
00123 
00124 KisFilterConfiguration * KisDlgAdjustmentLayer::filterConfiguration() const
00125 {
00126     return m_currentFilter->configuration(m_currentConfigWidget);
00127 }
00128 
00129 QString KisDlgAdjustmentLayer::layerName() const
00130 {
00131     return m_layerName->text();
00132 }
00133 
00134 void KisDlgAdjustmentLayer::slotConfigChanged()
00135 {
00136     if(m_preview->getAutoUpdate())
00137     {
00138         refreshPreview();
00139     } else {
00140         m_preview->needUpdate();
00141     }
00142 }
00143 
00144 void KisDlgAdjustmentLayer::refreshPreview()
00145 {
00146     KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);
00147 
00148     m_preview->runFilter(m_currentFilter, config);
00149 }
00150 
00151 void KisDlgAdjustmentLayer::selectionHasChanged ( QIconViewItem * item )
00152 {
00153     KisFiltersIconViewItem* kisitem = (KisFiltersIconViewItem*) item;
00154 
00155     m_currentFilter = kisitem->filter();
00156 
00157     if ( m_currentConfigWidget != 0 )
00158     {
00159         m_configWidgetHolder->layout()->remove(m_currentConfigWidget);
00160 
00161         delete m_currentConfigWidget;
00162         m_currentConfigWidget = 0;
00163 
00164     } else {
00165 
00166         m_labelNoConfigWidget->hide();
00167     }
00168 
00169     if (m_dev) {
00170         m_currentConfigWidget = m_currentFilter->createConfigurationWidget(m_configWidgetHolder,
00171                                                                            m_dev);
00172     }
00173 
00174     if (m_currentConfigWidget != 0)
00175     {
00176         m_configWidgetHolder->layout()->add(m_currentConfigWidget);
00177         m_currentConfigWidget->show();
00178         connect(m_currentConfigWidget, SIGNAL(sigPleaseUpdatePreview()), this, SLOT(slotConfigChanged()));
00179     } else {
00180         m_labelNoConfigWidget->show();
00181     }
00182 
00183     if (!m_customName) {
00184         m_freezeName = true;
00185         m_layerName->setText(m_currentFilter->id().name());
00186         m_freezeName = false;
00187     }
00188 
00189     enableButtonOK( !m_layerName->text().isEmpty() );
00190     refreshPreview();
00191 }
00192 
00193 #include "kis_dlg_adjustment_layer.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys