krita

kis_dlg_adj_layer_props.cc

00001 /*
00002  *  Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 #include <klocale.h>
00019 
00020 #include <qgroupbox.h>
00021 #include <qlabel.h>
00022 #include <qlayout.h>
00023 
00024 #include <klineedit.h>
00025 #include <klocale.h>
00026 
00027 #include "kis_filter_config_widget.h"
00028 #include "kis_transaction.h"
00029 #include "kis_filter.h"
00030 #include "kis_filter_configuration.h"
00031 #include "kis_filters_listview.h"
00032 #include "kis_image.h"
00033 #include "kis_previewwidget.h"
00034 #include "kis_layer.h"
00035 #include "kis_adjustment_layer.h"
00036 #include "kis_paint_device.h"
00037 #include "kis_paint_layer.h"
00038 #include "kis_group_layer.h"
00039 #include "kis_dlg_adj_layer_props.h"
00040 #include "kis_filter.h"
00041 #include "kis_filter_configuration.h"
00042 
00043 KisDlgAdjLayerProps::KisDlgAdjLayerProps(KisAdjustmentLayerSP layer,
00044                                          const QString & layerName,
00045                                          const QString & caption,
00046                                          QWidget *parent,
00047                                          const char *name)
00048     : KDialogBase(parent, name, true, "", Ok | Cancel)
00049 {
00050     Q_ASSERT( layer );
00051     m_layer = layer;
00052 
00053     KisLayerSP next = layer->nextSibling();
00054     Q_ASSERT( next );
00055 
00056     m_currentConfiguration = layer->filter();
00057     m_currentFilter = KisFilterRegistry::instance()->get(m_currentConfiguration->name());
00058     if (!m_currentFilter) {
00059         kdWarning() << "No filter specified!\n";
00060     }
00061 
00062     KisPaintDeviceSP dev = 0;
00063 
00064     KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(next.data());
00065     if (pl) {
00066         dev = pl->paintDevice();
00067     }
00068     else {
00069         KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(next.data());
00070         if (gl) {
00071             dev = gl->projection(gl->extent());
00072         }
00073         else {
00074             KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(next.data());
00075             if (al) {
00076                 dev = al->cachedPaintDevice();
00077             }
00078         }
00079     }
00080 
00081     setCaption(caption);
00082     QWidget * page = new QWidget(this, "page widget");
00083     QHBoxLayout * layout = new QHBoxLayout(page, 0, 6);
00084     setMainWidget(page);
00085 
00086     m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
00087     m_preview->slotSetDevice( dev );
00088 
00089     connect( m_preview, SIGNAL(updated()), this, SLOT(refreshPreview()));
00090     layout->addWidget(m_preview, 1, 1);
00091 
00092     QVBoxLayout *v1 = new QVBoxLayout( layout );
00093     QHBoxLayout *hl = new QHBoxLayout( v1 );
00094 
00095     QLabel * lblName = new QLabel(i18n("Layer name:"), page, "lblName");
00096     hl->addWidget(lblName, 0, 0);
00097 
00098     m_layerName = new KLineEdit(page, "m_layerName");
00099     m_layerName->setText(layerName);
00100     m_layerName->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
00101     hl->addWidget(m_layerName, 0, 1);
00102     connect( m_layerName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) );
00103 
00104     if ( m_currentFilter ) {
00105         m_currentConfigWidget = m_currentFilter->createConfigurationWidget(page, dev);
00106         if (m_currentConfigWidget) {
00107             m_currentConfigWidget->setConfiguration( m_currentConfiguration );
00108         }
00109     }
00110     if ( m_currentFilter == 0 || m_currentConfigWidget == 0 ) {
00111         QLabel * labelNoConfigWidget = new QLabel( i18n("No configuration options are available for this filter"), page );
00112         v1->addWidget( labelNoConfigWidget );
00113     }
00114     else {
00115         v1->addWidget( m_currentConfigWidget );
00116         connect(m_currentConfigWidget, SIGNAL(sigPleaseUpdatePreview()), this, SLOT(slotConfigChanged()));
00117     }
00118 
00119     refreshPreview();
00120     enableButtonOK( !m_layerName->text().isEmpty() );
00121 
00122 }
00123 
00124 void KisDlgAdjLayerProps::slotNameChanged( const QString & text )
00125 {
00126     enableButtonOK( !text.isEmpty() );
00127 }
00128 
00129 KisFilterConfiguration * KisDlgAdjLayerProps::filterConfiguration() const
00130 {
00131     return m_currentFilter->configuration(m_currentConfigWidget);
00132 }
00133 
00134 QString KisDlgAdjLayerProps::layerName() const
00135 {
00136     return m_layerName->text();
00137 }
00138 
00139 void KisDlgAdjLayerProps::slotConfigChanged()
00140 {
00141     if(m_preview->getAutoUpdate())
00142     {
00143         refreshPreview();
00144     } else {
00145         m_preview->needUpdate();
00146     }
00147 }
00148 
00149 void KisDlgAdjLayerProps::refreshPreview()
00150 {
00151     if (!m_preview) {
00152         kdDebug() << "no preview!\n";
00153         return;
00154     }
00155 
00156     KisPaintDeviceSP layer =  m_preview->getDevice();
00157 
00158     if (!layer) {
00159         return;
00160     }
00161 
00162     if (!m_currentFilter) {
00163         return;
00164     }
00165     KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);
00166 
00167     QRect rect = layer->extent();
00168     KisTransaction cmd("Temporary transaction", layer.data());
00169     m_currentFilter->process(layer.data(), layer.data(), config, rect);
00170     m_preview->slotUpdate();
00171     cmd.unexecute();
00172 }
00173 
00174 #include "kis_dlg_adj_layer_props.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys