Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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 "qquicktoolbar_p.h"
7#if QT_CONFIG(quicktemplates2_container)
8#include "qquicktabbar_p.h"
10#endif
11
13
18
73
74namespace {
75 enum Position {
76 Header,
77 Footer
78 };
79
81Q_STATIC_ASSERT(int(Footer) == int(QQuickToolBar::Footer));
82
83#if QT_CONFIG(quicktemplates2_container)
85 Q_STATIC_ASSERT(int(Footer) == int(QQuickTabBar::Footer));
86
89#endif
90
91 static void setPos(QQuickItem *item, Position position)
92 {
93 if (QQuickToolBar *toolBar = qobject_cast<QQuickToolBar *>(item))
94 toolBar->setPosition(static_cast<QQuickToolBar::Position>(position));
95#if QT_CONFIG(quicktemplates2_container)
96 else if (QQuickTabBar *tabBar = qobject_cast<QQuickTabBar *>(item))
97 tabBar->setPosition(static_cast<QQuickTabBar::Position>(position));
98 else if (QQuickDialogButtonBox *buttonBox = qobject_cast<QQuickDialogButtonBox *>(item))
99 buttonBox->setPosition(static_cast<QQuickDialogButtonBox::Position>(position));
100#endif
101 }
102}
103
105{
106 Q_Q(QQuickPage);
107 const qreal hh = header && header->isVisible() ? header->height() : 0;
108 const qreal fh = footer && footer->isVisible() ? footer->height() : 0;
109 const qreal hsp = hh > 0 ? spacing : 0;
110 const qreal fsp = fh > 0 ? spacing : 0;
111
112 if (contentItem) {
113 contentItem->setY(q->topPadding() + hh + hsp);
114 contentItem->setX(q->leftPadding());
115 contentItem->setWidth(q->availableWidth());
116 contentItem->setHeight(q->availableHeight() - hh - fh - hsp - fsp);
117 }
118
119 if (header) {
120 header->setY(0);
121 header->setWidth(q->width());
122 }
123
124 if (footer) {
125 footer->setY(q->height() - footer->height());
126 footer->setWidth(q->width());
127 }
128}
129
134
136{
137 Q_Q(QQuickPage);
139 if (item == header) {
141 emit q->implicitHeaderWidthChanged();
142 emit q->implicitHeaderHeightChanged();
143 relayout();
144 } else if (item == footer) {
146 emit q->implicitFooterWidthChanged();
147 emit q->implicitFooterHeightChanged();
148 relayout();
149 }
150}
151
153{
154 Q_Q(QQuickPage);
156
157 // Avoid binding loops by skipping signal emission if we're already doing it.
159 return;
160
161 if (item == header)
162 emit q->implicitHeaderWidthChanged();
163 else if (item == footer)
164 emit q->implicitFooterWidthChanged();
165}
166
168{
169 Q_Q(QQuickPage);
171
172 // Avoid binding loops by skipping signal emission if we're already doing it.
174 return;
175
176 if (item == header)
177 emit q->implicitHeaderHeightChanged();
178 else if (item == footer)
179 emit q->implicitFooterHeightChanged();
180}
181
188
190{
191 Q_Q(QQuickPage);
193 if (item == header) {
194 header = nullptr;
195 relayout();
196 emit q->implicitHeaderWidthChanged();
197 emit q->implicitHeaderHeightChanged();
198 emit q->headerChanged();
199 } else if (item == footer) {
200 footer = nullptr;
201 relayout();
202 emit q->implicitFooterWidthChanged();
203 emit q->implicitFooterHeightChanged();
204 emit q->footerChanged();
205 }
206}
207
209 : QQuickPane(*(new QQuickPagePrivate), parent)
210{
211}
212
214 : QQuickPane(dd, parent)
215{
216}
217
219{
220 Q_D(QQuickPage);
221 if (d->header)
222 QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, LayoutChanges);
223 if (d->footer)
224 QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, LayoutChanges);
225}
226
268{
269 return d_func()->title;
270}
271
273{
274 Q_D(QQuickPage);
275 if (d->title == title)
276 return;
277
278 d->title = title;
281}
282
296{
297 Q_D(const QQuickPage);
298 return d->header;
299}
300
302{
303 Q_D(QQuickPage);
304 if (d->header == header)
305 return;
306
307 if (d->header) {
308 QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, LayoutChanges);
309 d->header->setParentItem(nullptr);
310 }
311 d->header = header;
312 if (header) {
313 header->setParentItem(this);
314 QQuickItemPrivate::get(header)->addItemChangeListener(d, LayoutChanges);
315 if (qFuzzyIsNull(header->z()))
316 header->setZ(1);
318 }
320 d->relayout();
322}
323
337{
338 Q_D(const QQuickPage);
339 return d->footer;
340}
341
343{
344 Q_D(QQuickPage);
345 if (d->footer == footer)
346 return;
347
348 if (d->footer) {
349 QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, LayoutChanges);
350 d->footer->setParentItem(nullptr);
351 }
352 d->footer = footer;
353 if (footer) {
354 footer->setParentItem(this);
355 QQuickItemPrivate::get(footer)->addItemChangeListener(d, LayoutChanges);
356 if (qFuzzyIsNull(footer->z()))
357 footer->setZ(1);
358 setPos(footer, Footer);
359 }
361 d->relayout();
363}
364
377{
378 Q_D(const QQuickPage);
379 if (!d->header || !d->header->isVisible())
380 return 0;
381 return d->header->implicitWidth();
382}
383
396{
397 Q_D(const QQuickPage);
398 if (!d->header || !d->header->isVisible())
399 return 0;
400 return d->header->implicitHeight();
401}
402
415{
416 Q_D(const QQuickPage);
417 if (!d->footer || !d->footer->isVisible())
418 return 0;
419 return d->footer->implicitWidth();
420}
421
434{
435 Q_D(const QQuickPage);
436 if (!d->footer || !d->footer->isVisible())
437 return 0;
438 return d->footer->implicitHeight();
439}
440
442{
443 Q_D(QQuickPage);
445 d->relayout();
446}
447
448void QQuickPage::spacingChange(qreal newSpacing, qreal oldSpacing)
449{
450 Q_D(QQuickPage);
451 QQuickPane::spacingChange(newSpacing, oldSpacing);
452 d->relayout();
453}
454
455#if QT_CONFIG(accessibility)
456QAccessible::Role QQuickPage::accessibleRole() const
457{
458 return QAccessible::PageTab;
459}
460
461void QQuickPage::accessibilityActiveChanged(bool active)
462{
463 Q_D(QQuickPage);
464 QQuickPane::accessibilityActiveChanged(active);
465
466 if (active)
468}
469#endif
470
472
473#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 itemVisibilityChanged(QQuickItem *)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setParentItem(QQuickItem *parent)
qreal z
\qmlproperty real QtQuick::Item::z
Definition qquickitem.h:74
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:76
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 itemDestroyed(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:484
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
#define Q_STATIC_ASSERT(Condition)
Definition qassert.h:108
static QString header(const QString &name)
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
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:187
QString title
[35]
QGraphicsItem * item
rect setPos(100, 100)