From 31da70ff8e86946475c55fb78d3ff4092d4537de Mon Sep 17 00:00:00 2001 From: Pasi Matilainen Date: Mon, 14 Nov 2011 15:39:25 +0100 Subject: Fix QDockWidget titlebar button positioning on Mac OS X Move the QDockWidget close and float buttons from the right end of the dock widget title bar to the left end to avoid Mac App Store rejection. Task-number: QTBUG-19493 Reviewed-by: Friedemann Kleint (cherry picked from commit 3b2bd144b7873daf2e7119248dbac7c0f0253993) Change-Id: I3b2bd144b7873daf2e7119248dbac7c0f0253993 --- src/widgets/styles/qmacstyle_mac.mm | 101 ++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 59f51ce2c6..f6eacd28dc 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -4465,6 +4465,107 @@ QRect QMacStyle::subElementRect(SubElement sr, const QStyleOption *opt, rect.setTop(rect.top() + SIZE(6 /* AHIG */, 3 /* guess */, 2 /* AHIG */)); } break; +#ifndef QT_NO_DOCKWIDGET + case SE_DockWidgetCloseButton: + case SE_DockWidgetFloatButton: + case SE_DockWidgetTitleBarText: + case SE_DockWidgetIcon: { + int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget); + int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget); + QRect srect = opt->rect; + + const QStyleOptionDockWidget *dwOpt + = qstyleoption_cast(opt); + bool canClose = dwOpt == 0 ? true : dwOpt->closable; + bool canFloat = dwOpt == 0 ? false : dwOpt->floatable; + const QStyleOptionDockWidgetV2 *v2 + = qstyleoption_cast(opt); + bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar; + + // If this is a vertical titlebar, we transpose and work as if it was + // horizontal, then transpose again. + if (verticalTitleBar) { + QSize size = srect.size(); + size.transpose(); + srect.setSize(size); + } + + do { + int right = srect.right(); + int left = srect.left(); + + QRect closeRect; + if (canClose) { + QSize sz = standardIcon(QStyle::SP_TitleBarCloseButton, + opt, widget).actualSize(QSize(iconSize, iconSize)); + sz += QSize(buttonMargin, buttonMargin); + if (verticalTitleBar) + sz.transpose(); + closeRect = QRect(left, + srect.center().y() - sz.height()/2, + sz.width(), sz.height()); + left = closeRect.right() + 1; + } + if (sr == SE_DockWidgetCloseButton) { + rect = closeRect; + break; + } + + QRect floatRect; + if (canFloat) { + QSize sz = standardIcon(QStyle::SP_TitleBarNormalButton, + opt, widget).actualSize(QSize(iconSize, iconSize)); + sz += QSize(buttonMargin, buttonMargin); + if (verticalTitleBar) + sz.transpose(); + floatRect = QRect(left, + srect.center().y() - sz.height()/2, + sz.width(), sz.height()); + left = floatRect.right() + 1; + } + if (sr == SE_DockWidgetFloatButton) { + rect = floatRect; + break; + } + + QRect iconRect; + if (const QDockWidget *dw = qobject_cast(widget)) { + QIcon icon; + if (dw->isFloating()) + icon = dw->windowIcon(); + if (!icon.isNull() + && icon.cacheKey() != QApplication::windowIcon().cacheKey()) { + QSize sz = icon.actualSize(QSize(rect.height(), rect.height())); + if (verticalTitleBar) + sz.transpose(); + iconRect = QRect(right - sz.width(), srect.center().y() - sz.height()/2, + sz.width(), sz.height()); + right = iconRect.left() - 1; + } + } + if (sr == SE_DockWidgetIcon) { + rect = iconRect; + break; + } + + QRect textRect = QRect(left, srect.top(), + right - left, srect.height()); + if (sr == SE_DockWidgetTitleBarText) { + rect = textRect; + break; + } + } while (false); + + if (verticalTitleBar) { + rect = QRect(srect.left() + rect.top() - srect.top(), + srect.top() + srect.right() - rect.right(), + rect.height(), rect.width()); + } else { + rect = visualRect(opt->direction, srect, rect); + } + break; + } +#endif default: rect = QWindowsStyle::subElementRect(sr, opt, widget); break; -- cgit v1.2.3