File indexing completed on 2025-01-05 03:51:40
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2004-07-09 0007 * Description : a tool to blur an image 0008 * 0009 * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 2009 by Andi Clemens <andi dot clemens at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #include "blurtool.h" 0017 0018 // Qt includes 0019 0020 #include <QGridLayout> 0021 #include <QLabel> 0022 #include <QIcon> 0023 0024 // KDE includes 0025 0026 #include <kconfiggroup.h> 0027 #include <ksharedconfig.h> 0028 #include <klocalizedstring.h> 0029 0030 // Local includes 0031 0032 #include "dnuminput.h" 0033 #include "blurfilter.h" 0034 #include "editortoolsettings.h" 0035 #include "imageiface.h" 0036 #include "imageregionwidget.h" 0037 0038 namespace DigikamEditorBlurToolPlugin 0039 { 0040 0041 class Q_DECL_HIDDEN BlurTool::Private 0042 { 0043 public: 0044 0045 explicit Private() 0046 : radiusInput (nullptr), 0047 previewWidget(nullptr), 0048 gboxSettings (nullptr) 0049 { 0050 } 0051 0052 static const QString configGroupName; 0053 static const QString configRadiusAdjustmentEntry; 0054 0055 DIntNumInput* radiusInput; 0056 ImageRegionWidget* previewWidget; 0057 EditorToolSettings* gboxSettings; 0058 }; 0059 0060 const QString BlurTool::Private::configGroupName(QLatin1String("gaussianblur Tool")); 0061 const QString BlurTool::Private::configRadiusAdjustmentEntry(QLatin1String("RadiusAdjustment")); 0062 0063 // -------------------------------------------------------- 0064 0065 BlurTool::BlurTool(QObject* const parent) 0066 : EditorToolThreaded(parent), 0067 d (new Private) 0068 { 0069 setObjectName(QLatin1String("gaussianblur")); 0070 setToolHelp(QLatin1String("blursharpentool.anchor")); 0071 0072 d->gboxSettings = new EditorToolSettings(nullptr); 0073 d->previewWidget = new ImageRegionWidget; 0074 0075 // -------------------------------------------------------- 0076 0077 QLabel* const label = new QLabel(i18n("Smoothness:")); 0078 d->radiusInput = new DIntNumInput(); 0079 d->radiusInput->setRange(0, 100, 1); 0080 d->radiusInput->setDefaultValue(0); 0081 d->radiusInput->setWhatsThis(i18n("A smoothness of 0 has no effect, " 0082 "1 and above determine the Gaussian blur matrix radius " 0083 "that determines how much to blur the image.")); 0084 0085 // -------------------------------------------------------- 0086 0087 const int spacing = d->gboxSettings->spacingHint(); 0088 0089 QGridLayout* const grid = new QGridLayout( ); 0090 grid->addWidget(label, 0, 0, 1, 2); 0091 grid->addWidget(d->radiusInput, 1, 0, 1, 2); 0092 grid->setRowStretch(2, 10); 0093 grid->setContentsMargins(spacing, spacing, spacing, spacing); 0094 grid->setSpacing(spacing); 0095 d->gboxSettings->plainPage()->setLayout(grid); 0096 0097 // -------------------------------------------------------- 0098 0099 setPreviewModeMask(PreviewToolBar::AllPreviewModes); 0100 setToolSettings(d->gboxSettings); 0101 setToolView(d->previewWidget); 0102 0103 // -------------------------------------------------------- 0104 0105 connect(d->radiusInput, SIGNAL(valueChanged(int)), 0106 this, SLOT(slotTimer())); 0107 } 0108 0109 BlurTool::~BlurTool() 0110 { 0111 delete d; 0112 } 0113 0114 void BlurTool::readSettings() 0115 { 0116 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0117 KConfigGroup group = config->group(d->configGroupName); 0118 d->radiusInput->setValue(group.readEntry(d->configRadiusAdjustmentEntry, d->radiusInput->defaultValue())); 0119 } 0120 0121 void BlurTool::writeSettings() 0122 { 0123 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0124 KConfigGroup group = config->group(d->configGroupName); 0125 group.writeEntry(d->configRadiusAdjustmentEntry, d->radiusInput->value()); 0126 config->sync(); 0127 } 0128 0129 void BlurTool::slotResetSettings() 0130 { 0131 d->radiusInput->blockSignals(true); 0132 d->radiusInput->slotReset(); 0133 d->radiusInput->blockSignals(false); 0134 } 0135 0136 void BlurTool::preparePreview() 0137 { 0138 DImg img = d->previewWidget->getOriginalRegionImage(); 0139 setFilter(new BlurFilter(&img, this, d->radiusInput->value())); 0140 } 0141 0142 void BlurTool::setPreviewImage() 0143 { 0144 DImg preview = filter()->getTargetImage(); 0145 d->previewWidget->setPreviewImage(preview); 0146 } 0147 0148 void BlurTool::prepareFinal() 0149 { 0150 ImageIface iface; 0151 setFilter(new BlurFilter(iface.original(), this, d->radiusInput->value())); 0152 } 0153 0154 void BlurTool::setFinalImage() 0155 { 0156 ImageIface iface; 0157 iface.setOriginal(i18n("Gaussian Blur"), filter()->filterAction(), filter()->getTargetImage()); 0158 } 0159 0160 } // namespace DigikamEditorBlurToolPlugin 0161 0162 #include "moc_blurtool.cpp"