File indexing completed on 2025-01-19 03:53:49

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-11-03
0007  * Description : A dialog base class which can handle multiple pages.
0008  *
0009  * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 1999-2001 by Mirko Boehm <mirko at kde dot org>
0011  * SPDX-FileCopyrightText: 1999-2001 by Espen Sand <espen at kde dot org>
0012  * SPDX-FileCopyrightText: 1999-2001 by Holger Freyther <freyther at kde dot org>
0013  * SPDX-FileCopyrightText: 2005-2006 by Olivier Goffart <ogoffart at kde dot org>
0014  *
0015  * SPDX-License-Identifier: GPL-2.0-or-later
0016  *
0017  * ============================================================ */
0018 
0019 #include "dconfigdlg.h"
0020 
0021 // Qt includes
0022 
0023 #include <QTimer>
0024 #include <QLayout>
0025 
0026 namespace Digikam
0027 {
0028 
0029 class Q_DECL_HIDDEN DConfigDlgPrivate
0030 {
0031     Q_DECLARE_PUBLIC(DConfigDlg)
0032 
0033 protected:
0034 
0035     explicit DConfigDlgPrivate(DConfigDlg* const parent)
0036         : q_ptr      (parent),
0037           mPageWidget(nullptr),
0038           mButtonBox (nullptr)
0039     {
0040     }
0041 
0042     virtual ~DConfigDlgPrivate()
0043     {
0044     }
0045 
0046     void init()
0047     {
0048         Q_Q(DConfigDlg);
0049         delete q->layout();
0050 
0051         QVBoxLayout* const layout = new QVBoxLayout;
0052         q->setLayout(layout);
0053 
0054         if (mPageWidget)
0055         {
0056             q->connect(mPageWidget, SIGNAL(currentPageChanged(DConfigDlgWdgItem*,DConfigDlgWdgItem*)),
0057                        q, SIGNAL(currentPageChanged(DConfigDlgWdgItem*,DConfigDlgWdgItem*)));
0058 
0059             q->connect(mPageWidget, &DConfigDlgWdg::pageRemoved,
0060                        q, &DConfigDlg::pageRemoved);
0061 
0062             layout->addWidget(mPageWidget);
0063         }
0064         else
0065         {
0066             layout->addStretch();
0067         }
0068 
0069         if (mButtonBox)
0070         {
0071             q->connect(mButtonBox, &QDialogButtonBox::accepted,
0072                        q, &QDialog::accept);
0073 
0074             q->connect(mButtonBox, &QDialogButtonBox::rejected,
0075                        q, &QDialog::reject);
0076 
0077             layout->addWidget(mButtonBox);
0078         }
0079     }
0080 
0081 protected:
0082 
0083     DConfigDlg* const q_ptr;
0084     DConfigDlgWdg*    mPageWidget;
0085     QDialogButtonBox* mButtonBox;
0086 
0087 private:
0088 
0089     Q_DISABLE_COPY(DConfigDlgPrivate)
0090 };
0091 
0092 // ------------------------------------------------------------------------
0093 
0094 DConfigDlg::DConfigDlg(QWidget* const parent, Qt::WindowFlags flags)
0095     : QDialog(parent, flags),
0096       d_ptr  (new DConfigDlgPrivate(this))
0097 {
0098     Q_D(DConfigDlg);
0099     d->mPageWidget = new DConfigDlgWdg(this);
0100     d->mPageWidget->layout()->setContentsMargins(QMargins());
0101 
0102     d->mButtonBox  = new QDialogButtonBox(this);
0103     d->mButtonBox->setObjectName(QLatin1String("buttonbox"));
0104     d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0105 
0106     d->init();
0107 }
0108 
0109 DConfigDlg::DConfigDlg(DConfigDlgWdg* const widget, QWidget* const parent, Qt::WindowFlags flags)
0110     : QDialog(parent, flags),
0111       d_ptr  (new DConfigDlgPrivate(this))
0112 {
0113     Q_D(DConfigDlg);
0114     Q_ASSERT(widget);
0115     widget->setParent(this);
0116     d->mPageWidget = widget;
0117     d->mButtonBox  = new QDialogButtonBox(this);
0118     d->mButtonBox->setObjectName(QLatin1String("buttonbox"));
0119     d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0120 
0121     d->init();
0122 }
0123 
0124 DConfigDlg::DConfigDlg(DConfigDlgPrivate& dd, DConfigDlgWdg* const widget, QWidget* const parent, Qt::WindowFlags flags)
0125     : QDialog(parent, flags),
0126       d_ptr  (&dd)
0127 {
0128     Q_D(DConfigDlg);
0129 
0130     if (widget)
0131     {
0132         widget->setParent(this);
0133         d->mPageWidget = widget;
0134     }
0135     else
0136     {
0137         d->mPageWidget = new DConfigDlgWdg(this);
0138     }
0139 
0140     d->mButtonBox = new QDialogButtonBox(this);
0141     d->mButtonBox->setObjectName(QLatin1String("buttonbox"));
0142     d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0143     d->init();
0144 }
0145 
0146 DConfigDlg::~DConfigDlg()
0147 {
0148     delete d_ptr;
0149 }
0150 
0151 void DConfigDlg::setFaceType(FaceType faceType)
0152 {
0153     d_func()->mPageWidget->setFaceType(static_cast<DConfigDlgWdg::FaceType>(faceType));
0154 }
0155 
0156 DConfigDlgWdgItem* DConfigDlg::addPage(QWidget* const widget, const QString& name)
0157 {
0158     return d_func()->mPageWidget->addPage(widget, name);
0159 }
0160 
0161 void DConfigDlg::addPage(DConfigDlgWdgItem* const item)
0162 {
0163     d_func()->mPageWidget->addPage(item);
0164 }
0165 
0166 DConfigDlgWdgItem* DConfigDlg::insertPage(DConfigDlgWdgItem* const before, QWidget* const widget, const QString& name)
0167 {
0168     return d_func()->mPageWidget->insertPage(before, widget, name);
0169 }
0170 
0171 void DConfigDlg::insertPage(DConfigDlgWdgItem* const before, DConfigDlgWdgItem* const item)
0172 {
0173     d_func()->mPageWidget->insertPage(before, item);
0174 }
0175 
0176 DConfigDlgWdgItem* DConfigDlg::addSubPage(DConfigDlgWdgItem* const parent, QWidget* const widget, const QString& name)
0177 {
0178     return d_func()->mPageWidget->addSubPage(parent, widget, name);
0179 }
0180 
0181 void DConfigDlg::addSubPage(DConfigDlgWdgItem* const parent, DConfigDlgWdgItem* const item)
0182 {
0183     d_func()->mPageWidget->addSubPage(parent, item);
0184 }
0185 
0186 void DConfigDlg::removePage(DConfigDlgWdgItem* const item)
0187 {
0188     d_func()->mPageWidget->removePage(item);
0189 }
0190 
0191 void DConfigDlg::setCurrentPage(DConfigDlgWdgItem* const item)
0192 {
0193     d_func()->mPageWidget->setCurrentPage(item);
0194 }
0195 
0196 DConfigDlgWdgItem* DConfigDlg::currentPage() const
0197 {
0198     return d_func()->mPageWidget->currentPage();
0199 }
0200 
0201 void DConfigDlg::setStandardButtons(QDialogButtonBox::StandardButtons buttons)
0202 {
0203     d_func()->mButtonBox->setStandardButtons(buttons);
0204 }
0205 
0206 QPushButton* DConfigDlg::button(QDialogButtonBox::StandardButton which) const
0207 {
0208     return d_func()->mButtonBox->button(which);
0209 }
0210 
0211 void DConfigDlg::addActionButton(QAbstractButton* const button)
0212 {
0213     d_func()->mButtonBox->addButton(button, QDialogButtonBox::ActionRole);
0214 }
0215 
0216 DConfigDlgWdg* DConfigDlg::pageWidget()
0217 {
0218     return d_func()->mPageWidget;
0219 }
0220 
0221 const DConfigDlgWdg* DConfigDlg::pageWidget() const
0222 {
0223     return d_func()->mPageWidget;
0224 }
0225 
0226 void DConfigDlg::setPageWidget(DConfigDlgWdg* const widget)
0227 {
0228     delete d_func()->mPageWidget;
0229     d_func()->mPageWidget = widget;
0230     d_func()->init();
0231 }
0232 
0233 QDialogButtonBox* DConfigDlg::buttonBox()
0234 {
0235     return d_func()->mButtonBox;
0236 }
0237 
0238 const QDialogButtonBox* DConfigDlg::buttonBox() const
0239 {
0240     return d_func()->mButtonBox;
0241 }
0242 
0243 void DConfigDlg::setButtonBox(QDialogButtonBox* const box)
0244 {
0245     delete d_func()->mButtonBox;
0246     d_func()->mButtonBox = box;
0247     d_func()->init();
0248 }
0249 
0250 } // namespace Digikam
0251 
0252 #include "moc_dconfigdlg.cpp"