KWidgetsAddons

kpagedialog.cpp
1 /*
2  This file is part of the KDE Libraries
3  SPDX-FileCopyrightText: 1999-2001 Mirko Boehm <[email protected]>
4  SPDX-FileCopyrightText: 1999-2001 Espen Sand <[email protected]>
5  SPDX-FileCopyrightText: 1999-2001 Holger Freyther <[email protected]>
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 
18  : KPageDialog(*new KPageDialogPrivate(this), nullptr, parent, flags)
19 {
20 }
21 
23  : KPageDialog(*new KPageDialogPrivate(this), widget, parent, flags)
24 {
25  Q_ASSERT(widget);
26 }
27 
28 KPageDialog::KPageDialog(KPageDialogPrivate &dd, KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags)
29  : QDialog(parent, flags)
30  , d_ptr(&dd)
31 {
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 
45 KPageDialog::~KPageDialog() = default;
46 
48 {
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  if (faceType == KPageDialog::Auto || faceType == KPageDialog::List || faceType == KPageDialog::FlatList) {
57  layout()->setContentsMargins(0, 0, 0, 0);
58  } else {
59  const QStyle *style = d->mPageWidget->style();
64  }
65 }
66 
68 {
70 
71  return d->mPageWidget->addPage(widget, name);
72 }
73 
75 {
77 
78  d->mPageWidget->addPage(item);
79 }
80 
82 {
84 
85  return d->mPageWidget->insertPage(before, widget, name);
86 }
87 
89 {
91 
92  d->mPageWidget->insertPage(before, item);
93 }
94 
96 {
98 
99  return d->mPageWidget->addSubPage(parent, widget, name);
100 }
101 
103 {
104  Q_D(KPageDialog);
105 
106  d->mPageWidget->addSubPage(parent, item);
107 }
108 
110 {
111  Q_D(KPageDialog);
112 
113  d->mPageWidget->removePage(item);
114 }
115 
117 {
118  Q_D(KPageDialog);
119 
120  d->mPageWidget->setCurrentPage(item);
121 }
122 
124 {
125  Q_D(const KPageDialog);
126 
127  return d->mPageWidget->currentPage();
128 }
129 
131 {
132  Q_D(KPageDialog);
133 
134  d->mButtonBox->setStandardButtons(buttons);
135 }
136 
138 {
139  Q_D(const KPageDialog);
140 
141  return d->mButtonBox->button(which);
142 }
143 
145 {
146  Q_D(KPageDialog);
147 
148  d->mButtonBox->addButton(button, QDialogButtonBox::ActionRole);
149 }
150 
152 {
153  Q_D(KPageDialog);
154 
155  return d->mPageWidget;
156 }
157 
159 {
160  Q_D(KPageDialog);
161 
162  delete d->mPageWidget;
163  d->mPageWidget = widget;
164  d->init();
165 }
166 
168 {
169  Q_D(const KPageDialog);
170 
171  return d->mPageWidget;
172 }
173 
175 {
176  Q_D(KPageDialog);
177 
178  return d->mButtonBox;
179 }
180 
182 {
183  Q_D(const KPageDialog);
184 
185  return d->mButtonBox;
186 }
187 
189 {
190  Q_D(KPageDialog);
191 
192  delete d->mButtonBox;
193  d->mButtonBox = box;
194  d->init();
195 }
196 
197 #include "moc_kpagedialog.cpp"
KPageDialog(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Creates a new page dialog.
Definition: kpagedialog.cpp:17
void setParent(QWidget *parent)
KPageWidgetItem * addSubPage(KPageWidgetItem *parent, QWidget *widget, const QString &name)
Inserts a new sub page in the dialog.
Definition: kpagedialog.cpp:95
@ List
A dialog with an icon list on the left side and a representation of the contents on the right side.
Definition: kpagedialog.h:102
QLayout * layout() const const
KPageWidget * pageWidget()
Returns the page widget of the dialog or a null pointer if no page widget is set.
KPageWidgetItem * insertPage(KPageWidgetItem *before, QWidget *widget, const QString &name)
Inserts a new page in the dialog.
Definition: kpagedialog.cpp:81
void setFaceType(FaceType faceType)
Sets the face type of the dialog.
Definition: kpagedialog.cpp:47
void setButtonBox(QDialogButtonBox *box)
Set the button box of the dialog.
virtual int pixelMetric(QStyle::PixelMetric metric, const QStyleOption *option, const QWidget *widget) const const=0
typedef WindowFlags
@ FlatList
A dialog with an flat list with small icons on the left side and a representation of the contents on ...
Definition: kpagedialog.h:117
@ Auto
A dialog with a face based on the structure of the available pages.
Definition: kpagedialog.h:93
QStyle * style() const const
Page widget with many layouts (faces). A KPageView with hierarchical page model.
Definition: kpagewidget.h:24
PM_LayoutLeftMargin
KPageWidgetItem * addPage(QWidget *widget, const QString &name)
Adds a new top level page to the dialog.
Definition: kpagedialog.cpp:67
void setPageWidget(KPageWidget *widget)
Set the page widget of the dialog.
void addActionButton(QAbstractButton *button)
Set an action button.
void removePage(KPageWidgetItem *item)
Removes the page associated with the given KPageWidgetItem.
A dialog base class which can handle multiple pages.
Definition: kpagedialog.h:77
void setContentsMargins(int left, int top, int right, int bottom)
FaceType
The face types supported.
Definition: kpagedialog.h:86
KPageWidgetItem * currentPage() const
Returns the KPageWidgetItem for the current page or a null pointer if there is no current page.
void setStandardButtons(QDialogButtonBox::StandardButtons buttons)
Sets the collection of standard buttons displayed by this dialog.
FaceType
This enum is used to decide which type of navigation view shall be used in the page view.
Definition: kpageview.h:60
void setCurrentPage(KPageWidgetItem *item)
Sets the page which is associated with the given KPageWidgetItem to be the current page and emits the...
QPushButton * button(QDialogButtonBox::StandardButton which) const
Returns the QPushButton corresponding to the standard button which, or a null pointer if the standard...
~KPageDialog() override
Destroys the page dialog.
QDialogButtonBox * buttonBox()
Returns the button box of the dialog or a null pointer if no button box is set.
QObject * parent() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Dec 5 2023 04:01:59 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.