aboutsummaryrefslogtreecommitdiffstats
path: root/src/controls
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-06-30 15:22:04 +0200
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-06-30 20:54:39 +0000
commite3b0bfe43ec8b2f804185cb1c16529fe60353647 (patch)
tree9c23318c4351a16a0539f601a27dad1f1680e114 /src/controls
parent7dda04281b255c3feef526fc9b6dc4c18c740144 (diff)
ApplicationWindow: improve the layouting of header & footer
In the following snippet: ApplicationWindow { header: TextField { } } TextField should stay at the width of AppWindow. It should obviously not start following its implicit width changes whilst typing... Change-Id: I2a2a2a2862e27acb2d676ac482123312a1d390c1 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/controls')
-rw-r--r--src/controls/qquickapplicationwindow.cpp54
-rw-r--r--src/controls/qquickapplicationwindow_p.h2
2 files changed, 37 insertions, 19 deletions
diff --git a/src/controls/qquickapplicationwindow.cpp b/src/controls/qquickapplicationwindow.cpp
index d8ad346a..c642c208 100644
--- a/src/controls/qquickapplicationwindow.cpp
+++ b/src/controls/qquickapplicationwindow.cpp
@@ -60,13 +60,14 @@ class QQuickApplicationWindowPrivate : public QQuickItemChangeListener
Q_DECLARE_PUBLIC(QQuickApplicationWindow)
public:
- QQuickApplicationWindowPrivate() : contentWidth(0), contentHeight(0), header(Q_NULLPTR), footer(Q_NULLPTR) { }
+ QQuickApplicationWindowPrivate() : complete(false), contentWidth(0), contentHeight(0), header(Q_NULLPTR), footer(Q_NULLPTR) { }
void relayout();
void itemImplicitWidthChanged(QQuickItem *item) Q_DECL_OVERRIDE;
void itemImplicitHeightChanged(QQuickItem *item) Q_DECL_OVERRIDE;
+ bool complete;
qreal contentWidth;
qreal contentHeight;
QQuickItem *header;
@@ -84,10 +85,23 @@ void QQuickApplicationWindowPrivate::relayout()
content->setY(hh);
content->setHeight(q->height() - hh - fh);
- if (header)
+ if (header) {
header->setY(-hh);
- if (footer)
+ QQuickItemPrivate *p = QQuickItemPrivate::get(header);
+ if (!p->widthValid) {
+ header->setWidth(q->width());
+ p->widthValid = false;
+ }
+ }
+
+ if (footer) {
footer->setY(content->height());
+ QQuickItemPrivate *p = QQuickItemPrivate::get(footer);
+ if (!p->widthValid) {
+ footer->setWidth(q->width());
+ p->widthValid = false;
+ }
+ }
}
void QQuickApplicationWindowPrivate::itemImplicitWidthChanged(QQuickItem *item)
@@ -143,6 +157,8 @@ void QQuickApplicationWindow::setHeader(QQuickItem *header)
p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
if (qFuzzyIsNull(header->z()))
header->setZ(1);
+ if (isComponentComplete())
+ d->relayout();
}
emit headerChanged();
}
@@ -174,6 +190,8 @@ void QQuickApplicationWindow::setFooter(QQuickItem *footer)
p->addItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight);
if (qFuzzyIsNull(footer->z()))
footer->setZ(1);
+ if (isComponentComplete())
+ d->relayout();
}
emit footerChanged();
}
@@ -227,25 +245,23 @@ void QQuickApplicationWindow::setContentHeight(qreal height)
}
}
-void QQuickApplicationWindow::resizeEvent(QResizeEvent *event)
+bool QQuickApplicationWindow::isComponentComplete() const
{
- QQuickWindowQmlImpl::resizeEvent(event);
+ Q_D(const QQuickApplicationWindow);
+ return d->complete;
+}
+
+void QQuickApplicationWindow::componentComplete()
+{
+ Q_D(QQuickApplicationWindow);
+ d->complete = true;
+ QQuickWindowQmlImpl::componentComplete();
+}
+void QQuickApplicationWindow::resizeEvent(QResizeEvent *event)
+{
Q_D(QQuickApplicationWindow);
- if (d->header) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(d->header);
- if (!p->widthValid) {
- d->header->setWidth(width());
- p->widthValid = false;
- }
- }
- if (d->footer) {
- QQuickItemPrivate *p = QQuickItemPrivate::get(d->footer);
- if (!p->widthValid) {
- d->footer->setWidth(width());
- p->widthValid = false;
- }
- }
+ QQuickWindowQmlImpl::resizeEvent(event);
d->relayout();
}
diff --git a/src/controls/qquickapplicationwindow_p.h b/src/controls/qquickapplicationwindow_p.h
index 6d7522fe..01aaa345 100644
--- a/src/controls/qquickapplicationwindow_p.h
+++ b/src/controls/qquickapplicationwindow_p.h
@@ -86,6 +86,8 @@ Q_SIGNALS:
void contentHeightChanged();
protected:
+ bool isComponentComplete() const;
+ void componentComplete() Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
private: