00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 if( next )
00065 {
00066 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(next.data());
00067 if (pl) {
00068 dev = pl->paintDevice();
00069 }
00070 else {
00071 KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(next.data());
00072 if (gl) {
00073 dev = gl->projection(gl->extent());
00074 }
00075 else {
00076 KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(next.data());
00077 if (al) {
00078 dev = al->cachedPaintDevice();
00079 }
00080 }
00081 }
00082 } else {
00083 dev = new KisPaintDevice(m_layer->image()->colorSpace());
00084 }
00085 setCaption(caption);
00086 QWidget * page = new QWidget(this, "page widget");
00087 QHBoxLayout * layout = new QHBoxLayout(page, 0, 6);
00088 setMainWidget(page);
00089
00090 m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
00091 m_preview->slotSetDevice( dev );
00092
00093 connect( m_preview, SIGNAL(updated()), this, SLOT(refreshPreview()));
00094 layout->addWidget(m_preview, 1, 1);
00095
00096 QVBoxLayout *v1 = new QVBoxLayout( layout );
00097 QHBoxLayout *hl = new QHBoxLayout( v1 );
00098
00099 QLabel * lblName = new QLabel(i18n("Layer name:"), page, "lblName");
00100 hl->addWidget(lblName, 0, 0);
00101
00102 m_layerName = new KLineEdit(page, "m_layerName");
00103 m_layerName->setText(layerName);
00104 m_layerName->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
00105 hl->addWidget(m_layerName, 0, 1);
00106 connect( m_layerName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) );
00107
00108 if ( m_currentFilter ) {
00109 m_currentConfigWidget = m_currentFilter->createConfigurationWidget(page, dev);
00110 if (m_currentConfigWidget) {
00111 m_currentConfigWidget->setConfiguration( m_currentConfiguration );
00112 }
00113 }
00114 if ( m_currentFilter == 0 || m_currentConfigWidget == 0 ) {
00115 QLabel * labelNoConfigWidget = new QLabel( i18n("No configuration options are available for this filter"), page );
00116 v1->addWidget( labelNoConfigWidget );
00117 }
00118 else {
00119 v1->addWidget( m_currentConfigWidget );
00120 connect(m_currentConfigWidget, SIGNAL(sigPleaseUpdatePreview()), this, SLOT(slotConfigChanged()));
00121 }
00122
00123 refreshPreview();
00124 enableButtonOK( !m_layerName->text().isEmpty() );
00125
00126 }
00127
00128 void KisDlgAdjLayerProps::slotNameChanged( const QString & text )
00129 {
00130 enableButtonOK( !text.isEmpty() );
00131 }
00132
00133 KisFilterConfiguration * KisDlgAdjLayerProps::filterConfiguration() const
00134 {
00135 return m_currentFilter->configuration(m_currentConfigWidget);
00136 }
00137
00138 QString KisDlgAdjLayerProps::layerName() const
00139 {
00140 return m_layerName->text();
00141 }
00142
00143 void KisDlgAdjLayerProps::slotConfigChanged()
00144 {
00145 if(m_preview->getAutoUpdate())
00146 {
00147 refreshPreview();
00148 } else {
00149 m_preview->needUpdate();
00150 }
00151 }
00152
00153 void KisDlgAdjLayerProps::refreshPreview()
00154 {
00155 if (!m_preview) {
00156 kdDebug() << "no preview!\n";
00157 return;
00158 }
00159
00160 KisPaintDeviceSP layer = m_preview->getDevice();
00161
00162 if (!layer) {
00163 return;
00164 }
00165
00166 if (!m_currentFilter) {
00167 return;
00168 }
00169 KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);
00170
00171 QRect rect = layer->extent();
00172 KisTransaction cmd("Temporary transaction", layer.data());
00173 m_currentFilter->process(layer.data(), layer.data(), config, rect);
00174 m_preview->slotUpdate();
00175 cmd.unexecute();
00176 }
00177
00178 #include "kis_dlg_adj_layer_props.moc"