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);
135void HeaderFooterLayout::setSpacing(qreal spacing)
158void HeaderFooterLayout::geometryChange(
const QRectF &newGeometry,
const QRectF &oldGeometry)
160 if (newGeometry != oldGeometry) {
167void HeaderFooterLayout::componentComplete()
175void HeaderFooterLayout::updatePolish()
182void HeaderFooterLayout::markAsDirty()
190void HeaderFooterLayout::performLayout()
197 m_performingLayout =
true;
201 updateImplicitSize();
203 const QSizeF newSize =
size();
204 qreal headerHeight = 0;
205 qreal footerHeight = 0;
208 m_header->setWidth(newSize.
width());
209 if (m_header->isVisible()) {
210 headerHeight = m_header->height() + m_spacing;
214 m_footer->setY(newSize.
height() - m_footer->height());
215 m_footer->setWidth(newSize.
width());
216 if (m_footer->isVisible()) {
217 footerHeight = m_footer->height() + m_spacing;
221 m_contentItem->setY(headerHeight);
222 m_contentItem->setWidth(newSize.
width());
223 m_contentItem->setHeight(newSize.
height() - headerHeight - footerHeight);
226 m_performingLayout =
false;
229void HeaderFooterLayout::updateImplicitSize()
234 if (m_header && m_header->isVisible()) {
235 impWidth = std::max(impWidth, m_header->implicitWidth());
236 impHeight += m_header->implicitHeight() + m_spacing;
238 if (m_footer && m_footer->isVisible()) {
239 impWidth = std::max(impWidth, m_footer->implicitWidth());
240 impHeight += m_footer->implicitHeight() + m_spacing;
242 if (m_contentItem && m_contentItem->isVisible()) {
243 impWidth = std::max(impWidth, m_contentItem->implicitWidth());
244 impHeight += m_contentItem->implicitHeight();
246 setImplicitSize(impWidth, impHeight);
249void HeaderFooterLayout::disconnectItem(
QQuickItem *item)
258#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