@@ -87,34 +87,35 @@ inline ControlState calcControlState(const QStyleOption *option)
8787
8888} // namespace StyleOptionHelper
8989
90- # define AcceptMedium u" \uF78C " _s
91- // QStringLiteral(u"\uE73C")
92- # define Dash12 u" \uE629 " _s
93- # define CheckMark u" \uE73E " _s
94-
95- # define CaretLeftSolid8 u" \uEDD9 " _s
96- # define CaretRightSolid8 u" \uEDDA " _s
97- # define CaretUpSolid8 u" \uEDDB " _s
98- # define CaretDownSolid8 u" \uEDDC " _s
99-
100- # define ChevronDown u" \uE70D " _s
101- # define ChevronUp u" \uE70E " _s
102-
103- # define ChevronDownMed u" \uE972 " _s
104- # define ChevronLeftMed u" \uE973 " _s
105- # define ChevronRightMed u" \uE974 " _s
106-
107- # define ChevronUpSmall u" \uE96D " _s
108- # define ChevronDownSmall u" \uE96E " _s
109-
110- # define ChromeMinimize u" \uE921 " _s
111- # define ChromeMaximize u" \uE922 " _s
112- # define ChromeRestore u" \uE923 " _s
113- # define ChromeClose u" \uE8BB " _s
90+ enum class Icon : ushort
91+ {
92+ AcceptMedium = 0xF78C ,
93+ Dash12 = 0xE629 ,
94+ CheckMark = 0xE73E ,
95+ CaretLeftSolid8 = 0xEDD9 ,
96+ CaretRightSolid8 = 0xEDDA ,
97+ CaretUpSolid8 = 0xEDDB ,
98+ CaretDownSolid8 = 0xEDDC ,
99+ ChevronDown = 0xE70D ,
100+ ChevronUp = 0xE70E ,
101+ ChevronDownMed = 0xE972 ,
102+ ChevronLeftMed = 0xE973 ,
103+ ChevronRightMed = 0xE974 ,
104+ ChevronUpSmall = 0xE96D ,
105+ ChevronDownSmall = 0xE96E ,
106+ ChromeMinimize = 0xE921 ,
107+ ChromeMaximize = 0xE922 ,
108+ ChromeRestore = 0xE923 ,
109+ ChromeClose = 0xE8BB ,
110+ More = 0xE712 ,
111+ Help = 0xE897 ,
112+ Clear = 0xE894 ,
113+ };
114114
115- #define More u" \uE712 " _s
116- #define Help u" \uE897 " _s
117- #define Clear u" \uE894 " _s
115+ static inline QString fluentIcon (Icon i)
116+ {
117+ return QChar (ushort (i));
118+ }
118119
119120template <typename R, typename P, typename B>
120121static inline void drawRoundedRect (QPainter *p, R &&rect, P &&pen, B &&brush)
@@ -316,18 +317,18 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
316317{
317318 QWindows11StylePrivate *d = const_cast <QWindows11StylePrivate*>(d_func ());
318319
319- const auto drawTitleBarButton = [&](ComplexControl control, SubControl sc, const QString &str ) {
320+ const auto drawTitleBarButton = [&](ComplexControl control, SubControl sc, Icon ico ) {
320321 using namespace StyleOptionHelper ;
321322 const QRect buttonRect = proxy ()->subControlRect (control, option, sc, widget);
322323 if (buttonRect.isValid ()) {
323324 const bool hover = option->activeSubControls == sc && isHover (option);
324325 if (hover)
325326 painter->fillRect (buttonRect, winUI3Color (subtleHighlightColor));
326327 painter->setPen (option->palette .color (QPalette::WindowText));
327- painter->drawText (buttonRect, Qt::AlignCenter, str );
328+ painter->drawText (buttonRect, Qt::AlignCenter, fluentIcon (ico) );
328329 }
329330 };
330- const auto drawTitleBarCloseButton = [&](ComplexControl control, SubControl sc, const QString &str ) {
331+ const auto drawTitleBarCloseButton = [&](ComplexControl control, SubControl sc, Icon ico ) {
331332 using namespace StyleOptionHelper ;
332333 const QRect buttonRect = proxy ()->subControlRect (control, option, sc, widget);
333334 if (buttonRect.isValid ()) {
@@ -349,7 +350,7 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
349350 break ;
350351 }
351352 painter->setPen (pen);
352- painter->drawText (buttonRect, Qt::AlignCenter, str );
353+ painter->drawText (buttonRect, Qt::AlignCenter, fluentIcon (ico) );
353354 }
354355 };
355356
@@ -437,7 +438,7 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
437438 cp->setFont (d->assetFont );
438439 cp->setPen (sb->palette .buttonText ().color ());
439440 cp->setBrush (Qt::NoBrush);
440- cp->drawText (rect, Qt::AlignCenter, isUp ? ChevronUp : ChevronDown);
441+ cp->drawText (rect, Qt::AlignCenter, fluentIcon ( isUp ? Icon:: ChevronUp : Icon:: ChevronDown) );
441442 };
442443 if (sub & SC_SpinBoxUp) drawUpDown (SC_SpinBoxUp);
443444 if (sub & SC_SpinBoxDown) drawUpDown (SC_SpinBoxDown);
@@ -600,7 +601,7 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
600601 QRectF rect = proxy ()->subControlRect (CC_ComboBox, option, SC_ComboBoxArrow, widget).adjusted (4 , 0 , -4 , 1 );
601602 painter->setFont (d->assetFont );
602603 painter->setPen (controlTextColor (option));
603- painter->drawText (rect, Qt::AlignCenter, ChevronDownMed);
604+ painter->drawText (rect, Qt::AlignCenter, fluentIcon (Icon:: ChevronDownMed) );
604605 }
605606 if (state & State_KeyboardFocusChange && hasFocus) {
606607 QStyleOptionFocusRect fropt;
@@ -662,9 +663,9 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
662663 f.setPointSize (6 );
663664 cp->setFont (f);
664665 cp->setPen (Qt::gray);
665- const auto str = vertical ? CaretDownSolid8
666- : (isRtl ? CaretLeftSolid8 : CaretRightSolid8);
667- cp->drawText (rect, Qt::AlignCenter, str );
666+ const auto ico = vertical ? Icon:: CaretDownSolid8
667+ : (isRtl ? Icon:: CaretLeftSolid8 : Icon:: CaretRightSolid8);
668+ cp->drawText (rect, Qt::AlignCenter, fluentIcon (ico) );
668669 }
669670 }
670671 if (sub & SC_ScrollBarSubLine) {
@@ -674,9 +675,9 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
674675 f.setPointSize (6 );
675676 cp->setFont (f);
676677 cp->setPen (Qt::gray);
677- const auto str = vertical ? CaretUpSolid8
678- : (isRtl ? CaretRightSolid8 : CaretLeftSolid8);
679- cp->drawText (rect, Qt::AlignCenter, str );
678+ const auto ico = vertical ? Icon:: CaretUpSolid8
679+ : (isRtl ? Icon:: CaretRightSolid8 : Icon:: CaretLeftSolid8);
680+ cp->drawText (rect, Qt::AlignCenter, fluentIcon (ico) );
680681 }
681682 }
682683 }
@@ -686,9 +687,9 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
686687 QFont buttonFont = QFont (d->assetFont );
687688 buttonFont.setPointSize (8 );
688689 painter->setFont (buttonFont);
689- drawTitleBarCloseButton (CC_MdiControls, SC_MdiCloseButton, ChromeClose);
690- drawTitleBarButton (CC_MdiControls, SC_MdiNormalButton, ChromeRestore);
691- drawTitleBarButton (CC_MdiControls, SC_MdiMinButton, ChromeMinimize);
690+ drawTitleBarCloseButton (CC_MdiControls, SC_MdiCloseButton, Icon:: ChromeClose);
691+ drawTitleBarButton (CC_MdiControls, SC_MdiNormalButton, Icon:: ChromeRestore);
692+ drawTitleBarButton (CC_MdiControls, SC_MdiMinButton, Icon:: ChromeMinimize);
692693 }
693694 break ;
694695 case CC_TitleBar:
@@ -716,39 +717,39 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
716717 // min button
717718 if (shouldDrawButton (SC_TitleBarMinButton, Qt::WindowMinimizeButtonHint) &&
718719 !(titlebar->titleBarState & Qt::WindowMinimized)) {
719- drawTitleBarButton (CC_TitleBar, SC_TitleBarMinButton, ChromeMinimize);
720+ drawTitleBarButton (CC_TitleBar, SC_TitleBarMinButton, Icon:: ChromeMinimize);
720721 }
721722
722723 // max button
723724 if (shouldDrawButton (SC_TitleBarMaxButton, Qt::WindowMaximizeButtonHint) &&
724725 !(titlebar->titleBarState & Qt::WindowMaximized)) {
725- drawTitleBarButton (CC_TitleBar, SC_TitleBarMaxButton, ChromeMaximize);
726+ drawTitleBarButton (CC_TitleBar, SC_TitleBarMaxButton, Icon:: ChromeMaximize);
726727 }
727728
728729 // close button
729730 if (shouldDrawButton (SC_TitleBarCloseButton, Qt::WindowSystemMenuHint))
730- drawTitleBarCloseButton (CC_TitleBar, SC_TitleBarCloseButton, ChromeClose);
731+ drawTitleBarCloseButton (CC_TitleBar, SC_TitleBarCloseButton, Icon:: ChromeClose);
731732
732733 // normalize button
733734 if ((titlebar->subControls & SC_TitleBarNormalButton) &&
734735 (((titlebar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
735736 (titlebar->titleBarState & Qt::WindowMinimized)) ||
736737 ((titlebar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
737738 (titlebar->titleBarState & Qt::WindowMaximized)))) {
738- drawTitleBarButton (CC_TitleBar, SC_TitleBarNormalButton, ChromeRestore);
739+ drawTitleBarButton (CC_TitleBar, SC_TitleBarNormalButton, Icon:: ChromeRestore);
739740 }
740741
741742 // context help button
742743 if (shouldDrawButton (SC_TitleBarContextHelpButton, Qt::WindowContextHelpButtonHint))
743- drawTitleBarButton (CC_TitleBar, SC_TitleBarContextHelpButton, Help);
744+ drawTitleBarButton (CC_TitleBar, SC_TitleBarContextHelpButton, Icon:: Help);
744745
745746 // shade button
746747 if (shouldDrawButton (SC_TitleBarShadeButton, Qt::WindowShadeButtonHint))
747- drawTitleBarButton (CC_TitleBar, SC_TitleBarShadeButton, ChevronUpSmall);
748+ drawTitleBarButton (CC_TitleBar, SC_TitleBarShadeButton, Icon:: ChevronUpSmall);
748749
749750 // unshade button
750751 if (shouldDrawButton (SC_TitleBarUnshadeButton, Qt::WindowShadeButtonHint))
751- drawTitleBarButton (CC_TitleBar, SC_TitleBarUnshadeButton, ChevronDownSmall);
752+ drawTitleBarButton (CC_TitleBar, SC_TitleBarUnshadeButton, Icon:: ChevronDownSmall);
752753
753754 // window icon for system menu
754755 if (shouldDrawButton (SC_TitleBarSysMenu, Qt::WindowSystemMenuHint)) {
@@ -872,9 +873,9 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
872873 f.setPointSize (6 );
873874 painter->setFont (f);
874875 painter->setPen (header->palette .text ().color ());
875- painter-> drawText (option-> rect , Qt::AlignCenter,
876- indicator == QStyleOptionHeader::SortUp ? ChevronDown
877- : ChevronUp );
876+ const auto ico = indicator == QStyleOptionHeader::SortUp ? Icon::ChevronDown
877+ : Icon::ChevronUp;
878+ painter-> drawText (option-> rect , Qt::AlignCenter, fluentIcon (ico) );
878879 }
879880 }
880881 break ;
@@ -892,8 +893,9 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
892893 painter->setFont (d->assetFont );
893894 painter->setPen (controlTextColor (option, QPalette::Window));
894895 qreal clipWidth = 1.0 ;
896+ const QString str = fluentIcon (Icon::AcceptMedium);
895897 QFontMetrics fm (d->assetFont );
896- QRectF clipRect = fm.boundingRect (AcceptMedium );
898+ QRectF clipRect = fm.boundingRect (str );
897899 if (d->transitionsEnabled () && option->styleObject ) {
898900 QNumberStyleAnimation *animation = qobject_cast<QNumberStyleAnimation *>(
899901 d->animation (option->styleObject ));
@@ -904,13 +906,13 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
904906 clipRect.moveCenter (center);
905907 clipRect.setLeft (rect.x () + (rect.width () - clipRect.width ()) / 2.0 + 0.5 );
906908 clipRect.setWidth (clipWidth * clipRect.width ());
907- painter->drawText (clipRect, Qt::AlignVCenter | Qt::AlignLeft, AcceptMedium );
909+ painter->drawText (clipRect, Qt::AlignVCenter | Qt::AlignLeft, str );
908910 } else if (isPartial) {
909911 QFont f (d->assetFont );
910912 f.setPointSize (6 );
911913 painter->setFont (f);
912914 painter->setPen (controlTextColor (option, QPalette::Window));
913- painter->drawText (rect, Qt::AlignCenter, Dash12);
915+ painter->drawText (rect, Qt::AlignCenter, fluentIcon (Icon:: Dash12) );
914916 }
915917 }
916918 break ;
@@ -923,8 +925,10 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption
923925 painter->setFont (f);
924926 painter->setPen (option->palette .color (isOpen ? QPalette::Active : QPalette::Disabled,
925927 QPalette::WindowText));
926- const auto str = isOpen ? ChevronDownMed : (isReverse ? ChevronLeftMed : ChevronRightMed);
927- painter->drawText (option->rect , Qt::AlignCenter, str);
928+ const auto ico = isOpen ? Icon::ChevronDownMed
929+ : (isReverse ? Icon::ChevronLeftMed
930+ : Icon::ChevronRightMed);
931+ painter->drawText (option->rect , Qt::AlignCenter, fluentIcon (ico));
928932 }
929933 }
930934 break ;
@@ -1511,7 +1515,7 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
15111515 if (isEnabled)
15121516 penColor.setAlpha (percentToAlpha (60.63 )); // fillColorTextSecondary
15131517 painter->setPen (penColor);
1514- painter->drawText (vindRect, Qt::AlignCenter, ChevronDownMed);
1518+ painter->drawText (vindRect, Qt::AlignCenter, fluentIcon (Icon:: ChevronDownMed) );
15151519 }
15161520 }
15171521 break ;
@@ -1587,8 +1591,7 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
15871591 QPainterStateGuard psg (painter);
15881592 painter->setFont (d->assetFont );
15891593 painter->setPen (option->palette .text ().color ());
1590- const auto textToDraw = QStringLiteral (u" \uE73E " );
1591- painter->drawText (vRect, Qt::AlignCenter, textToDraw);
1594+ painter->drawText (vRect, Qt::AlignCenter, fluentIcon (Icon::CheckMark));
15921595 }
15931596 if (menuitem->menuHasCheckableItems )
15941597 xOffset += checkMarkWidth + contentItemHMargin;
@@ -1669,8 +1672,8 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
16691672 QRect vSubMenuRect = visualMenuRect (submenuRect);
16701673 painter->setPen (option->palette .text ().color ());
16711674 const bool isReverse = option->direction == Qt::RightToLeft;
1672- const auto str = isReverse ? ChevronLeftMed : ChevronRightMed;
1673- painter->drawText (vSubMenuRect, Qt::AlignCenter, str );
1675+ const auto ico = isReverse ? Icon:: ChevronLeftMed : Icon:: ChevronRightMed;
1676+ painter->drawText (vSubMenuRect, Qt::AlignCenter, fluentIcon (ico) );
16741677 }
16751678 }
16761679 break ;
@@ -2335,7 +2338,7 @@ int QWindows11Style::pixelMetric(PixelMetric metric, const QStyleOption *option,
23352338 QFont f (d->assetFont );
23362339 f.setPointSize (qRound (fontSize * 0 .9f )); // a little bit smaller
23372340 QFontMetrics fm (f);
2338- const auto width = fm.horizontalAdvance (ChevronDownMed);
2341+ const auto width = fm.horizontalAdvance (fluentIcon (Icon:: ChevronDownMed) );
23392342 m_fontPoint2ChevronDownMedWidth.insert (fontSize, width);
23402343 res += width;
23412344 } else {
@@ -2601,15 +2604,15 @@ QIcon QWindows11Style::standardIcon(StandardPixmap standardIcon,
26012604 switch (standardIcon) {
26022605 case SP_LineEditClearButton: {
26032606 if (d->m_lineEditClearButton .isNull ()) {
2604- auto e = new WinFontIconEngine (Clear, d->assetFont );
2607+ auto e = new WinFontIconEngine (fluentIcon (Icon:: Clear) , d->assetFont );
26052608 d->m_lineEditClearButton = QIcon (e);
26062609 }
26072610 return d->m_lineEditClearButton ;
26082611 }
26092612 case SP_ToolBarHorizontalExtensionButton:
26102613 case SP_ToolBarVerticalExtensionButton: {
26112614 if (d->m_toolbarExtensionButton .isNull ()) {
2612- auto e = new WinFontIconEngine (More, d->assetFont );
2615+ auto e = new WinFontIconEngine (fluentIcon (Icon:: More) , d->assetFont );
26132616 e->setScale (1.0 );
26142617 d->m_toolbarExtensionButton = QIcon (e);
26152618 }
0 commit comments