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: 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 "expoblendingitemspage.h"
0017 
0018 // Qt includes
0019 
0020 #include <QLabel>
0021 #include <QVBoxLayout>
0022 #include <QPixmap>
0023 #include <QTimer>
0024 #include <QStandardPaths>
0025 
0026 // KDE includes
0027 
0028 #include <klocalizedstring.h>
0029 
0030 // Local includes
0031 
0032 #include "digikam_debug.h"
0033 #include "ditemslist.h"
0034 #include "expoblendingmanager.h"
0035 #include "expoblendingthread.h"
0036 #include "dlayoutbox.h"
0037 
0038 namespace DigikamGenericExpoBlendingPlugin
0039 {
0040 
0041 class Q_DECL_HIDDEN ItemsPage::Private
0042 {
0043 public:
0044 
0045     explicit Private()
0046       : list(nullptr),
0047         mngr(nullptr)
0048     {
0049     }
0050 
0051     DItemsList*         list;
0052     ExpoBlendingManager* mngr;
0053 };
0054 
0055 ItemsPage::ItemsPage(ExpoBlendingManager* const mngr, QWizard* const dlg)
0056     : DWizardPage(dlg, QString::fromLatin1("<b>%1</b>").arg(i18nc("@title:window", "Set Bracketed Images"))),
0057       d          (new Private)
0058 {
0059     d->mngr = mngr;
0060 
0061     DVBox* const vbox    = new DVBox(this);
0062     QLabel* const label1 = new QLabel(vbox);
0063     label1->setWordWrap(true);
0064     label1->setText(QString::fromUtf8("<qt>"
0065                                       "<p>%1</p>"
0066                                       "<ul><li>%2</li>"
0067                                       "<li>%3</li>"
0068                                       "<li>%4</li></ul>"
0069                                       "</qt>")
0070                    .arg(i18nc("@info", "Set here the list of your bracketed images to fuse. Please follow these conditions"))
0071                    .arg(i18nc("@info", "At least 2 images from the same subject must be added to the stack."))
0072                    .arg(i18nc("@info", "Do not mix images with different color depth."))
0073                    .arg(i18nc("@info", "All images must have the same dimensions.")));
0074 
0075     d->list = new DItemsList(vbox);
0076     d->list->setObjectName(QLatin1String("ExpoBlending ImagesList"));
0077     d->list->listView()->setColumn(DItemsListView::User1, i18nc("@title: column", "Exposure (EV)"), true);
0078     d->list->slotAddImages(d->mngr->itemsList());
0079 
0080     setPageWidget(vbox);
0081 
0082     QPixmap leftPix(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String("digikam/data/assistant-stack.png")));
0083     setLeftBottomPix(leftPix.scaledToWidth(128, Qt::SmoothTransformation));
0084 
0085     connect(d->mngr->thread(), SIGNAL(starting(DigikamGenericExpoBlendingPlugin::ExpoBlendingActionData)),
0086             this, SLOT(slotExpoBlendingAction(DigikamGenericExpoBlendingPlugin::ExpoBlendingActionData)));
0087 
0088     connect(d->mngr->thread(), SIGNAL(finished(DigikamGenericExpoBlendingPlugin::ExpoBlendingActionData)),
0089             this, SLOT(slotExpoBlendingAction(DigikamGenericExpoBlendingPlugin::ExpoBlendingActionData)));
0090 
0091     connect(d->list, SIGNAL(signalAddItems(QList<QUrl>)),
0092             this, SLOT(slotAddItems(QList<QUrl>)));
0093 
0094     connect(d->list, SIGNAL(signalImageListChanged()),
0095             this, SLOT(slotImageListChanged()));
0096 
0097     QTimer::singleShot(0, this, SLOT(slotSetupList()));
0098 }
0099 
0100 ItemsPage::~ItemsPage()
0101 {
0102     delete d;
0103 }
0104 
0105 void ItemsPage::slotSetupList()
0106 {
0107     slotAddItems(d->mngr->itemsList());
0108 }
0109 
0110 void ItemsPage::slotAddItems(const QList<QUrl>& urls)
0111 {
0112     if (!urls.isEmpty())
0113     {
0114         d->mngr->thread()->identifyFiles(urls);
0115 
0116         if (!d->mngr->thread()->isRunning())
0117         {
0118             d->mngr->thread()->start();
0119         }
0120     }
0121 
0122     slotImageListChanged();
0123 }
0124 
0125 QList<QUrl> ItemsPage::itemUrls() const
0126 {
0127     return d->list->imageUrls();
0128 }
0129 
0130 void ItemsPage::setIdentity(const QUrl& url, const QString& identity)
0131 {
0132     DItemsListViewItem* item = d->list->listView()->findItem(url);
0133 
0134     if (item)
0135     {
0136         item->setText(DItemsListView::User1, identity);
0137     }
0138 }
0139 
0140 void ItemsPage::slotImageListChanged()
0141 {
0142     Q_EMIT signalItemsPageIsValid(d->list->imageUrls().count() > 1);
0143 }
0144 
0145 void ItemsPage::slotExpoBlendingAction(const DigikamGenericExpoBlendingPlugin::ExpoBlendingActionData& ad)
0146 {
0147     QString text;
0148 
0149     if (!ad.starting)           // Something is complete...
0150     {
0151         switch (ad.action)
0152         {
0153             case(EXPOBLENDING_IDENTIFY):
0154             {
0155                 setIdentity(ad.inUrls[0], ad.message);
0156                 break;
0157             }
0158 
0159             default:
0160             {
0161                 qCWarning(DIGIKAM_DPLUGIN_GENERIC_LOG) << "Unknown action";
0162                 break;
0163             }
0164         }
0165     }
0166 }
0167 
0168 } // namespace DigikamGenericExpoBlendingPlugin
0169 
0170 #include "moc_expoblendingitemspage.cpp"