File indexing completed on 2025-03-09 03:50:51

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-13
0007  * Description : a tool to blend bracketed images.
0008  *
0009  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2012-2015 by Benjamin Girault <benjamin dot girault at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "expoblendingwizard.h"
0017 
0018 // KDE includes
0019 
0020 #include <klocalizedstring.h>
0021 
0022 // Locale includes
0023 
0024 #include "expoblendingintropage.h"
0025 #include "expoblendingitemspage.h"
0026 #include "expoblendinglastpage.h"
0027 #include "expoblendingmanager.h"
0028 #include "expoblendingpreprocesspage.h"
0029 
0030 namespace DigikamGenericExpoBlendingPlugin
0031 {
0032 
0033 class Q_DECL_HIDDEN ExpoBlendingWizard::Private
0034 {
0035 public:
0036 
0037     explicit Private()
0038       : mngr             (nullptr),
0039         introPage        (nullptr),
0040         itemsPage        (nullptr),
0041         preProcessingPage(nullptr),
0042         lastPage         (nullptr),
0043         preProcessed     (false)
0044     {
0045     }
0046 
0047     ExpoBlendingManager*        mngr;
0048 
0049     ExpoBlendingIntroPage*      introPage;
0050     ItemsPage*                  itemsPage;
0051     ExpoBlendingPreProcessPage* preProcessingPage;
0052     ExpoBlendingLastPage*       lastPage;
0053 
0054     bool                        preProcessed;
0055 };
0056 
0057 ExpoBlendingWizard::ExpoBlendingWizard(ExpoBlendingManager* const mngr, QWidget* const parent)
0058     : DWizardDlg(parent, QLatin1String("ExpoBlending Wizard")),
0059       d         (new Private)
0060 {
0061     setModal(false);
0062     setWindowTitle(i18nc("@title:window", "Stacked Images Tool"));
0063 
0064     d->mngr              = mngr;
0065     d->introPage         = new ExpoBlendingIntroPage(d->mngr, this);
0066     d->itemsPage         = new ItemsPage(d->mngr, this);
0067     d->preProcessingPage = new ExpoBlendingPreProcessPage(d->mngr, this);
0068     d->lastPage          = new ExpoBlendingLastPage(d->mngr, this);
0069 
0070     // ---------------------------------------------------------------
0071 
0072     connect(d->introPage, SIGNAL(signalExpoBlendingIntroPageIsValid(bool)),
0073             this, SLOT(slotExpoBlendingIntroPageIsValid(bool)));
0074 
0075     connect(d->itemsPage, SIGNAL(signalItemsPageIsValid(bool)),
0076             this, SLOT(slotItemsPageIsValid(bool)));
0077 
0078     connect(d->preProcessingPage, SIGNAL(signalPreProcessed(ExpoBlendingItemUrlsMap)),
0079             this, SLOT(slotPreProcessed(ExpoBlendingItemUrlsMap)));
0080 
0081     connect(this, SIGNAL(currentIdChanged(int)),
0082             this, SLOT(slotCurrentIdChanged(int)));
0083 
0084     d->introPage->setComplete(d->introPage->binariesFound());
0085 }
0086 
0087 ExpoBlendingWizard::~ExpoBlendingWizard()
0088 {
0089     delete d;
0090 }
0091 
0092 ExpoBlendingManager* ExpoBlendingWizard::manager() const
0093 {
0094     return d->mngr;
0095 }
0096 
0097 QList<QUrl> ExpoBlendingWizard::itemUrls() const
0098 {
0099     return d->itemsPage->itemUrls();
0100 }
0101 
0102 bool ExpoBlendingWizard::validateCurrentPage()
0103 {
0104     if      (currentPage() == d->itemsPage)
0105     {
0106         d->mngr->setItemsList(d->itemsPage->itemUrls());
0107     }
0108     else if (currentPage() == d->preProcessingPage && !d->preProcessed)
0109     {
0110         // Do not give access to Next button during alignment process.
0111 
0112         d->preProcessingPage->setComplete(false);
0113         d->preProcessingPage->process();
0114         d->preProcessed = true;
0115 
0116         // Next is handled with signals/slots
0117 
0118         return false;
0119     }
0120 
0121     return true;
0122 }
0123 
0124 void ExpoBlendingWizard::slotCurrentIdChanged(int id)
0125 {
0126     if ((page(id) != d->lastPage) && d->preProcessed)
0127     {
0128         d->preProcessed = false;
0129         d->preProcessingPage->cancel();
0130         d->preProcessingPage->setComplete(true);
0131     }
0132 }
0133 
0134 void ExpoBlendingWizard::slotExpoBlendingIntroPageIsValid(bool binariesFound)
0135 {
0136     d->introPage->setComplete(binariesFound);
0137 }
0138 
0139 void ExpoBlendingWizard::slotPreProcessed(const ExpoBlendingItemUrlsMap& map)
0140 {
0141     if (map.isEmpty())
0142     {
0143         // pre-processing failed.
0144 
0145         d->preProcessingPage->setComplete(false);
0146         d->preProcessed = false;
0147     }
0148     else
0149     {
0150         // pre-processing Done.
0151 
0152         d->mngr->setPreProcessedMap(map);
0153         next();
0154     }
0155 }
0156 
0157 void ExpoBlendingWizard::slotItemsPageIsValid(bool valid)
0158 {
0159     d->itemsPage->setComplete(valid);
0160 }
0161 
0162 } // namespace DigikamGenericExpoBlendingPlugin
0163 
0164 #include "moc_expoblendingwizard.cpp"