summaryrefslogtreecommitdiffstats
path: root/chalk/ui/kis_dlg_adjustment_layer.cc
blob: 0594659bc362610eaf4abea2dcbb39b91247d517 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 *  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 <klocale.h>

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

#include <klineedit.h>
#include <klocale.h>

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

KisDlgAdjustmentLayer::KisDlgAdjustmentLayer(KisImage * img,
                                             const TQString & /*layerName*/,
                                             const TQString & caption,
                                             TQWidget *parent,
                                             const char *name)
    : KDialogBase(parent, name, true, "", Ok | Cancel)
    , m_image(img)
    , m_currentFilter(0)
    , m_customName(false)
    , m_freezeName(false)
{
    Q_ASSERT(img);

    KisLayerSP activeLayer = img->activeLayer();
    m_dev = 0;

    KisPaintLayer * pl = dynamic_cast<KisPaintLayer*>(activeLayer.data());
    if (pl) {
        m_dev = pl->paintDevice();
    }
    else {
        KisGroupLayer * gl = dynamic_cast<KisGroupLayer*>(activeLayer.data());
        if (gl) {
            m_dev = gl->projection(img->bounds());
        }
        else {
            KisAdjustmentLayer * al = dynamic_cast<KisAdjustmentLayer*>(activeLayer.data());
            if (al) {
                m_dev = al->cachedPaintDevice();
            }
        }
    }

    setCaption(caption);
    TQWidget * page = new TQWidget(this, "page widget");
    TQGridLayout * grid = new TQGridLayout(page, 3, 2, 0, 6);
    setMainWidget(page);

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

    m_layerName = new KLineEdit(page, "m_layerName");
    grid->addWidget(m_layerName, 0, 1);
    connect( m_layerName, TQT_SIGNAL( textChanged ( const TQString & ) ), this, TQT_SLOT( slotNameChanged( const TQString & ) ) );

    m_filtersList = new KisFiltersListView(m_dev,  page, true, "dlgadjustment.filtersList");
    connect(m_filtersList , TQT_SIGNAL(selectionChanged(TQIconViewItem*)), this, TQT_SLOT(selectionHasChanged(TQIconViewItem* )));
    grid->addMultiCellWidget(m_filtersList, 1, 2, 0, 0);

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

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

    m_configWidgetHolder = new TQGroupBox(i18n("Configuration"), page, "currentConfigWidget");
    m_configWidgetHolder->setColumnLayout(0, Qt::Horizontal);
    grid->addWidget(m_configWidgetHolder, 2, 1);

    m_labelNoConfigWidget = new TQLabel(i18n("No configuration options are available for this filter"),
                                        m_configWidgetHolder);
    m_configWidgetHolder->tqlayout()->add(m_labelNoConfigWidget);
    m_labelNoConfigWidget->hide();

    resize( TQSize(600, 480).expandedTo(minimumSizeHint()) );

    m_currentConfigWidget = 0;

    enableButtonOK(0);
}

void KisDlgAdjustmentLayer::slotNameChanged( const TQString & text )
{
    if (m_freezeName)
        return;

    m_customName = !text.isEmpty();
    enableButtonOK( m_currentFilter && m_customName );
}

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

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

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

void KisDlgAdjustmentLayer::refreshPreview()
{
    KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);

    m_preview->runFilter(m_currentFilter, config);
}

void KisDlgAdjustmentLayer::selectionHasChanged ( TQIconViewItem * item )
{
    KisFiltersIconViewItem* kisitem = (KisFiltersIconViewItem*) item;

    m_currentFilter = kisitem->filter();

    if ( m_currentConfigWidget != 0 )
    {
        m_configWidgetHolder->tqlayout()->remove(m_currentConfigWidget);

        delete m_currentConfigWidget;
        m_currentConfigWidget = 0;

    } else {

        m_labelNoConfigWidget->hide();
    }

    if (m_dev) {
        m_currentConfigWidget = m_currentFilter->createConfigurationWidget(m_configWidgetHolder,
                                                                           m_dev);
    }

    if (m_currentConfigWidget != 0)
    {
        m_configWidgetHolder->tqlayout()->add(m_currentConfigWidget);
        m_currentConfigWidget->show();
        connect(m_currentConfigWidget, TQT_SIGNAL(sigPleaseUpdatePreview()), this, TQT_SLOT(slotConfigChanged()));
    } else {
        m_labelNoConfigWidget->show();
    }

    if (!m_customName) {
        m_freezeName = true;
        m_layerName->setText(m_currentFilter->id().name());
        m_freezeName = false;
    }

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

#include "kis_dlg_adjustment_layer.moc"