File indexing completed on 2024-04-28 03:59:09

0001 /*
0002     This file is part of the KDE Libraries
0003     SPDX-FileCopyrightText: 1999-2001 Mirko Boehm <mirko@kde.org>
0004     SPDX-FileCopyrightText: 1999-2001 Espen Sand <espen@kde.org>
0005     SPDX-FileCopyrightText: 1999-2001 Holger Freyther <freyther@kde.org>
0006     SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org>
0007 
0008     SPDX-License-Identifier: LGPL-2.0-or-later
0009 */
0010 
0011 #include "kpagedialog.h"
0012 #include "kpagedialog_p.h"
0013 
0014 #include <QLayout>
0015 #include <QStyle>
0016 
0017 KPageDialog::KPageDialog(QWidget *parent, Qt::WindowFlags flags)
0018     : KPageDialog(*new KPageDialogPrivate(this), nullptr, parent, flags)
0019 {
0020 }
0021 
0022 KPageDialog::KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags)
0023     : KPageDialog(*new KPageDialogPrivate(this), widget, parent, flags)
0024 {
0025     Q_ASSERT(widget);
0026 }
0027 
0028 KPageDialog::KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags)
0029     : QDialog(parent, flags)
0030     , d_ptr(&dd)
0031 {
0032     Q_D(KPageDialog);
0033     if (widget) {
0034         widget->setParent(this);
0035         d->mPageWidget = widget;
0036     } else {
0037         d->mPageWidget = new KPageWidget(this);
0038     }
0039     d->mButtonBox = new QDialogButtonBox(this);
0040     d->mButtonBox->setObjectName(QStringLiteral("buttonbox"));
0041     d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0042     d->init();
0043 }
0044 
0045 KPageDialog::~KPageDialog() = default;
0046 
0047 void KPageDialog::setFaceType(FaceType faceType)
0048 {
0049     Q_D(KPageDialog);
0050 
0051     d->mPageWidget->setFaceType(static_cast<KPageWidget::FaceType>(faceType));
0052 
0053     // Use zero margins for dialogs with the sidebar style so that the sidebar
0054     // can be flush with the window edge; margins for the content are added
0055     // automatically
0056     layout()->setContentsMargins(0, 0, 0, 0);
0057 }
0058 
0059 KPageWidgetItem *KPageDialog::addPage(QWidget *widget, const QString &name)
0060 {
0061     Q_D(KPageDialog);
0062 
0063     return d->mPageWidget->addPage(widget, name);
0064 }
0065 
0066 void KPageDialog::addPage(KPageWidgetItem *item)
0067 {
0068     Q_D(KPageDialog);
0069 
0070     d->mPageWidget->addPage(item);
0071 }
0072 
0073 KPageWidgetItem *KPageDialog::insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
0074 {
0075     Q_D(KPageDialog);
0076 
0077     return d->mPageWidget->insertPage(before, widget, name);
0078 }
0079 
0080 void KPageDialog::insertPage(KPageWidgetItem *before, KPageWidgetItem *item)
0081 {
0082     Q_D(KPageDialog);
0083 
0084     d->mPageWidget->insertPage(before, item);
0085 }
0086 
0087 KPageWidgetItem *KPageDialog::addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name)
0088 {
0089     Q_D(KPageDialog);
0090 
0091     return d->mPageWidget->addSubPage(parent, widget, name);
0092 }
0093 
0094 void KPageDialog::addSubPage(KPageWidgetItem *parent, KPageWidgetItem *item)
0095 {
0096     Q_D(KPageDialog);
0097 
0098     d->mPageWidget->addSubPage(parent, item);
0099 }
0100 
0101 void KPageDialog::removePage(KPageWidgetItem *item)
0102 {
0103     Q_D(KPageDialog);
0104 
0105     d->mPageWidget->removePage(item);
0106 }
0107 
0108 void KPageDialog::setCurrentPage(KPageWidgetItem *item)
0109 {
0110     Q_D(KPageDialog);
0111 
0112     d->mPageWidget->setCurrentPage(item);
0113 }
0114 
0115 KPageWidgetItem *KPageDialog::currentPage() const
0116 {
0117     Q_D(const KPageDialog);
0118 
0119     return d->mPageWidget->currentPage();
0120 }
0121 
0122 void KPageDialog::setStandardButtons(QDialogButtonBox::StandardButtons buttons)
0123 {
0124     Q_D(KPageDialog);
0125 
0126     d->mButtonBox->setStandardButtons(buttons);
0127 }
0128 
0129 QPushButton *KPageDialog::button(QDialogButtonBox::StandardButton which) const
0130 {
0131     Q_D(const KPageDialog);
0132 
0133     return d->mButtonBox->button(which);
0134 }
0135 
0136 void KPageDialog::addActionButton(QAbstractButton *button)
0137 {
0138     Q_D(KPageDialog);
0139 
0140     d->mButtonBox->addButton(button, QDialogButtonBox::ActionRole);
0141 }
0142 
0143 KPageWidget *KPageDialog::pageWidget()
0144 {
0145     Q_D(KPageDialog);
0146 
0147     return d->mPageWidget;
0148 }
0149 
0150 void KPageDialog::setPageWidget(KPageWidget *widget)
0151 {
0152     Q_D(KPageDialog);
0153 
0154     delete d->mPageWidget;
0155     d->mPageWidget = widget;
0156     d->init();
0157 }
0158 
0159 const KPageWidget *KPageDialog::pageWidget() const
0160 {
0161     Q_D(const KPageDialog);
0162 
0163     return d->mPageWidget;
0164 }
0165 
0166 QDialogButtonBox *KPageDialog::buttonBox()
0167 {
0168     Q_D(KPageDialog);
0169 
0170     return d->mButtonBox;
0171 }
0172 
0173 const QDialogButtonBox *KPageDialog::buttonBox() const
0174 {
0175     Q_D(const KPageDialog);
0176 
0177     return d->mButtonBox;
0178 }
0179 
0180 void KPageDialog::setButtonBox(QDialogButtonBox *box)
0181 {
0182     Q_D(KPageDialog);
0183 
0184     delete d->mButtonBox;
0185     d->mButtonBox = box;
0186     d->init();
0187 }
0188 
0189 #include "moc_kpagedialog.cpp"