summaryrefslogtreecommitdiffstats
path: root/chalk/plugins/viewplugins/filtersgallery/kis_dlg_filtersgallery.cpp
blob: e0bec7ec6afe745a2c2928b870ef8889d0740749 (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
/*
 * This file is part of Chalk
 *
 * Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
 * 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 "kis_dlg_filtersgallery.h"

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

#include <kis_filter.h>
#include <kis_filter_config_widget.h>
#include <kis_filters_listview.h>
#include <kis_paint_device.h>
#include <kis_paint_layer.h>
#include <kis_previewwidget.h>
#include <kis_transaction.h>
#include <kis_types.h>
#include <kis_view.h>

#include "kis_wdg_filtersgallery.h"

namespace Chalk {
namespace Plugins {
namespace FiltersGallery {


KisDlgFiltersGallery::KisDlgFiltersGallery(KisView* view, TQWidget* parent,const char *name)
  : KDialogBase(parent,name, true,i18n("Filters Gallery"), Ok | Cancel), m_view(view),m_currentConfigWidget(0), m_currentFilter(0)
{
   // Initialize main widget
    m_widget = new KisWdgFiltersGallery(this);
    m_widget->filtersList->setLayer(view->canvasSubject()->currentImg()->activeLayer());
    m_widget->filtersList->setProfile(view->canvasSubject()->monitorProfile());
    
    setMainWidget(m_widget);
    // Initialize filters list
    connect(m_widget->filtersList , TQT_SIGNAL(selectionChanged(TQIconViewItem*)), this, TQT_SLOT(selectionHasChanged(TQIconViewItem* )));
    // Initialize configWidgetHolder
    m_widget->configWidgetHolder->setColumnLayout ( 0, Qt::Horizontal );
    //m_widget->configWidgetHolder->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Minimum);
    // Initialize preview widget
    
    if (m_view->canvasSubject()->currentImg() && m_view->canvasSubject()->currentImg()->activeDevice())
    {
        m_widget->previewWidget->slotSetDevice( m_view->canvasSubject()->currentImg()->activeDevice().data() );
    }
    connect( m_widget->previewWidget, TQT_SIGNAL(updated()), this, TQT_SLOT(refreshPreview()));
    resize( minimumSizeHint());
    m_widget->previewWidget->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::MinimumExpanding);
    m_labelNoCW = new TQLabel(i18n("No configuration options are available for this filter."), m_widget->configWidgetHolder);
    m_widget->configWidgetHolder->layout()->add(m_labelNoCW);
    m_labelNoCW->hide();
}

KisDlgFiltersGallery::~KisDlgFiltersGallery()
{
}

void KisDlgFiltersGallery::selectionHasChanged ( TQIconViewItem * item )
{
    KisFiltersIconViewItem* kisitem = (KisFiltersIconViewItem*) item;
    m_currentFilter = kisitem->filter();
    if(m_currentConfigWidget != 0)
    {
        m_widget->configWidgetHolder->layout()->remove(m_currentConfigWidget);
        delete m_currentConfigWidget;
        m_currentConfigWidget = 0;
    } else {
        m_labelNoCW->hide();
    }
    KisImageSP img = m_view->canvasSubject()->currentImg();
    KisPaintLayerSP activeLayer = dynamic_cast<KisPaintLayer*>(img->activeLayer().data());
    
    if (activeLayer)
       m_currentConfigWidget = m_currentFilter->createConfigurationWidget(m_widget->configWidgetHolder, activeLayer->paintDevice());
    
    if(m_currentConfigWidget != 0) {
        //m_currentConfigWidget->setSizePolicy(TQSizePolicy::Fixed, TQSizePolicy::Fixed);
        m_widget->configWidgetHolder->layout()->add(m_currentConfigWidget);
        m_currentConfigWidget->show();
        connect(m_currentConfigWidget, TQT_SIGNAL(sigPleaseUpdatePreview()), this, TQT_SLOT(slotConfigChanged()));
    }
    else {
        m_labelNoCW->show();
    }
    
    refreshPreview();
}

void KisDlgFiltersGallery::slotConfigChanged()
{
    if(m_widget->previewWidget->getAutoUpdate())
    {
        refreshPreview();
    } else {
        m_widget->previewWidget->needUpdate();
    }
}


void KisDlgFiltersGallery::refreshPreview( )
{
    if(!m_currentFilter) return;

    KisFilterConfiguration* config = m_currentFilter->configuration(m_currentConfigWidget);

    m_widget->previewWidget->runFilter(m_currentFilter, config);
}

}
}
}

#include "kis_dlg_filtersgallery.moc"