Debian Codegraph @

src/gui/settingsDialog/WatermarkSettings.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "WatermarkSettings.h"
21
22 WatermarkSettings::WatermarkSettings(const QSharedPointer<IConfig> &config, const QSharedPointer<IScaledSizeProvider> &scaledSizeProvider) :
23 mConfig(config),
24 mScaledSizeProvider(scaledSizeProvider),
25 mLayout(new QGridLayout(this)),
26 mRotateWatermarkCheckbox(new QCheckBox(this)),
27 mWatermarkImageLabel(new QLabel(this)),
28 mUpdateWatermarkImageButton(new QPushButton(this))
29 {
30 initGui();
31 loadConfig();
32 }
33
34 WatermarkSettings::~WatermarkSettings()
35 {
36 delete mRotateWatermarkCheckbox;
37 delete mWatermarkImageLabel;
38 delete mUpdateWatermarkImageButton;
39 }
40
41 void WatermarkSettings::saveSettings()
42 {
43 mConfig->setRotateWatermarkEnabled(mRotateWatermarkCheckbox->isChecked());
44 }
45
46 void WatermarkSettings::initGui()
47 {
48 mWatermarkImageLabel->setPixmap(mWatermarkImageLoader.load());
49 mWatermarkImageLabel->setToolTip(tr("Watermark Image"));
50 mWatermarkImageLabel->setAutoFillBackground(true);
51 mWatermarkImageLabel->setFixedSize(mScaledSizeProvider->scaledSize(QSize(100, 100)));
52 mWatermarkImageLabel->setScaledContents(true);
53 mWatermarkImageLabel->setStyleSheet(QLatin1String("QLabel { background-color : white; }"));
54 mUpdateWatermarkImageButton->setText(tr("Update"));
55 connect(mUpdateWatermarkImageButton, &QPushButton::clicked, this, &WatermarkSettings::updateWatermarkImageClicked);
56
57 mRotateWatermarkCheckbox->setText(tr("Rotate Watermark"));
58 mRotateWatermarkCheckbox->setToolTip(tr("When enabled, Watermark will be added with a rotation of 45°"));
59
60 mLayout->setAlignment(Qt::AlignTop);
61 mLayout->addWidget(mWatermarkImageLabel, 0, 0);
62 mLayout->addWidget(mUpdateWatermarkImageButton, 0, 1, Qt::AlignLeft);
63 mLayout->setRowMinimumHeight(1, 15);
64 mLayout->addWidget(mRotateWatermarkCheckbox, 2, 0);
65
66 setTitle(tr("Watermark Settings"));
67 setLayout(mLayout);
68 }
69
70 void WatermarkSettings::loadConfig()
71 {
72 mRotateWatermarkCheckbox->setChecked(mConfig->rotateWatermarkEnabled());
73 }
74
75 void WatermarkSettings::updateWatermarkImageClicked()
76 {
77 UpdateWatermarkOperation operation(this);
78 auto successful = operation.execute();
79
80 if(successful) {
81 mWatermarkImageLabel->setPixmap(mWatermarkImageLoader.load());
82 }
83 }