aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-09-30 09:55:08 +0200
committerJ-P Nurmi <jpnurmi@qt.io>2016-09-30 08:31:28 +0000
commitc74dde76c5e27396e70ab1b8498f2c74f68134c0 (patch)
tree75ddb4fb15be12f86a4f6c5d490aadb9e0dcd001 /src
parentb4ce31415baba84ca82aec68f4480b3e6ac89b90 (diff)
TabBar: re-layout as appropriate in tab button size changes
Auto-tested by the next change. Change-Id: I28ff7e82c0255b93d23cff7cbe111406d525f24b Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquickcontainer.cpp9
-rw-r--r--src/quicktemplates2/qquickcontainer_p_p.h1
-rw-r--r--src/quicktemplates2/qquicktabbar.cpp14
3 files changed, 19 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickcontainer.cpp b/src/quicktemplates2/qquickcontainer.cpp
index 34e198fc..be2acf39 100644
--- a/src/quicktemplates2/qquickcontainer.cpp
+++ b/src/quicktemplates2/qquickcontainer.cpp
@@ -144,7 +144,8 @@ static QQuickItem *effectiveContentItem(QQuickItem *item)
return item;
}
-QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(nullptr), currentIndex(-1), updatingCurrent(false)
+QQuickContainerPrivate::QQuickContainerPrivate() : contentModel(nullptr), currentIndex(-1), updatingCurrent(false),
+ changeTypes(Destroyed | Parent | SiblingOrder)
{
}
@@ -164,7 +165,7 @@ void QQuickContainerPrivate::cleanup()
for (int i = 0; i < count; ++i) {
QQuickItem *item = itemAt(i);
if (item)
- QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent | QQuickItemPrivate::SiblingOrder);
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, changeTypes);
}
if (contentItem) {
@@ -196,7 +197,7 @@ void QQuickContainerPrivate::insertItem(int index, QQuickItem *item)
updatingCurrent = true;
item->setParentItem(effectiveContentItem(contentItem));
- QQuickItemPrivate::get(item)->addItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent | QQuickItemPrivate::SiblingOrder);
+ QQuickItemPrivate::get(item)->addItemChangeListener(this, changeTypes);
contentModel->insert(index, item);
q->itemAdded(index, item);
@@ -242,7 +243,7 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item)
currentChanged = true;
}
- QQuickItemPrivate::get(item)->removeItemChangeListener(this, QQuickItemPrivate::Destroyed | QQuickItemPrivate::Parent | QQuickItemPrivate::SiblingOrder);
+ QQuickItemPrivate::get(item)->removeItemChangeListener(this, changeTypes);
item->setParentItem(nullptr);
contentModel->remove(index);
diff --git a/src/quicktemplates2/qquickcontainer_p_p.h b/src/quicktemplates2/qquickcontainer_p_p.h
index 30076a31..3b60ad8c 100644
--- a/src/quicktemplates2/qquickcontainer_p_p.h
+++ b/src/quicktemplates2/qquickcontainer_p_p.h
@@ -90,6 +90,7 @@ public:
QQmlObjectModel *contentModel;
int currentIndex;
bool updatingCurrent;
+ QQuickItemPrivate::ChangeTypes changeTypes;
};
QT_END_NAMESPACE
diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp
index bf6c4e74..27df1c99 100644
--- a/src/quicktemplates2/qquicktabbar.cpp
+++ b/src/quicktemplates2/qquicktabbar.cpp
@@ -86,11 +86,15 @@ public:
void updateCurrentIndex();
void updateLayout();
+ void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) override;
+
+ bool updatingLayout;
QQuickTabBar::Position position;
};
-QQuickTabBarPrivate::QQuickTabBarPrivate() : position(QQuickTabBar::Header)
+QQuickTabBarPrivate::QQuickTabBarPrivate() : updatingLayout(false), position(QQuickTabBar::Header)
{
+ changeTypes |= Geometry;
}
void QQuickTabBarPrivate::updateCurrentItem()
@@ -132,14 +136,22 @@ void QQuickTabBarPrivate::updateLayout()
const qreal totalSpacing = qMax(0, count - 1) * spacing;
const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / resizableItems.count();
+ updatingLayout = true;
for (QQuickItem *item : qAsConst(resizableItems)) {
item->setWidth(itemWidth);
QQuickItemPrivate::get(item)->widthValid = false;
}
+ updatingLayout = false;
}
}
}
+void QQuickTabBarPrivate::itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &)
+{
+ if (!updatingLayout)
+ updateLayout();
+}
+
QQuickTabBar::QQuickTabBar(QQuickItem *parent) :
QQuickContainer(*(new QQuickTabBarPrivate), parent)
{