From 2c40c98a5b3ff4f16c4ad71b5707d5271945819e Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Thu, 18 Nov 2010 12:15:03 +0200 Subject: QToolbar should fill available width on Symbian Normally QStyle provides a minimum size for a widget. However, to imitate native toolbar behavior, QToolBar should occupy available screen estate on Symbian (with QS60Style). This is only supported for horizontal QToolBars as native side does not have same functionality for vertical toolbars. QToolbar size now tries to take into account available size of parent reduced by margins (if several parents, then each can reduce the available space by their margins). Also, toolbar internal pixel metrics data (item spacing, item margins) are taken into account. Task-number: QTBUG-13120 Reviewed-by: Janne Koskinen --- src/gui/styles/qs60style.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 5fe9050..5eddc98 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2536,6 +2536,56 @@ QSize QS60Style::sizeFromContents(ContentsType ct, const QStyleOption *opt, if (const QStyleOptionToolButton *toolBtn = qstyleoption_cast(opt)) if (toolBtn->subControls & SC_ToolButtonMenu) sz += QSize(pixelMetric(PM_MenuButtonIndicator), 0); + + //Make toolbuttons in toolbar stretch the whole screen area + if (widget && qobject_cast(widget->parentWidget())) { + const QToolBar *tb = qobject_cast(widget->parentWidget()); + const bool parentCanGrowHorizontally = !(tb->sizePolicy().horizontalPolicy() == QSizePolicy::Fixed || + tb->sizePolicy().horizontalPolicy() == QSizePolicy::Maximum) && tb->orientation() == Qt::Horizontal; + + if (parentCanGrowHorizontally) { + int visibleButtons = 0; + //Make the auto-stretch to happen only for horizontal orientation + if (tb && tb->orientation() == Qt::Horizontal) { + QList actionList = tb->actions(); + for (int i = 0; i < actionList.count(); i++) { + if (actionList.at(i)->isVisible()) + visibleButtons++; + } + } + + if (widget->parentWidget() && visibleButtons > 0) { + QWidget *w = const_cast(widget); + int toolBarMaxWidth = 0; + int totalMargin = 0; + while (w) { + //honor fixed width parents + if (w->maximumWidth() == w->minimumWidth()) + toolBarMaxWidth = qMax(toolBarMaxWidth, w->maximumWidth()); + if (w->layout() && w->windowType() == Qt::Widget) { + totalMargin += w->layout()->contentsMargins().left() + + w->layout()->contentsMargins().right(); + } + w = w->parentWidget(); + } + totalMargin += 2 * pixelMetric(QStyle::PM_ToolBarFrameWidth); + + if (toolBarMaxWidth == 0) + toolBarMaxWidth = + QApplication::desktop()->availableGeometry(widget->parentWidget()).width(); + //Reduce the margins, toolbar frame, item spacing and internal margin from available area + toolBarMaxWidth -= totalMargin; + + //ensure that buttons are side-by-side and not on top of each other + const int toolButtonWidth = (toolBarMaxWidth / visibleButtons) + - pixelMetric(QStyle::PM_ToolBarItemSpacing) + - pixelMetric(QStyle::PM_ToolBarItemMargin) + //toolbar frame needs to be reduced again, since QToolBarLayout adds it for each toolbar action + - 2 * pixelMetric(QStyle::PM_ToolBarFrameWidth) - 1; + sz.setWidth(qMax(toolButtonWidth, sz.width())); + } + } + } break; case CT_PushButton: sz = QCommonStyle::sizeFromContents( ct, opt, csz, widget); -- cgit v0.12