krita
kis_dlg_adj_layer_props.cc00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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_filters_listview.h"
00033 #include "kis_image.h"
00034 #include "kis_previewwidget.h"
00035 #include "kis_layer.h"
00036 #include "kis_adjustment_layer.h"
00037 #include "kis_paint_device.h"
00038 #include "kis_paint_layer.h"
00039 #include "kis_group_layer.h"
00040 #include "kis_dlg_adj_layer_props.h"
00041 #include "kis_filter.h"
00042 #include "kis_filter_configuration.h"
00043
00044 KisDlgAdjLayerProps::KisDlgAdjLayerProps(KisAdjustmentLayerSP layer,
00045 const QString & layerName,
00046 const QString & caption,
00047 QWidget *parent,
00048 const char *name)
00049 : KDialogBase(parent, name, true, "", Ok | Cancel)
00050 {
00051 Q_ASSERT( layer );
00052 m_layer = layer;
00053
00054 KisLayerSP next = layer->nextSibling();
00055 Q_ASSERT( next );
00056
00057 m_currentConfiguration = layer->filter();
00058 m_currentFilter = KisFilterRegistry::instance()->get(m_currentConfiguration->name());
00059 if (!m_currentFilter) {
00060 kdWarning() << "No filter specified!\n";
00061 }
00062
00063 KisPaintDeviceSP dev = 0;
00064
00065 if( next )
00066 {
00067 KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(next.data());
00068 if (pl) {
00069 dev = pl->paintDevice();
00070 }
00071 else {
00072 KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(next.data());
00073 if (gl) {
00074 dev = gl->projection(gl->extent());
00075 }
00076 else {
00077 KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(next.data());
00078 if (al) {
00079 dev = al->cachedPaintDevice();
00080 }
00081 }
00082 }
00083 } else {
00084 dev = new KisPaintDevice(m_layer->image()->colorSpace());
00085 }
00086 setCaption(caption);
00087 QWidget * page = new QWidget(this, "page widget");
00088 QHBoxLayout * layout = new QHBoxLayout(page, 0, 6);
00089 setMainWidget(page);
00090
00091 m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
00092 m_preview->slotSetDevice( dev );
00093
00094 connect( m_preview, SIGNAL(updated()), this, SLOT(refreshPreview()));
00095 layout->addWidget(m_preview, 1, 1);
00096
00097 QVBoxLayout *v1 = new QVBoxLayout( layout );
00098 QHBoxLayout *hl = new QHBoxLayout( v1 );
00099
00100 QLabel * lblName = new QLabel(i18n("Layer name:"), page, "lblName");
00101 hl->addWidget(lblName, 0, 0);
00102
00103 m_layerName = new KLineEdit(page, "m_layerName");
00104 m_layerName->setText(layerName);
00105 m_layerName->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
00106 hl->addWidget(m_layerName, 0, 1);
00107 connect( m_layerName, SIGNAL( textChanged ( const QString & ) ), this, SLOT( slotNameChanged( const QString & ) ) );
00108
00109 if ( m_currentFilter ) {
00110 m_currentConfigWidget = m_currentFilter->createConfigurationWidget(page, dev);
00111 if (m_currentConfigWidget) {
00112 m_currentConfigWidget->setConfiguration( m_currentConfiguration );
00113 }
00114 }
00115 if ( m_currentFilter == 0 || m_currentConfigWidget == 0 ) {
00116 QLabel * labelNoConfigWidget = new QLabel( i18n("No configuration options are available for this filter"), page );
00117 v1->addWidget( labelNoConfigWidget );
00118 }
00119 else {
00120 v1->addWidget( m_currentConfigWidget );
00121 connect(m_currentConfigWidget, SIGNAL(sigPleaseUpdatePreview()), this, SLOT(slotConfigChanged()));
00122 }
00123
00124 refreshPreview();
00125 enableButtonOK( !m_layerName->text().isEmpty() );
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 if (!m_currentFilter) {
00161 return;
00162 }
00163 KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);
00164
00165 m_preview->runFilter(m_currentFilter, config);
00166 }
00167
00168 #include "kis_dlg_adj_layer_props.moc"
|