summaryrefslogtreecommitdiffstats
path: root/src/gui/styles
diff options
context:
space:
mode:
authorSami Merila <sami.merila@nokia.com>2010-11-19 10:47:36 (GMT)
committerSami Merila <sami.merila@nokia.com>2010-11-19 10:47:36 (GMT)
commitd2fbb87ab12e9530e162a30df3cb00184af3fe8b (patch)
tree876e72ceda41172d252d6cdb0c80085a4908851c /src/gui/styles
parentb0691b5a95c80ecd94867873e912e6952a2ec1b4 (diff)
parentcd14bd2c7645e29af325095c1adf29d61f0e6f61 (diff)
downloadQt-d2fbb87ab12e9530e162a30df3cb00184af3fe8b.zip
Qt-d2fbb87ab12e9530e162a30df3cb00184af3fe8b.tar.gz
Qt-d2fbb87ab12e9530e162a30df3cb00184af3fe8b.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/qt-water-team into 4.7
Diffstat (limited to 'src/gui/styles')
-rw-r--r--src/gui/styles/qs60style.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp
index 22cb7d6..a58c8e5 100644
--- a/src/gui/styles/qs60style.cpp
+++ b/src/gui/styles/qs60style.cpp
@@ -2537,6 +2537,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);