Debian Codegraph @

core/dplugins/bqm/enhance/redeyecorrection/redeyecorrection.cpp

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 16/08/2016
7 * Description : A Red-Eye tool for automatic detection and correction filter.
8 *
9 * SPDX-FileCopyrightText: 2016 by Omar Amin <Omar dot moh dot amin at gmail dot com>
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 *
13 * ============================================================ */
14
15 #include "redeyecorrection.h"
16
17 // Qt includes
18
19 #include <QLabel>
20 #include <QWidget>
21
22 // KDE includes
23
24 #include <klocalizedstring.h>
25
26 // Local includes
27
28 #include "dimg.h"
29
30 namespace DigikamBqmRedEyeCorrectionPlugin
31 {
32
33 RedEyeCorrection::RedEyeCorrection(QObject* const parent)
34 : BatchTool(QLatin1String("RedEyeCorrection"), EnhanceTool, parent)
35 {
36 }
37
38 BatchTool* RedEyeCorrection::clone(QObject* const parent) const
39 {
40 return new RedEyeCorrection(parent);
41 }
42
43 void RedEyeCorrection::registerSettingsWidget()
44 {
45 m_settingsWidget = new QWidget;
46 m_settingsView = new RedEyeCorrectionSettings(m_settingsWidget);
47
48 connect(m_settingsView, SIGNAL(signalSettingsChanged()),
49 this, SLOT(slotSettingsChanged()));
50
51 BatchTool::registerSettingsWidget();
52 }
53
54 BatchToolSettings RedEyeCorrection::defaultSettings()
55 {
56 BatchToolSettings prm;
57 RedEyeCorrectionContainer defaultPrm = m_settingsView->defaultSettings();
58
59 prm.insert(QLatin1String("redtoavgratio"), (double)defaultPrm.m_redToAvgRatio);
60
61 return prm;
62 }
63
64 void RedEyeCorrection::slotAssignSettings2Widget()
65 {
66 RedEyeCorrectionContainer prm;
67 prm.m_redToAvgRatio = settings().value(QLatin1String("redtoavgratio")).toDouble();
68 m_settingsView->setSettings(prm);
69 }
70
71 void RedEyeCorrection::slotSettingsChanged()
72 {
73 BatchToolSettings prm;
74 RedEyeCorrectionContainer currentPrm = m_settingsView->settings();
75
76 prm.insert(QLatin1String("redtoavgratio"), (double)currentPrm.m_redToAvgRatio);
77
78 BatchTool::slotSettingsChanged(prm);
79 }
80
81 bool RedEyeCorrection::toolOperations()
82 {
83 if (!loadToDImg())
84 {
85 return false;
86 }
87
88 RedEyeCorrectionContainer prm;
89 prm.m_redToAvgRatio = settings().value(QLatin1String("redtoavgratio")).toDouble();
90
91 m_redEyeCFilter = new RedEyeCorrectionFilter(&image(), nullptr, prm);
92 applyFilter(m_redEyeCFilter);
93
94 delete m_redEyeCFilter;
95 m_redEyeCFilter = nullptr;
96
97 return (savefromDImg());
98 }
99
100 void RedEyeCorrection::cancel()
101 {
102 if (m_redEyeCFilter)
103 {
104 m_redEyeCFilter->cancelFilter();
105 }
106
107 BatchTool::cancel();
108 }
109
110 } // namespace DigikamBqmRedEyeCorrectionPlugin
111
112 #include "moc_redeyecorrection.cpp"