diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-04-24 17:22:22 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-04-25 11:46:30 +0000 |
commit | 5a79be4df2e61c9c3bdef202c4d32771343f1c2a (patch) | |
tree | 0e2f9a53363e98afddd7650bb642ee68c6ada649 /src/quicktemplates2/qquicktabbar.cpp | |
parent | 0e0f96303b4896b8e6a7e6575ca9e134e4dbd78b (diff) |
TabBar: fix the layout with mixed-height items
Especially now that we have icons and configurable display layouts,
TabButtons can have different heights. For example, due to dynamic
display changes:
TabBar {
TabButton {
text: ...
icon.name: ...
display: checked ? TabButton.TextUnderIcon : TabButton.IconOnly
}
TabButton {
text: ...
icon.name: ...
display: checked ? TabButton.TextUnderIcon : TabButton.IconOnly
}
}
This patch makes the layouting code set the correct height for items
that don't have an explicit height, and vertically center aligns those
that do, to make the layout look nice with varying height items.
Change-Id: Iad76dc326990a92cba1be294aea42f314f54632c
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquicktabbar.cpp')
-rw-r--r-- | src/quicktemplates2/qquicktabbar.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp index 7ce8a21e..98bf94c7 100644 --- a/src/quicktemplates2/qquicktabbar.cpp +++ b/src/quicktemplates2/qquicktabbar.cpp @@ -152,38 +152,47 @@ void QQuickTabBarPrivate::updateLayout() qreal maxHeight = 0; qreal totalWidth = 0; qreal reservedWidth = 0; + int resizableCount = 0; - QVector<QQuickItem *> resizableItems; - resizableItems.reserve(count); + QVector<QQuickItem *> allItems; + allItems.reserve(count); for (int i = 0; i < count; ++i) { QQuickItem *item = q->itemAt(i); if (item) { QQuickItemPrivate *p = QQuickItemPrivate::get(item); if (!p->widthValid) { - resizableItems += item; + ++resizableCount; totalWidth += item->implicitWidth(); } else { reservedWidth += item->width(); totalWidth += item->width(); } maxHeight = qMax(maxHeight, item->implicitHeight()); + allItems += item; } } const qreal totalSpacing = qMax(0, count - 1) * spacing; totalWidth += totalSpacing; - if (!resizableItems.isEmpty()) { - const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / resizableItems.count(); + const qreal itemWidth = (contentItem->width() - reservedWidth - totalSpacing) / resizableCount; - updatingLayout = true; - for (QQuickItem *item : qAsConst(resizableItems)) { + updatingLayout = true; + for (QQuickItem *item : qAsConst(allItems)) { + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + if (!p->widthValid) { item->setWidth(itemWidth); - QQuickItemPrivate::get(item)->widthValid = false; + p->widthValid = false; + } + if (!p->heightValid) { + item->setHeight(hasContentHeight ? contentHeight : maxHeight); + p->heightValid = false; + } else { + item->setY((maxHeight - item->height()) / 2); } - updatingLayout = false; } + updatingLayout = false; bool contentWidthChange = false; if (!hasContentWidth && !qFuzzyCompare(contentWidth, totalWidth)) { |