1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2004-12-23
* Description : a tool to shear an image
*
* SPDX-FileCopyrightText: 2004-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "sheartool.h"
// Qt includes
#include <QCheckBox>
#include <QGridLayout>
#include <QImage>
#include <QLabel>
#include <QIcon>
// KDE includes
#include <ksharedconfig.h>
#include <kconfiggroup.h>
#include <klocalizedstring.h>
// Local includes
#include "dlayoutbox.h"
#include "dnuminput.h"
#include "dimg.h"
#include "editortoolsettings.h"
#include "imageiface.h"
#include "imageguidewidget.h"
#include "shearfilter.h"
#include "dexpanderbox.h"
namespace DigikamEditorShearToolPlugin
{
class Q_DECL_HIDDEN ShearTool::Private
{
public:
Private() = default;
const QString configGroupName = QLatin1String("shear Tool");
const QString configAntiAliasingEntry = QLatin1String("Anti Aliasing");
const QString configMainHAngleEntry = QLatin1String("Main HAngle");
const QString configMainVAngleEntry = QLatin1String("Main VAngle");
const QString configFineHAngleEntry = QLatin1String("Fine HAngle");
const QString configFineVAngleEntry = QLatin1String("Fine VAngle");
QLabel* newWidthLabel = nullptr;
QLabel* newHeightLabel = nullptr;
QCheckBox* antialiasInput = nullptr;
DIntNumInput* mainHAngleInput = nullptr;
DIntNumInput* mainVAngleInput = nullptr;
DDoubleNumInput* fineHAngleInput = nullptr;
DDoubleNumInput* fineVAngleInput = nullptr;
ImageGuideWidget* previewWidget = nullptr;
EditorToolSettings* gboxSettings = nullptr;
};
// --------------------------------------------------------
ShearTool::ShearTool(QObject* const parent)
: EditorToolThreaded(parent),
d (new Private)
{
setObjectName(QLatin1String("sheartool"));
d->previewWidget = new ImageGuideWidget(nullptr, true, ImageGuideWidget::HVGuideMode);
d->previewWidget->setWhatsThis(i18n("This is the shear operation preview. "
"If you move the mouse cursor on this preview, "
"a vertical and horizontal dashed line will be drawn "
"to guide you in adjusting the shear correction. "
"Release the left mouse button to freeze the dashed "
"line's position."));
setToolView(d->previewWidget);
setPreviewModeMask(PreviewToolBar::UnSplitPreviewModes);
// -------------------------------------------------------------
QString temp;
ImageIface iface;
d->gboxSettings = new EditorToolSettings(nullptr);
d->gboxSettings->setTools(EditorToolSettings::ColorGuide);
// -------------------------------------------------------------
QLabel* label1 = new QLabel(i18n("New width:"));
d->newWidthLabel = new QLabel(temp.setNum(iface.originalSize().width()) + i18n(" px"));
d->newWidthLabel->setAlignment(Qt::AlignBottom | Qt::AlignRight);
QLabel* label2 = new QLabel(i18n("New height:"));
d->newHeightLabel = new QLabel(temp.setNum(iface.originalSize().height()) + i18n(" px"));
d->newHeightLabel->setAlignment(Qt::AlignBottom | Qt::AlignRight);
QLabel* label3 = new QLabel(i18n("Main horizontal angle:"));
d->mainHAngleInput = new DIntNumInput;
d->mainHAngleInput->setRange(-45, 45, 1);
d->mainHAngleInput->setDefaultValue(0);
d->mainHAngleInput->setWhatsThis( i18n("The main horizontal shearing angle, in degrees."));
QLabel* label4 = new QLabel(i18n("Fine horizontal angle:"));
d->fineHAngleInput = new DDoubleNumInput;
d->fineHAngleInput->setRange(-1.0, 1.0, 0.01);
d->fineHAngleInput->setDefaultValue(0);
d->fineHAngleInput->setWhatsThis( i18n("This value in degrees will be added to main "
"horizontal angle value to set fine adjustments."));
QLabel* label5 = new QLabel(i18n("Main vertical angle:"));
d->mainVAngleInput = new DIntNumInput;
d->mainVAngleInput->setRange(-45, 45, 1);
d->mainVAngleInput->setDefaultValue(0);
d->mainVAngleInput->setWhatsThis( i18n("The main vertical shearing angle, in degrees."));
QLabel* label6 = new QLabel(i18n("Fine vertical angle:"));
d->fineVAngleInput = new DDoubleNumInput;
d->fineVAngleInput->setRange(-1.0, 1.0, 0.01);
d->fineVAngleInput->setDefaultValue(0);
d->fineVAngleInput->setWhatsThis( i18n("This value in degrees will be added to main vertical "
"angle value to set fine adjustments."));
d->antialiasInput = new QCheckBox(i18n("Anti-Aliasing"));
d->antialiasInput->setWhatsThis( i18n("Enable this option to apply the anti-aliasing filter "
"to the sheared image. "
"To smooth the target image, it will be blurred a little."));
DLineWidget* line = new DLineWidget(Qt::Horizontal);
// -------------------------------------------------------------
const int spacing = d->gboxSettings->spacingHint();
QGridLayout* grid = new QGridLayout;
grid->setSpacing(0);
grid->addWidget(label1, 0, 0, 1, 1);
grid->addWidget(d->newWidthLabel, 0, 1, 1, 2);
grid->addWidget(label2, 1, 0, 1, 1);
grid->addWidget(d->newHeightLabel, 1, 1, 1, 2);
grid->addWidget(line, 2, 0, 1, 3);
grid->addWidget(label3, 3, 0, 1, 3);
grid->addWidget(d->mainHAngleInput, 4, 0, 1, 3);
grid->addWidget(label4, 5, 0, 1, 3);
grid->addWidget(d->fineHAngleInput, 6, 0, 1, 3);
grid->addWidget(label5, 7, 0, 1, 1);
grid->addWidget(d->mainVAngleInput, 8, 0, 1, 3);
grid->addWidget(label6, 9, 0, 1, 3);
grid->addWidget(d->fineVAngleInput, 10, 0, 1, 3);
grid->addWidget(d->antialiasInput, 11, 0, 1, 3);
grid->setRowStretch(12, 10);
grid->setContentsMargins(spacing, spacing, spacing, spacing);
grid->setSpacing(spacing);
d->gboxSettings->plainPage()->setLayout(grid);
// -------------------------------------------------------------
setToolSettings(d->gboxSettings);
// -------------------------------------------------------------
connect(d->mainHAngleInput, SIGNAL(valueChanged(int)),
this, SLOT(slotTimer()));
connect(d->fineHAngleInput, SIGNAL(valueChanged(double)),
this, SLOT(slotTimer()));
connect(d->mainVAngleInput, SIGNAL(valueChanged(int)),
this, SLOT(slotTimer()));
connect(d->fineVAngleInput, SIGNAL(valueChanged(double)),
this, SLOT(slotTimer()));
connect(d->antialiasInput, SIGNAL(toggled(bool)),
this, SLOT(slotPreview()));
connect(d->gboxSettings, SIGNAL(signalColorGuideChanged()),
this, SLOT(slotColorGuideChanged()));
}
ShearTool::~ShearTool()
{
delete d;
}
void ShearTool::slotColorGuideChanged()
{
d->previewWidget->slotChangeGuideColor(d->gboxSettings->guideColor());
d->previewWidget->slotChangeGuideSize(d->gboxSettings->guideSize());
}
void ShearTool::readSettings()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(d->configGroupName);
// d->mainHAngleInput->setValue(group.readEntry(d->configMainHAngleEntry, d->mainHAngleInput->defaultValue()));
// d->mainVAngleInput->setValue(group.readEntry(d->configMainVAngleEntry, d->mainVAngleInput->defaultValue()));
// d->fineHAngleInput->setValue(group.readEntry(d->configFineHAngleEntry, d->fineHAngleInput->defaultValue()));
// d->fineVAngleInput->setValue(group.readEntry(d->configFineVAngleEntry, d->fineVAngleInput->defaultValue()));
d->antialiasInput->setChecked(group.readEntry(d->configAntiAliasingEntry, true));
slotPreview();
}
void ShearTool::writeSettings()
{
KSharedConfig::Ptr config = KSharedConfig::openConfig();
KConfigGroup group = config->group(d->configGroupName);
// group.writeEntry(d->configMainHAngleEntry, d->mainHAngleInput->value());
// group.writeEntry(d->configMainVAngleEntry, d->mainVAngleInput->value());
// group.writeEntry(d->configFineHAngleEntry, d->fineHAngleInput->value());
// group.writeEntry(d->configFineVAngleEntry, d->fineVAngleInput->value());
group.writeEntry(d->configAntiAliasingEntry, d->antialiasInput->isChecked());
config->sync();
}
void ShearTool::slotResetSettings()
{
d->mainHAngleInput->blockSignals(true);
d->mainVAngleInput->blockSignals(true);
d->fineHAngleInput->blockSignals(true);
d->fineVAngleInput->blockSignals(true);
d->antialiasInput->blockSignals(true);
d->mainHAngleInput->slotReset();
d->mainVAngleInput->slotReset();
d->fineHAngleInput->slotReset();
d->fineVAngleInput->slotReset();
d->antialiasInput->setChecked(true);
d->mainHAngleInput->blockSignals(false);
d->mainVAngleInput->blockSignals(false);
d->fineHAngleInput->blockSignals(false);
d->fineVAngleInput->blockSignals(false);
d->antialiasInput->blockSignals(false);
slotPreview();
}
void ShearTool::preparePreview()
{
float hAngle = d->mainHAngleInput->value() + d->fineHAngleInput->value();
float vAngle = d->mainVAngleInput->value() + d->fineVAngleInput->value();
bool antialiasing = d->antialiasInput->isChecked();
QColor background = Qt::black;
ImageIface* const iface = d->previewWidget->imageIface();<--- Variable 'iface' can be declared as pointer to const
int orgW = iface->originalSize().width();
int orgH = iface->originalSize().height();
DImg preview = iface->preview();
setFilter(new ShearFilter(&preview, this, hAngle, vAngle, antialiasing, background, orgW, orgH));
}
void ShearTool::prepareFinal()
{
float hAngle = d->mainHAngleInput->value() + d->fineHAngleInput->value();
float vAngle = d->mainVAngleInput->value() + d->fineVAngleInput->value();
bool antialiasing = d->antialiasInput->isChecked();
QColor background = Qt::black;
ImageIface iface;
int orgW = iface.originalSize().width();
int orgH = iface.originalSize().height();
DImg* const orgImage = iface.original();
setFilter(new ShearFilter(orgImage, this, hAngle, vAngle, antialiasing, background, orgW, orgH));
}
void ShearTool::setPreviewImage()
{
ImageIface* const iface = d->previewWidget->imageIface();
int w = iface->previewSize().width();
int h = iface->previewSize().height();
DImg imTemp = filter()->getTargetImage().smoothScale(w, h, Qt::KeepAspectRatio);
DImg imDest( w, h, filter()->getTargetImage().sixteenBit(), filter()->getTargetImage().hasAlpha() );
imDest.fill( DColor(d->previewWidget->palette().color(QPalette::Window).rgb(),
filter()->getTargetImage().sixteenBit()) );
imDest.bitBltImage(&imTemp, (w-imTemp.width())/2, (h-imTemp.height())/2);
iface->setPreview(imDest.smoothScale(iface->previewSize()));
d->previewWidget->updatePreview();
ShearFilter* const tool = dynamic_cast<ShearFilter*>(filter());<--- Variable 'tool' can be declared as pointer to const
if (tool)
{
QSize newSize = tool->getNewSize();
QString temp;
d->newWidthLabel->setText(temp.setNum( newSize.width()) + i18n(" px") );
d->newHeightLabel->setText(temp.setNum( newSize.height()) + i18n(" px") );
}
}
void ShearTool::setFinalImage()
{
ImageIface iface;
DImg targetImage = filter()->getTargetImage();
iface.setOriginal(i18n("Shear Tool"), filter()->filterAction(), targetImage);
}
} // namespace DigikamEditorShearToolPlugin
#include "moc_sheartool.cpp"
|