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
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2010-03-16
 * Description : Free rotation settings view.
 *
 * SPDX-FileCopyrightText: 2010-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "freerotationsettings.h"

// Qt includes

#include <QGridLayout>
#include <QLabel>
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QCheckBox>
#include <QUrl>
#include <QApplication>
#include <QStyle>

// KDE includes

#include <kconfiggroup.h>
#include <klocalizedstring.h>

// Local includes

#include "digikam_debug.h"
#include "dcolorselector.h"
#include "dexpanderbox.h"
#include "dnuminput.h"
#include "dcombobox.h"

namespace Digikam
{

class Q_DECL_HIDDEN FreeRotationSettings::Private
{
public:

    Private() = default;

public:

    const QString configAutoCropTypeEntry       = QLatin1String("Auto Crop Type");
    const QString configAntiAliasingEntry       = QLatin1String("Anti Aliasing");
    const QString configBackgroundColorEntry    = QLatin1String("Background Color");

    QCheckBox*       antialiasInput             = nullptr;

    DIntNumInput*    angleInput                 = nullptr;
    DDoubleNumInput* fineAngleInput             = nullptr;
    DComboBox*       autoCropCB                 = nullptr;
    DColorSelector*  backgroundColor            = nullptr;
};

// --------------------------------------------------------

FreeRotationSettings::FreeRotationSettings(QWidget* const parent)
    : QWidget(parent),
      d      (new Private)
{
    const int spacing       = layoutSpacing();


    QGridLayout* const grid = new QGridLayout(this);

    // --------------------------------------------------------

    QLabel* const label3 = new QLabel(i18n("Main angle:"));
    d->angleInput        = new DIntNumInput;
    d->angleInput->setRange(-180, 180, 1);
    d->angleInput->setDefaultValue(0);
    d->angleInput->setWhatsThis(i18n("An angle in degrees by which to rotate the image. "
                                     "A positive angle rotates the image clockwise; "
                                     "a negative angle rotates it counter-clockwise."));

    QLabel* const label4 = new QLabel(i18n("Fine angle:"));
    d->fineAngleInput    = new DDoubleNumInput;
    d->fineAngleInput->setRange(-1.0, 1.0, 0.01);
    d->fineAngleInput->setDefaultValue(0);
    d->fineAngleInput->setWhatsThis(i18n("This value in degrees will be added to main angle value "
                                         "to set fine target angle."));

    d->antialiasInput = new QCheckBox(i18n("Anti-Aliasing"));
    d->antialiasInput->setWhatsThis(i18n("Enable this option to apply the anti-aliasing filter "
                                         "to the rotated image. "
                                         "In order to smooth the target image, it will be blurred a little."));

    QLabel* const label5 = new QLabel(i18n("Auto-crop:"));
    d->autoCropCB        = new DComboBox;
    d->autoCropCB->addItem(i18nc("no autocrop", "None"));
    d->autoCropCB->addItem(i18n("Widest Area"));
    d->autoCropCB->addItem(i18n("Largest Area"));
    d->autoCropCB->setDefaultIndex(FreeRotationContainer::NoAutoCrop);
    d->autoCropCB->setWhatsThis(i18n("Select the method to process image auto-cropping "
                                     "to remove black frames around a rotated image here."));

    QLabel* const label6 = new QLabel(i18n("Background color:"));
    d->backgroundColor   = new DColorSelector();
    d->backgroundColor->setColor(Qt::black);

    // -------------------------------------------------------------

    grid->addWidget(label3,             0, 0, 1, 1);
    grid->addWidget(d->angleInput,      1, 0, 1, 2);
    grid->addWidget(label4,             2, 0, 1, 1);
    grid->addWidget(d->fineAngleInput,  3, 0, 1, 2);
    grid->addWidget(d->antialiasInput,  4, 0, 1, -1);
    grid->addWidget(label5,             5, 0, 1, 1);
    grid->addWidget(d->autoCropCB,      5, 1, 1, 1);
    grid->addWidget(label6,             6, 0, 1, 1);
    grid->addWidget(d->backgroundColor, 6, 1, 1, 1);
    grid->setContentsMargins(spacing, spacing, spacing, spacing);
    grid->setSpacing(spacing);

    // -------------------------------------------------------------

    connect(d->antialiasInput, SIGNAL(toggled(bool)),
            this, SIGNAL(signalSettingsChanged()));

    connect(d->autoCropCB, SIGNAL(activated(int)),
            this, SIGNAL(signalSettingsChanged()));

    connect(d->angleInput, SIGNAL(valueChanged(int)),
            this, SIGNAL(signalSettingsChanged()));

    connect(d->fineAngleInput, SIGNAL(valueChanged(double)),
            this, SIGNAL(signalSettingsChanged()));

    connect(d->backgroundColor, SIGNAL(signalColorSelected(QColor)),
            this, SIGNAL(signalSettingsChanged()));
}

FreeRotationSettings::~FreeRotationSettings()
{
    delete d;
}

FreeRotationContainer FreeRotationSettings::settings() const
{
    FreeRotationContainer prm;
    prm.angle           = (double)d->angleInput->value() + d->fineAngleInput->value();
    prm.antiAlias       = d->antialiasInput->isChecked();
    prm.autoCrop        = d->autoCropCB->currentIndex();
    prm.backgroundColor = d->backgroundColor->color();

    return prm;
}

void FreeRotationSettings::setSettings(const FreeRotationContainer& settings)<--- Shadow argument
{
    blockSignals(true);

    d->angleInput->setValue((int)(settings.angle));
    d->fineAngleInput->setValue(settings.angle - (double)d->angleInput->value());
    d->antialiasInput->setChecked(settings.antiAlias);
    d->autoCropCB->setCurrentIndex(settings.autoCrop);
    d->backgroundColor->setColor(settings.backgroundColor);

    blockSignals(false);
}

void FreeRotationSettings::resetToDefault()
{
    blockSignals(true);

    d->angleInput->slotReset();
    d->fineAngleInput->slotReset();
    d->antialiasInput->setChecked(true);
    d->autoCropCB->slotReset();
    d->backgroundColor->setColor(Qt::black);

    blockSignals(false);
}

FreeRotationContainer FreeRotationSettings::defaultSettings() const
{
    FreeRotationContainer prm;
    prm.angle           = d->angleInput->defaultValue();
    prm.antiAlias       = true;
    prm.autoCrop        = d->autoCropCB->defaultIndex();
    prm.backgroundColor = Qt::black;

    return prm;
}

void FreeRotationSettings::readSettings(const KConfigGroup& group)
{
    d->autoCropCB->setCurrentIndex(group.readEntry(d->configAutoCropTypeEntry,  d->autoCropCB->defaultIndex()));
    d->backgroundColor->setColor(group.readEntry(d->configBackgroundColorEntry, QColor(Qt::black)));
    d->antialiasInput->setChecked(group.readEntry(d->configAntiAliasingEntry,   true));
    d->angleInput->slotReset();
    d->fineAngleInput->slotReset();
}

void FreeRotationSettings::writeSettings(KConfigGroup& group)
{
    group.writeEntry(d->configAutoCropTypeEntry,    d->autoCropCB->currentIndex());
    group.writeEntry(d->configAntiAliasingEntry,    d->antialiasInput->isChecked());
    group.writeEntry(d->configBackgroundColorEntry, d->backgroundColor->color());
}

} // namespace Digikam

#include "moc_freerotationsettings.cpp"