diff options
author | Sami Merila <sami.merila@nokia.com> | 2010-11-18 10:15:03 (GMT) |
---|---|---|
committer | Sami Merila <sami.merila@nokia.com> | 2010-11-18 10:15:03 (GMT) |
commit | 2c40c98a5b3ff4f16c4ad71b5707d5271945819e (patch) | |
tree | c02cab0c3f25d688b70ece507fe3b21415de3ab1 /src/gui/styles | |
parent | 569b076bb650c5082109d6406616c7536ac9f79f (diff) | |
download | Qt-2c40c98a5b3ff4f16c4ad71b5707d5271945819e.zip Qt-2c40c98a5b3ff4f16c4ad71b5707d5271945819e.tar.gz Qt-2c40c98a5b3ff4f16c4ad71b5707d5271945819e.tar.bz2 |
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
Diffstat (limited to 'src/gui/styles')
-rw-r--r-- | src/gui/styles/qs60style.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
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<const QStyleOptionToolButton *>(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<const QToolBar *>(widget->parentWidget())) { + const QToolBar *tb = qobject_cast<const QToolBar *>(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<QAction*> 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<QWidget *>(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); |