File indexing completed on 2025-03-09 03:52:10

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2005-05-21
0007  * Description : setup tab for slideshow options.
0008  *
0009  * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2019-2020 by Minh Nghia Duong <minhnghiaduong997 at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "setupslideshow_dialog.h"
0017 
0018 // Qt includes
0019 
0020 #include <QCheckBox>
0021 #include <QGroupBox>
0022 #include <QLabel>
0023 #include <QVBoxLayout>
0024 #include <QApplication>
0025 #include <QScreen>
0026 #include <QStyle>
0027 #include <QComboBox>
0028 #include <QDialogButtonBox>
0029 #include <QPushButton>
0030 
0031 // KDE includes
0032 
0033 #include <klocalizedstring.h>
0034 
0035 // Local includes
0036 
0037 #include "dlayoutbox.h"
0038 #include "dnuminput.h"
0039 #include "dfontselect.h"
0040 #include "digikam_debug.h"
0041 #include "slideshowsettings.h"
0042 
0043 using namespace Digikam;
0044 
0045 namespace DigikamGenericSlideShowPlugin
0046 {
0047 
0048 class Q_DECL_HIDDEN SetupSlideShowDialog::Private
0049 {
0050 public:
0051 
0052     explicit Private()
0053       : startWithCurrent    (nullptr),
0054         loopMode            (nullptr),
0055         suffleMode          (nullptr),
0056         showName            (nullptr),
0057         showDate            (nullptr),
0058         showApertureFocal   (nullptr),
0059         showExpoSensitivity (nullptr),
0060         showMakeModel       (nullptr),
0061         showLensModel       (nullptr),
0062         showLabels          (nullptr),
0063         showRating          (nullptr),
0064         showComment         (nullptr),
0065         showTitle           (nullptr),
0066         showTags            (nullptr),
0067         showCapIfNoTitle    (nullptr),
0068         showProgress        (nullptr),
0069         screenPlacement     (nullptr),
0070         captionFont         (nullptr),
0071         delayInput          (nullptr),
0072         settings            (nullptr)
0073     {
0074     }
0075 
0076     QCheckBox*         startWithCurrent;
0077     QCheckBox*         loopMode;
0078     QCheckBox*         suffleMode;
0079     QCheckBox*         showName;
0080     QCheckBox*         showDate;
0081     QCheckBox*         showApertureFocal;
0082     QCheckBox*         showExpoSensitivity;
0083     QCheckBox*         showMakeModel;
0084     QCheckBox*         showLensModel;
0085     QCheckBox*         showLabels;
0086     QCheckBox*         showRating;
0087     QCheckBox*         showComment;
0088     QCheckBox*         showTitle;
0089     QCheckBox*         showTags;
0090     QCheckBox*         showCapIfNoTitle;
0091     QCheckBox*         showProgress;
0092 
0093     QComboBox*         screenPlacement;
0094 
0095     DFontSelect*       captionFont;
0096     DIntNumInput*      delayInput;
0097 
0098     SlideShowSettings* settings;
0099 };
0100 
0101 // --------------------------------------------------------
0102 
0103 SetupSlideShowDialog::SetupSlideShowDialog(SlideShowSettings* const settings, QWidget* const parent)
0104     : DPluginDialog(parent, QLatin1String("Slideshow Settings")),
0105       d            (new Private)
0106 {
0107     setModal(true);
0108     setPlugin(settings->plugin);
0109     setWindowTitle(i18nc("@title:window", "Slideshow Settings"));
0110 
0111     m_buttons->addButton(QDialogButtonBox::Close);
0112     m_buttons->addButton(QDialogButtonBox::Ok);
0113     m_buttons->button(QDialogButtonBox::Ok)->setDefault(true);
0114 
0115     QWidget* const panel      = new QWidget(this);
0116     const int spacing         = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0117                                      QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0118 
0119     DHBox* const hbox1        = new DHBox(panel);
0120     new QLabel(i18n("Delay between images:"), hbox1);
0121     d->delayInput             = new DIntNumInput(hbox1);
0122     d->delayInput->setDefaultValue(5);
0123     d->delayInput->setRange(1, 3600, 1);
0124     d->delayInput->setWhatsThis(i18n("The delay, in seconds, between images."));
0125 
0126     d->startWithCurrent       = new QCheckBox(i18n("Start with current image"), panel);
0127     d->startWithCurrent->setWhatsThis(i18n("If this option is enabled, the Slideshow will be started "
0128                                            "with the current image selected in the images list."));
0129 
0130     d->loopMode               = new QCheckBox(i18n("Slideshow runs in a loop"), panel);
0131     d->loopMode->setWhatsThis(i18n("Run the slideshow in a loop."));
0132 
0133     d->suffleMode             = new QCheckBox(i18n("Shuffle images"), panel);
0134     d->suffleMode->setWhatsThis(i18n("If this option is enabled, the Slideshow will run in random order"));
0135 
0136     d->showProgress           = new QCheckBox(i18n("Show progress indicator"), panel);
0137     d->showProgress->setWhatsThis(i18n("Show a progress indicator with pending items to show and time progression."));
0138 
0139     d->showName               = new QCheckBox(i18n("Show image file name"), panel);
0140     d->showName->setWhatsThis(i18n("Show the image file name at the bottom of the screen."));
0141 
0142     d->showDate               = new QCheckBox(i18n("Show image creation date"), panel);
0143     d->showDate->setWhatsThis(i18n("Show the image creation time/date at the bottom of the screen."));
0144 
0145     d->showApertureFocal      = new QCheckBox(i18n("Show camera aperture and focal length"), panel);
0146     d->showApertureFocal->setWhatsThis(i18n("Show the camera aperture and focal length at the bottom of the screen."));
0147 
0148     d->showExpoSensitivity    = new QCheckBox(i18n("Show camera exposure and sensitivity"), panel);
0149     d->showExpoSensitivity->setWhatsThis(i18n("Show the camera exposure and sensitivity at the bottom of the screen."));
0150 
0151     d->showMakeModel          = new QCheckBox(i18n("Show camera make and model"), panel);
0152     d->showMakeModel->setWhatsThis(i18n("Show the camera make and model at the bottom of the screen."));
0153 
0154     d->showLensModel          = new QCheckBox(i18n("Show camera lens model"), panel);
0155     d->showLensModel->setWhatsThis(i18n("Show the camera lens model at the bottom of the screen."));
0156 
0157     d->showComment            = new QCheckBox(i18n("Show image caption"), panel);
0158     d->showComment->setWhatsThis(i18n("Show the image caption at the bottom of the screen."));
0159 
0160     d->showTitle              = new QCheckBox(i18n("Show image title"), panel);
0161     d->showTitle->setWhatsThis(i18n("Show the image title at the bottom of the screen."));
0162 
0163     d->showCapIfNoTitle       = new QCheckBox(i18n("Show image caption if it has not title"), panel);
0164     d->showCapIfNoTitle->setWhatsThis(i18n("Show the image caption at the bottom of the screen if no titles existed."));
0165 
0166     d->showTags               = new QCheckBox(i18n("Show image tags"), panel);
0167     d->showTags->setWhatsThis(i18n("Show the digiKam image tag names at the bottom of the screen."));
0168 
0169     d->showLabels             = new QCheckBox(i18n("Show image labels"), panel);
0170     d->showLabels->setWhatsThis(i18n("Show the digiKam image color label and pick label at the bottom of the screen."));
0171 
0172     d->showRating             = new QCheckBox(i18n("Show image rating"), panel);
0173     d->showRating->setWhatsThis(i18n("Show the digiKam image rating at the bottom of the screen."));
0174 
0175     d->captionFont            = new DFontSelect(i18n("Caption font:"), panel);
0176     d->captionFont->setToolTip(i18n("Select here the font used to display text in the slideshow."));
0177 
0178     DHBox* const screenSelectBox = new DHBox(panel);
0179     new QLabel(i18n("Screen placement:"), screenSelectBox);
0180     d->screenPlacement           = new QComboBox(screenSelectBox);
0181     d->screenPlacement->setToolTip(i18n("In case of multi-screen computer, select here the monitor to slide contents."));
0182 
0183     QStringList choices;
0184     choices.append(i18nc("@label:listbox The current screen, for the presentation mode", "Current Screen"));
0185     choices.append(i18nc("@label:listbox The default screen for the presentation mode",  "Default Screen"));
0186 
0187     for (int i = 0 ; i < qApp->screens().count() ; ++i)
0188     {
0189         QString model = qApp->screens().at(i)->model();
0190         choices.append(i18nc("@label:listbox %1 is the screen number (0, 1, ...)", "Screen %1", i) +
0191                              QString::fromUtf8(" (%1)").arg(model.left(model.length() - 1)));
0192     }
0193 
0194     d->screenPlacement->addItems(choices);
0195 
0196     QLabel* const keyNote        = new QLabel(i18n("<b>Note: This dialog for the Slideshow Settings "
0197                                                    "can be activated at any time with the F2 key.</b>"), panel);
0198     keyNote->setWordWrap(true);
0199     keyNote->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
0200 
0201     // Disable and uncheck the "Show captions if no title" checkbox if the "Show comment" checkbox enabled
0202 
0203     connect(d->showComment, SIGNAL(stateChanged(int)),
0204             this, SLOT(slotSetUnchecked(int)));
0205 
0206     connect(d->showComment, SIGNAL(toggled(bool)),
0207             d->showCapIfNoTitle, SLOT(setDisabled(bool)));
0208 
0209     // Only digiKam support this feature, showFoto do not support digiKam database information.
0210 
0211     if (qApp->applicationName() == QLatin1String("showfoto"))
0212     {
0213         d->showCapIfNoTitle->hide();
0214         d->showLabels->hide();
0215         d->showRating->hide();
0216         d->showTitle->hide();
0217         d->showTags->hide();
0218     }
0219 
0220     QGridLayout* const grid   = new QGridLayout(panel);
0221     grid->addWidget(hbox1,                   0, 0, 1, 2);
0222     grid->addWidget(d->startWithCurrent,     1, 0, 1, 1);
0223     grid->addWidget(d->showRating,           1, 1, 1, 1);
0224     grid->addWidget(d->suffleMode,           2, 0, 1, 1);
0225     grid->addWidget(d->loopMode,             2, 1, 1, 1);
0226     grid->addWidget(d->showName,             3, 0, 1, 1);
0227     grid->addWidget(d->showProgress,         3, 1, 1, 1);
0228     grid->addWidget(d->showApertureFocal,    4, 0, 1, 1);
0229     grid->addWidget(d->showDate,             4, 1, 1, 1);
0230     grid->addWidget(d->showMakeModel,        5, 0, 1, 1);
0231     grid->addWidget(d->showExpoSensitivity,  5, 1, 1, 1);
0232     grid->addWidget(d->showLensModel,        6, 0, 1, 1);
0233     grid->addWidget(d->showComment,          6, 1, 1, 1);
0234     grid->addWidget(d->showTitle,            7, 0, 1, 1);
0235     grid->addWidget(d->showCapIfNoTitle,     7, 1, 1, 1);
0236     grid->addWidget(d->showTags,             8, 0, 1, 1);
0237     grid->addWidget(d->showLabels,           8, 1, 1, 1);
0238     grid->addWidget(d->captionFont,          9, 0, 1, 2);
0239     grid->addWidget(screenSelectBox,        10, 0, 1, 2);
0240     grid->addWidget(keyNote,                11, 0, 1, 2);
0241     grid->setRowStretch(12, 10);
0242     grid->setContentsMargins(spacing, spacing, spacing, spacing);
0243     grid->setSpacing(spacing);
0244 
0245     QVBoxLayout* mainLayout = new QVBoxLayout(this);
0246     mainLayout->addWidget(panel);
0247     mainLayout->addWidget(m_buttons);
0248 
0249     setLayout(mainLayout);
0250 
0251     connect(m_buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()),
0252             this, SLOT(slotApplySettings()));
0253 
0254     connect(m_buttons->button(QDialogButtonBox::Close), SIGNAL(clicked()),
0255             this, SLOT(reject()));
0256 
0257     d->settings = settings;
0258 
0259     readSettings();
0260 }
0261 
0262 SetupSlideShowDialog::~SetupSlideShowDialog()
0263 {
0264     delete d;
0265 }
0266 
0267 void SetupSlideShowDialog::slotSetUnchecked(int)
0268 {
0269     d->showCapIfNoTitle->setCheckState(Qt::Unchecked);
0270 }
0271 
0272 void SetupSlideShowDialog::slotApplySettings()
0273 {
0274     d->settings->delay                 = d->delayInput->value();
0275     d->settings->startWithCurrent      = d->startWithCurrent->isChecked();
0276     d->settings->loop                  = d->loopMode->isChecked();
0277     d->settings->suffle                = d->suffleMode->isChecked();
0278     d->settings->printName             = d->showName->isChecked();
0279     d->settings->printDate             = d->showDate->isChecked();
0280     d->settings->printApertureFocal    = d->showApertureFocal->isChecked();
0281     d->settings->printExpoSensitivity  = d->showExpoSensitivity->isChecked();
0282     d->settings->printMakeModel        = d->showMakeModel->isChecked();
0283     d->settings->printLensModel        = d->showLensModel->isChecked();
0284     d->settings->printComment          = d->showComment->isChecked();
0285     d->settings->printTitle            = d->showTitle->isChecked();
0286     d->settings->printCapIfNoTitle     = d->showCapIfNoTitle->isChecked();
0287     d->settings->printTags             = d->showTags->isChecked();
0288     d->settings->printLabels           = d->showLabels->isChecked();
0289     d->settings->printRating           = d->showRating->isChecked();
0290     d->settings->showProgressIndicator = d->showProgress->isChecked();
0291     d->settings->captionFont           = d->captionFont->font();
0292     d->settings->slideScreen           = d->screenPlacement->currentIndex() - 2;
0293 
0294     d->settings->writeToConfig();
0295 
0296     accept();
0297 }
0298 
0299 void SetupSlideShowDialog::readSettings()
0300 {
0301     d->delayInput->setValue(d->settings->delay);
0302     d->startWithCurrent->setChecked(d->settings->startWithCurrent);
0303     d->loopMode->setChecked(d->settings->loop);
0304     d->suffleMode->setChecked(d->settings->suffle);
0305     d->showName->setChecked(d->settings->printName);
0306     d->showDate->setChecked(d->settings->printDate);
0307     d->showApertureFocal->setChecked(d->settings->printApertureFocal);
0308     d->showExpoSensitivity->setChecked(d->settings->printExpoSensitivity);
0309     d->showMakeModel->setChecked(d->settings->printMakeModel);
0310     d->showLensModel->setChecked(d->settings->printLensModel);
0311     d->showComment->setChecked(d->settings->printComment);
0312     d->showTitle->setChecked(d->settings->printTitle);
0313     d->showCapIfNoTitle->setChecked(d->settings->printCapIfNoTitle);
0314     d->showTags->setChecked(d->settings->printTags);
0315     d->showLabels->setChecked(d->settings->printLabels);
0316     d->showRating->setChecked(d->settings->printRating);
0317     d->showProgress->setChecked(d->settings->showProgressIndicator);
0318     d->captionFont->setFont(d->settings->captionFont);
0319 
0320     const int screen = d->settings->slideScreen;
0321 
0322     if ((screen >= -2) && (screen < qApp->screens().count()))
0323     {
0324         d->screenPlacement->setCurrentIndex(screen + 2);
0325     }
0326     else
0327     {
0328         d->screenPlacement->setCurrentIndex(0);
0329         d->settings->slideScreen = -2;
0330         d->settings->writeToConfig();
0331     }
0332 }
0333 
0334 } // namespace DigikamGenericSlideShowPlugin
0335 
0336 #include "moc_setupslideshow_dialog.cpp"