1 /* This file is part of the KDE project
2 * Copyright (c) 2009 Jan Hambrecht <jaham@gmx.net>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "BlendEffectConfigWidget.h"
21 #include "BlendEffect.h"
22 #include "KoFilterEffect.h"
23
24 #include <kcombobox.h>
25 #include <klocalizedstring.h>
26
27 #include <QGridLayout>
28 #include <QLabel>
29
BlendEffectConfigWidget(QWidget * parent)30 BlendEffectConfigWidget::BlendEffectConfigWidget(QWidget *parent)
31 : KoFilterEffectConfigWidgetBase(parent), m_effect(0)
32 {
33 QGridLayout * g = new QGridLayout(this);
34
35 g->addWidget(new QLabel(i18n("Blend mode"), this), 0, 0);
36 m_mode = new KComboBox(this);
37 m_mode->addItem(i18n("Normal"));
38 m_mode->addItem(i18n("Multiply"));
39 m_mode->addItem(i18n("Screen"));
40 m_mode->addItem(i18n("Darken"));
41 m_mode->addItem(i18n("Lighten"));
42 g->addWidget(m_mode, 0, 1);
43 g->addItem(new QSpacerItem(0, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 1, 0);
44
45 setLayout(g);
46
47 connect(m_mode, SIGNAL(currentIndexChanged(int)), this, SLOT(modeChanged(int)));
48 }
49
editFilterEffect(KoFilterEffect * filterEffect)50 bool BlendEffectConfigWidget::editFilterEffect(KoFilterEffect * filterEffect)
51 {
52 m_effect = dynamic_cast<BlendEffect*>(filterEffect);
53 if (!m_effect)
54 return false;
55
56 m_mode->blockSignals(true);
57
58 switch (m_effect->blendMode()) {
59 case BlendEffect::Normal:
60 m_mode->setCurrentIndex(0);
61 break;
62 case BlendEffect::Multiply:
63 m_mode->setCurrentIndex(1);
64 break;
65 case BlendEffect::Screen:
66 m_mode->setCurrentIndex(2);
67 break;
68 case BlendEffect::Darken:
69 m_mode->setCurrentIndex(3);
70 break;
71 case BlendEffect::Lighten:
72 m_mode->setCurrentIndex(4);
73 break;
74 }
75
76 m_mode->blockSignals(false);
77
78 return true;
79 }
80
modeChanged(int index)81 void BlendEffectConfigWidget::modeChanged(int index)
82 {
83 if (!m_effect)
84 return;
85
86 m_effect->setBlendMode(static_cast<BlendEffect::BlendMode>(index));
87
88 emit filterChanged();
89 }
90