File indexing completed on 2025-01-05 03:51:28
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-05-03 0007 * Description : blur image batch tool. 0008 * 0009 * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #include "blur.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QGridLayout> 0021 #include <QWidget> 0022 #include <QApplication> 0023 #include <QStyle> 0024 0025 // KDE includes 0026 0027 #include <klocalizedstring.h> 0028 0029 // Local includes 0030 0031 #include "dimg.h" 0032 #include "blurfilter.h" 0033 0034 namespace DigikamBqmBlurPlugin 0035 { 0036 0037 Blur::Blur(QObject* const parent) 0038 : BatchTool(QLatin1String("Blur"), EnhanceTool, parent), 0039 m_radiusInput (nullptr), 0040 m_changeSettings(true) 0041 { 0042 } 0043 0044 Blur::~Blur() 0045 { 0046 } 0047 0048 BatchTool* Blur::clone(QObject* const parent) const 0049 { 0050 return new Blur(parent); 0051 } 0052 0053 void Blur::registerSettingsWidget() 0054 { 0055 const int spacing = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0056 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)); 0057 0058 m_settingsWidget = new QWidget; 0059 QLabel* label = new QLabel(i18n("Smoothness:")); 0060 m_radiusInput = new DIntNumInput(); 0061 m_radiusInput->setRange(0, 100, 1); 0062 m_radiusInput->setDefaultValue(0); 0063 m_radiusInput->setWhatsThis(i18n("A smoothness of 0 has no effect, " 0064 "1 and above determine the Gaussian blur matrix radius " 0065 "that determines how much to blur the image.")); 0066 0067 QGridLayout* grid = new QGridLayout(m_settingsWidget); 0068 grid->addWidget(label, 0, 0, 1, 2); 0069 grid->addWidget(m_radiusInput, 1, 0, 1, 2); 0070 grid->setRowStretch(2, 10); 0071 grid->setContentsMargins(spacing, spacing, spacing, spacing); 0072 grid->setSpacing(spacing); 0073 0074 connect(m_radiusInput, SIGNAL(valueChanged(int)), 0075 this, SLOT(slotSettingsChanged())); 0076 0077 BatchTool::registerSettingsWidget(); 0078 } 0079 0080 BatchToolSettings Blur::defaultSettings() 0081 { 0082 BatchToolSettings settings; 0083 settings.insert(QLatin1String("Radius"), (int)m_radiusInput->defaultValue()); 0084 return settings; 0085 } 0086 0087 void Blur::slotAssignSettings2Widget() 0088 { 0089 m_changeSettings = false; 0090 m_radiusInput->setValue(settings()[QLatin1String("Radius")].toInt()); 0091 m_changeSettings = true; 0092 } 0093 0094 void Blur::slotSettingsChanged() 0095 { 0096 if (m_changeSettings) 0097 { 0098 BatchToolSettings settings; 0099 settings.insert(QLatin1String("Radius"), (int)m_radiusInput->value()); 0100 BatchTool::slotSettingsChanged(settings); 0101 } 0102 } 0103 0104 bool Blur::toolOperations() 0105 { 0106 if (!loadToDImg()) 0107 { 0108 return false; 0109 } 0110 0111 double radius = settings()[QLatin1String("Radius")].toInt(); 0112 0113 BlurFilter blur(&image(), nullptr, radius); 0114 applyFilter(&blur); 0115 0116 return savefromDImg(); 0117 } 0118 0119 } // namespace DigikamBqmBlurPlugin 0120 0121 #include "moc_blur.cpp"