diff --git a/qrenderdoc/Code/QRDUtils.cpp b/qrenderdoc/Code/QRDUtils.cpp index 551197231..d3ede0ed6 100644 --- a/qrenderdoc/Code/QRDUtils.cpp +++ b/qrenderdoc/Code/QRDUtils.cpp @@ -240,7 +240,7 @@ struct RichResourceText { QString resname = GetTruncatedResourceName(ctx, v.value()).toHtmlEscaped(); html += lit("%1" - "") + "") .arg(resname) .arg(highdpi ? lit("@2x") : QString()); text += resname; diff --git a/qrenderdoc/Styles/RDStyle/RDStyle.cpp b/qrenderdoc/Styles/RDStyle/RDStyle.cpp index 6ae399a36..b5a9a0719 100644 --- a/qrenderdoc/Styles/RDStyle/RDStyle.cpp +++ b/qrenderdoc/Styles/RDStyle/RDStyle.cpp @@ -135,6 +135,11 @@ void start(QAbstractAnimation *anim) } }; +static QWindow *widgetWindow(const QWidget *widget) +{ + return widget ? widget->window()->windowHandle() : NULL; +} + RDStyle::RDStyle(ColorScheme scheme) : RDTweakedNativeStyle(new QCommonStyle()) { m_Scheme = scheme; @@ -913,18 +918,18 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl const QStyleOptionToolButton *toolbutton = qstyleoption_cast(opt); QStyleOptionToolButton labelTextIcon = *toolbutton; - labelTextIcon.rect = subControlRect(control, opt, SC_ToolButton, widget); + labelTextIcon.rect = proxy()->subControlRect(control, opt, SC_ToolButton, widget); // draw the label text/icon - drawControl(CE_ToolButtonLabel, &labelTextIcon, p, widget); + proxy()->drawControl(CE_ToolButtonLabel, &labelTextIcon, p, widget); // draw the menu arrow, if there is one if((toolbutton->subControls & SC_ToolButtonMenu) || (toolbutton->features & QStyleOptionToolButton::HasMenu)) { QStyleOptionToolButton menu = *toolbutton; - menu.rect = subControlRect(control, opt, SC_ToolButtonMenu, widget); - drawPrimitive(PE_IndicatorArrowDown, &menu, p, widget); + menu.rect = proxy()->subControlRect(control, opt, SC_ToolButtonMenu, widget); + proxy()->drawPrimitive(PE_IndicatorArrowDown, &menu, p, widget); } return; @@ -939,7 +944,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl const QStyleOptionGroupBox *group = qstyleoption_cast(opt); - QRect labelRect = subControlRect(CC_GroupBox, opt, QStyle::SC_GroupBoxLabel, widget); + QRect labelRect = proxy()->subControlRect(CC_GroupBox, opt, QStyle::SC_GroupBoxLabel, widget); labelRect.adjust(Constants::GroupHMargin, Constants::GroupVMargin, Constants::GroupHMargin, Constants::GroupVMargin); @@ -953,8 +958,8 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl penRole = QPalette::NoRole; } - drawItemText(p, labelRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextHideMnemonic, group->palette, - group->state & State_Enabled, group->text, penRole); + proxy()->drawItemText(p, labelRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextHideMnemonic, + group->palette, group->state & State_Enabled, group->text, penRole); labelRect.setRight(subControlRect(CC_GroupBox, opt, QStyle::SC_GroupBoxFrame, widget).right()); labelRect.adjust(-Constants::GroupHMargin / 2, 0, -Constants::GroupHMargin, 0); @@ -964,12 +969,12 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl if(opt->subControls & QStyle::SC_GroupBoxCheckBox) { - QRect checkBoxRect = subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, widget); + QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, widget); QStyleOptionButton box; (QStyleOption &)box = *(QStyleOption *)opt; box.rect = checkBoxRect; - drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); + proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); } return; @@ -1004,7 +1009,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl { p->setPen(QPen(sliderBrush, 2.5)); - QRectF rect = subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarSubLine, widget); + QRectF rect = proxy()->subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarSubLine, widget); rect = rect.adjusted(margin, margin, -margin, -margin); @@ -1053,7 +1058,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl { p->setPen(QPen(sliderBrush, 2.5)); - QRectF rect = subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarAddLine, widget); + QRectF rect = proxy()->subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarAddLine, widget); rect = rect.adjusted(margin, margin, -margin, -margin); @@ -1104,7 +1109,8 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl if((opt->state & activeHover) == activeHover) { QRect hoverRect = - subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarAddPage, widget) + proxy() + ->subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarAddPage, widget) .united(subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarSubPage, widget)); QPainterPath path; @@ -1113,7 +1119,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl p->fillPath(path, hoverBrush); } - QRect slider = subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarSlider, widget); + QRect slider = proxy()->subControlRect(CC_ScrollBar, opt, QStyle::SC_ScrollBarSlider, widget); if(slider.isValid() && (opt->state & State_Enabled)) { @@ -1134,7 +1140,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl { drawRoundedRectBorder(opt, p, widget, QPalette::Base, false); - QRectF rect = subControlRect(control, opt, QStyle::SC_ComboBoxArrow, widget); + QRectF rect = proxy()->subControlRect(control, opt, QStyle::SC_ComboBoxArrow, widget); p->save(); p->setRenderHint(QPainter::Antialiasing); @@ -1190,7 +1196,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl p->drawLine(rect.topRight(), rect.bottomRight()); - rect = subControlRect(control, opt, QStyle::SC_SpinBoxUp, widget); + rect = proxy()->subControlRect(control, opt, QStyle::SC_SpinBoxUp, widget); p->setClipRect(rect); @@ -1241,7 +1247,7 @@ void RDStyle::drawComplexControl(ComplexControl control, const QStyleOptionCompl p->drawPath(path); } - rect = subControlRect(control, opt, QStyle::SC_SpinBoxDown, widget); + rect = proxy()->subControlRect(control, opt, QStyle::SC_SpinBoxDown, widget); p->setClipRect(rect); @@ -1319,7 +1325,7 @@ void RDStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *opt, Q QStyleOptionFrame frameOpt = *frame; frameOpt.frameShape = QFrame::Panel; - drawControl(CE_ShapedFrame, &frameOpt, p, widget); + proxy()->drawControl(CE_ShapedFrame, &frameOpt, p, widget); return; } else if(element == QStyle::PE_FrameFocusRect) @@ -1487,7 +1493,7 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain const QStyleOptionButton *radiobutton = qstyleoption_cast(opt); if(radiobutton) { - QRectF rect = subElementRect(SE_CheckBoxIndicator, opt, widget); + QRectF rect = proxy()->subElementRect(SE_CheckBoxIndicator, opt, widget); rect = rect.adjusted(1.5, 1.5, -1, -1); @@ -1530,7 +1536,7 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain p->restore(); QStyleOptionButton labelText = *radiobutton; - labelText.rect = subElementRect(SE_RadioButtonContents, &labelText, widget); + labelText.rect = proxy()->subElementRect(SE_RadioButtonContents, &labelText, widget); drawControl(CE_RadioButtonLabel, &labelText, p, widget); } @@ -1541,7 +1547,7 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain const QStyleOptionButton *checkbox = qstyleoption_cast(opt); if(checkbox) { - QRectF rect = subElementRect(SE_CheckBoxIndicator, opt, widget).adjusted(1, 1, -1, -1); + QRectF rect = proxy()->subElementRect(SE_CheckBoxIndicator, opt, widget).adjusted(1, 1, -1, -1); QPen outlinePen(outlineBrush(opt->palette), 1.0); @@ -1579,8 +1585,8 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain p->restore(); QStyleOptionButton labelText = *checkbox; - labelText.rect = subElementRect(SE_CheckBoxContents, &labelText, widget); - drawControl(CE_CheckBoxLabel, &labelText, p, widget); + labelText.rect = proxy()->subElementRect(SE_CheckBoxContents, &labelText, widget); + proxy()->drawControl(CE_CheckBoxLabel, &labelText, p, widget); } return; @@ -1594,19 +1600,19 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain if(!checkbox->icon.isNull()) { - drawItemPixmap(p, rect, Qt::AlignLeft | Qt::AlignVCenter, - checkbox->icon.pixmap( - checkbox->iconSize.width(), checkbox->iconSize.height(), - checkbox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled)); + proxy()->drawItemPixmap( + p, rect, Qt::AlignLeft | Qt::AlignVCenter, + checkbox->icon.pixmap(widgetWindow(widget), checkbox->iconSize, + checkbox->state & State_Enabled ? QIcon::Normal : QIcon::Disabled)); rect.setLeft(rect.left() + checkbox->iconSize.width() + Constants::CheckMargin); } if(!checkbox->text.isEmpty()) { - drawItemText(p, rect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, - checkbox->palette, checkbox->state & State_Enabled, checkbox->text, - QPalette::WindowText); + proxy()->drawItemText(p, rect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, + checkbox->palette, checkbox->state & State_Enabled, checkbox->text, + QPalette::WindowText); } } @@ -1775,23 +1781,24 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain if(!menuitem->icon.isNull()) { - int iconSize = pixelMetric(QStyle::PM_SmallIconSize, opt, widget); + int iconSize = proxy()->pixelMetric(QStyle::PM_SmallIconSize, opt, widget); - QPixmap pix = menuitem->icon.pixmap( - iconSize, iconSize, (menuitem->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); + QPixmap pix = + menuitem->icon.pixmap(widgetWindow(widget), QSize(iconSize, iconSize), + (menuitem->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); if(!pix.isNull()) { QRectF iconRect = rect; iconRect.setWidth(iconSize); - drawItemPixmap(p, iconRect.toRect(), Qt::AlignCenter | Qt::AlignTop | Qt::TextShowMnemonic, - pix); + proxy()->drawItemPixmap(p, iconRect.toRect(), + Qt::AlignCenter | Qt::AlignTop | Qt::TextShowMnemonic, pix); rect.adjust(iconSize + Constants::MenuBarMargin, 0, 0, 0); } } else if(menuitem->checkType != QStyleOptionMenuItem::NotCheckable) { - int checkSize = pixelMetric(QStyle::PM_SmallIconSize, opt, widget); + int checkSize = proxy()->pixelMetric(QStyle::PM_SmallIconSize, opt, widget); QRectF checkRect = rect.adjusted(1, 1, -1, -1); checkRect.setWidth(checkSize); @@ -1812,7 +1819,7 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain box.state |= State_On; else box.state &= ~State_On; - drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); + proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); rect.adjust(checkSize + Constants::MenuBarMargin, 0, 0, 0); } @@ -1820,8 +1827,9 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain if(menuitem->menuItemType == QStyleOptionMenuItem::Normal) { p->setFont(menuitem->font); - drawItemText(p, rect.toRect(), Qt::AlignCenter | Qt::AlignTop | Qt::TextShowMnemonic, - menuitem->palette, menuitem->state & State_Enabled, menuitem->text, textrole); + proxy()->drawItemText(p, rect.toRect(), Qt::AlignCenter | Qt::AlignTop | Qt::TextShowMnemonic, + menuitem->palette, menuitem->state & State_Enabled, menuitem->text, + textrole); } p->restore(); @@ -1880,9 +1888,10 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain // draw the icon, if it exists if(!menuitem->icon.isNull()) { - drawItemPixmap( + proxy()->drawItemPixmap( p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter, - menuitem->icon.pixmap(Constants::MenuBarIconSize, Constants::MenuBarIconSize, + menuitem->icon.pixmap(widgetWindow(widget), + QSize(Constants::MenuBarIconSize, Constants::MenuBarIconSize), menuitem->state & State_Enabled ? QIcon::Normal : QIcon::Disabled)); } else if(menuitem->checkType != QStyleOptionMenuItem::NotCheckable) @@ -1906,7 +1915,7 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain box.state |= State_On; else box.state &= ~State_On; - drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); + proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget); } if(menuitem->menuHasCheckableItems) @@ -1927,25 +1936,28 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain if(tabIndex < 0) { - drawItemText(p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, - menuitem->palette, menuitem->state & State_Enabled, menuitem->text, textrole); + proxy()->drawItemText( + p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, + menuitem->palette, menuitem->state & State_Enabled, menuitem->text, textrole); } else { QString title = text.left(tabIndex); QString shortcut = text.mid(tabIndex + 1, -1); - drawItemText(p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, - menuitem->palette, menuitem->state & State_Enabled, title, textrole); - drawItemText(p, rect.toRect(), Qt::AlignRight | Qt::AlignVCenter | Qt::TextShowMnemonic, - menuitem->palette, menuitem->state & State_Enabled, shortcut, textrole); + proxy()->drawItemText(p, rect.toRect(), + Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, + menuitem->palette, menuitem->state & State_Enabled, title, textrole); + proxy()->drawItemText( + p, rect.toRect(), Qt::AlignRight | Qt::AlignVCenter | Qt::TextShowMnemonic, + menuitem->palette, menuitem->state & State_Enabled, shortcut, textrole); } if(menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) { QStyleOptionMenuItem submenu = *menuitem; submenu.rect.setLeft(submenu.rect.right() - Constants::MenuSubmenuWidth); - drawPrimitive(PE_IndicatorArrowRight, &submenu, p, widget); + proxy()->drawPrimitive(PE_IndicatorArrowRight, &submenu, p, widget); } } @@ -1963,15 +1975,16 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain if(!tab->icon.isNull()) { - drawItemPixmap(p, rect, Qt::AlignLeft | Qt::AlignVCenter, - tab->icon.pixmap(tab->iconSize.width(), tab->iconSize.height(), - tab->state & State_Enabled ? QIcon::Normal : QIcon::Disabled)); + proxy()->drawItemPixmap( + p, rect, Qt::AlignLeft | Qt::AlignVCenter, + tab->icon.pixmap(widgetWindow(widget), tab->iconSize, + tab->state & State_Enabled ? QIcon::Normal : QIcon::Disabled)); rect.setLeft(rect.left() + tab->iconSize.width() + Constants::TabMargin); } - drawItemText(p, rect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, tab->palette, - tab->state & State_Enabled, tab->text, QPalette::WindowText); + proxy()->drawItemText(p, rect, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, + tab->palette, tab->state & State_Enabled, tab->text, QPalette::WindowText); return; } else if(control == QStyle::CE_TabBarTabShape) @@ -2017,8 +2030,8 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain } else if(control == QStyle::CE_TabBarTab) { - drawControl(CE_TabBarTabShape, opt, p, widget); - drawControl(CE_TabBarTabLabel, opt, p, widget); + proxy()->drawControl(CE_TabBarTabShape, opt, p, widget); + proxy()->drawControl(CE_TabBarTabLabel, opt, p, widget); return; } else if(control == QStyle::CE_DockWidgetTitle) @@ -2048,9 +2061,9 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain const QStyleOptionDockWidget *dockwidget = qstyleoption_cast(opt); - drawItemText(p, rect.toRect().adjusted(Constants::TabMargin, 0, 0, 0), - Qt::AlignLeft | Qt::AlignTop | Qt::TextHideMnemonic, dockwidget->palette, - dockwidget->state & State_Enabled, dockwidget->title, QPalette::WindowText); + proxy()->drawItemText(p, rect.toRect().adjusted(Constants::TabMargin, 0, 0, 0), + Qt::AlignLeft | Qt::AlignTop | Qt::TextHideMnemonic, dockwidget->palette, + dockwidget->state & State_Enabled, dockwidget->title, QPalette::WindowText); return; } @@ -2073,14 +2086,16 @@ void RDStyle::drawControl(ControlElement control, const QStyleOption *opt, QPain // draw the icon, if it exists if(!header->icon.isNull()) { - drawItemPixmap( + proxy()->drawItemPixmap( p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter, - header->icon.pixmap(Constants::ItemHeaderIconSize, Constants::ItemHeaderIconSize, + header->icon.pixmap(widgetWindow(widget), + QSize(Constants::ItemHeaderIconSize, Constants::ItemHeaderIconSize), header->state & State_Enabled ? QIcon::Normal : QIcon::Disabled)); } - drawItemText(p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, - header->palette, header->state & State_Enabled, header->text, QPalette::WindowText); + proxy()->drawItemText(p, rect.toRect(), Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, + header->palette, header->state & State_Enabled, header->text, + QPalette::WindowText); if(header->sortIndicator != QStyleOptionHeader::None) { @@ -2141,8 +2156,8 @@ void RDStyle::drawRoundedRectBorder(const QStyleOption *opt, QPainter *p, const p->setRenderHint(QPainter::Antialiasing); - int xshift = pixelMetric(PM_ButtonShiftHorizontal, opt, widget); - int yshift = pixelMetric(PM_ButtonShiftVertical, opt, widget); + int xshift = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget); + int yshift = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget); QRect rect = opt->rect.adjusted(0, 0, -1, -1); diff --git a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp index 0a6202e90..ea6fb8967 100644 --- a/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp +++ b/qrenderdoc/Styles/RDTweakedNativeStyle/RDTweakedNativeStyle.cpp @@ -35,8 +35,14 @@ namespace Constants static const int MenuBarItemHPadding = 4; static const int MenuBarItemVPadding = 2; static const int MenuBarItemSpacing = 4; +static const int ToolButtonIconSpacing = 4; }; +static QWindow *widgetWindow(const QWidget *widget) +{ + return widget ? widget->window()->windowHandle() : NULL; +} + RDTweakedNativeStyle::RDTweakedNativeStyle(QStyle *parent) : QProxyStyle(parent) { } @@ -367,7 +373,7 @@ void RDTweakedNativeStyle::drawControl(ControlElement control, const QStyleOptio } int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine; - if(!styleHint(SH_UnderlineShortcut, opt, widget)) + if(!proxy()->styleHint(SH_UnderlineShortcut, opt, widget)) flags |= Qt::TextHideMnemonic; rect.adjust(Constants::MenuBarItemHPadding, Constants::MenuBarItemVPadding, @@ -375,8 +381,9 @@ void RDTweakedNativeStyle::drawControl(ControlElement control, const QStyleOptio int iconSize = pixelMetric(QStyle::PM_SmallIconSize, opt, widget); - QPixmap pix = menuopt->icon.pixmap( - iconSize, iconSize, (menuopt->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); + QPixmap pix = + menuopt->icon.pixmap(widgetWindow(widget), QSize(iconSize, iconSize), + (menuopt->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled); if(!pix.isNull()) { @@ -390,7 +397,98 @@ void RDTweakedNativeStyle::drawControl(ControlElement control, const QStyleOptio return; } + else if(control == QStyle::CE_ToolButtonLabel) + { + // unfortunately Qt made a 'fix' at some point to some unalterable magic numbers which reduces + // the spacing around the icon and ends up being too small at least in cases we care about. + // So we instead render the label ourselves + const QStyleOptionToolButton *toolopt = qstyleoption_cast(opt); + + QRect rect = toolopt->rect; + + // even though our style doesn't shift the button contents, this is the tweaked native style so + // we need to check for that + if(toolopt->state & (State_Sunken | State_On)) + { + rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolopt, widget), + proxy()->pixelMetric(PM_ButtonShiftVertical, toolopt, widget)); + } + + int textFlags = Qt::TextShowMnemonic; + if(!proxy()->styleHint(SH_UnderlineShortcut, opt, widget)) + textFlags |= Qt::TextHideMnemonic; + + // fetch the icon if we're not text-only and there's a valid icon + QPixmap pixmap; + QSize iconSize = toolopt->iconSize; + if(!toolopt->icon.isNull() && toolopt->toolButtonStyle != Qt::ToolButtonTextOnly) + { + QIcon::Mode mode = QIcon::Normal; + + if((toolopt->state & State_Enabled) == 0) + mode = QIcon::Disabled; + else if((opt->state & (State_AutoRaise | State_MouseOver)) == + (State_AutoRaise | State_MouseOver)) + mode = QIcon::Active; + + iconSize.setWidth(qMin(toolopt->iconSize.width(), toolopt->rect.width())); + iconSize.setHeight(qMin(toolopt->iconSize.height(), toolopt->rect.height())); + + pixmap = toolopt->icon.pixmap(widget->window()->windowHandle(), iconSize, mode, + toolopt->state & State_On ? QIcon::On : QIcon::Off); + double d = widget->devicePixelRatioF(); + iconSize = pixmap.size(); + iconSize /= pixmap.devicePixelRatio(); + } + + // if we're only rendering the icon, render it now centred + if(toolopt->toolButtonStyle == Qt::ToolButtonIconOnly) + { + drawItemPixmap(p, rect, Qt::AlignCenter, pixmap); + } + else + { + // otherwise we're expecting to render text, set the font + p->setFont(toolopt->font); + + QRect iconRect = rect, textRect = rect; + + if(toolopt->toolButtonStyle == Qt::ToolButtonTextOnly) + { + textFlags |= Qt::AlignCenter; + iconRect = QRect(); + } + else if(toolopt->toolButtonStyle == Qt::ToolButtonTextUnderIcon) + { + // take spacing above and below for the icon + iconRect.setHeight(iconSize.height() + Constants::ToolButtonIconSpacing * 2); + // place the text below the icon + textRect.setTop(textRect.top() + iconRect.height()); + // center the text below the icon + textFlags |= Qt::AlignCenter; + } + else + { + // take spacing left and right for the icon and remove it from the text rect + iconRect.setWidth(iconSize.width() + Constants::ToolButtonIconSpacing * 2); + textRect.setLeft(textRect.left() + iconRect.width()); + + // left align the text horizontally next to the icon, but still vertically center it. + textFlags |= Qt::AlignLeft | Qt::AlignVCenter; + } + + if(iconRect.isValid()) + proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, iconRect), + Qt::AlignCenter, pixmap); + + proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, textRect), textFlags, + toolopt->palette, toolopt->state & State_Enabled, toolopt->text, + QPalette::ButtonText); + } + + return; + } // https://bugreports.qt.io/browse/QTBUG-14949 // work around itemview rendering bug - the first line in a multi-line text that is elided stops // all subsequent text from rendering. Should be fixed in 5.11, but for all other versions we need @@ -398,7 +496,7 @@ void RDTweakedNativeStyle::drawControl(ControlElement control, const QStyleOptio // // However in 5.11.1 at least on macOS it still seems to be broken #if 1 //(QT_VERSION < QT_VERSION_CHECK(5, 11, 0)) - if(control == QStyle::CE_ItemViewItem) + else if(control == QStyle::CE_ItemViewItem) { const QStyleOptionViewItem *viewopt = qstyleoption_cast(opt);