8#include "headerfooterlayout.h"
13HeaderFooterLayout::HeaderFooterLayout(
QQuickItem *parent)
16 , m_performingLayout(false)
20HeaderFooterLayout::~HeaderFooterLayout()
22 disconnectItem(m_header);
23 disconnectItem(m_contentItem);
24 disconnectItem(m_footer);
27void HeaderFooterLayout::setHeader(
QQuickItem *item)
29 if (m_header == item) {
34 disconnectItem(m_header);
35 m_header->setParentItem(
nullptr);
41 m_header->setParentItem(
this);
42 if (m_header->z() == 0) {
50 if (m_header->inherits(
"QQuickTabBar") || m_header->inherits(
"QQuickToolBar") || m_header->inherits(
"QQuickDialogButtonBox")) {
52 m_header->setProperty(
"position", 0);
66void HeaderFooterLayout::setContentItem(
QQuickItem *item)
68 if (m_contentItem == item) {
73 disconnectItem(m_contentItem);
74 m_contentItem->setParentItem(
nullptr);
80 m_contentItem->setParentItem(
this);
88 Q_EMIT contentItemChanged();
96void HeaderFooterLayout::setFooter(
QQuickItem *item)
98 if (m_footer == item) {
103 disconnectItem(m_footer);
104 m_footer->setParentItem(
nullptr);
110 m_footer->setParentItem(
this);
111 if (m_footer->z() == 0) {
119 if (m_footer->inherits(
"QQuickTabBar") || m_footer->inherits(
"QQuickToolBar") || m_footer->inherits(
"QQuickDialogButtonBox")) {
121 m_footer->setProperty(
"position", 1);
140void HeaderFooterLayout::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
142 if (newGeometry != oldGeometry) {
149void HeaderFooterLayout::componentComplete()
157void HeaderFooterLayout::updatePolish()
164void HeaderFooterLayout::markAsDirty()
172void HeaderFooterLayout::performLayout()
179 m_performingLayout =
true;
183 updateImplicitSize();
185 const QSizeF newSize =
size();
186 qreal headerHeight = 0;
187 qreal footerHeight = 0;
190 m_header->setWidth(newSize.
width());
191 if (m_header->isVisible()) {
192 headerHeight = m_header->height();
196 m_footer->setY(newSize.
height() - m_footer->height());
197 m_footer->setWidth(newSize.
width());
198 if (m_footer->isVisible()) {
199 footerHeight = m_footer->height();
203 m_contentItem->setY(headerHeight);
204 m_contentItem->setWidth(newSize.
width());
205 m_contentItem->setHeight(newSize.
height() - headerHeight - footerHeight);
208 m_performingLayout =
false;
211void HeaderFooterLayout::updateImplicitSize()
216 if (m_header && m_header->isVisible()) {
217 impWidth = std::max(impWidth, m_header->implicitWidth());
218 impHeight += m_header->implicitHeight();
220 if (m_footer && m_footer->isVisible()) {
221 impWidth = std::max(impWidth, m_footer->implicitWidth());
222 impHeight += m_footer->implicitHeight();
224 if (m_contentItem && m_contentItem->isVisible()) {
225 impWidth = std::max(impWidth, m_contentItem->implicitWidth());
226 impHeight += m_contentItem->implicitHeight();
228 setImplicitSize(impWidth, impHeight);
231void HeaderFooterLayout::disconnectItem(
QQuickItem *item)
240#include "moc_headerfooterlayout.cpp"
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
virtual void componentComplete() override
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void implicitHeightChanged()
void implicitWidthChanged()
bool isComponentComplete() const const
QSizeF size() const const
qreal height() const const
qreal width() const const