1/*
2 This file is part of the KDE Libraries
3 SPDX-FileCopyrightText: 1999-2001 Mirko Boehm <mirko@kde.org>
4 SPDX-FileCopyrightText: 1999-2001 Espen Sand <espen@kde.org>
5 SPDX-FileCopyrightText: 1999-2001 Holger Freyther <freyther@kde.org>
6 SPDX-FileCopyrightText: 2005-2006 Olivier Goffart <ogoffart at kde.org>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#include "kpagedialog.h"
12#include "kpagedialog_p.h"
13
14#include <QLayout>
15#include <QStyle>
16
17KPageDialog::KPageDialog(QWidget *parent, Qt::WindowFlags flags)
18 : KPageDialog(*new KPageDialogPrivate(this), nullptr, parent, flags)
19{
20}
21
22KPageDialog::KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags)
23 : KPageDialog(*new KPageDialogPrivate(this), widget, parent, flags)
24{
25 Q_ASSERT(widget);
26}
27
28KPageDialog::KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags)
29 : QDialog(parent, flags)
30 , d_ptr(&dd)
31{
32 Q_D(KPageDialog);
33 if (widget) {
34 widget->setParent(this);
35 d->mPageWidget = widget;
36 } else {
37 d->mPageWidget = new KPageWidget(this);
38 }
39 d->mButtonBox = new QDialogButtonBox(this);
40 d->mButtonBox->setObjectName(QStringLiteral("buttonbox"));
41 d->mButtonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
42 d->init();
43}
44
45KPageDialog::~KPageDialog() = default;
46
47void KPageDialog::setFaceType(FaceType faceType)
48{
49 Q_D(KPageDialog);
50
51 d->mPageWidget->setFaceType(static_cast<KPageWidget::FaceType>(faceType));
52
53 // Use zero margins for dialogs with the sidebar style so that the sidebar
54 // can be flush with the window edge; margins for the content are added
55 // automatically
56 layout()->setContentsMargins(left: 0, top: 0, right: 0, bottom: 0);
57}
58
59KPageWidgetItem *KPageDialog::addPage(QWidget *widget, const QString &name)
60{
61 Q_D(KPageDialog);
62
63 return d->mPageWidget->addPage(widget, name);
64}
65
66void KPageDialog::addPage(KPageWidgetItem *item)
67{
68 Q_D(KPageDialog);
69
70 d->mPageWidget->addPage(item);
71}
72
73KPageWidgetItem *KPageDialog::insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
74{
75 Q_D(KPageDialog);
76
77 return d->mPageWidget->insertPage(before, widget, name);
78}
79
80void KPageDialog::insertPage(KPageWidgetItem *before, KPageWidgetItem *item)
81{
82 Q_D(KPageDialog);
83
84 d->mPageWidget->insertPage(before, item);
85}
86
87KPageWidgetItem *KPageDialog::addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name)
88{
89 Q_D(KPageDialog);
90
91 return d->mPageWidget->addSubPage(parent, widget, name);
92}
93
94void KPageDialog::addSubPage(KPageWidgetItem *parent, KPageWidgetItem *item)
95{
96 Q_D(KPageDialog);
97
98 d->mPageWidget->addSubPage(parent, item);
99}
100
101void KPageDialog::removePage(KPageWidgetItem *item)
102{
103 Q_D(KPageDialog);
104
105 d->mPageWidget->removePage(item);
106}
107
108void KPageDialog::setCurrentPage(KPageWidgetItem *item)
109{
110 Q_D(KPageDialog);
111
112 d->mPageWidget->setCurrentPage(item);
113}
114
115KPageWidgetItem *KPageDialog::currentPage() const
116{
117 Q_D(const KPageDialog);
118
119 return d->mPageWidget->currentPage();
120}
121
122void KPageDialog::setStandardButtons(QDialogButtonBox::StandardButtons buttons)
123{
124 Q_D(KPageDialog);
125
126 d->mButtonBox->setStandardButtons(buttons);
127}
128
129QPushButton *KPageDialog::button(QDialogButtonBox::StandardButton which) const
130{
131 Q_D(const KPageDialog);
132
133 return d->mButtonBox->button(which);
134}
135
136void KPageDialog::addActionButton(QAbstractButton *button)
137{
138 Q_D(KPageDialog);
139
140 d->mButtonBox->addButton(button, role: QDialogButtonBox::ActionRole);
141}
142
143KPageWidget *KPageDialog::pageWidget()
144{
145 Q_D(KPageDialog);
146
147 return d->mPageWidget;
148}
149
150void KPageDialog::setPageWidget(KPageWidget *widget)
151{
152 Q_D(KPageDialog);
153
154 delete d->mPageWidget;
155 d->mPageWidget = widget;
156 d->init();
157}
158
159const KPageWidget *KPageDialog::pageWidget() const
160{
161 Q_D(const KPageDialog);
162
163 return d->mPageWidget;
164}
165
166QDialogButtonBox *KPageDialog::buttonBox()
167{
168 Q_D(KPageDialog);
169
170 return d->mButtonBox;
171}
172
173const QDialogButtonBox *KPageDialog::buttonBox() const
174{
175 Q_D(const KPageDialog);
176
177 return d->mButtonBox;
178}
179
180void KPageDialog::setButtonBox(QDialogButtonBox *box)
181{
182 Q_D(KPageDialog);
183
184 delete d->mButtonBox;
185 d->mButtonBox = box;
186 d->init();
187}
188
189#include "moc_kpagedialog.cpp"
190

source code of kwidgetsaddons/src/kpagedialog.cpp