1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2005-03-10
7 * Description : a tool to apply texture over an image
8 *
9 * Copyright (C) 2005-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 * Copyright (C) 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
11 *
12 * This program is free software; you can redistribute it
13 * and/or modify it under the terms of the GNU General
14 * Public License as published by the Free Software Foundation;
15 * either version 2, or (at your option)
16 * any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * ============================================================ */
24
25 #include "texturetool.h"
26
27 // Qt includes
28
29 #include <QGridLayout>
30 #include <QImage>
31 #include <QLabel>
32 #include <QIcon>
33
34 // KDE includes
35
36 #include <kconfiggroup.h>
37 #include <ksharedconfig.h>
38 #include <klocalizedstring.h>
39
40 // Local includes
41
42 #include "dimg.h"
43 #include "editortoolsettings.h"
44 #include "imageiface.h"
45 #include "imageregionwidget.h"
46 #include "texturesettings.h"
47 #include "texturefilter.h"
48
49 namespace DigikamEditorTextureToolPlugin
50 {
51
52 class Q_DECL_HIDDEN TextureTool::Private
53 {
54 public:
55
Private()56 explicit Private()
57 : configGroupName(QLatin1String("texture Tool")),
58 settingsView (nullptr),
59 previewWidget (nullptr),
60 gboxSettings (nullptr)
61 {
62 }
63
64 const QString configGroupName;
65
66 TextureSettings* settingsView;
67 ImageRegionWidget* previewWidget;
68 EditorToolSettings* gboxSettings;
69 };
70
71 // --------------------------------------------------------
72
TextureTool(QObject * const parent)73 TextureTool::TextureTool(QObject* const parent)
74 : EditorToolThreaded(parent),
75 d (new Private)
76 {
77 setObjectName(QLatin1String("texture"));
78
79 // -------------------------------------------------------------
80
81 d->gboxSettings = new EditorToolSettings(nullptr);
82 d->previewWidget = new ImageRegionWidget;
83 d->settingsView = new TextureSettings(d->gboxSettings->plainPage());
84
85 // -------------------------------------------------------------
86
87 setToolSettings(d->gboxSettings);
88 setToolView(d->previewWidget);
89 setPreviewModeMask(PreviewToolBar::AllPreviewModes);
90
91 // -------------------------------------------------------------
92
93 connect(d->settingsView, SIGNAL(signalSettingsChanged()),
94 this, SLOT(slotTimer()));
95 }
96
~TextureTool()97 TextureTool::~TextureTool()
98 {
99 delete d;
100 }
101
readSettings()102 void TextureTool::readSettings()
103 {
104 KSharedConfig::Ptr config = KSharedConfig::openConfig();
105 KConfigGroup group = config->group(d->configGroupName);
106
107 d->settingsView->readSettings(group);
108 }
109
writeSettings()110 void TextureTool::writeSettings()
111 {
112 KSharedConfig::Ptr config = KSharedConfig::openConfig();
113 KConfigGroup group = config->group(d->configGroupName);
114
115 d->settingsView->writeSettings(group);
116
117 group.sync();
118 }
119
slotResetSettings()120 void TextureTool::slotResetSettings()
121 {
122 d->settingsView->resetToDefault();
123 }
124
preparePreview()125 void TextureTool::preparePreview()
126 {
127 DImg image = d->previewWidget->getOriginalRegionImage();
128 TextureContainer settings = d->settingsView->settings();
129 setFilter(new TextureFilter(&image, this, settings));
130 }
131
prepareFinal()132 void TextureTool::prepareFinal()
133 {
134 ImageIface iface;
135 TextureContainer settings = d->settingsView->settings();
136 setFilter(new TextureFilter(iface.original(), this, settings));
137 }
138
setPreviewImage()139 void TextureTool::setPreviewImage()
140 {
141 d->previewWidget->setPreviewImage(filter()->getTargetImage());
142 }
143
setFinalImage()144 void TextureTool::setFinalImage()
145 {
146 ImageIface iface;
147 iface.setOriginal(i18n("Texture"), filter()->filterAction(), filter()->getTargetImage());
148 }
149
150 } // namespace DigikamEditorTextureToolPlugin
151