1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2020-08-13
7  * Description : batch tool to add texture.
8  *
9  * Copyright (C) 2020 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #include "texture.h"
25 
26 // Qt includes
27 
28 #include <QWidget>
29 
30 // KDE includes
31 
32 #include <klocalizedstring.h>
33 
34 // Local includes
35 
36 #include "digikam_debug.h"
37 #include "dimg.h"
38 #include "texturefilter.h"
39 
40 namespace DigikamBqmTexturePlugin
41 {
42 
Texture(QObject * const parent)43 Texture::Texture(QObject* const parent)
44     : BatchTool(QLatin1String("Texture"), DecorateTool, parent),
45       m_settingsView(nullptr)
46 {
47 }
48 
~Texture()49 Texture::~Texture()
50 {
51 }
52 
clone(QObject * const parent) const53 BatchTool* Texture::clone(QObject* const parent) const
54 {
55     return new Texture(parent);
56 }
57 
registerSettingsWidget()58 void Texture::registerSettingsWidget()
59 {
60     m_settingsWidget = new QWidget;
61     m_settingsView   = new TextureSettings(m_settingsWidget);
62     m_settingsView->resetToDefault();
63 
64     connect(m_settingsView, SIGNAL(signalSettingsChanged()),
65             this, SLOT(slotSettingsChanged()));
66 
67     BatchTool::registerSettingsWidget();
68 }
69 
defaultSettings()70 BatchToolSettings Texture::defaultSettings()
71 {
72     BatchToolSettings prm;
73     TextureContainer defaultPrm = m_settingsView->defaultSettings();
74 
75     prm.insert(QLatin1String("blendGain"),   defaultPrm.blendGain);
76     prm.insert(QLatin1String("textureType"), defaultPrm.textureType);
77 
78     return prm;
79 }
80 
slotAssignSettings2Widget()81 void Texture::slotAssignSettings2Widget()
82 {
83     TextureContainer prm;
84 
85     prm.blendGain   = settings()[QLatin1String("blendGain")].toInt();
86     prm.textureType = settings()[QLatin1String("textureType")].toInt();
87 
88     m_settingsView->setSettings(prm);
89 }
90 
slotSettingsChanged()91 void Texture::slotSettingsChanged()
92 {
93     BatchToolSettings prm;
94     TextureContainer currentPrm = m_settingsView->settings();
95 
96     prm.insert(QLatin1String("blendGain"),   currentPrm.blendGain);
97     prm.insert(QLatin1String("textureType"), currentPrm.textureType);
98 
99     BatchTool::slotSettingsChanged(prm);
100 }
101 
toolOperations()102 bool Texture::toolOperations()
103 {
104     if (!loadToDImg())
105     {
106         return false;
107     }
108 
109     TextureContainer prm;
110     prm.blendGain   = settings()[QLatin1String("blendGain")].toInt();
111     prm.textureType = settings()[QLatin1String("textureType")].toInt();
112 
113     TextureFilter bd(&image(), nullptr, prm);
114     applyFilter(&bd);
115 
116     return (savefromDImg());
117 }
118 
119 } // namespace DigikamBqmTexturePlugin
120