summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_dlg_adj_layer_props.cpp
blob: f7d75310eb7cd1af0bc6c98d20b39ab0a69d5aeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *  Copyright (c) 2006 Boudewijn Rempt <boud@valdyas.org>
 *  Copyright (c) 2007 Benjamin Schleimer <bensch128@yahoo.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
#include <tdelocale.h>

#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>

#include <klineedit.h>
#include <tdelocale.h>

#include "kis_filter_config_widget.h"
#include "kis_transaction.h"
#include "kis_filter.h"
#include "kis_filter_configuration.h"
#include "kis_filters_listview.h"
#include "kis_image.h"
#include "kis_previewwidget.h"
#include "kis_layer.h"
#include "kis_adjustment_layer.h"
#include "kis_paint_device.h"
#include "kis_paint_layer.h"
#include "kis_group_layer.h"
#include "kis_dlg_adj_layer_props.h"
#include "kis_filter.h"
#include "kis_filter_configuration.h"

KisDlgAdjLayerProps::KisDlgAdjLayerProps(KisAdjustmentLayerSP layer,
                                         const TQString & layerName,
                                         const TQString & caption,
                                         TQWidget *parent,
                                         const char *name)
    : KDialogBase(parent, name, true, "", Ok | Cancel)
{
    Q_ASSERT( layer );
    m_layer = layer;

    KisLayerSP next = layer->nextSibling();
    Q_ASSERT( next );

    m_currentConfiguration = layer->filter();
    m_currentFilter = KisFilterRegistry::instance()->get(m_currentConfiguration->name());
    if (!m_currentFilter) {
        kdWarning() << "No filter specified!\n";
    }

    KisPaintDeviceSP dev = 0;

    if( next )
    {
        KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(next.data());
        if (pl) {
            dev = pl->paintDevice();
        }
        else {
            KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(next.data());
            if (gl) {
                dev = gl->projection(gl->extent());
            }
            else {
                KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(next.data());
                if (al) {
                    dev = al->cachedPaintDevice();
                }
            }
        }
    } else {
        dev = new KisPaintDevice(m_layer->image()->colorSpace());
    }
    setCaption(caption);
    TQWidget * page = new TQWidget(this, "page widget");
    TQHBoxLayout * layout = new TQHBoxLayout(page, 0, 6);
    setMainWidget(page);

    m_preview = new KisPreviewWidget(page, "dlgadjustment.preview");
    m_preview->slotSetDevice( dev );

    connect( m_preview, TQT_SIGNAL(updated()), this, TQT_SLOT(refreshPreview()));
    layout->addWidget(m_preview, 1, 1);

    TQVBoxLayout *v1 = new TQVBoxLayout( layout );
    TQHBoxLayout *hl = new TQHBoxLayout( v1 );

    TQLabel * lblName = new TQLabel(i18n("Layer name:"), page, "lblName");
    hl->addWidget(lblName, 0, 0);

    m_layerName = new KLineEdit(page, "m_layerName");
    m_layerName->setText(layerName);
    m_layerName->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::Fixed);
    hl->addWidget(m_layerName, 0, 1);
    connect( m_layerName, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slotNameChanged( const TQString & ) ) );

    if ( m_currentFilter ) {
        m_currentConfigWidget = m_currentFilter->createConfigurationWidget(page, dev);
        if (m_currentConfigWidget) {
            m_currentConfigWidget->setConfiguration( m_currentConfiguration );
        }
    }
    if ( m_currentFilter == 0 || m_currentConfigWidget == 0 ) {
        TQLabel * labelNoConfigWidget = new TQLabel( i18n("No configuration options are available for this filter"), page );
        v1->addWidget( labelNoConfigWidget );
    }
    else {
        v1->addWidget( m_currentConfigWidget );
        connect(m_currentConfigWidget, TQT_SIGNAL(sigPleaseUpdatePreview()), this, TQT_SLOT(slotConfigChanged()));
    }

    refreshPreview();
    enableButtonOK( !m_layerName->text().isEmpty() );
}

void KisDlgAdjLayerProps::slotNameChanged( const TQString & text )
{
    enableButtonOK( !text.isEmpty() );
}

KisFilterConfiguration * KisDlgAdjLayerProps::filterConfiguration() const
{
    return m_currentFilter->configuration(m_currentConfigWidget);
}

TQString KisDlgAdjLayerProps::layerName() const
{
    return m_layerName->text();
}

void KisDlgAdjLayerProps::slotConfigChanged()
{
    if(m_preview->getAutoUpdate())
    {
        refreshPreview();
    } else {
        m_preview->needUpdate();
    }
}

void KisDlgAdjLayerProps::refreshPreview()
{
    if (!m_preview) {
        kdDebug() << "no preview!\n";
        return;
    }

    if (!m_currentFilter) {
        return;
    }
    KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);

    m_preview->runFilter(m_currentFilter, config);
}

#include "kis_dlg_adj_layer_props.moc"