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 <jpnurmi@digia.com>
This commit is contained in:
parent
201bd2e59a
commit
6300caf01f
@ -3629,7 +3629,7 @@ QRect QGtkStyle::subControlRect(ComplexControl control, const QStyleOptionComple
|
||||
#ifndef QT_NO_GROUPBOX
|
||||
|
||||
case CC_GroupBox:
|
||||
if (qstyleoption_cast<const QStyleOptionGroupBox *>(option)) {
|
||||
if (const QStyleOptionGroupBox * groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(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<const QGroupBox *>(widget)) {
|
||||
QFontMetrics fontMetrics = option->fontMetrics;
|
||||
if (qobject_cast<const QGroupBox *>(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;
|
||||
|
Loading…
Reference in New Issue
Block a user