~ubuntu-branches/ubuntu/saucy/digikam/saucy

« back to all changes in this revision

Viewing changes to imageplugins/filters/raindroptool.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-09-23 18:18:55 UTC
  • mfrom: (1.2.36 upstream)
  • Revision ID: package-import@ubuntu.com-20110923181855-ifs67wxkugshev9k
Tags: 2:2.1.1-0ubuntu1
[ Rohan Garg ]
* New upstream release (LP: #834190)
  - debian/control
    + Build with libqtwebkit-dev
 - debian/kipi-plugins-common
    + Install libkvkontakte required by kipi-plugins
 - debian/digikam
    + Install panoramagui

[ Philip Muškovac ]
* New upstream release
  - debian/control:
    + Add libcv-dev, libcvaux-dev, libhighgui-dev, libboost-graph1.46-dev,
      libksane-dev, libxml2-dev, libxslt-dev, libqt4-opengl-dev, libqjson-dev,
      libgpod-dev and libqca2-dev to build-deps
    + Add packages for kipi-plugins, libmediawiki, libkface, libkgeomap and
      libkvkontakte
  - debian/rules:
    + Don't build with gphoto2 since it doesn't build with it.
  - Add kubuntu_fix_test_linking.diff to fix linking of the dngconverter test
  - update install files
  - update kubuntu_01_mysqld_executable_name.diff for new cmake layout
    and rename to kubuntu_mysqld_executable_name.diff
* Fix typo in digikam-data description (LP: #804894)
* Fix Vcs links

[ Felix Geyer ]
* Move library data files to the new packages libkface-data, libkgeomap-data
  and libkvkontakte-data.
* Override version of the embedded library packages to 1.0~digikam<version>.
* Exclude the library packages from digikam-dbg to prevent file conflicts in
  the future.
* Call dh_install with --list-missing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================
2
 
 *
3
 
 * This file is a part of digiKam project
4
 
 * http://www.digikam.org
5
 
 *
6
 
 * Date        : 2004-09-30
7
 
 * Description : a plugin to add rain drop over an image
8
 
 *
9
 
 * Copyright (C) 2004-2010 by Gilles Caulier <caulier dot gilles at gmail dot com>
10
 
 * Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11
 
 *
12
 
 * This program is free software; you can redistribute it
13
 
 * and/or modify it under the terms of the GNU General
14
 
 * Public License as published by the Free Software Foundation;
15
 
 * either version 2, or (at your option)
16
 
 * any later version.
17
 
 *
18
 
 * This program is distributed in the hope that it will be useful,
19
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 
 * GNU General Public License for more details.
22
 
 *
23
 
 * ============================================================ */
24
 
 
25
 
#include "raindroptool.moc"
26
 
 
27
 
// Qt includes
28
 
 
29
 
#include <QFrame>
30
 
#include <QGridLayout>
31
 
#include <QImage>
32
 
#include <QLabel>
33
 
 
34
 
// KDE includes
35
 
 
36
 
#include <kapplication.h>
37
 
#include <kconfig.h>
38
 
#include <kconfiggroup.h>
39
 
#include <kglobal.h>
40
 
#include <kiconloader.h>
41
 
#include <klocale.h>
42
 
#include <knuminput.h>
43
 
#include <kstandarddirs.h>
44
 
 
45
 
// LibKDcraw includes
46
 
 
47
 
#include <libkdcraw/rnuminput.h>
48
 
 
49
 
// Local includes
50
 
 
51
 
#include "editortoolsettings.h"
52
 
#include "imageiface.h"
53
 
#include "imageguidewidget.h"
54
 
#include "raindropfilter.h"
55
 
 
56
 
using namespace KDcrawIface;
57
 
 
58
 
namespace DigikamFxFiltersImagePlugin
59
 
{
60
 
 
61
 
class RainDropTool::RainDropToolPriv
62
 
{
63
 
public:
64
 
 
65
 
    RainDropToolPriv() :
66
 
        dropInput(0),
67
 
        amountInput(0),
68
 
        coeffInput(0),
69
 
        previewWidget(0),
70
 
        gboxSettings(0)
71
 
    {}
72
 
 
73
 
    static const QString configGroupName;
74
 
    static const QString configDropAdjustmentEntry;
75
 
    static const QString configAmountAdjustmentEntry;
76
 
    static const QString configCoeffAdjustmentEntry;
77
 
 
78
 
    RIntNumInput*        dropInput;
79
 
    RIntNumInput*        amountInput;
80
 
    RIntNumInput*        coeffInput;
81
 
 
82
 
    ImageGuideWidget*    previewWidget;
83
 
    EditorToolSettings*  gboxSettings;
84
 
};
85
 
const QString RainDropTool::RainDropToolPriv::configGroupName("raindrops Tool");
86
 
const QString RainDropTool::RainDropToolPriv::configDropAdjustmentEntry("DropAdjustment");
87
 
const QString RainDropTool::RainDropToolPriv::configAmountAdjustmentEntry("AmountAdjustment");
88
 
const QString RainDropTool::RainDropToolPriv::configCoeffAdjustmentEntry("CoeffAdjustment");
89
 
 
90
 
// --------------------------------------------------------
91
 
 
92
 
RainDropTool::RainDropTool(QObject* parent)
93
 
    : EditorToolThreaded(parent),
94
 
      d(new RainDropToolPriv)
95
 
{
96
 
    setObjectName("raindrops");
97
 
    setToolName(i18n("Raindrops"));
98
 
    setToolIcon(SmallIcon("raindrop"));
99
 
 
100
 
    d->previewWidget = new ImageGuideWidget(0, false, ImageGuideWidget::HVGuideMode);
101
 
    d->previewWidget->setWhatsThis(i18n("This is the preview of the Raindrop effect."
102
 
                                        "<p>Note: if you have previously selected an area in the editor, "
103
 
                                        "this will be unaffected by the filter. You can use this method to "
104
 
                                        "disable the Raindrops effect on a human face, for example.</p>"));
105
 
 
106
 
    setToolView(d->previewWidget);
107
 
    setPreviewModeMask(PreviewToolBar::AllPreviewModes);
108
 
 
109
 
    // -------------------------------------------------------------
110
 
 
111
 
    d->gboxSettings = new EditorToolSettings;
112
 
    d->gboxSettings->setButtons(EditorToolSettings::Default|
113
 
                                EditorToolSettings::Ok|
114
 
                                EditorToolSettings::Try|
115
 
                                EditorToolSettings::Cancel);
116
 
 
117
 
 
118
 
    // -------------------------------------------------------------
119
 
 
120
 
    QLabel* label1 = new QLabel(i18n("Drop size:"));
121
 
    d->dropInput   = new RIntNumInput;
122
 
    d->dropInput->setRange(0, 200, 1);
123
 
    d->dropInput->setSliderEnabled(true);
124
 
    d->dropInput->setDefaultValue(80);
125
 
    d->dropInput->setWhatsThis( i18n("Set here the raindrops' size."));
126
 
 
127
 
    // -------------------------------------------------------------
128
 
 
129
 
    QLabel* label2 = new QLabel(i18n("Number:"));
130
 
    d->amountInput = new RIntNumInput;
131
 
    d->amountInput->setRange(1, 500, 1);
132
 
    d->amountInput->setSliderEnabled(true);
133
 
    d->amountInput->setDefaultValue(150);
134
 
    d->amountInput->setWhatsThis( i18n("This value controls the maximum number of raindrops."));
135
 
 
136
 
    // -------------------------------------------------------------
137
 
 
138
 
    QLabel* label3 = new QLabel(i18n("Fish eyes:"));
139
 
    d->coeffInput  = new RIntNumInput;
140
 
    d->coeffInput->setRange(1, 100, 1);
141
 
    d->coeffInput->setSliderEnabled(true);
142
 
    d->coeffInput->setDefaultValue(30);
143
 
    d->coeffInput->setWhatsThis( i18n("This value is the fish-eye-effect optical "
144
 
                                      "distortion coefficient."));
145
 
 
146
 
    // -------------------------------------------------------------
147
 
 
148
 
    QGridLayout* mainLayout = new QGridLayout;
149
 
    mainLayout->addWidget(label1,         0, 0, 1, 3);
150
 
    mainLayout->addWidget(d->dropInput,   1, 0, 1, 3);
151
 
    mainLayout->addWidget(label2,         2, 0, 1, 3);
152
 
    mainLayout->addWidget(d->amountInput, 3, 0, 1, 3);
153
 
    mainLayout->addWidget(label3,         4, 0, 1, 3);
154
 
    mainLayout->addWidget(d->coeffInput,  5, 0, 1, 3);
155
 
    mainLayout->setRowStretch(6, 10);
156
 
    mainLayout->setMargin(d->gboxSettings->spacingHint());
157
 
    mainLayout->setSpacing(d->gboxSettings->spacingHint());
158
 
    d->gboxSettings->plainPage()->setLayout(mainLayout);
159
 
 
160
 
    // -------------------------------------------------------------
161
 
 
162
 
    setToolSettings(d->gboxSettings);
163
 
    init();
164
 
}
165
 
 
166
 
RainDropTool::~RainDropTool()
167
 
{
168
 
    delete d;
169
 
}
170
 
 
171
 
void RainDropTool::readSettings()
172
 
{
173
 
    KSharedConfig::Ptr config = KGlobal::config();
174
 
    KConfigGroup group        = config->group(d->configGroupName);
175
 
 
176
 
    blockWidgetSignals(true);
177
 
 
178
 
    d->dropInput->setValue(group.readEntry(d->configDropAdjustmentEntry,     d->dropInput->defaultValue()));
179
 
    d->amountInput->setValue(group.readEntry(d->configAmountAdjustmentEntry, d->amountInput->defaultValue()));
180
 
    d->coeffInput->setValue(group.readEntry(d->configCoeffAdjustmentEntry,   d->coeffInput->defaultValue()));
181
 
 
182
 
    blockWidgetSignals(false);
183
 
}
184
 
 
185
 
void RainDropTool::writeSettings()
186
 
{
187
 
    KSharedConfig::Ptr config = KGlobal::config();
188
 
    KConfigGroup group        = config->group(d->configGroupName);
189
 
    group.writeEntry(d->configDropAdjustmentEntry,   d->dropInput->value());
190
 
    group.writeEntry(d->configAmountAdjustmentEntry, d->amountInput->value());
191
 
    group.writeEntry(d->configCoeffAdjustmentEntry,  d->coeffInput->value());
192
 
 
193
 
    group.sync();
194
 
}
195
 
 
196
 
void RainDropTool::slotResetSettings()
197
 
{
198
 
    blockWidgetSignals(true);
199
 
 
200
 
    d->dropInput->slotReset();
201
 
    d->amountInput->slotReset();
202
 
    d->coeffInput->slotReset();
203
 
 
204
 
    blockWidgetSignals(false);
205
 
 
206
 
    slotEffect();
207
 
}
208
 
 
209
 
void RainDropTool::prepareEffect()
210
 
{
211
 
    int drop   = d->dropInput->value();
212
 
    int amount = d->amountInput->value();
213
 
    int coeff  = d->coeffInput->value();
214
 
 
215
 
    ImageIface* iface = d->previewWidget->imageIface();
216
 
 
217
 
    // Selected data from the image
218
 
    QRect selection( iface->selectedXOrg(), iface->selectedYOrg(),
219
 
                     iface->selectedWidth(), iface->selectedHeight() );
220
 
 
221
 
    setFilter(new RainDropFilter(iface->getOriginalImg(), this, drop, amount, coeff, &selection));
222
 
}
223
 
 
224
 
void RainDropTool::prepareFinal()
225
 
{
226
 
    int drop   = d->dropInput->value();
227
 
    int amount = d->amountInput->value();
228
 
    int coeff  = d->coeffInput->value();
229
 
 
230
 
    ImageIface iface(0, 0);
231
 
 
232
 
    // Selected data from the image
233
 
    QRect selection( iface.selectedXOrg(), iface.selectedYOrg(),
234
 
                     iface.selectedWidth(), iface.selectedHeight() );
235
 
 
236
 
    setFilter(new RainDropFilter(iface.getOriginalImg(), this, drop, amount, coeff, &selection));
237
 
}
238
 
 
239
 
void RainDropTool::putPreviewData()
240
 
{
241
 
    ImageIface* iface = d->previewWidget->imageIface();
242
 
    DImg imDest       = filter()->getTargetImage().smoothScale(iface->previewWidth(), iface->previewHeight());
243
 
    iface->putPreviewImage(imDest.bits());
244
 
 
245
 
    d->previewWidget->updatePreview();
246
 
}
247
 
 
248
 
void RainDropTool::putFinalData()
249
 
{
250
 
    ImageIface iface(0, 0);
251
 
    iface.putOriginalImage(i18n("RainDrop"), filter()->getTargetImage().bits());
252
 
}
253
 
 
254
 
void RainDropTool::blockWidgetSignals(bool b)
255
 
{
256
 
    d->dropInput->blockSignals(b);
257
 
    d->amountInput->blockSignals(b);
258
 
    d->coeffInput->blockSignals(b);
259
 
}
260
 
 
261
 
}  // namespace DigikamFxFiltersImagePlugin