Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickpage.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickpage_p.h"
5#include "qquickpage_p_p.h"
6#include "qquicktabbar_p.h"
7#include "qquicktoolbar_p.h"
9
11
16
71
72namespace {
73 enum Position {
74 Header,
75 Footer
76 };
77
78 Q_STATIC_ASSERT(int(Header) == int(QQuickTabBar::Header));
79 Q_STATIC_ASSERT(int(Footer) == int(QQuickTabBar::Footer));
80
81 Q_STATIC_ASSERT(int(Header) == int(QQuickToolBar::Header));
82 Q_STATIC_ASSERT(int(Footer) == int(QQuickToolBar::Footer));
83
86
87 static void setPos(QQuickItem *item, Position position)
88 {
89 if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(item))
90 toolBar->setPosition(static_cast<QQuickToolBar::Position>(position));
91 else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(item))
92 tabBar->setPosition(static_cast<QQuickTabBar::Position>(position));
93 else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(item))
94 buttonBox->setPosition(static_cast<QQuickDialogButtonBox::Position>(position));
95 }
96}
97
99{
100 Q_Q(QQuickPage);
101 const qreal hh = header && header->isVisible() ? header->height() : 0;
102 const qreal fh = footer && footer->isVisible() ? footer->height() : 0;
103 const qreal hsp = hh > 0 ? spacing : 0;
104 const qreal fsp = fh > 0 ? spacing : 0;
105
106 if (contentItem) {
107 contentItem->setY(q->topPadding() + hh + hsp);
108 contentItem->setX(q->leftPadding());
109 contentItem->setWidth(q->availableWidth());
110 contentItem->setHeight(q->availableHeight() - hh - fh - hsp - fsp);
111 }
112
113 if (header)
114 header->setWidth(q->width());
115
116 if (footer) {
117 footer->setY(q->height() - footer->height());
118 footer->setWidth(q->width());
119 }
120}
121
123{
124 relayout();
125}
126
128{
129 Q_Q(QQuickPage);
131 if (item == header) {
133 emit q->implicitHeaderWidthChanged();
134 emit q->implicitHeaderHeightChanged();
135 relayout();
136 } else if (item == footer) {
138 emit q->implicitFooterWidthChanged();
139 emit q->implicitFooterHeightChanged();
140 relayout();
141 }
142}
143
145{
146 Q_Q(QQuickPage);
148
149 // Avoid binding loops by skipping signal emission if we're already doing it.
151 return;
152
153 if (item == header)
154 emit q->implicitHeaderWidthChanged();
155 else if (item == footer)
156 emit q->implicitFooterWidthChanged();
157}
158
160{
161 Q_Q(QQuickPage);
163
164 // Avoid binding loops by skipping signal emission if we're already doing it.
166 return;
167
168 if (item == header)
169 emit q->implicitHeaderHeightChanged();
170 else if (item == footer)
171 emit q->implicitFooterHeightChanged();
172}
173
175{
177 if (item == header || item == footer)
178 relayout();
179}
180
182{
183 Q_Q(QQuickPage);
185 if (item == header) {
186 header = nullptr;
187 relayout();
188 emit q->implicitHeaderWidthChanged();
189 emit q->implicitHeaderHeightChanged();
190 emit q->headerChanged();
191 } else if (item == footer) {
192 footer = nullptr;
193 relayout();
194 emit q->implicitFooterWidthChanged();
195 emit q->implicitFooterHeightChanged();
196 emit q->footerChanged();
197 }
198}
199
202{
203}
204
206 : QQuickPane(dd, parent)
207{
208}
209
211{
212 Q_D(QQuickPage);
213 if (d->header)
215 if (d->footer)
217}
218
260{
261 return d_func()->title;
262}
263
265{
266 Q_D(QQuickPage);
267 if (d->title == title)
268 return;
269
270 d->title = title;
273}
274
288{
289 Q_D(const QQuickPage);
290 return d->header;
291}
292
294{
295 Q_D(QQuickPage);
296 if (d->header == header)
297 return;
298
299 if (d->header) {
301 d->header->setParentItem(nullptr);
302 }
303 d->header = header;
304 if (header) {
305 header->setParentItem(this);
307 if (qFuzzyIsNull(header->z()))
308 header->setZ(1);
309 setPos(header, Header);
310 }
312 d->relayout();
314}
315
329{
330 Q_D(const QQuickPage);
331 return d->footer;
332}
333
335{
336 Q_D(QQuickPage);
337 if (d->footer == footer)
338 return;
339
340 if (d->footer) {
342 d->footer->setParentItem(nullptr);
343 }
344 d->footer = footer;
345 if (footer) {
346 footer->setParentItem(this);
348 if (qFuzzyIsNull(footer->z()))
349 footer->setZ(1);
350 setPos(footer, Footer);
351 }
353 d->relayout();
355}
356
369{
370 Q_D(const QQuickPage);
371 if (!d->header || !d->header->isVisible())
372 return 0;
373 return d->header->implicitWidth();
374}
375
388{
389 Q_D(const QQuickPage);
390 if (!d->header || !d->header->isVisible())
391 return 0;
392 return d->header->implicitHeight();
393}
394
407{
408 Q_D(const QQuickPage);
409 if (!d->footer || !d->footer->isVisible())
410 return 0;
411 return d->footer->implicitWidth();
412}
413
426{
427 Q_D(const QQuickPage);
428 if (!d->footer || !d->footer->isVisible())
429 return 0;
430 return d->footer->implicitHeight();
431}
432
434{
435 Q_D(QQuickPage);
437 d->relayout();
438}
439
440void QQuickPage::spacingChange(qreal newSpacing, qreal oldSpacing)
441{
442 Q_D(QQuickPage);
443 QQuickPane::spacingChange(newSpacing, oldSpacing);
444 d->relayout();
445}
446
447#if QT_CONFIG(accessibility)
448QAccessible::Role QQuickPage::accessibleRole() const
449{
450 return QAccessible::PageTab;
451}
452
453void QQuickPage::accessibilityActiveChanged(bool active)
454{
455 Q_D(QQuickPage);
456 QQuickPane::accessibilityActiveChanged(active);
457
458 if (active)
460}
461#endif
462
464
465#include "moc_qquickpage_p.cpp"
QQuickDeferredPointer< QQuickItem > contentItem
virtual void spacingChange(qreal newSpacing, qreal oldSpacing)
void maybeSetAccessibleName(const QString &name)
virtual void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &)
virtual void itemDestroyed(QQuickItem *)
virtual void itemVisibilityChanged(QQuickItem *)
void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types)
void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
void setParentItem(QQuickItem *parent)
qreal z
\qmlproperty real QtQuick::Item::z
Definition qquickitem.h:75
bool isVisible() const
void setHeight(qreal)
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
qreal height
This property holds the height of this item.
Definition qquickitem.h:77
void setZ(qreal)
void setWidth(qreal)
void setX(qreal)
void setY(qreal)
void itemDestroyed(QQuickItem *item) override
void itemVisibilityChanged(QQuickItem *item) override
QQuickItem * footer
QQuickItem * header
bool emittingImplicitSizeChangedSignals
void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override
void itemImplicitWidthChanged(QQuickItem *item) override
void itemImplicitHeightChanged(QQuickItem *item) override
void resizeContent() override
qreal implicitFooterWidth
void setFooter(QQuickItem *footer)
void headerChanged()
void setTitle(const QString &title)
void spacingChange(qreal newSpacing, qreal oldSpacing) override
QString title
void titleChanged()
qreal implicitHeaderHeight
qreal implicitFooterHeight
void setHeader(QQuickItem *header)
QQuickItem * header
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
QQuickPage(QQuickItem *parent=nullptr)
void footerChanged()
QQuickItem * footer
qreal implicitHeaderWidth
void itemImplicitWidthChanged(QQuickItem *item) override
void itemImplicitHeightChanged(QQuickItem *item) override
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
\inmodule QtCore\reentrant
Definition qrect.h:483
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
Combined button and popup list for selecting options.
#define Q_STATIC_ASSERT(Condition)
Definition qassert.h:105
static QString header(const QString &name)
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:303
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QT_BEGIN_NAMESPACE const QQuickItemPrivate::ChangeTypes LayoutChanges
Styled page control with support for a header and footer.
#define emit
double qreal
Definition qtypes.h:92
QString title
[35]
QGraphicsItem * item
rect setPos(100, 100)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent