diff options
Diffstat (limited to 'src/plugins/styles/modernwindows')
| -rw-r--r-- | src/plugins/styles/modernwindows/qwindows11style.cpp | 61 | ||||
| -rw-r--r-- | src/plugins/styles/modernwindows/qwindows11style_p.h | 3 |
2 files changed, 36 insertions, 28 deletions
diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index 6fd857828d3..e9b90d787bc 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -596,7 +596,7 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt if (sub & SC_ComboBoxArrow) { QRectF rect = proxy()->subControlRect(CC_ComboBox, option, SC_ComboBoxArrow, widget); painter->setFont(d->assetFont); - painter->setPen(controlTextColor(option)); + painter->setPen(controlTextColor(option, true)); painter->drawText(rect, Qt::AlignCenter, fluentIcon(Icon::ChevronDownMed)); } if (state & State_KeyboardFocusChange && hasFocus) { @@ -887,7 +887,7 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption if (isOn) { painter->setFont(d->assetFont); - painter->setPen(controlTextColor(option, QPalette::Window)); + painter->setPen(controlTextColor(option)); qreal clipWidth = 1.0; const QString str = fluentIcon(Icon::AcceptMedium); QFontMetrics fm(d->assetFont); @@ -907,19 +907,24 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption QFont f(d->assetFont); f.setPointSize(6); painter->setFont(f); - painter->setPen(controlTextColor(option, QPalette::Window)); + painter->setPen(controlTextColor(option)); painter->drawText(rect, Qt::AlignCenter, fluentIcon(Icon::Dash12)); } } break; case PE_IndicatorBranch: { if (option->state & State_Children) { + const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option); const bool isReverse = option->direction == Qt::RightToLeft; const bool isOpen = option->state & QStyle::State_Open; + const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget); QFont f(d->assetFont); - f.setPointSize(6); + f.setPointSize(8); painter->setFont(f); - painter->setPen(option->palette.color(isOpen ? QPalette::Active : QPalette::Disabled, + if (view && view->alternatingRowColors() && vopt && vopt->state & State_Selected) + painter->setPen(winUI3Color(textOnAccentPrimary)); + else + painter->setPen(option->palette.color(isOpen ? QPalette::Active : QPalette::Disabled, QPalette::WindowText)); const auto ico = isOpen ? Icon::ChevronDownMed : (isReverse ? Icon::ChevronLeftMed @@ -1071,14 +1076,16 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption if (option->state & State_Selected && !highContrastTheme) { // keep in sync with CE_ItemViewItem QListView indicator painting - const auto col = option->palette.accent().color(); - painter->setBrush(col); - painter->setPen(col); - const auto xPos = isRtl ? rect.right() - 4.5f : rect.left() + 3.5f; - const auto yOfs = rect.height() / 4.; - QRectF r(QPointF(xPos, rect.y() + yOfs), - QPointF(xPos + 1, rect.y() + rect.height() - yOfs)); - painter->drawRoundedRect(r, 1, 1); + if (!qobject_cast<const QTableView *>(widget)) { + const auto col = option->palette.accent().color(); + painter->setBrush(col); + painter->setPen(col); + const auto xPos = isRtl ? rect.right() - 4.5f : rect.left() + 3.5f; + const auto yOfs = rect.height() / 4.; + QRectF r(QPointF(xPos, rect.y() + yOfs), + QPointF(xPos + 1, rect.y() + rect.height() - yOfs)); + painter->drawRoundedRect(r, 1, 1); + } } const bool isTreeDecoration = vopt->features.testFlag( @@ -1099,7 +1106,7 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption } const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget); - painter->setBrush(view->alternatingRowColors() ? vopt->palette.highlight() : WINUI3Colors[colorSchemeIndex][subtleHighlightColor]); + painter->setBrush(view->alternatingRowColors() && state & State_Selected ? calculateAccentColor(option) : WINUI3Colors[colorSchemeIndex][subtleHighlightColor]); painter->setPen(Qt::NoPen); if (isFirst) { QPainterStateGuard psg(painter); @@ -1207,7 +1214,7 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op case QStyle::CE_ComboBoxLabel: #if QT_CONFIG(combobox) if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) { - painter->setPen(controlTextColor(option)); + painter->setPen(controlTextColor(option, true)); QStyleOptionComboBox newOption = *cb; newOption.rect.adjust(4,0,-4,0); QCommonStyle::drawControl(element, &newOption, painter, widget); @@ -1753,13 +1760,13 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op } } const bool highlightCurrent = vopt->state.testAnyFlags(State_Selected | State_MouseOver); + const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget); if (highlightCurrent) { if (highContrastTheme) { painter->setBrush(vopt->palette.highlight()); } else { - const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget); - painter->setBrush(view && view->alternatingRowColors() - ? vopt->palette.highlight() + painter->setBrush(view && view->alternatingRowColors() && vopt->state & State_Selected + ? calculateAccentColor(option) : winUI3Color(subtleHighlightColor)); } } else { @@ -1815,8 +1822,13 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op vopt->icon.paint(painter, iconRect, vopt->decorationAlignment, mode, state); } - painter->setPen(highlightCurrent && highContrastTheme ? vopt->palette.base().color() - : vopt->palette.text().color()); + if (highlightCurrent && highContrastTheme) { + painter->setPen(vopt->palette.base().color()); + } else if ((view && view->alternatingRowColors() && highlightCurrent && vopt->state & State_Selected)) { + painter->setPen(winUI3Color(textOnAccentPrimary)); + } else { + painter->setPen(vopt->palette.text().color()); + } d->viewItemDrawText(painter, vopt, textRect); // paint a vertical marker for QListView @@ -2725,7 +2737,7 @@ QBrush QWindows11Style::inputFillBrush(const QStyleOption *option, const QWidget return winUI3Color(fillControlDefault); } -QColor QWindows11Style::controlTextColor(const QStyleOption *option, QPalette::ColorRole role) const +QColor QWindows11Style::controlTextColor(const QStyleOption *option, bool ignoreIsChecked) const { using namespace StyleOptionHelper; static constexpr WINUI3Color colorEnums[2][4] = { @@ -2738,12 +2750,9 @@ QColor QWindows11Style::controlTextColor(const QStyleOption *option, QPalette::C if (option->palette.isBrushSet(QPalette::Current, QPalette::ButtonText)) return option->palette.buttonText().color(); - const int colorIndex = isChecked(option) ? 1 : 0; + const int colorIndex = !ignoreIsChecked && isChecked(option) ? 1 : 0; const auto state = calcControlState(option); - const auto alpha = winUI3Color(colorEnums[colorIndex][int(state)]); - QColor col = option->palette.color(role); - col.setAlpha(alpha.alpha()); - return col; + return winUI3Color(colorEnums[colorIndex][int(state)]); } void QWindows11Style::drawLineEditFrame(QPainter *p, const QRectF &rect, const QStyleOption *o, bool isEditable) const diff --git a/src/plugins/styles/modernwindows/qwindows11style_p.h b/src/plugins/styles/modernwindows/qwindows11style_p.h index 96c2c4136e0..9d0cdda3e33 100644 --- a/src/plugins/styles/modernwindows/qwindows11style_p.h +++ b/src/plugins/styles/modernwindows/qwindows11style_p.h @@ -104,8 +104,7 @@ private: QBrush controlFillBrush(const QStyleOption *option, ControlType controlType) const; QBrush inputFillBrush(const QStyleOption *option, const QWidget *widget) const; // ControlType::ControlAlt can be mapped to QPalette directly - QColor controlTextColor(const QStyleOption *option, - QPalette::ColorRole role = QPalette::ButtonText) const; + QColor controlTextColor(const QStyleOption *option, bool ignoreIsChecked = false) const; void drawLineEditFrame(QPainter *p, const QRectF &rect, const QStyleOption *o, bool isEditable = true) const; inline QColor winUI3Color(enum WINUI3Color col) const; |
