File indexing completed on 2025-01-05 03:52:06

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-04-04
0007  * Description : a tool to generate HTML image galleries
0008  *
0009  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "htmlimagesettingspage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QIcon>
0020 #include <QWidget>
0021 #include <QHBoxLayout>
0022 #include <QLabel>
0023 #include <QGridLayout>
0024 #include <QSpacerItem>
0025 #include <QCheckBox>
0026 #include <QSpinBox>
0027 #include <QComboBox>
0028 #include <QRadioButton>
0029 #include <QApplication>
0030 #include <QStyle>
0031 
0032 // KDE includes
0033 
0034 #include <klocalizedstring.h>
0035 
0036 // Local includes
0037 
0038 #include "invisiblebuttongroup.h"
0039 #include "galleryinfo.h"
0040 #include "htmlwizard.h"
0041 
0042 namespace DigikamGenericHtmlGalleryPlugin
0043 {
0044 
0045 class Q_DECL_HIDDEN HTMLImageSettingsPage::Private
0046 {
0047 public:
0048 
0049     explicit Private()
0050       : kcfg_thumbnailSquare(nullptr)
0051     {
0052     }
0053 
0054     QCheckBox* kcfg_thumbnailSquare;
0055 };
0056 
0057 HTMLImageSettingsPage::HTMLImageSettingsPage(QWizard* const dialog, const QString& title)
0058     : DWizardPage(dialog, title),
0059       d          (new Private)
0060 {
0061     setObjectName(QLatin1String("ImageSettingsPage"));
0062 
0063     const int spacing   = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0064                                QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0065 
0066     QWidget* const box  = new QWidget(this);
0067 
0068     QLabel* const label = new QLabel(this);
0069     label->setObjectName(QLatin1String("label"));
0070     QFont font;
0071     font.setBold(true);
0072     font.setWeight(QFont::Bold);
0073     label->setFont(font);
0074     label->setText(i18n("Full Image Properties:"));
0075 
0076     QRadioButton* const mSaveImageButton = new QRadioButton(this);
0077     mSaveImageButton->setObjectName(QLatin1String("mSaveImageButton"));
0078     mSaveImageButton->setChecked(true);
0079     mSaveImageButton->setText(i18n("Save image"));
0080 
0081     QLabel* const textLabel2_2_2_2 = new QLabel(this);
0082     textLabel2_2_2_2->setObjectName(QLatin1String("textLabel2_2_2_2"));
0083     textLabel2_2_2_2->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
0084     textLabel2_2_2_2->setWordWrap(false);
0085     textLabel2_2_2_2->setText(i18n("Format:"));
0086 
0087     QComboBox* const kcfg_fullFormat = new QComboBox(this);
0088     kcfg_fullFormat->setObjectName(QLatin1String("kcfg_fullFormat"));
0089     kcfg_fullFormat->clear();
0090     kcfg_fullFormat->insertItems(0, QStringList() << i18n("JPEG") << i18n("PNG"));
0091     textLabel2_2_2_2->setBuddy(kcfg_fullFormat);
0092 
0093     QSpacerItem* const spacer4 = new QSpacerItem(312, 17, QSizePolicy::Expanding,
0094                                                  QSizePolicy::Minimum);
0095 
0096     QLabel* const textLabel4 = new QLabel(this);
0097     textLabel4->setObjectName(QLatin1String("textLabel4"));
0098     textLabel4->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
0099     textLabel4->setWordWrap(false);
0100     textLabel4->setText(i18n("Quality:"));
0101 
0102     QSpinBox* const kcfg_fullQuality = new QSpinBox(this);
0103     kcfg_fullQuality->setObjectName(QLatin1String("kcfg_fullQuality"));
0104     kcfg_fullQuality->setMaximum(100);
0105     textLabel4->setBuddy(kcfg_fullQuality);
0106 
0107     QSpacerItem* const horizontalSpacer_6 = new QSpacerItem(40, 20, QSizePolicy::Fixed,
0108                                                             QSizePolicy::Minimum);
0109 
0110     QWidget* const widget = new QWidget(this);
0111     widget->setObjectName(QLatin1String("widget"));
0112 
0113     QCheckBox* const kcfg_fullResize = new QCheckBox(widget);
0114     kcfg_fullResize->setObjectName(QLatin1String("kcfg_fullResize"));
0115     kcfg_fullResize->setChecked(true);
0116     kcfg_fullResize->setText(i18n("Max size:"));
0117 
0118     QSpinBox* const kcfg_fullSize = new QSpinBox(widget);
0119     kcfg_fullSize->setObjectName(QLatin1String("kcfg_fullSize"));
0120     kcfg_fullSize->setMinimum(1);
0121     kcfg_fullSize->setMaximum(9999);
0122     kcfg_fullSize->setValue(800);
0123 
0124     QSpacerItem* const horizontalSpacer_2 = new QSpacerItem(188, 27, QSizePolicy::Expanding,
0125                                                             QSizePolicy::Minimum);
0126 
0127     QHBoxLayout* const horizontalLayout_2 = new QHBoxLayout(widget);
0128     horizontalLayout_2->setContentsMargins(QMargins());
0129     horizontalLayout_2->setSpacing(spacing);
0130     horizontalLayout_2->setObjectName(QLatin1String("horizontalLayout_2"));
0131     horizontalLayout_2->addWidget(kcfg_fullResize);
0132     horizontalLayout_2->addWidget(kcfg_fullSize);
0133     horizontalLayout_2->addItem(horizontalSpacer_2);
0134 
0135     QCheckBox* const kcfg_copyOriginalImage = new QCheckBox(this);
0136     kcfg_copyOriginalImage->setObjectName(QLatin1String("kcfg_copyOriginalImage"));
0137     kcfg_copyOriginalImage->setChecked(false);
0138     kcfg_copyOriginalImage->setText(i18n("Include full-size original images for download"));
0139 
0140     QSpacerItem* const horizontalSpacer_3 = new QSpacerItem(40, 20, QSizePolicy::Expanding,
0141                                                             QSizePolicy::Minimum);
0142 
0143     QHBoxLayout* const horizontalLayout = new QHBoxLayout();
0144     horizontalLayout->setContentsMargins(QMargins());
0145     horizontalLayout->setSpacing(spacing);
0146     horizontalLayout->setObjectName(QLatin1String("horizontalLayout"));
0147     horizontalLayout->addWidget(kcfg_copyOriginalImage);
0148     horizontalLayout->addItem(horizontalSpacer_3);
0149 
0150     QRadioButton* const mUseOriginalImageButton = new QRadioButton(this);
0151     mUseOriginalImageButton->setObjectName(QLatin1String("mUseOriginalImageButton"));
0152     mUseOriginalImageButton->setText(i18n("Use original image"));
0153 
0154     QSpacerItem* const verticalSpacer = new QSpacerItem(20, 20, QSizePolicy::Minimum,
0155                                                         QSizePolicy::Fixed);
0156 
0157     QLabel* const label_2 = new QLabel(this);
0158     label_2->setObjectName(QLatin1String("label_2"));
0159     label_2->setFont(font);
0160     label_2->setText(i18n("Thumbnail Properties:"));
0161 
0162     QLabel* const textLabel2_2_2 = new QLabel(this);
0163     textLabel2_2_2->setObjectName(QLatin1String("textLabel2_2_2"));
0164     textLabel2_2_2->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
0165     textLabel2_2_2->setWordWrap(false);
0166     textLabel2_2_2->setText(i18n("Format:"));
0167 
0168     QComboBox* const kcfg_thumbnailFormat = new QComboBox(this);
0169     kcfg_thumbnailFormat->setObjectName(QLatin1String("kcfg_thumbnailFormat"));
0170     kcfg_thumbnailFormat->clear();
0171     kcfg_thumbnailFormat->insertItems(0, QStringList() << i18n("JPEG") << i18n("PNG"));
0172     textLabel2_2_2->setBuddy(kcfg_thumbnailFormat);
0173 
0174     QSpacerItem* const horizontalSpacer_7 = new QSpacerItem(40, 27, QSizePolicy::Fixed,
0175                                                             QSizePolicy::Minimum);
0176 
0177     QLabel* const textLabel4_2 = new QLabel(this);
0178     textLabel4_2->setObjectName(QLatin1String("textLabel4_2"));
0179     textLabel4_2->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
0180     textLabel4_2->setWordWrap(false);
0181     textLabel4_2->setText(i18n("Quality:"));
0182 
0183     QSpinBox* const kcfg_thumbnailQuality = new QSpinBox(this);
0184     kcfg_thumbnailQuality->setObjectName(QLatin1String("kcfg_thumbnailQuality"));
0185     kcfg_thumbnailQuality->setMaximum(100);
0186     textLabel4_2->setBuddy(kcfg_thumbnailQuality);
0187 
0188     QSpacerItem* const horizontalSpacer_4 = new QSpacerItem(309, 27, QSizePolicy::Expanding,
0189                                                             QSizePolicy::Minimum);
0190 
0191     QLabel* const textLabel2_2 = new QLabel(this);
0192     textLabel2_2->setObjectName(QLatin1String("textLabel2_2"));
0193     textLabel2_2->setAlignment(Qt::AlignRight | Qt::AlignTrailing | Qt::AlignVCenter);
0194     textLabel2_2->setWordWrap(false);
0195     textLabel2_2->setText(i18n("Size:"));
0196 
0197     QSpinBox* const kcfg_thumbnailSize = new QSpinBox(this);
0198     kcfg_thumbnailSize->setObjectName(QLatin1String("kcfg_thumbnailSize"));
0199     kcfg_thumbnailSize->setMinimum(1);
0200     kcfg_thumbnailSize->setMaximum(9999);
0201     kcfg_thumbnailSize->setValue(160);
0202     textLabel2_2->setBuddy(kcfg_thumbnailSize);
0203 
0204     d->kcfg_thumbnailSquare = new QCheckBox(this);
0205     d->kcfg_thumbnailSquare->setObjectName(QLatin1String("kcfg_thumbnailSquare"));
0206     d->kcfg_thumbnailSquare->setEnabled(false);
0207     d->kcfg_thumbnailSquare->setCheckable(true);
0208     d->kcfg_thumbnailSquare->setChecked(true);
0209     d->kcfg_thumbnailSquare->setText(i18n("Square thumbnails"));
0210 
0211     QSpacerItem* const verticalSpacer_2 = new QSpacerItem(20, 40, QSizePolicy::Minimum,
0212                                                           QSizePolicy::Expanding);
0213 
0214     QGridLayout* const gridLayout       = new QGridLayout(box);
0215     gridLayout->setContentsMargins(QMargins());
0216     gridLayout->setSpacing(spacing);
0217     gridLayout->setObjectName(QLatin1String("gridLayout"));
0218     gridLayout->addWidget(label,                    0, 0, 1, 2);
0219     gridLayout->addWidget(mSaveImageButton,         1, 0, 1, 2);
0220     gridLayout->addWidget(textLabel2_2_2_2,         2, 1, 1, 1);
0221     gridLayout->addWidget(kcfg_fullFormat,          2, 2, 1, 1);
0222     gridLayout->addItem(spacer4,                    2, 3, 1, 1);
0223     gridLayout->addWidget(textLabel4,               3, 1, 1, 1);
0224     gridLayout->addWidget(kcfg_fullQuality,         3, 2, 1, 1);
0225     gridLayout->addItem(horizontalSpacer_6,         4, 0, 1, 1);
0226     gridLayout->addWidget(widget,                   4, 2, 1, 2);
0227     gridLayout->addLayout(horizontalLayout,         5, 2, 1, 2);
0228     gridLayout->addWidget(mUseOriginalImageButton,  6, 0, 1, 3);
0229     gridLayout->addItem(verticalSpacer,             7, 0, 1, 1);
0230     gridLayout->addWidget(label_2,                  8, 0, 1, 2);
0231     gridLayout->addWidget(textLabel2_2_2,           9, 1, 1, 1);
0232     gridLayout->addWidget(kcfg_thumbnailFormat,     9, 2, 1, 1);
0233     gridLayout->addItem(horizontalSpacer_7,        10, 0, 1, 1);
0234     gridLayout->addWidget(textLabel4_2,            10, 1, 1, 1);
0235     gridLayout->addWidget(kcfg_thumbnailQuality,   10, 2, 1, 1);
0236     gridLayout->addItem(horizontalSpacer_4,        10, 3, 1, 1);
0237     gridLayout->addWidget(textLabel2_2,            11, 1, 1, 1);
0238     gridLayout->addWidget(kcfg_thumbnailSize,      11, 2, 1, 1);
0239     gridLayout->addWidget(d->kcfg_thumbnailSquare, 12, 2, 1, 2);
0240     gridLayout->addItem(verticalSpacer_2,          13, 3, 1, 1);
0241 
0242     setPageWidget(box);
0243     setLeftBottomPix(QIcon::fromTheme(QLatin1String("configure")));
0244 
0245     setTabOrder(mSaveImageButton,        kcfg_fullFormat);
0246     setTabOrder(kcfg_fullFormat,         kcfg_fullQuality);
0247     setTabOrder(kcfg_fullQuality,        kcfg_fullResize);
0248     setTabOrder(kcfg_fullResize,         kcfg_fullSize);
0249     setTabOrder(kcfg_fullSize,           kcfg_copyOriginalImage);
0250     setTabOrder(kcfg_copyOriginalImage,  mUseOriginalImageButton);
0251     setTabOrder(mUseOriginalImageButton, kcfg_thumbnailFormat);
0252     setTabOrder(kcfg_thumbnailFormat,    kcfg_thumbnailQuality);
0253     setTabOrder(kcfg_thumbnailQuality,   kcfg_thumbnailSize);
0254     setTabOrder(kcfg_thumbnailSize,      d->kcfg_thumbnailSquare);
0255 
0256     connect(kcfg_fullResize, SIGNAL(toggled(bool)),
0257             kcfg_fullSize, SLOT(setEnabled(bool)));
0258 
0259     connect(mSaveImageButton, SIGNAL(toggled(bool)),
0260             kcfg_fullFormat, SLOT(setEnabled(bool)));
0261 
0262     connect(mSaveImageButton, SIGNAL(toggled(bool)),
0263             kcfg_fullQuality, SLOT(setEnabled(bool)));
0264 
0265     connect(mSaveImageButton, SIGNAL(toggled(bool)),
0266             kcfg_copyOriginalImage, SLOT(setEnabled(bool)));
0267 
0268     connect(mSaveImageButton, SIGNAL(toggled(bool)),
0269             textLabel2_2_2_2, SLOT(setEnabled(bool)));
0270 
0271     connect(mSaveImageButton, SIGNAL(toggled(bool)),
0272             textLabel4, SLOT(setEnabled(bool)));
0273 
0274     connect(mSaveImageButton, SIGNAL(toggled(bool)),
0275             widget, SLOT(setEnabled(bool)));
0276 
0277     InvisibleButtonGroup* const group = new InvisibleButtonGroup(this);
0278     group->setObjectName(QLatin1String("kcfg_useOriginalImageAsFullImage"));
0279     group->addButton(mSaveImageButton,        false);
0280     group->addButton(mUseOriginalImageButton, true);
0281 }
0282 
0283 HTMLImageSettingsPage::~HTMLImageSettingsPage()
0284 {
0285     delete d;
0286 }
0287 
0288 void HTMLImageSettingsPage::initializePage()
0289 {
0290     HTMLWizard* const wizard      = dynamic_cast<HTMLWizard*>(assistant());
0291 
0292     if (!wizard)
0293         return;
0294 
0295     GalleryTheme::Ptr theme       = wizard->galleryTheme();
0296     bool allowNonsquareThumbnails = theme->allowNonsquareThumbnails();
0297 
0298     d->kcfg_thumbnailSquare->setEnabled(allowNonsquareThumbnails);
0299 
0300     if (!allowNonsquareThumbnails)
0301     {
0302         d->kcfg_thumbnailSquare->setChecked(true);
0303     }
0304 }
0305 
0306 } // namespace DigikamGenericHtmlGalleryPlugin
0307 
0308 #include "moc_htmlimagesettingspage.cpp"