From b4ce31415baba84ca82aec68f4480b3e6ac89b90 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 29 Sep 2016 15:58:07 +0200 Subject: TabBar: fix mixing of fixed and implicitly resized tabs Don't calculate the implicit item width based on the total width of the whole control, but based on the available width that is left after subtracting the items that have an explicit width and won't be resized. Change-Id: Iae18dd9c9756b6f2afa143baab7d2501ce9d4697 Task-number: QTBUG-56265 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktabbar.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/quicktemplates2/qquicktabbar.cpp') diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp index 6fe734bb..bf6c4e74 100644 --- a/src/quicktemplates2/qquicktabbar.cpp +++ b/src/quicktemplates2/qquicktabbar.cpp @@ -113,16 +113,28 @@ void QQuickTabBarPrivate::updateLayout() Q_Q(QQuickTabBar); const int count = contentModel->count(); if (count > 0 && contentItem) { - const qreal itemWidth = (contentItem->width() - qMax(0, count - 1) * spacing) / count; + qreal reservedWidth = 0; + QVector resizableItems; + resizableItems.reserve(count); for (int i = 0; i < count; ++i) { QQuickItem *item = q->itemAt(i); if (item) { QQuickItemPrivate *p = QQuickItemPrivate::get(item); - if (!p->widthValid) { - item->setWidth(itemWidth); - p->widthValid = false; - } + if (!p->widthValid) + resizableItems += item; + else + reservedWidth += item->width(); + } + } + + if (!resizableItems.isEmpty()) { + const qreal totalSpacing = qMax(0, count - 1) * spacing; + const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / resizableItems.count(); + + for (QQuickItem *item : qAsConst(resizableItems)) { + item->setWidth(itemWidth); + QQuickItemPrivate::get(item)->widthValid = false; } } } -- cgit v1.2.3 From c74dde76c5e27396e70ab1b8498f2c74f68134c0 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Fri, 30 Sep 2016 09:55:08 +0200 Subject: TabBar: re-layout as appropriate in tab button size changes Auto-tested by the next change. Change-Id: I28ff7e82c0255b93d23cff7cbe111406d525f24b Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquicktabbar.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/quicktemplates2/qquicktabbar.cpp') 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) { -- cgit v1.2.3