1
/* ============================================================
3
* This file is a part of digiKam project
4
* http://www.digikam.org
7
* Description : a plugin to add rain drop over an image
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>
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)
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.
23
* ============================================================ */
25
#include "raindroptool.moc"
30
#include <QGridLayout>
36
#include <kapplication.h>
38
#include <kconfiggroup.h>
40
#include <kiconloader.h>
42
#include <knuminput.h>
43
#include <kstandarddirs.h>
47
#include <libkdcraw/rnuminput.h>
51
#include "editortoolsettings.h"
52
#include "imageiface.h"
53
#include "imageguidewidget.h"
54
#include "raindropfilter.h"
56
using namespace KDcrawIface;
58
namespace DigikamFxFiltersImagePlugin
61
class RainDropTool::RainDropToolPriv
73
static const QString configGroupName;
74
static const QString configDropAdjustmentEntry;
75
static const QString configAmountAdjustmentEntry;
76
static const QString configCoeffAdjustmentEntry;
78
RIntNumInput* dropInput;
79
RIntNumInput* amountInput;
80
RIntNumInput* coeffInput;
82
ImageGuideWidget* previewWidget;
83
EditorToolSettings* gboxSettings;
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");
90
// --------------------------------------------------------
92
RainDropTool::RainDropTool(QObject* parent)
93
: EditorToolThreaded(parent),
94
d(new RainDropToolPriv)
96
setObjectName("raindrops");
97
setToolName(i18n("Raindrops"));
98
setToolIcon(SmallIcon("raindrop"));
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>"));
106
setToolView(d->previewWidget);
107
setPreviewModeMask(PreviewToolBar::AllPreviewModes);
109
// -------------------------------------------------------------
111
d->gboxSettings = new EditorToolSettings;
112
d->gboxSettings->setButtons(EditorToolSettings::Default|
113
EditorToolSettings::Ok|
114
EditorToolSettings::Try|
115
EditorToolSettings::Cancel);
118
// -------------------------------------------------------------
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."));
127
// -------------------------------------------------------------
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."));
136
// -------------------------------------------------------------
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."));
146
// -------------------------------------------------------------
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);
160
// -------------------------------------------------------------
162
setToolSettings(d->gboxSettings);
166
RainDropTool::~RainDropTool()
171
void RainDropTool::readSettings()
173
KSharedConfig::Ptr config = KGlobal::config();
174
KConfigGroup group = config->group(d->configGroupName);
176
blockWidgetSignals(true);
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()));
182
blockWidgetSignals(false);
185
void RainDropTool::writeSettings()
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());
196
void RainDropTool::slotResetSettings()
198
blockWidgetSignals(true);
200
d->dropInput->slotReset();
201
d->amountInput->slotReset();
202
d->coeffInput->slotReset();
204
blockWidgetSignals(false);
209
void RainDropTool::prepareEffect()
211
int drop = d->dropInput->value();
212
int amount = d->amountInput->value();
213
int coeff = d->coeffInput->value();
215
ImageIface* iface = d->previewWidget->imageIface();
217
// Selected data from the image
218
QRect selection( iface->selectedXOrg(), iface->selectedYOrg(),
219
iface->selectedWidth(), iface->selectedHeight() );
221
setFilter(new RainDropFilter(iface->getOriginalImg(), this, drop, amount, coeff, &selection));
224
void RainDropTool::prepareFinal()
226
int drop = d->dropInput->value();
227
int amount = d->amountInput->value();
228
int coeff = d->coeffInput->value();
230
ImageIface iface(0, 0);
232
// Selected data from the image
233
QRect selection( iface.selectedXOrg(), iface.selectedYOrg(),
234
iface.selectedWidth(), iface.selectedHeight() );
236
setFilter(new RainDropFilter(iface.getOriginalImg(), this, drop, amount, coeff, &selection));
239
void RainDropTool::putPreviewData()
241
ImageIface* iface = d->previewWidget->imageIface();
242
DImg imDest = filter()->getTargetImage().smoothScale(iface->previewWidth(), iface->previewHeight());
243
iface->putPreviewImage(imDest.bits());
245
d->previewWidget->updatePreview();
248
void RainDropTool::putFinalData()
250
ImageIface iface(0, 0);
251
iface.putOriginalImage(i18n("RainDrop"), filter()->getTargetImage().bits());
254
void RainDropTool::blockWidgetSignals(bool b)
256
d->dropInput->blockSignals(b);
257
d->amountInput->blockSignals(b);
258
d->coeffInput->blockSignals(b);
261
} // namespace DigikamFxFiltersImagePlugin