Skip to content

NEW: option to draw QGroupBox label on top of the frame (Windows-like) #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/phantom/phantomstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ static const bool AllowToolBarAutoRaise = true;
static const bool ShowItemViewDecorationSelected = false;
static const bool UseQMenuForComboBoxPopup = true;
static const bool ItemView_UseFontHeightForDecorationSize = true;
static const bool GroupBoxLabelOnFrame = true;

// Whether or not the non-raised tabs in a tab bar have shininess/highlights to
// them. Setting this to false adds an extra visual hint for distinguishing
Expand Down Expand Up @@ -3128,7 +3129,23 @@ void PhantomStyle::drawComplexControl(ComplexControl control,
frame.midLineWidth = groupBox->midLineWidth;
frame.rect = proxy()->subControlRect(CC_GroupBox, option,
SC_GroupBoxFrame, widget);
if (Ph::GroupBoxLabelOnFrame) {
painter->save();
QRegion region(groupBox->rect);
if (!groupBox->text.isEmpty()) {
QRect finalRect;
if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox) {
finalRect = checkBoxRect.united(textRect);
} else {
finalRect = textRect;
}
region -= finalRect.adjusted(-2, 0, 2, 0);
}
painter->setClipRegion(region);
}
proxy()->drawPrimitive(PE_FrameGroupBox, &frame, painter, widget);
if (Ph::GroupBoxLabelOnFrame)
painter->restore();
}

// Draw title
Expand Down Expand Up @@ -4728,19 +4745,26 @@ QRect PhantomStyle::subControlRect(ComplexControl control,
case SC_GroupBoxFrame:
case SC_GroupBoxContents: {
QRect r = option->rect;
int topMargin = 0;
if (groupBox->subControls & (SC_GroupBoxLabel | SC_GroupBoxCheckBox)) {
int fontHeight = option->fontMetrics.height();
int topMargin =
qMax(pixelMetric(PM_ExclusiveIndicatorHeight), fontHeight);
topMargin +=
(int)((qreal)fontHeight * Ph::GroupBox_LabelBottomMarginFontRatio);
topMargin = qMax(pixelMetric(PM_IndicatorHeight), fontHeight);
if (Ph::GroupBoxLabelOnFrame) {
topMargin /= 2;
} else {
topMargin += (int)((qreal)fontHeight *
Ph::GroupBox_LabelBottomMarginFontRatio);
}
r.setTop(r.top() + topMargin);
}
if (subControl == SC_GroupBoxContents &&
groupBox->subControls & SC_GroupBoxFrame) {
// Testing against groupBox->features for the frame type doesn't seem
// to work here.
r.adjust(1, 1, -1, -1);
if (Ph::GroupBoxLabelOnFrame)
r.adjust(1, topMargin, -1, -topMargin);
else
r.adjust(1, 1, -1, -1);
}
return r;
}
Expand All @@ -4757,13 +4781,12 @@ QRect PhantomStyle::subControlRect(ComplexControl control,
proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
int indicatorHeight =
proxy()->pixelMetric(PM_IndicatorHeight, option, widget);
int margin = 0;
int indicatorRightSpace = textHeight / 3;
int contentWidth = textWidth;
if (option->subControls & QStyle::SC_GroupBoxCheckBox) {
contentWidth += indicatorWidth + indicatorRightSpace;
}
int x = margin;
int x = Ph::GroupBoxLabelOnFrame ? indicatorHeight / 2 : 0;
int y = 0;
switch (groupBox->textAlignment & Qt::AlignHorizontal_Mask) {
case Qt::AlignHCenter:
Expand Down