File indexing completed on 2025-01-05 03:53:17

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2019-04-02
0007  * Description : plugin to export image as wallpaper - Settings dialog
0008  *
0009  * SPDX-FileCopyrightText: 2019      by Igor Antropov <antropovi at yahoo dot com>
0010  * SPDX-FileCopyrightText: 2019-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "wallpaperplugindlg.h"
0017 
0018 // Qt includes
0019 
0020 #include <QLabel>
0021 #include <QComboBox>
0022 #include <QPushButton>
0023 #include <QVBoxLayout>
0024 #include <QGridLayout>
0025 #include <QApplication>
0026 #include <QStyle>
0027 
0028 // KDE includes
0029 
0030 #include <klocalizedstring.h>
0031 
0032 // Local includes
0033 
0034 #include "wallpaperplugin.h"
0035 
0036 namespace DigikamGenericWallpaperPlugin
0037 {
0038 
0039 class Q_DECL_HIDDEN WallpaperPluginDlg::Private
0040 {
0041 public:
0042 
0043     explicit Private()
0044       : layoutCB(nullptr),
0045         page    (nullptr)
0046     {
0047     }
0048 
0049     QComboBox* layoutCB;
0050     QWidget*   page;
0051 };
0052 
0053 WallpaperPluginDlg::WallpaperPluginDlg(DPlugin* const plugin, QWidget* const parent)
0054     : DPluginDialog(parent, QLatin1String("WallpaperPluginDlg")),
0055       d            (new Private)
0056 {
0057     setPlugin(plugin);
0058     setWindowIcon(plugin->icon());
0059     setWindowTitle(i18nc("@title:window", "WallPaper Settings"));
0060 
0061     m_buttons->addButton(QDialogButtonBox::Cancel);
0062     m_buttons->addButton(QDialogButtonBox::Ok);
0063     m_buttons->button(QDialogButtonBox::Ok)->setDefault(true);
0064     d->page                  = new QWidget(this);
0065     QVBoxLayout* const vbx   = new QVBoxLayout(this);
0066     vbx->addWidget(d->page);
0067     vbx->addWidget(m_buttons);
0068     setLayout(vbx);
0069     setModal(false);
0070 
0071     // -------------------
0072 
0073     const int spacing       = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0074                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0075 
0076     QGridLayout* const grid = new QGridLayout(d->page);
0077     QLabel* const lbl       = new QLabel(i18n("Wallpaper Layout:"), d->page);
0078     d->layoutCB             = new QComboBox(d->page);
0079     d->layoutCB->addItem(i18n("Adjusted"),                   WallpaperPlugin::Adjusted);
0080 
0081 #ifndef Q_OS_WIN
0082 
0083     d->layoutCB->addItem(i18n("Adjusted with Aspect ratio"), WallpaperPlugin::AdjustedAspectRatio);
0084     d->layoutCB->addItem(i18n("Adjusted and cropped"),       WallpaperPlugin::AdjustedCropped);
0085 
0086 #endif
0087 
0088     d->layoutCB->addItem(i18n("Mosaic"),                     WallpaperPlugin::Mosaic);
0089     d->layoutCB->addItem(i18n("Centered"),                   WallpaperPlugin::Centered);
0090     lbl->setBuddy(d->layoutCB);
0091 
0092     grid->addWidget(lbl,         0, 0, 1, 1);
0093     grid->addWidget(d->layoutCB, 0, 1, 1, 1);
0094     grid->setSpacing(spacing);
0095 
0096     // -------------------
0097 
0098     connect(m_buttons->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
0099             this, &WallpaperPluginDlg::reject);
0100 
0101     connect(m_buttons->button(QDialogButtonBox::Ok), &QPushButton::clicked,
0102             this, &WallpaperPluginDlg::accept);
0103 
0104     // -------------------
0105 
0106     adjustSize();
0107 }
0108 
0109 WallpaperPluginDlg::~WallpaperPluginDlg()
0110 {
0111     delete d;
0112 }
0113 
0114 int WallpaperPluginDlg::wallpaperLayout() const
0115 {
0116     return (d->layoutCB->currentData().toInt());
0117 }
0118 
0119 } // namespace DigikamGenericWallpaperPlugin
0120 
0121 #include "moc_wallpaperplugindlg.cpp"