| 1 |
/* ============================================================ |
| 2 |
* |
| 3 |
* This file is a part of digiKam project |
| 4 |
* https://www.digikam.org |
| 5 |
* |
| 6 |
* Date : 2010-05-03 |
| 7 |
* Description : blur image batch tool. |
| 8 |
* |
| 9 |
* SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com> |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 12 |
* |
| 13 |
* ============================================================ */ |
| 14 |
|
| 15 |
#include "blur.h" |
| 16 |
|
| 17 |
// Qt includes |
| 18 |
|
| 19 |
#include <QLabel> |
| 20 |
#include <QGridLayout> |
| 21 |
#include <QWidget> |
| 22 |
#include <QApplication> |
| 23 |
#include <QStyle> |
| 24 |
|
| 25 |
// KDE includes |
| 26 |
|
| 27 |
#include <klocalizedstring.h> |
| 28 |
|
| 29 |
// Local includes |
| 30 |
|
| 31 |
#include "dimg.h" |
| 32 |
#include "blurfilter.h" |
| 33 |
|
| 34 |
namespace DigikamBqmBlurPlugin |
| 35 |
{ |
| 36 |
|
| 37 |
Blur::Blur(QObject* const parent) |
| 38 |
: BatchTool(QLatin1String("Blur"), EnhanceTool, parent) |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
BatchTool* Blur::clone(QObject* const parent) const |
| 43 |
{ |
| 44 |
return new Blur(parent); |
| 45 |
} |
| 46 |
|
| 47 |
void Blur::registerSettingsWidget() |
| 48 |
{ |
| 49 |
const int spacing = layoutSpacing(); |
| 50 |
|
| 51 |
|
| 52 |
m_settingsWidget = new QWidget; |
| 53 |
QLabel* label = new QLabel(i18n("Smoothness:")); |
| 54 |
m_radiusInput = new DIntNumInput(); |
| 55 |
m_radiusInput->setRange(0, 100, 1); |
| 56 |
m_radiusInput->setDefaultValue(0); |
| 57 |
m_radiusInput->setWhatsThis(i18n("A smoothness of 0 has no effect, " |
| 58 |
"1 and above determine the Gaussian blur matrix radius " |
| 59 |
"that determines how much to blur the image.")); |
| 60 |
|
| 61 |
QGridLayout* grid = new QGridLayout(m_settingsWidget); |
| 62 |
grid->addWidget(label, 0, 0, 1, 2); |
| 63 |
grid->addWidget(m_radiusInput, 1, 0, 1, 2); |
| 64 |
grid->setRowStretch(2, 10); |
| 65 |
grid->setContentsMargins(spacing, spacing, spacing, spacing); |
| 66 |
grid->setSpacing(spacing); |
| 67 |
|
| 68 |
connect(m_radiusInput, SIGNAL(valueChanged(int)), |
| 69 |
this, SLOT(slotSettingsChanged())); |
| 70 |
|
| 71 |
BatchTool::registerSettingsWidget(); |
| 72 |
} |
| 73 |
|
| 74 |
BatchToolSettings Blur::defaultSettings() |
| 75 |
{ |
| 76 |
BatchToolSettings settings; |
| 77 |
settings.insert(QLatin1String("Radius"), (int)m_radiusInput->defaultValue()); |
| 78 |
return settings; |
| 79 |
} |
| 80 |
|
| 81 |
void Blur::slotAssignSettings2Widget() |
| 82 |
{ |
| 83 |
m_changeSettings = false; |
| 84 |
m_radiusInput->setValue(settings().value(QLatin1String("Radius")).toInt()); |
| 85 |
m_changeSettings = true; |
| 86 |
} |
| 87 |
|
| 88 |
void Blur::slotSettingsChanged() |
| 89 |
{ |
| 90 |
if (m_changeSettings) |
| 91 |
{ |
| 92 |
BatchToolSettings settings; |
| 93 |
settings.insert(QLatin1String("Radius"), (int)m_radiusInput->value()); |
| 94 |
BatchTool::slotSettingsChanged(settings); |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
bool Blur::toolOperations() |
| 99 |
{ |
| 100 |
if (!loadToDImg()) |
| 101 |
{ |
| 102 |
return false; |
| 103 |
} |
| 104 |
|
| 105 |
double radius = settings().value(QLatin1String("Radius")).toInt(); |
| 106 |
|
| 107 |
BlurFilter blur(&image(), nullptr, radius); |
| 108 |
applyFilter(&blur); |
| 109 |
|
| 110 |
return savefromDImg(); |
| 111 |
} |
| 112 |
|
| 113 |
} // namespace DigikamBqmBlurPlugin |
| 114 |
|
| 115 |
#include "moc_blur.cpp" |