From 6300caf01fd79df48c516dd3882028a26b5fe4b4 Mon Sep 17 00:00:00 2001 From: Jens Bache-Wiig Date: Tue, 16 Apr 2013 06:12:30 -0700 Subject: QGtkStyle: Remove widget dependency from GroupBox This patch makes it possible to draw a checkable groupbox without passing a widget pointer. Task-number: QTBUG-29867 Change-Id: I9b74bcffa0401c88f9dcbcd9816081b7f03a5173 Reviewed-by: J-P Nurmi --- src/widgets/styles/qgtkstyle.cpp | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp index 15fa00d8a6..2697afb077 100644 --- a/src/widgets/styles/qgtkstyle.cpp +++ b/src/widgets/styles/qgtkstyle.cpp @@ -3629,7 +3629,7 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple #ifndef QT_NO_GROUPBOX case CC_GroupBox: - if (qstyleoption_cast(option)) { + if (const QStyleOptionGroupBox * groupBox = qstyleoption_cast(option)) { rect = option->rect.adjusted(0, groupBoxTopMargin, 0, -groupBoxBottomMargin); int topMargin = 0; int topHeight = 0; @@ -3645,27 +3645,29 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple return frameRect.adjusted(leftMarginExtension + margin, margin + topHeight + groupBoxTitleMargin, -margin, -margin); } - if (const QGroupBox *groupBoxWidget = qobject_cast(widget)) { + QFontMetrics fontMetrics = option->fontMetrics; + if (qobject_cast(widget)) { //Prepare metrics for a bold font QFont font = widget->font(); font.setBold(true); - QFontMetrics fontMetrics(font); - QSize textRect = fontMetrics.boundingRect(groupBoxWidget->title()).size() + QSize(4, 4); - int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget); - int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget); - - if (subControl == SC_GroupBoxCheckBox) { - rect.setWidth(indicatorWidth); - rect.setHeight(indicatorHeight); - rect.moveTop((textRect.height() - indicatorHeight) / 2); - - } else if (subControl == SC_GroupBoxLabel) { - if (groupBoxWidget->isCheckable()) - rect.adjust(indicatorWidth + 4, 0, 0, 0); - rect.setSize(textRect); - } - rect = visualRect(option->direction, option->rect, rect); + fontMetrics = QFontMetrics(font); + } + + QSize textRect = fontMetrics.boundingRect(groupBox->text).size() + QSize(4, 4); + int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget); + int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, option, widget); + + if (subControl == SC_GroupBoxCheckBox) { + rect.setWidth(indicatorWidth); + rect.setHeight(indicatorHeight); + rect.moveTop((textRect.height() - indicatorHeight) / 2); + + } else if (subControl == SC_GroupBoxLabel) { + if (groupBox->subControls & SC_GroupBoxCheckBox) + rect.adjust(indicatorWidth + 4, 0, 0, 0); + rect.setSize(textRect); } + rect = visualRect(option->direction, option->rect, rect); } return rect; -- cgit v1.2.3