File indexing completed on 2025-01-19 03:55:43

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 template to create wizard page.
0008  *
0009  * SPDX-FileCopyrightText: 2009-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 "dwizardpage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QHBoxLayout>
0020 #include <QLabel>
0021 #include <QVBoxLayout>
0022 #include <QStandardPaths>
0023 #include <QApplication>
0024 #include <QStyle>
0025 #include <QScrollArea>
0026 #include <QWizard>
0027 
0028 namespace Digikam
0029 {
0030 
0031 class Q_DECL_HIDDEN DWizardPage::Private
0032 {
0033 public:
0034 
0035     explicit Private()
0036       : isComplete      (true),
0037         id              (-1),
0038         leftView        (nullptr),
0039         logo            (nullptr),
0040         leftBottomPix   (nullptr),
0041         hlay            (nullptr),
0042         dlg             (nullptr)
0043     {
0044     }
0045 
0046     bool         isComplete;
0047     int          id;
0048 
0049     QWidget*     leftView;
0050     QLabel*      logo;
0051     QLabel*      leftBottomPix;
0052 
0053     QHBoxLayout* hlay;
0054 
0055     QWizard*     dlg;
0056 };
0057 
0058 DWizardPage::DWizardPage(QWizard* const dlg, const QString& title)
0059     : QWizardPage(dlg),
0060       d          (new Private)
0061 {
0062     setTitle(title);
0063 
0064     const int spacing     = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0065                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0066 
0067     QScrollArea* const sv = new QScrollArea(this);
0068     QWidget* const panel  = new QWidget(sv->viewport());
0069     sv->setWidget(panel);
0070     sv->setWidgetResizable(true);
0071 
0072     d->hlay                    = new QHBoxLayout(panel);
0073     d->leftView                = new QWidget(panel);
0074     QVBoxLayout* const vboxLay = new QVBoxLayout(d->leftView);
0075     d->logo                    = new QLabel(d->leftView);
0076     d->logo->setAlignment(Qt::AlignTop);
0077     d->logo->setPixmap(QIcon::fromTheme(QLatin1String("digikam")).pixmap(QSize(128, 128)));
0078 
0079     QWidget* const space = new QLabel(d->leftView);
0080     d->leftBottomPix     = new QLabel(d->leftView);
0081     d->leftBottomPix->setAlignment(Qt::AlignBottom);
0082 
0083     vboxLay->addWidget(d->logo);
0084     vboxLay->addWidget(space);
0085     vboxLay->addWidget(d->leftBottomPix);
0086     vboxLay->setStretchFactor(space, 10);
0087     vboxLay->setContentsMargins(spacing, spacing, spacing, spacing);
0088     vboxLay->setSpacing(spacing);
0089 
0090     QFrame* const vline = new QFrame(panel);
0091     vline->setLineWidth(1);
0092     vline->setMidLineWidth(0);
0093     vline->setFrameShape(QFrame::VLine);
0094     vline->setFrameShadow(QFrame::Sunken);
0095     vline->setMinimumSize(2, 0);
0096     vline->updateGeometry();
0097 
0098     d->hlay->addWidget(d->leftView);
0099     d->hlay->addWidget(vline);
0100     d->hlay->setContentsMargins(QMargins());
0101     d->hlay->setSpacing(spacing);
0102 
0103     QVBoxLayout* const layout = new QVBoxLayout;
0104     layout->addWidget(sv);
0105     setLayout(layout);
0106 
0107     d->dlg = dlg;
0108     d->id  = d->dlg->addPage(this);
0109 }
0110 
0111 DWizardPage::~DWizardPage()
0112 {
0113     delete d;
0114 }
0115 
0116 void DWizardPage::setComplete(bool b)
0117 {
0118     d->isComplete = b;
0119     Q_EMIT completeChanged();
0120 }
0121 
0122 bool DWizardPage::isComplete() const
0123 {
0124     return d->isComplete;
0125 }
0126 
0127 int DWizardPage::id() const
0128 {
0129     return d->id;
0130 }
0131 
0132 void DWizardPage::setShowLeftView(bool v)
0133 {
0134     d->leftView->setVisible(v);
0135 }
0136 
0137 void DWizardPage::setPageWidget(QWidget* const w)
0138 {
0139     d->hlay->addWidget(w);
0140     d->hlay->setStretchFactor(w, 10);
0141 }
0142 
0143 void DWizardPage::removePageWidget(QWidget* const w)
0144 {
0145     d->hlay->removeWidget(w);
0146 }
0147 
0148 void DWizardPage::setLeftBottomPix(const QPixmap& pix)
0149 {
0150     d->leftBottomPix->setPixmap(pix);
0151 }
0152 
0153 void DWizardPage::setLeftBottomPix(const QIcon& icon)
0154 {
0155     d->leftBottomPix->setPixmap(icon.pixmap(128));
0156 }
0157 
0158 QWizard* DWizardPage::assistant() const
0159 {
0160     return d->dlg;
0161 }
0162 
0163 } // namespace Digikam
0164 
0165 #include "moc_dwizardpage.cpp"