5#include <QtCore/private/qcore_ohos_p.h>
6#include <QtCore/private/qnapi_p.h>
7#include <QtCore/private/qohosmemoizingjsthreadfetcher_p.h>
8#include <QtCore/private/qohoslogger_p.h>
9#include <QtCore/qhash.h>
10#include <QtGui/qfont.h>
11#include <QtGui/qfontmetrics.h>
12#include <QtGui/qicon.h>
13#include <QtGui/qpainter.h>
14#include <QtGui/qpainterpath.h>
15#include <QtWidgets/qabstractscrollarea.h>
16#include <QtWidgets/qcheckbox.h>
17#include <QtWidgets/qcombobox.h>
18#include <QtWidgets/qlineedit.h>
19#include <QtWidgets/qlistview.h>
20#include <QtWidgets/qmdisubwindow.h>
21#include <QtWidgets/qpushbutton.h>
22#include <QtWidgets/qradiobutton.h>
23#include <QtWidgets/qscrollbar.h>
24#include <QtWidgets/qspinbox.h>
25#include <QtWidgets/qstyleditemdelegate.h>
26#include <QtWidgets/qstyleoption.h>
27#include <QtWidgets/qtoolbutton.h>
28#include <QtWidgets/qtreeview.h>
29#include "qpa/qplatformtheme.h"
30#include "private/qguiapplication_p.h"
31#include "private/qstylehelper_p.h"
39QString ohosThemeIconName(QStyle::StandardPixmap standardPixmap)
41 switch (standardPixmap) {
42 case QStyle::SP_ComputerIcon:
return QStringLiteral(
"computer");
43 case QStyle::SP_DesktopIcon:
return QStringLiteral(
"user-desktop");
44 case QStyle::SP_TrashIcon:
return QStringLiteral(
"user-trash");
45 case QStyle::SP_DriveNetIcon:
return QStringLiteral(
"network-workgroup");
46 case QStyle::SP_DriveHDIcon:
return QStringLiteral(
"drive-harddisk");
47 case QStyle::SP_DirClosedIcon:
return QStringLiteral(
"folder");
48 case QStyle::SP_DirIcon:
return QStringLiteral(
"folder");
49 case QStyle::SP_FileIcon:
return QStringLiteral(
"text-x-generic");
56constexpr int checkBoxOrRadioButtonIndicatorSize = 24;
57constexpr int checkBoxOrRadioButtonIndicatorStrokeWidth = 1;
58constexpr int checkBoxOrRadioButtonIndicatorGap = 2;
59constexpr int checkBoxOrRadioButtonHoverSize =
60 checkBoxOrRadioButtonIndicatorSize + (2 * checkBoxOrRadioButtonIndicatorGap);
61constexpr int checkBoxOrRadioButtonFocusStrokeWidth = 2;
62constexpr int checkBoxOrRadioButtonSize =
63 checkBoxOrRadioButtonIndicatorSize + (2 * checkBoxOrRadioButtonIndicatorGap)
64 + (2 * checkBoxOrRadioButtonFocusStrokeWidth);
65constexpr int checkBoxCheckMarkStrokeWidth = 2;
66constexpr int checkBoxCheckMarkShadowWidth = 1;
67constexpr double checkBoxCheckMarkShadowOpacity = 0.05;
68constexpr int radioButtonIndicatorStrokeWidth = 6;
70constexpr int textCursorWidth = 1;
72constexpr int itemViewItemHorizontalMargin = 16;
73constexpr int itemViewItemVerticalMargin = 8;
74constexpr int itemViewItemWithDecorationVerticalMargin = 10;
75constexpr int itemViewItemSpacing = 8;
76constexpr int itemViewSeparatorHeight = 5;
78constexpr int focusFrameWidth = 2;
79constexpr int focusFrameCornerRadius = 16;
81constexpr int headerDefaultSectionSizeVertical = 48;
83constexpr double lineEditCornerRadius = 32.0;
84constexpr int lineEditHorizontalMargin = 16;
85constexpr int lineEditVerticalMargin = 9;
87constexpr int menuBarItemSpacing = 16;
88constexpr int menuBarVerticalMargin = 8;
89constexpr int menuBarHorizontalMargin = 8;
91constexpr int menuItemVerticalMargin = 8;
92constexpr int menuItemCornerRadius = 4;
93constexpr int menuItemHoverHorizontalMargin = 4;
95constexpr int pushButtonHorizontalMargin = 16;
96constexpr int pushButtonVerticalMargin = 8;
97constexpr int pushButtonCornerRadius = 8;
98constexpr int pushButtonFocusFrameGap = 2;
99constexpr int pushButtonFocusFrameWidth = 2;
101constexpr int progressBarMinHeight = 24;
102constexpr int progressBarGrooveHeight = 4;
103constexpr int progressBarCornerRadius = 2;
105constexpr int shadowXSRadius = 22;
107constexpr int sliderThickness = 40;
108constexpr int sliderGrooveHeight = 4;
109constexpr int sliderCornerRadius = 2;
110constexpr int sliderThumbSize = 16;
111constexpr int sliderHoverSize = 4;
112constexpr int sliderFocusStrokeWidth = 2;
114constexpr int smallIconSize = 12;
116constexpr int splitterHandleWidth = 6;
117constexpr int splitterWidth = 12;
119constexpr int titleBarHeight = 46;
121constexpr int toolButtonCornerRadius = 4;
122constexpr int toolButtonFocusFrameWidth = 2;
124constexpr int arrowSymbolSize = 16;
126constexpr int toolTipCornerRadius = 8;
127constexpr int toolTipFrameWidth = 8;
128constexpr int toolTipBackgroundAlpha = 204;
130constexpr int spinBoxFrameHeight = 32;
131constexpr int spinBoxButtonBoxWidth = 32;
132constexpr int spinBoxButtonBoxHeight = 16;
133constexpr int spinBoxEditHorizontalMargin = 4;
134constexpr double spinBoxFrameRadius = 12.0;
135constexpr int spinBoxFrameStroke = 2;
137constexpr int maxScrollBarSize = 9;
138constexpr int thinScrollBarSize = 3;
139constexpr int thickScrollBarSize = 6;
141constexpr int tabBarTabRadius = 8;
142constexpr int tabBarTabFrameWidth = 2;
143constexpr int tabBarTabUnderLineWidth = 2;
145constexpr int groupBoxBottomPadding = 8;
146constexpr int groupBoxFrameCornerRadius = 8;
147constexpr int groupBoxHorizontalPadding = 12;
148constexpr int groupBoxTitleToContentSpacing = 8;
149constexpr int groupBoxTopPadding = 24;
151constexpr int comboBoxVerticalMargin = 4;
152constexpr int comboBoxFrameRadius = 8;
153constexpr int comboBoxFrameLeftRightPadding = 16;
154constexpr int comboBoxFocusFrameWidth = 2;
156constexpr int tabWidgetFrameWidth = 1;
158constexpr double ohos_id_alpha_disabled = 0.4;
159constexpr double ohos_id_alpha_content_tertiary = 0.4;
161QColor makeInactiveOrDisabledFromColor(
const QColor &color)
163 auto disabledColor = color;
164 disabledColor.setAlphaF(qBound(0.0, color.alphaF() * ohos_id_alpha_disabled, 1.0));
166 return disabledColor;
170bool qobjectIsInstanceOf(
const QObject *obj)
172 return qobject_cast<
const T *>(obj) !=
nullptr;
176bool qStyleOptionIs(
const QStyleOption *option)
178 return qstyleoption_cast<
const T *>(option) !=
nullptr;
181bool isItemViewSeparator(
const QModelIndex &index)
183 return index.data(Qt::AccessibleDescriptionRole).toString() == QLatin1String(
"separator");
186bool isFirstItem(
const QModelIndex &index)
188 return index.isValid() && index.row() == 0 && index.column() == 0;
191bool isLastItem(
const QModelIndex &index)
193 return index.isValid()
194 && index.row() == index.model()->rowCount(index.parent()) - 1
195 && index.column() == index.model()->columnCount(index.parent()) - 1;
198bool isHoverable(
const QWidget *widget)
200 static bool (*
const hoverTypeCheckFuncs[])(
const QObject *obj) = {
201 &qobjectIsInstanceOf<QCheckBox>,
202 &qobjectIsInstanceOf<QPushButton>,
203 &qobjectIsInstanceOf<QRadioButton>,
204 &qobjectIsInstanceOf<QSlider>,
205 &qobjectIsInstanceOf<QToolButton>,
206 &qobjectIsInstanceOf<QComboBox>,
207 &qobjectIsInstanceOf<QScrollBar>,
211 std::begin(hoverTypeCheckFuncs),
std::end(hoverTypeCheckFuncs),
212 [&](
const auto &typeCheckFunc) {
213 return typeCheckFunc(widget);
217QRect adjusted(
const QRect &rect,
int growth)
219 return rect.adjusted(-growth, -growth, growth, growth);
222QFont getGroupBoxTitleFont(
const QWidget *widget)
224 const bool widgetHasItsOwnFont = widget !=
nullptr && widget->testAttribute(Qt::WA_SetFont);
225 if (widgetHasItsOwnFont)
226 return widget->font();
228 const auto *themeFont =
229 QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::GroupBoxTitleFont);
230 return themeFont !=
nullptr ? *themeFont : QFont();
233QColor getSunkenOrHoverColor(
bool isSunken,
const QPalette &palette)
236 ? palette.color(QPalette::Active, QPalette::Dark)
237 : palette.color(QPalette::Active, QPalette::Light);
240void paintOnStackTop(QPainter &painter,
const std::function<
void(QPainter &painter)> &paint)
247void drawLine(QPainter &painter,
const QPen &pen,
const QPoint &aPoint,
const QPoint &bPoint)
249 paintOnStackTop(painter, [&](QPainter &painter) {
250 painter.setRenderHints(QPainter::Antialiasing);
252 painter.drawLine(aPoint, bPoint);
256void drawEllipse(QPainter &painter,
const QPen &pen,
const QBrush &brush,
const QRect &rect)
259 painter.setRenderHints(QPainter::Antialiasing);
261 painter.setBrush(brush);
262 painter.drawEllipse(rect);
266void drawRect(QPainter &painter,
const QPen &pen,
const QBrush &brush,
const QRect &rect)
268 paintOnStackTop(painter, [&](QPainter &painter) {
269 painter.setRenderHints(QPainter::Antialiasing);
271 painter.setBrush(brush);
272 painter.drawRect(rect);
277 QPainter &painter,
const QPen &pen,
const QBrush &brush,
const QRectF &rect, qreal xRadius, qreal yRadius)
279 paintOnStackTop(painter, [&](QPainter &painter) {
280 painter.setRenderHints(QPainter::Antialiasing);
282 painter.setBrush(brush);
283 painter.drawRoundedRect(rect, xRadius, yRadius);
287QPainterPath roundedPathInRect(
288 const QRectF &rect, qreal topLeftCornerRadius, qreal topRightCornerRadius, qreal bottomLeftCornerRadius,
289 qreal bottomRightCornerRadius)
293 const auto bottom = rect.y() + rect.height();
294 const auto right = rect.x() + rect.width();
296 const auto topLeftDiameter = 2 * topLeftCornerRadius;
297 path.moveTo(rect.x() + topLeftCornerRadius, rect.y());
298 path.arcTo(rect.x(), rect.y(), topLeftDiameter, topLeftDiameter, 90.0, 90.0);
300 const auto bottomLeftDiameter = 2 * bottomLeftCornerRadius;
301 path.lineTo(rect.x(), bottom - bottomLeftCornerRadius);
302 path.arcTo(rect.x(), bottom - bottomLeftDiameter, bottomLeftDiameter, bottomLeftDiameter, 180.0, 90.0);
304 const auto bottomRightDiameter = 2 * bottomRightCornerRadius;
305 path.lineTo(right - bottomRightCornerRadius, bottom);
307 right - bottomRightDiameter, bottom - bottomRightDiameter, bottomRightDiameter, bottomRightDiameter, 270.0,
310 const auto topRightDiameter = 2 * topRightCornerRadius;
311 path.lineTo(right, rect.y() + topRightCornerRadius);
312 path.arcTo(right - topRightDiameter, rect.y(), topRightDiameter, topRightDiameter, 360.0, 90.0);
319void drawPath(QPainter &painter,
const QPen &pen,
const QBrush &brush,
const QPainterPath& path)
321 paintOnStackTop(painter, [&](QPainter &painter) {
322 painter.setRenderHints(QPainter::Antialiasing);
324 painter.setBrush(brush);
325 painter.drawPath(path);
330 QPainter &painter,
const QPen &pen,
const QBrush brush,
const QRectF &rect, qreal topLeftCornerRadius,
331 qreal topRightCornerRadius, qreal bottomLeftCornerRadius, qreal bottomRightCornerRadius)
334 painter, pen, brush, roundedPathInRect(rect, topLeftCornerRadius, topRightCornerRadius, bottomLeftCornerRadius,
335 bottomRightCornerRadius));
339 QPainter &painter,
const QPen &pen,
const QBrush &brush,
const std::vector<QPointF> &polygonPoints)
341 paintOnStackTop(painter, [&](
auto &p) {
342 p.setRenderHint(QPainter::Antialiasing);
345 p.drawPolyline(polygonPoints.data(), polygonPoints.size());
349void drawCheckMark(QPainter &painter,
const QRectF &rect,
const QColor &color)
351 constexpr QPointF startFraction(0.25, 0.49);
352 constexpr QPointF middleFraction(0.44, 0.68);
353 constexpr QPointF endFraction(0.76, 0.33);
354 const auto pointInRect = [&rect](
const QPointF &fraction) {
356 rect.x() + rect.width() * fraction.x(), rect.y() + rect.height() * fraction.y());
358 const std::vector<QPointF> checkMarkPoints = {
359 pointInRect(startFraction), pointInRect(middleFraction), pointInRect(endFraction)};
360 const auto makeCheckMarkPen = [](
const QColor &penColor,
int width) {
361 return QPen(penColor, width, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
363 QColor shadowColor(Qt::black);
364 shadowColor.setAlphaF(checkBoxCheckMarkShadowOpacity);
368 shadowColor, checkBoxCheckMarkStrokeWidth + 2 * checkBoxCheckMarkShadowWidth),
369 Qt::NoBrush, checkMarkPoints);
371 painter, makeCheckMarkPen(color, checkBoxCheckMarkStrokeWidth), Qt::NoBrush,
375enum class ArrowDirection { Up, Down, Left, Right };
378 QPainter &painter,
const QRectF &boundingRect, qreal arrowSize, ArrowDirection direction,
381 const auto arrowWidth = 2;
382 const auto arrowCenter = boundingRect.center();
383 auto arrowRect = QRectF(0, 0, arrowSize, arrowSize * 0.5);
384 arrowRect.moveCenter(arrowCenter);
385 arrowRect.adjust(arrowWidth * 0.5, arrowWidth * 0.5, -arrowWidth * 0.5, -arrowWidth * 0.5);
387 const std::vector<QPointF> polygonPoints = {
388 QPointF(arrowRect.x(), arrowRect.y()),
389 QPointF(arrowRect.x() + arrowRect.width() * 0.5, arrowRect.y() + arrowRect.height()),
390 QPointF(arrowRect.x() + arrowRect.width(), arrowRect.y())
393 paintOnStackTop(painter, [&](
auto &p) {
394 p.translate(arrowCenter);
396 case ArrowDirection::Down:
398 case ArrowDirection::Up:
401 case ArrowDirection::Left:
404 case ArrowDirection::Right:
408 p.translate(-arrowCenter);
411 p, QPen(color, arrowWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), Qt::NoBrush,
416enum class ArrowSymbol {
424std::optional<
char32_t> tryGetArrowSymbolCodepoint(QOhosJsState &jsState,
const char *ohosSymbolName)
427 return jsState.eval<QNapi::Number>(
428 "@ohos.resourceManager.getSysResourceManager().getSymbolByName(*)",
429 {ohosSymbolName}).Uint32Value();
430 }
catch (
const Napi::Error &error) {
432 "%s: getSymbolByName('%s') failed: %s",
433 Q_FUNC_INFO, ohosSymbolName, error.what());
438QOhosMemoizingJsThreadFetcher<QHash<ArrowSymbol,
char32_t>> arrowSymbolCodepointsFetcher(
439 [](QOhosJsState &jsState) -> std::optional<QHash<ArrowSymbol,
char32_t>> {
440 constexpr std::pair<ArrowSymbol,
const char *> ohosSymbolNames[] = {
441 {ArrowSymbol::ChevronUp,
"chevron_up"},
442 {ArrowSymbol::ChevronDown,
"chevron_down"},
443 {ArrowSymbol::ChevronLeft,
"chevron_left"},
444 {ArrowSymbol::ChevronRight,
"chevron_right"},
445 {ArrowSymbol::TriangleDown,
"arrowtriangle_down_fill"},
448 QHash<ArrowSymbol,
char32_t> codepoints;
449 for (
const auto &[symbol, ohosSymbolName] : ohosSymbolNames) {
450 const auto optCodepoint = tryGetArrowSymbolCodepoint(jsState, ohosSymbolName);
452 codepoints.insert(symbol, *optCodepoint);
456 "HM Symbol arrow codepoints");
458QFont arrowSymbolFont()
460 QFont font(QStringLiteral(
"HM Symbol"));
461 font.setStyleStrategy(QFont::NoFontMerging);
462 font.setPixelSize(arrowSymbolSize);
466bool tryDrawArrowSymbol(
467 QPainter &painter, ArrowSymbol symbol,
const QRectF &boundingRect,
const QColor &color)
469 if (boundingRect.isEmpty())
472 const auto optCodepoints = arrowSymbolCodepointsFetcher.optValue();
476 const auto codepointIt = optCodepoints->constFind(symbol);
477 if (codepointIt == optCodepoints->cend())
480 const char32_t codepoint = *codepointIt;
481 const QFont symbolFont = arrowSymbolFont();
482 if (!QFontMetricsF(symbolFont).inFontUcs4(codepoint))
485 QPainterPath glyphPath;
486 glyphPath.addText(QPointF(), symbolFont, QString::fromUcs4(&codepoint, 1));
487 const QRectF inkRect = glyphPath.boundingRect();
488 if (inkRect.isEmpty())
491 const qreal scale =
std::min(
492 { 1.0, boundingRect.width() / inkRect.width(), boundingRect.height() / inkRect.height() });
493 paintOnStackTop(painter, [&](QPainter &painter) {
494 painter.setRenderHint(QPainter::Antialiasing);
495 painter.translate(boundingRect.center());
496 painter.scale(scale, scale);
497 painter.translate(-inkRect.center());
498 painter.fillPath(glyphPath, color);
503bool isDropDownArrow(
const QStyleOption *option,
const QWidget *widget)
505 if (qstyleoption_cast<
const QStyleOptionComboBox *>(option))
507 if (
const auto *buttonOption = qstyleoption_cast<
const QStyleOptionButton *>(option)) {
508 if (buttonOption->features.testFlag(QStyleOptionButton::HasMenu))
511 if (
const auto *toolButtonOption = qstyleoption_cast<
const QStyleOptionToolButton *>(option)) {
512 if (toolButtonOption->features.testFlag(QStyleOptionToolButton::HasMenu))
515 if (qobject_cast<
const QComboBox *>(widget))
517 if (
const auto *pushButton = qobject_cast<
const QPushButton *>(widget))
518 return pushButton->menu() !=
nullptr;
519 if (
const auto *toolButton = qobject_cast<
const QToolButton *>(widget))
520 return toolButton->arrowType() != Qt::DownArrow;
524ArrowSymbol chevronSymbol(ArrowDirection direction)
527 case ArrowDirection::Up:
528 return ArrowSymbol::ChevronUp;
529 case ArrowDirection::Down:
530 return ArrowSymbol::ChevronDown;
531 case ArrowDirection::Left:
532 return ArrowSymbol::ChevronLeft;
533 case ArrowDirection::Right:
534 return ArrowSymbol::ChevronRight;
536 Q_UNREACHABLE_RETURN(ArrowSymbol::ChevronDown);
539void drawCheckBoxOrRadioButtonIndicator(QPainter &painter,
const QStyleOption &option,
bool isCheckBox)
541 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
542 const auto isOn = option.state.testFlag(QStyle::State_On);
543 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
544 const auto isSunken = option.state.testFlag(QStyle::State_Sunken);
547 painter.setRenderHints(QPainter::Antialiasing);
549 painter.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
551 QRect hoverRect(0, 0, checkBoxOrRadioButtonHoverSize, checkBoxOrRadioButtonHoverSize);
552 hoverRect.moveCenter(option.rect.center());
553 if (isMouseOver || isSunken)
554 drawEllipse(painter, Qt::NoPen, getSunkenOrHoverColor(isSunken, option.palette), hoverRect);
556 QRect indicatorRect(0, 0, checkBoxOrRadioButtonIndicatorSize, checkBoxOrRadioButtonIndicatorSize);
557 indicatorRect.moveCenter(option.rect.center());
559 auto activeColor = option.palette.color(QPalette::Active, QPalette::Highlight);
562 drawEllipse(painter, Qt::NoPen, activeColor, indicatorRect);
563 painter.setOpacity(1.0);
565 painter, indicatorRect,
566 option.palette.color(QPalette::Active, QPalette::BrightText));
569 painter, QPen(activeColor, radioButtonIndicatorStrokeWidth), Qt::NoBrush,
570 adjusted(indicatorRect, -radioButtonIndicatorStrokeWidth / 2));
573 const auto outlineColor = option.palette.color(QPalette::Inactive, QPalette::Button);
574 const auto backgroundBrush = option.palette.brush(QPalette::Inactive, QPalette::Base);
575 const auto discRect = adjusted(indicatorRect, -checkBoxOrRadioButtonIndicatorStrokeWidth);
578 painter, QPen(outlineColor, checkBoxOrRadioButtonIndicatorStrokeWidth), backgroundBrush,
581 if (
const auto *themePalette = QGuiApplicationPrivate::platformTheme()->palette(
583 ? QPlatformTheme::Palette::CheckBoxPalette
584 : QPlatformTheme::Palette::RadioButtonPalette)) {
585 const auto overlayOutlineColor = themePalette->color(QPalette::Inactive, QPalette::Button);
586 const auto overlayBackgroundBrush = themePalette->brush(QPalette::Inactive, QPalette::Base);
588 const bool shouldPresentOverlayForOverriddenOutlineColor =
589 outlineColor != overlayOutlineColor;
590 const bool shouldPresentOverlayForOverriddenBackgroundBrush =
591 backgroundBrush != overlayBackgroundBrush;
593 if (shouldPresentOverlayForOverriddenOutlineColor
594 || shouldPresentOverlayForOverriddenBackgroundBrush) {
597 shouldPresentOverlayForOverriddenOutlineColor
598 ? QPen(overlayOutlineColor, checkBoxOrRadioButtonIndicatorStrokeWidth)
600 shouldPresentOverlayForOverriddenBackgroundBrush
601 ? overlayBackgroundBrush
602 : QBrush(Qt::NoBrush),
611void drawLineEditBackground(QPainter &painter,
const QStyleOption &option)
613 auto radius =
std::min(
614 std::min(option.rect.size().width(), option.rect.size().height()) * 0.5, lineEditCornerRadius);
616 const auto colorGroup = option.palette.currentColorGroup();
617 const auto baseBrush = option.palette.brush(colorGroup, QPalette::Base);
619 drawRoundedRect(painter, Qt::NoPen, baseBrush, option.rect, radius, radius);
621 if (
const auto *ohosThemePalette = QGuiApplicationPrivate::platformTheme()->palette(
622 QPlatformTheme::Palette::TextLineEditPalette)) {
623 const auto overlayBaseBrush = ohosThemePalette->brush(colorGroup, QPalette::Base);
624 const bool shouldPresentOverlayForOverriddenBaseBrush = baseBrush != overlayBaseBrush;
625 if (shouldPresentOverlayForOverriddenBaseBrush)
626 drawRoundedRect(painter, Qt::NoPen, overlayBaseBrush, option.rect, radius, radius);
630QColor getPushButtonOverlayFill(
bool isPressed,
const QStyleOptionButton &option)
632 const auto role = isPressed ? QPalette::Dark : QPalette::Light;
633 if (
const auto *themePalette =
634 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ButtonPalette))
635 return themePalette->color(QPalette::Active, role);
636 return option.palette.color(QPalette::Active, role);
639bool hasPushButtonAccentBackground(
const QStyleOptionButton &option)
641 const auto isDefaultButton = option.features.testFlag(QStyleOptionButton::DefaultButton);
642 const auto isAutoDefaultButton = option.features.testFlag(QStyleOptionButton::AutoDefaultButton);
643 const auto isOn = option.state.testFlag(QStyle::State_On);
645 return isDefaultButton || (isOn && isAutoDefaultButton);
648QBrush getPushButtonBackgroundBrush(
const QStyleOptionButton &option)
650 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
652 if (hasPushButtonAccentBackground(option)) {
653 const auto accentColor = option.palette.color(QPalette::Active, QPalette::AlternateBase);
654 return isEnabled ? accentColor : makeInactiveOrDisabledFromColor(accentColor);
657 if (option.state.testFlag(QStyle::State_On))
658 return getPushButtonOverlayFill(
true, option);
660 return option.palette.brush(
661 isEnabled ? QPalette::Active : QPalette::Inactive, QPalette::Button);
664std::optional<QBrush> getPushButtonFillOverlayBrush(
const QStyleOptionButton &option)
666 const auto isDefaultButton = option.features.testFlag(QStyleOptionButton::DefaultButton);
667 const auto isOn = option.state.testFlag(QStyle::State_On);
668 if (isDefaultButton || isOn)
671 const auto colorGroup = option.state.testFlag(QStyle::State_Enabled)
673 : QPalette::Inactive;
674 if (option.palette.isBrushSet(colorGroup, QPalette::Button))
677 if (
const auto *themePalette =
678 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ButtonPalette)) {
679 const auto themeBrush = themePalette->brush(colorGroup, QPalette::Button);
680 if (option.palette.brush(colorGroup, QPalette::Button) != themeBrush)
687QColor getPushButtonTextColor(
const QStyleOptionButton &option)
689 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
691 return hasPushButtonAccentBackground(option)
692 ? option.palette.color(QPalette::Active, QPalette::BrightText)
693 : option.palette.color(
696 : QPalette::Disabled,
697 QPalette::ButtonText);
700void drawPushButtonBackground(QPainter &painter,
const QStyleOptionButton &option)
702 paintOnStackTop(painter, [&](QPainter &painter) {
703 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
704 const auto isSunken = option.state.testFlag(QStyle::State_Sunken);
706 painter.setRenderHints(QPainter::Antialiasing);
707 painter.setPen(Qt::NoPen);
709 auto adjustment = pushButtonFocusFrameGap + pushButtonFocusFrameWidth;
710 auto rect = option.rect.adjusted(adjustment, adjustment, -adjustment, -adjustment);
712 painter.setBrush(getPushButtonBackgroundBrush(option));
713 painter.drawRoundedRect(rect, pushButtonCornerRadius, pushButtonCornerRadius);
715 const auto fillOverlayBrush = getPushButtonFillOverlayBrush(option);
716 if (fillOverlayBrush) {
717 painter.setBrush(*fillOverlayBrush);
718 painter.drawRoundedRect(rect, pushButtonCornerRadius, pushButtonCornerRadius);
721 if (isMouseOver || isSunken) {
722 painter.setBrush(getPushButtonOverlayFill(isSunken, option));
723 painter.drawRoundedRect(rect, pushButtonCornerRadius, pushButtonCornerRadius);
728void drawPushButtonFocus(QPainter &painter,
const QStyleOption &option)
730 paintOnStackTop(painter, [&](QPainter &painter) {
731 painter.setRenderHints(QPainter::Antialiasing);
732 painter.setBrush(Qt::NoBrush);
733 painter.setPen(QPen(option.palette.color(QPalette::Active, QPalette::Highlight), pushButtonFocusFrameWidth));
734 auto cornerRadius = pushButtonCornerRadius + pushButtonFocusFrameGap;
735 painter.drawRoundedRect(option.rect, cornerRadius, cornerRadius);
739QRect getProgressBarGrooveRect(
const QStyleOptionProgressBar &option)
741 auto rect = option.rect;
742 const bool horizontal = option.state & QStyle::State_Horizontal;
744 rect.setHeight(progressBarGrooveHeight);
745 rect.moveTop(option.rect.center().y());
747 rect.setWidth(progressBarGrooveHeight);
748 rect.moveRight(option.rect.center().x());
754void drawProgressBarContent(QPainter &painter,
const QStyleOptionProgressBar &option)
756 auto rect = getProgressBarGrooveRect(option);
757 const bool horizontal = option.state & QStyle::State_Horizontal;
759 const bool isIndeterminate = option.maximum == 0 && option.minimum == 0;
760 if (isIndeterminate) {
762 drawRoundedRect(painter, Qt::NoPen, option.palette.brush(QPalette::Highlight),
763 rect, progressBarCornerRadius, progressBarCornerRadius);
767 const qint64 totalSteps =
std::max(qint64(1), qint64(option.maximum) - option.minimum);
768 const double fraction =
static_cast<
double>(qint64(option.progress) - option.minimum)
769 /
static_cast<
double>(totalSteps);
772 rect.setWidth(fraction * rect.width());
773 rect.moveLeft(option.invertedAppearance ? option.rect.width() - rect.width() : 0);
775 rect.setHeight(fraction * rect.height());
776 rect.moveTop(option.invertedAppearance ? 0 : option.rect.height() - rect.height());
780 painter, Qt::NoPen, option.palette.brush(QPalette::Highlight), rect, progressBarCornerRadius,
781 progressBarCornerRadius);
784void drawSliderGroove(QPainter &painter,
const QStyleOptionSlider &option)
787 painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Mid),
788 option.rect, sliderCornerRadius, sliderCornerRadius);
791 if (option.orientation == Qt::Horizontal) {
792 const auto sliderPosition = QStyle::sliderPositionFromValue(
793 option.minimum, option.maximum, option.sliderPosition, option.rect.width(), option.upsideDown);
794 fillRect = QRect(option.rect.topLeft(), QSize(sliderPosition, option.rect.height()));
796 const auto sliderPosition = QStyle::sliderPositionFromValue(
797 option.minimum, option.maximum, option.sliderPosition, option.rect.height(), option.upsideDown);
799 option.rect.x(), option.rect.y() + sliderPosition, option.rect.width(), option.rect.height() - sliderPosition);
802 painter, Qt::NoPen, option.palette.brush(QPalette::Highlight), fillRect, sliderCornerRadius,
806void drawSliderThumb(QPainter &painter,
const QStyleOptionSlider &option)
808 QRect shadowRect(0, 0, shadowXSRadius, shadowXSRadius);
809 shadowRect.moveCenter(option.rect.center());
811 QRadialGradient radialGrad(shadowRect.center(), shadowXSRadius * 1.0);
812 radialGrad.setColorAt(0.0, Qt::transparent);
813 radialGrad.setColorAt(1.0, option.palette.color(QPalette::Active, QPalette::Shadow));
815 drawEllipse(painter, Qt::NoPen, QBrush(radialGrad), shadowRect);
817 if (option.state.testFlag(QStyle::State_MouseOver))
818 drawEllipse(painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Light), option.rect);
820 auto adjustedRect = option.rect.adjusted(sliderHoverSize, sliderHoverSize, -sliderHoverSize, -sliderHoverSize);
821 drawEllipse(painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::BrightText), adjustedRect);
823 if (option.state.testFlag(QStyle::State_Sunken)) {
824 const auto *buttonPalette =
825 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ButtonPalette);
826 const auto pressedColor = buttonPalette
827 ? buttonPalette->color(QPalette::Active, QPalette::Dark)
828 : option.palette.color(QPalette::Active, QPalette::Dark);
829 drawEllipse(painter, Qt::NoPen, pressedColor, adjustedRect);
832 if (option.state.testFlag(QStyle::State_HasFocus)) {
834 painter, QPen(option.palette.color(QPalette::Active, QPalette::Highlight), sliderFocusStrokeWidth),
835 Qt::NoBrush, adjusted(option.rect, -1));
839void drawToolButton(QPainter &painter,
const QStyleOption &option)
841 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
842 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
843 const auto isSunken = option.state.testFlag(QStyle::State_Sunken);
846 painter, Qt::NoPen, option.palette.brush(isEnabled ? QPalette::Active : QPalette::Disabled, QPalette::Button),
847 option.rect, toolButtonCornerRadius, toolButtonCornerRadius);
849 if (isMouseOver || isSunken) {
851 painter, Qt::NoPen, getSunkenOrHoverColor(isSunken, option.palette), option.rect, toolButtonCornerRadius,
852 toolButtonCornerRadius);
856void drawToolBarbackground(QPainter &painter,
const QStyleOption &option)
858 paintOnStackTop(painter, [&](QPainter &painter) {
859 painter.setRenderHints(QPainter::Antialiasing);
860 painter.fillRect(option.rect, option.palette.brush(QPalette::Active, QPalette::Window));
864void drawMenuBarBarbackground(QPainter &painter,
const QStyleOption &option)
866 paintOnStackTop(painter, [&](QPainter &painter) {
867 painter.setRenderHints(QPainter::Antialiasing);
868 painter.fillRect(option.rect, option.palette.brush(QPalette::Active, QPalette::Window));
872void drawListItemSeparator(QPainter &painter,
const QStyleOption &option)
874 QPoint center = option.rect.center();
876 painter, option.palette.color(QPalette::Active, QPalette::Mid),
877 QPoint(option.rect.left(), center.y()), QPoint(option.rect.right(), center.y()));
880void drawMenuItem(QPainter &painter,
const QStyleOptionMenuItem &option,
int checkMarkSize,
int iconSize)
882 const auto contentRect = option.rect.adjusted(itemViewItemHorizontalMargin, 0, -itemViewItemHorizontalMargin, 0);
883 if (option.menuItemType == QStyleOptionMenuItem::Separator) {
884 auto copyOption = option;
885 copyOption.rect = contentRect;
886 drawListItemSeparator(painter, copyOption);
888 const bool isSelected = option.state.testFlag(QStyle::State_Selected);
889 const bool isSunken = option.state.testFlag(QStyle::State_Sunken);
891 if (isSelected || isSunken) {
893 painter, Qt::NoPen, getSunkenOrHoverColor(isSunken, option.palette),
894 option.rect.adjusted(menuItemHoverHorizontalMargin, 0, -menuItemHoverHorizontalMargin, 0),
895 menuItemCornerRadius, menuItemCornerRadius);
898 const bool isCheckable = option.checkType != QStyleOptionMenuItem::NotCheckable;
901 checkMarkRect = contentRect;
902 checkMarkRect.setWidth(checkMarkSize);
904 auto copyOption = option;
905 copyOption.rect = checkMarkRect;
907 copyOption.state |= QStyle::State_On;
909 drawCheckBoxOrRadioButtonIndicator(painter, copyOption,
true);
912 const bool hasIcon = !option.icon.isNull();
915 iconRect = QRect(contentRect.x(), contentRect.center().y() - iconSize * 0.5, iconSize, iconSize);
916 iconRect.moveLeft(checkMarkRect.right() + itemViewItemHorizontalMargin);
919 &painter, iconRect, Qt::AlignCenter,
920 option.state.testFlag(QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
921 option.checked ? QIcon::On : QIcon::Off);
924 QRect textRect = contentRect;
926 textRect.setLeft(checkMarkRect.right() + itemViewItemHorizontalMargin);
928 textRect.setLeft(iconRect.right() + itemViewItemHorizontalMargin);
929 paintOnStackTop(painter, [&](QPainter &painter) {
930 painter.setPen(option.palette.color(QPalette::Text));
932 textRect, (Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic), option.text);
937void drawMenuTearOff(QPainter &painter,
const QStyleOption &option)
939 const auto pointY = option.rect.y() + option.rect.height() / 2;
941 painter, QPen(option.palette.color(QPalette::Text), 1, Qt::DashLine), QPoint(option.rect.x(), pointY),
942 QPoint(option.rect.x() + option.rect.width(), pointY)
946void drawSplitter(QPainter &painter,
const QStyleOption &option)
948 constexpr int splitterAvailableSizeDivider = 12;
949 const bool isHorizontal = option.state.testFlag(QStyle::State_Horizontal);
951 if (option.rect.width() > 1 && option.rect.height() > 1) {
952 const auto handleSize = isHorizontal
953 ? QSize(splitterHandleWidth, option.rect.height() / splitterAvailableSizeDivider)
954 : QSize(option.rect.width() / splitterAvailableSizeDivider, splitterHandleWidth);
955 const auto handleRect = QRect(
957 (option.rect.width() - handleSize.width()) * 0.5,
958 (option.rect.height() - handleSize.height()) * 0.5),
960 const auto cornerRadius =
std::min(handleSize.width(), handleSize.height()) * 0.5;
962 painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Mid),
963 handleRect, cornerRadius, cornerRadius);
965 auto endPoint = isHorizontal ? option.rect.bottomLeft() : option.rect.topRight();
966 drawLine(painter, option.palette.dark().color(), option.rect.topLeft(), endPoint);
970void drawSpinBoxFrame(
971 QPainter &painter,
const QStyleOptionSpinBox &option,
const QRect &frameRect,
int frameWidth)
973 auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
976 option.frame && option.subControls.testFlag(QStyle::SC_SpinBoxFrame)
977 ? QPen(option.palette.color(QPalette::Active, QPalette::Mid), frameWidth)
980 const qreal strokeInset = frameWidth / 2.0;
981 const QRectF strokeRect = QRectF(frameRect)
982 .adjusted(strokeInset, strokeInset, -strokeInset, -strokeInset);
984 paintOnStackTop(painter, [&](
auto &p) {
985 p.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
987 p, pen, option.palette.window(), strokeRect, spinBoxFrameRadius, spinBoxFrameRadius);
991void drawSpinBoxButton(QPainter &painter,
const QStyleOptionSpinBox &option,
int penWidth)
993 const bool isDownButton = option.subControls == QStyle::SC_SpinBoxDown;
994 const bool mirrored = option.direction == Qt::RightToLeft;
996 const qreal strokeInset = penWidth / 2.0;
997 const qreal outerLeftInset = mirrored ? strokeInset : 0.0;
998 const qreal outerRightInset = mirrored ? 0.0 : -strokeInset;
999 const QRectF rect = isDownButton
1000 ? QRectF(option.rect).adjusted(outerLeftInset, 0.0, outerRightInset, -strokeInset)
1001 : QRectF(option.rect).adjusted(outerLeftInset, strokeInset, outerRightInset, 0.0);
1003 auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
1004 auto isPressed = option.state.testFlag(QStyle::State_Sunken);
1006 QPen pen(option.palette.color(QPalette::Active, QPalette::Mid), penWidth);
1007 QBrush brush(option.palette.window());
1010 brush = QBrush(option.palette.highlight());
1012 const qreal topLeftRadius = (mirrored && !isDownButton) ? spinBoxFrameRadius : 0.0;
1013 const qreal topRightRadius = (!mirrored && !isDownButton) ? spinBoxFrameRadius : 0.0;
1014 const qreal bottomLeftRadius = (mirrored && isDownButton) ? spinBoxFrameRadius : 0.0;
1015 const qreal bottomRightRadius = (!mirrored && isDownButton) ? spinBoxFrameRadius : 0.0;
1017 paintOnStackTop(painter, [&](
auto &p) {
1018 p.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
1020 p, pen, brush, rect, topLeftRadius, topRightRadius, bottomLeftRadius, bottomRightRadius);
1024void drawScrollBarSlider(QPainter &painter,
const QStyleOptionSlider &option)
1026 int scrollBarRadius =
1027 option.orientation == Qt::Vertical
1028 ? option.rect.width() * 0.5
1029 : option.rect.height() * 0.5;
1031 paintOnStackTop(painter, [&](QPainter &painter) {
1032 painter.setOpacity(ohos_id_alpha_content_tertiary);
1034 painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Midlight),
1035 option.rect, scrollBarRadius, scrollBarRadius);
1039Qt::Orientation tabBarShapeToOrientation(QTabBar::Shape shape)
1042 case QTabBar::RoundedNorth:
1043 case QTabBar::RoundedSouth:
1044 case QTabBar::TriangularNorth:
1045 case QTabBar::TriangularSouth:
1046 return Qt::Horizontal;
1047 case QTabBar::RoundedWest:
1048 case QTabBar::TriangularWest:
1049 case QTabBar::RoundedEast:
1050 case QTabBar::TriangularEast:
1051 return Qt::Vertical;
1055void drawTabBarTabShape(QPainter &painter,
const QStyleOptionTab &option)
1057 auto isSelected = option.state.testFlag(QStyle::State_Selected);
1058 auto isFocused = option.state.testFlag(QStyle::State_HasFocus);
1059 QRect rect(option.rect);
1060 adjusted(rect, -tabBarTabFrameWidth - 1);
1062 QPoint underLineStart, underLineEnd;
1063 if (tabBarShapeToOrientation(option.shape) == Qt::Horizontal) {
1064 int lineY = rect.y() + rect.height() - tabBarTabUnderLineWidth;
1065 underLineStart = QPoint(rect.x() + tabBarTabRadius, lineY);
1066 underLineEnd = QPoint(rect.x() + rect.width() - tabBarTabRadius, lineY);
1068 int lineX = rect.x();
1070 if (option.shape == QTabBar::RoundedWest || option.shape == QTabBar::TriangularWest)
1071 lineX += rect.width() - tabBarTabUnderLineWidth;
1073 lineX += tabBarTabUnderLineWidth;
1075 underLineStart = QPoint(lineX, rect.y() + tabBarTabRadius);
1076 underLineEnd = QPoint(lineX, rect.y() + rect.height() - tabBarTabRadius);
1079 drawRoundedRect(painter, Qt::NoPen, option.palette.window(), rect, tabBarTabRadius, tabBarTabRadius);
1080 if (!isFocused && isSelected)
1081 drawLine(painter, QPen(option.palette.highlight(), tabBarTabUnderLineWidth), underLineStart, underLineEnd);
1084void drawComboBoxFrame(QPainter &painter,
const QStyleOptionComboBox &option)
1086 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
1087 const auto isOpened = option.state.testFlag(QStyle::State_On);
1088 const auto isFocused = option.state.testFlag(QStyle::State_HasFocus);
1090 auto focusedPen = QPen(
1091 option.palette.color(QPalette::Active, QPalette::AlternateBase),
1092 comboBoxFocusFrameWidth);
1094 const auto buttonBrush = option.palette.brush(QPalette::Button);
1096 painter, isFocused ? focusedPen : Qt::NoPen, buttonBrush, option.rect,
1097 comboBoxFrameRadius, comboBoxFrameRadius);
1099 const auto *ohosThemePalette =
1100 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ComboBoxPalette);
1101 const auto overlayButtonBrush = ohosThemePalette->brush(QPalette::Button);
1103 bool shouldPresentOverlayForOverriddenButtonBrush = buttonBrush != overlayButtonBrush;
1104 if (shouldPresentOverlayForOverriddenButtonBrush)
1106 painter, Qt::NoPen, overlayButtonBrush, option.rect, comboBoxFrameRadius, comboBoxFrameRadius);
1108 if (isMouseOver || isOpened) {
1109 auto pen = isOpened ? focusedPen : Qt::NoPen;
1110 auto brush = getSunkenOrHoverColor(isOpened, option.palette);
1111 drawRoundedRect(painter, pen, brush, option.rect, comboBoxFrameRadius, comboBoxFrameRadius);
1115void drawComboBoxListViewItem(QPainter &painter,
const QStyleOptionViewItem &option,
const QBrush &brush)
1117 if (isFirstItem(option.index)) {
1119 painter, Qt::NoPen, brush, option.rect, focusFrameCornerRadius, focusFrameCornerRadius, 0, 0);
1120 }
else if (isLastItem(option.index)) {
1122 painter, Qt::NoPen, brush, option.rect, 0, 0, focusFrameCornerRadius, focusFrameCornerRadius);
1124 drawRect(painter, Qt::NoPen, brush, option.rect);
1128void drawTreeViewHighlightItem(QPainter &painter,
const QStyleOptionViewItem &option,
const QBrush &brush)
1130 switch (option.viewItemPosition) {
1131 case QStyleOptionViewItem::OnlyOne:
1133 painter, Qt::NoPen, brush, option.rect, focusFrameCornerRadius, focusFrameCornerRadius);
1135 case QStyleOptionViewItem::Beginning:
1137 painter, Qt::NoPen, brush, option.rect, focusFrameCornerRadius, 0, focusFrameCornerRadius, 0);
1139 case QStyleOptionViewItem::Invalid:
1140 case QStyleOptionViewItem::Middle:
1141 drawRect(painter, Qt::NoPen, brush, option.rect);
1143 case QStyleOptionViewItem::End:
1145 painter, Qt::NoPen, brush, option.rect, 0, focusFrameCornerRadius, 0, focusFrameCornerRadius);
1150void drawPanelItemViewItem(QPainter &painter,
const QStyleOptionViewItem &option,
bool isComboBoxListViewItem)
1152 if (isItemViewSeparator(option.index)) {
1153 auto copyOption = option;
1154 copyOption.rect = option.rect.adjusted(itemViewItemHorizontalMargin, 0, -itemViewItemHorizontalMargin, 0);
1155 drawListItemSeparator(painter, copyOption);
1157 auto isSelected = option.state.testFlag(QStyle::State_Selected);
1158 auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
1160 auto colorGroup = option.state.testFlag(QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled;
1161 if (colorGroup == QPalette::Normal && !option.state.testFlag(QStyle::State_Active))
1162 colorGroup = QPalette::Inactive;
1164 const QBrush brush =
1166 ? option.palette.brush(colorGroup, QPalette::Highlight)
1168 ? option.palette.color(QPalette::Active, QPalette::Light)
1169 : option.backgroundBrush.style() == Qt::NoBrush
1171 : option.backgroundBrush;
1173 if (isComboBoxListViewItem)
1174 drawComboBoxListViewItem(painter, option, brush);
1176 drawTreeViewHighlightItem(painter, option, brush);
1180void drawHeaderSection(QPainter &painter,
const QStyleOptionHeader &option)
1183 option.position == QStyleOptionHeader::OnlyOneSection
1185 : option.orientation == Qt::Horizontal
1186 ? option.rect.adjusted(-1, 0, 0, 0)
1187 : option.rect.adjusted(0, -1, 0, 0);
1189 drawRect(painter, QPen(Qt::black), option.palette.brush(QPalette::Button), rect);
1192void drawWindowBackgroundAndFrame(
1193 QPainter &painter,
const QStyleOptionFrame &option, QFlags<Qt::WindowState> state,
int titleBarHeight)
1195 const auto offset = option.lineWidth * 0.5;
1196 const auto windowFrameColor =
1197 state.testFlag(Qt::WindowActive)
1198 ? option.palette.color(QPalette::Active, QPalette::Base)
1199 : option.palette.color(QPalette::Inactive, QPalette::Base);
1200 if (state.testFlag(Qt::WindowMinimized)) {
1202 painter, QPen(windowFrameColor, option.lineWidth), Qt::NoBrush,
1203 option.rect.adjusted(offset, offset, -offset, -offset), focusFrameCornerRadius, focusFrameCornerRadius, 0,
1206 painter, Qt::NoPen, option.palette.brush(QPalette::Window),
1207 option.rect.adjusted(option.lineWidth, titleBarHeight, -option.lineWidth, 0));
1210 painter, Qt::NoPen, windowFrameColor, option.rect.adjusted(0, titleBarHeight, 0, 0), 0, 0,
1211 focusFrameCornerRadius, focusFrameCornerRadius);
1213 painter, Qt::NoPen, option.palette.brush(QPalette::Window),
1214 option.rect.adjusted(option.lineWidth, titleBarHeight, -option.lineWidth, -option.lineWidth),
1215 focusFrameCornerRadius, focusFrameCornerRadius);
1217 painter, QPen(windowFrameColor, option.lineWidth), Qt::NoBrush,
1218 option.rect.adjusted(offset, offset, -offset, -offset), focusFrameCornerRadius, focusFrameCornerRadius);
1222void drawToolTip(QPainter &painter,
const QStyleOptionFrame &option)
1225 painter, option.palette.color(QPalette::Active, QPalette::Base),
1226 option.palette.toolTipBase(), option.rect, toolTipCornerRadius,
1227 toolTipCornerRadius);
1230QRect titleBarSubControlRect(
const QStyleOptionTitleBar &option, QCommonStyle::SubControl subControl)
1232 const bool isMinimized = (option.titleBarState & Qt::WindowMinimized) != 0;
1233 const bool isMaximized = (option.titleBarState & Qt::WindowMaximized) != 0;
1235 const bool hasTitle = option.titleBarFlags.testFlag(Qt::WindowTitleHint);
1236 const bool hasSystemMenuButton = option.titleBarFlags.testFlag(Qt::WindowSystemMenuHint);
1237 const bool hasShadeButton = option.titleBarFlags.testFlag(Qt::WindowShadeButtonHint);
1238 const bool hasContextHelpButton = option.titleBarFlags.testFlag(Qt::WindowContextHelpButtonHint);
1239 const bool hasMinimizeButton = option.titleBarFlags.testFlag(Qt::WindowMinimizeButtonHint);
1240 const bool hasMaximizeButton = option.titleBarFlags.testFlag(Qt::WindowMaximizeButtonHint);
1242 const auto controlSize = QSize(30, 30);
1243 const int titleBarHorizontalMargin = 25;
1244 const int titleBarControlVerticalMargin = 15;
1246 const auto titleBarContentRect = QRect(
1247 option.rect.x() + titleBarHorizontalMargin, (option.rect.height() - controlSize.height()) / 2,
1248 option.rect.width() - 2 * titleBarHorizontalMargin, controlSize.height());
1249 const auto titleBarContentRectRight = titleBarContentRect.x() + titleBarContentRect.width();
1250 const auto delta = controlSize.width() + titleBarControlVerticalMargin;
1253 switch (subControl) {
1254 case QCommonStyle::SC_TitleBarSysMenu:
1255 if (hasSystemMenuButton)
1256 result = QRect(titleBarContentRect.topLeft(), controlSize);
1258 case QCommonStyle::SC_TitleBarLabel:
1260 result = titleBarContentRect;
1261 if (hasSystemMenuButton)
1262 result.adjust(delta, 0, -delta, 0);
1263 if (hasMinimizeButton)
1264 result.adjust(0, 0, -delta, 0);
1265 if (hasMaximizeButton)
1266 result.adjust(0, 0, -delta, 0);
1268 result.adjust(0, 0, -delta, 0);
1269 if (hasContextHelpButton)
1270 result.adjust(0, 0, -delta, 0);
1273 case QCommonStyle::SC_TitleBarMaxButton:
1274 if (!isMaximized && hasMaximizeButton) {
1276 QPoint(titleBarContentRectRight - 3 * delta + titleBarControlVerticalMargin,
1277 titleBarContentRect.y()), controlSize);
1280 case QCommonStyle::SC_TitleBarNormalButton:
1281 if (isMinimized && hasMinimizeButton) {
1283 QPoint(titleBarContentRectRight - 2 * delta + titleBarControlVerticalMargin,
1284 titleBarContentRect.y()), controlSize);
1285 }
else if (isMaximized && hasMaximizeButton) {
1287 QPoint(titleBarContentRectRight - 3 * delta + titleBarControlVerticalMargin,
1288 titleBarContentRect.y()), controlSize);
1291 case QCommonStyle::SC_TitleBarMinButton:
1292 if (!isMinimized && hasMinimizeButton) {
1294 QPoint(titleBarContentRectRight - 2 * delta + titleBarControlVerticalMargin,
1295 titleBarContentRect.y()), controlSize);
1298 case QCommonStyle::SC_TitleBarCloseButton:
1300 QPoint(titleBarContentRectRight - controlSize.width(), titleBarContentRect.y()), controlSize);
1302 case QCommonStyle::SC_TitleBarShadeButton:
1303 case QCommonStyle::SC_TitleBarUnshadeButton:
1305 QPoint(titleBarContentRectRight - 4 * delta + titleBarControlVerticalMargin,
1306 titleBarContentRect.y()), controlSize);
1308 case QCommonStyle::SC_TitleBarContextHelpButton:
1310 QPoint(titleBarContentRectRight - (hasShadeButton ? 5 : 4) * delta + titleBarControlVerticalMargin,
1311 titleBarContentRect.y()), controlSize);
1322QOhosStyle::QOhosStyle()
1327void QOhosStyle::drawPrimitive(
1328 PrimitiveElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget)
const
1332 if (qobjectIsInstanceOf<QAbstractScrollArea>(widget)) {
1333 if (
const auto *frameOption = qstyleoption_cast<
const QStyleOptionFrame *>(option)) {
1334 const int frameWidth = frameOption->lineWidth;
1336 *painter, QPen(option->palette.color(QPalette::Active, QPalette::Mid), frameWidth), Qt::NoBrush,
1337 adjusted(frameOption->rect, -frameWidth));
1339 QCommonStyle::drawPrimitive(element, option, painter, widget);
1341 }
else if (widget && !qobjectIsInstanceOf<QComboBox>(widget->parent())) {
1342 QCommonStyle::drawPrimitive(element, option, painter, widget);
1346 case PE_FrameWindow:
1347 if (qStyleOptionIs<QStyleOptionFrame>(option)) {
1348 drawWindowBackgroundAndFrame(
1349 *painter, *qstyleoption_cast<
const QStyleOptionFrame *>(option), widget->windowState(),
1350 pixelMetric(PM_TitleBarHeight, option, widget));
1353 case PE_FrameFocusRect:
1354 if (qstyleoption_cast<
const QStyleOptionFocusRect *>(option)) {
1355 if (qobjectIsInstanceOf<QPushButton>(widget)) {
1356 drawPushButtonFocus(*painter, *option);
1357 }
else if (qobjectIsInstanceOf<QToolButton>(widget)) {
1358 const auto menuButtonIndicatorSize =
1359 qobject_cast<
const QToolButton *>(widget)->popupMode() == QToolButton::MenuButtonPopup
1360 ? pixelMetric(PM_MenuButtonIndicator, option, widget)
1364 QPen(option->palette.color(QPalette::Active, QPalette::Highlight), toolButtonFocusFrameWidth),
1365 Qt::NoBrush, option->rect.adjusted(-1, -1, 1 + menuButtonIndicatorSize, 1),
1366 toolButtonCornerRadius, toolButtonCornerRadius);
1367 }
else if (qobjectIsInstanceOf<QCheckBox>(widget) || qobjectIsInstanceOf<QRadioButton>(widget)) {
1369 *painter, QPen(option->palette.color(QPalette::Active, QPalette::Highlight),
1370 checkBoxOrRadioButtonFocusStrokeWidth), Qt::NoBrush, option->rect);
1371 }
else if (qobjectIsInstanceOf<QTabBar>(widget)) {
1373 *painter, QPen(option->palette.highlight(), tabBarTabFrameWidth), Qt::NoBrush,
1374 option->rect, tabBarTabRadius, tabBarTabRadius);
1377 *painter, QPen(option->palette.color(QPalette::Active, QPalette::Highlight), focusFrameWidth),
1378 Qt::NoBrush, option->rect, focusFrameCornerRadius, focusFrameCornerRadius);
1382 case PE_PanelButtonCommand:
1383 if (qStyleOptionIs<QStyleOptionButton>(option))
1384 drawPushButtonBackground(*painter, *qstyleoption_cast<
const QStyleOptionButton *>(option));
1386 case PE_PanelButtonTool:
1387 if (qobjectIsInstanceOf<QMdiSubWindow>(widget)) {
1388 const QPalette *toolButtonThemePalette =
1389 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ToolButtonPalette);
1390 const auto panelButtonColor =
1391 toolButtonThemePalette->color(QPalette::Active, QPalette::AlternateBase);
1393 *painter, Qt::NoPen,
1394 widget->windowState().testFlag(Qt::WindowActive)
1396 : makeInactiveOrDisabledFromColor(panelButtonColor),
1399 const QToolButton *toolButton = qobject_cast<
const QToolButton *>(widget);
1400 const auto menuButtonIndicatorSize =
1401 toolButton !=
nullptr && toolButton->popupMode() == QToolButton::MenuButtonPopup
1402 ? pixelMetric(PM_MenuButtonIndicator, option, widget)
1404 auto optionCopy = *option;
1405 if (option->direction == Qt::RightToLeft)
1406 optionCopy.rect.setLeft(option->rect.left() - menuButtonIndicatorSize);
1408 optionCopy.rect.setWidth(option->rect.width() + menuButtonIndicatorSize);
1409 drawToolButton(*painter, optionCopy);
1412 case PE_PanelMenuBar:
1413 drawMenuBarBarbackground(*painter, *option);
1415 case PE_IndicatorCheckBox:
1416 drawCheckBoxOrRadioButtonIndicator(*painter, *option,
true);
1418 case PE_IndicatorRadioButton:
1419 drawCheckBoxOrRadioButtonIndicator(*painter, *option,
false);
1421 case PE_PanelLineEdit: {
1424 if (widget !=
nullptr && qobjectIsInstanceOf<QAbstractSpinBox>(widget->parentWidget()))
1431 if (widget !=
nullptr && qobjectIsInstanceOf<QComboBox>(widget->parentWidget()))
1437 auto optionCopy = *option;
1438 if (widget !=
nullptr && qstrcmp(widget->metaObject()->className(),
"QExpandingLineEdit") == 0) {
1439 optionCopy.palette.setColor(
1441 option->palette.color(QPalette::Active, QPalette::AlternateBase));
1444 drawLineEditBackground(*painter, optionCopy);
1447 case PE_PanelButtonBevel:
1448 if (qStyleOptionIs<QStyleOptionSpinBox>(option)) {
1450 *painter, *qstyleoption_cast<
const QStyleOptionSpinBox *>(option),
1451 pixelMetric(PM_SpinBoxFrameWidth, option, widget));
1454 case PE_IndicatorSpinDown:
1455 case PE_IndicatorSpinUp: {
1458 QRect indicatorRect = option->rect.adjusted(1, 2, 0, -2);
1459 constexpr int arrowWidth = 2;
1460 auto x = indicatorRect.x();
1461 auto y = indicatorRect.y();
1462 auto width = indicatorRect.width();
1463 auto height = indicatorRect.height();
1464 auto verticalSpacing = 4;
1465 auto horizontalSpacing = 7;
1467 qreal x1 = x + horizontalSpacing;
1468 qreal x2 = x + width * 0.5;
1469 qreal x3 = x + width - horizontalSpacing;
1472 if (element == PE_IndicatorSpinDown) {
1473 y1 = y + verticalSpacing;
1474 y2 = y + height - verticalSpacing;
1476 y1 = y + height - verticalSpacing;
1477 y2 = y + verticalSpacing;
1481 QPen indicatorPen(option->palette.color(QPalette::Active, QPalette::Text), arrowWidth);
1482 indicatorPen.setCapStyle(Qt::RoundCap);
1483 indicatorPen.setJoinStyle(Qt::RoundJoin);
1485 paintOnStackTop(*painter, [&](
auto &p) {
1486 p.setOpacity(option->state.testFlag(State_Enabled) ? 1.0 : ohos_id_alpha_disabled);
1487 p.setRenderHint(QPainter::Antialiasing);
1488 p.setPen(indicatorPen);
1489 p.setBrush(Qt::NoBrush);
1490 p.drawLine(x1, y1, x2, y2);
1491 p.drawLine(x2, y2, x3, y3);
1495 case PE_FrameGroupBox: {
1496 const auto frame = qstyleoption_cast<
const QStyleOptionFrame *>(option);
1497 if (frame !=
nullptr) {
1499 pen.setColor(option->palette.mid().color());
1501 frame->features.testFlag(QStyleOptionFrame::FrameFeature::Flat)
1502 ? Qt::NoPen : Qt::SolidLine);
1504 painter->setClipRegion(frame->rect);
1506 *painter, pen, option->palette.window(), frame->rect, groupBoxFrameCornerRadius,
1507 groupBoxFrameCornerRadius);
1511 case PE_IndicatorArrowUp:
1512 case PE_IndicatorArrowDown:
1513 case PE_IndicatorArrowLeft:
1514 case PE_IndicatorArrowRight: {
1515 const QRect availableRect = option->rect;
1516 int maxArrowSize = 0;
1517 if (qobjectIsInstanceOf<QComboBox>(widget)) {
1518 maxArrowSize = std::min(availableRect.width(), availableRect.height()) * 0.5;
1519 }
else if (qobjectIsInstanceOf<QToolButton>(widget) || qobjectIsInstanceOf<QPushButton>(widget)) {
1520 const auto menuButtonIndicatorSize = pixelMetric(PM_MenuButtonIndicator, option, widget);
1521 maxArrowSize = std::min(menuButtonIndicatorSize, widget->size().height()) * 0.5;
1523 maxArrowSize = std::min(availableRect.width(), availableRect.height());
1526 auto direction = ArrowDirection::Down;
1529 case PE_IndicatorArrowDown:
1531 case PE_IndicatorArrowUp:
1532 direction = ArrowDirection::Up;
1534 case PE_IndicatorArrowLeft:
1535 direction = ArrowDirection::Left;
1537 case PE_IndicatorArrowRight:
1538 direction = ArrowDirection::Right;
1542 const auto isEnabled = option->state.testFlag(QStyle::State_Enabled);
1544 direction == ArrowDirection::Down && isDropDownArrow(option, widget)
1545 ? ArrowSymbol::TriangleDown
1546 : chevronSymbol(direction);
1548 paintOnStackTop(*painter, [&](
auto &p) {
1549 p.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
1550 const auto arrowColor = option->palette.color(QPalette::Active, QPalette::WindowText);
1551 if (!tryDrawArrowSymbol(p, symbol, availableRect, arrowColor))
1552 drawArrow(p, availableRect, maxArrowSize, direction, arrowColor);
1556 case PE_IndicatorButtonDropDown: {
1557 if (qobjectIsInstanceOf<QToolButton>(widget))
1559 QCommonStyle::drawPrimitive(element, option, painter, widget);
1562 case PE_IndicatorHeaderArrow: {
1563 const auto headerOption = qstyleoption_cast<
const QStyleOptionHeader *>(option);
1564 if (headerOption ==
nullptr || headerOption->sortIndicator == QStyleOptionHeader::None)
1567 const auto direction = headerOption->sortIndicator == QStyleOptionHeader::SortDown
1568 ? ArrowDirection::Up
1569 : ArrowDirection::Down;
1571 const auto arrowColor = option->palette.color(QPalette::Active, QPalette::ButtonText);
1572 if (!tryDrawArrowSymbol(*painter, chevronSymbol(direction), option->rect, arrowColor))
1573 drawArrow(*painter, option->rect, option->rect.width(), direction, arrowColor);
1576 case PE_PanelItemViewItem:
1577 if (qStyleOptionIs<QStyleOptionViewItem>(option)) {
1578 drawPanelItemViewItem(
1579 *painter, *qstyleoption_cast<
const QStyleOptionViewItem *>(option),
1580 widget !=
nullptr && qstrcmp(widget->metaObject()->className(),
"QComboBoxListView") == 0);
1583 case PE_FrameTabWidget:
1584 if (qStyleOptionIs<QStyleOptionTabWidgetFrame>(option)) {
1585 QRect rect = option->rect;
1587 switch (qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(option)->shape) {
1588 case QTabBar::RoundedNorth:
1589 case QTabBar::TriangularNorth:
1590 rect.adjust(0, tabWidgetFrameWidth, 0, 0);
1592 case QTabBar::RoundedWest:
1593 case QTabBar::TriangularWest:
1594 rect.adjust(tabWidgetFrameWidth, 0, 0, 0);
1596 case QTabBar::RoundedSouth:
1597 case QTabBar::TriangularSouth:
1598 rect.adjust(0, 0, 0, -(tabWidgetFrameWidth * 2));
1600 case QTabBar::RoundedEast:
1601 case QTabBar::TriangularEast:
1602 rect.adjust(0, 0, -(tabWidgetFrameWidth * 2), 0);
1607 *painter, QPen(option->palette.color(QPalette::Dark), tabWidgetFrameWidth),
1611 case PE_PanelTipLabel:
1612 if (qStyleOptionIs<QStyleOptionFrame>(option))
1613 drawToolTip(*painter, *qstyleoption_cast<
const QStyleOptionFrame *>(option));
1616 QCommonStyle::drawPrimitive(element, option, painter, widget);
1621void QOhosStyle::drawControl(
1622 ControlElement element,
const QStyleOption *option, QPainter *painter,
const QWidget *widget)
const
1625 case CE_HeaderSection:
1626 if (qStyleOptionIs<QStyleOptionHeader>(option))
1627 drawHeaderSection(*painter, *qstyleoption_cast<
const QStyleOptionHeader *>(option));
1629 case CE_MenuBarEmptyArea:
1632 if (qStyleOptionIs<QStyleOptionMenuItem>(option)) {
1633 const auto *menuItemStyleOption = qstyleoption_cast<
const QStyleOptionMenuItem *>(option);
1635 *painter, *menuItemStyleOption, pixelMetric(PM_IndicatorWidth, option, widget),
1636 pixelMetric(PM_SmallIconSize, option, widget));
1637 if (menuItemStyleOption->menuItemType == QStyleOptionMenuItem::SubMenu) {
1638 const auto iconSize = pixelMetric(PM_SmallIconSize, option, widget);
1639 const auto menuItemRect = menuItemStyleOption->rect;
1641 QStyleOptionMenuItem menuArrowStyleOption = *menuItemStyleOption;
1642 menuArrowStyleOption.rect = QRect(
1643 menuItemRect.right() - itemViewItemHorizontalMargin - iconSize,
1644 menuItemRect.top() + (menuItemRect.height() - iconSize) / 2, iconSize, iconSize);
1645 QColor arrowColor = menuItemStyleOption->palette.color(QPalette::Active, QPalette::Text);
1646 menuArrowStyleOption.palette.setColor(
1647 QPalette::Active, QPalette::WindowText, arrowColor);
1649 menuArrowStyleOption.direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight,
1650 &menuArrowStyleOption, painter, widget);
1654 case CE_MenuTearoff:
1655 drawMenuTearOff(*painter, *option);
1657 case CE_ProgressBarGroove:
1658 if (qstyleoption_cast<
const QStyleOptionProgressBar *>(option)) {
1660 *painter, Qt::NoPen, option->palette.color(QPalette::Active, QPalette::Mid),
1661 getProgressBarGrooveRect(*qstyleoption_cast<
const QStyleOptionProgressBar *>(option)),
1662 progressBarCornerRadius, progressBarCornerRadius);
1665 case CE_ProgressBarContents:
1666 if (qstyleoption_cast<
const QStyleOptionProgressBar *>(option))
1667 drawProgressBarContent(*painter, *qstyleoption_cast<
const QStyleOptionProgressBar *>(option));
1669 case CE_ProgressBarLabel:
1672 drawSplitter(*painter, *option);
1675 drawToolBarbackground(*painter, *option);
1677 case CE_ScrollBarSlider:
1678 if (qStyleOptionIs<QStyleOptionSlider>(option))
1679 drawScrollBarSlider(*painter, *qstyleoption_cast<
const QStyleOptionSlider *>(option));
1681 case CE_TabBarTabShape: {
1682 auto tabOption = qstyleoption_cast<
const QStyleOptionTab *>(option);
1683 if (tabOption !=
nullptr)
1684 drawTabBarTabShape(*painter, *tabOption);
1687 case CE_TabBarTabLabel: {
1688 auto tabOption = qstyleoption_cast<
const QStyleOptionTab *>(option);
1689 if (tabOption !=
nullptr) {
1690 auto copy = *tabOption;
1691 if (!option->state.testFlag(State_Selected))
1692 copy.palette.setCurrentColorGroup(QPalette::Inactive);
1693 QCommonStyle::drawControl(element, ©, painter, widget);
1697 case CE_PushButtonLabel: {
1698 if (qStyleOptionIs<QStyleOptionButton>(option)) {
1699 auto buttonOption = qstyleoption_cast<
const QStyleOptionButton *>(option);
1701 auto buttonOptionCopy = *buttonOption;
1702 buttonOptionCopy.palette.setColor(QPalette::ButtonText, getPushButtonTextColor(*buttonOption));
1704 QCommonStyle::drawControl(element, &buttonOptionCopy, painter, widget);
1708 case CE_DockWidgetTitle: {
1709 const auto *dockWidgetOption = qstyleoption_cast<
const QStyleOptionDockWidget *>(option);
1710 if (dockWidgetOption ==
nullptr)
1712 auto dockWidgetOptionCopy = *dockWidgetOption;
1713 if (!dockWidgetOptionCopy.title.isEmpty()) {
1714 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
1715 if (dockWidgetOptionCopy.verticalTitleBar) {
1716 QRect rect = dockWidgetOptionCopy.rect;
1717 QRect verticalRect = rect.transposed();
1719 verticalRect.left() + rect.bottom() - titleRect.bottom(),
1720 verticalRect.top() + titleRect.left() - rect.left(),
1724 dockWidgetOptionCopy.title = painter->fontMetrics().elidedText(
1725 dockWidgetOptionCopy.title, Qt::ElideRight, titleRect.width());
1727 QCommonStyle::drawControl(element, &dockWidgetOptionCopy, painter, widget);
1731 QCommonStyle::drawControl(element, option, painter, widget);
1735void QOhosStyle::drawComplexControl(
1736 ComplexControl control,
const QStyleOptionComplex *option, QPainter *painter,
const QWidget *widget)
const
1740 const auto sliderStyleOption = qstyleoption_cast<
const QStyleOptionSlider *>(option);
1741 if (sliderStyleOption !=
nullptr) {
1742 if (option->subControls.testFlag(SC_SliderGroove)) {
1743 auto sliderStyleOptionCopy = *sliderStyleOption;
1744 sliderStyleOptionCopy.rect = subControlRect(control, option, SC_SliderGroove, widget);
1745 drawSliderGroove(*painter, sliderStyleOptionCopy);
1747 if (option->subControls.testFlag(SC_SliderHandle)) {
1748 auto sliderStyleOptionCopy = *sliderStyleOption;
1749 sliderStyleOptionCopy.rect = subControlRect(control, option, SC_SliderHandle, widget);
1750 drawSliderThumb(*painter, sliderStyleOptionCopy);
1756 if (qStyleOptionIs<QStyleOptionSpinBox>(option)) {
1757 auto spinBox = qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
1758 auto frameRect = subControlRect(control, spinBox, SC_SpinBoxFrame, widget);
1759 auto frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spinBox, widget);
1760 drawSpinBoxFrame(*painter, *spinBox, frameRect, frameWidth);
1762 auto copy = *spinBox;
1765 QCommonStyle::drawComplexControl(control, ©, painter, widget);
1768 case CC_ScrollBar: {
1769 const auto scrollBarStyleOption = qstyleoption_cast<
const QStyleOptionSlider *>(option);
1770 if (scrollBarStyleOption !=
nullptr) {
1771 if (option->subControls.testFlag(SC_ScrollBarSlider)) {
1772 auto scrollBarStyleOptionCopy = *scrollBarStyleOption;
1773 scrollBarStyleOptionCopy.rect = subControlRect(control, option, SC_ScrollBarSlider, widget);
1774 drawControl(CE_ScrollBarSlider, &scrollBarStyleOptionCopy, painter, widget);
1780 if (qStyleOptionIs<QStyleOptionGroupBox>(option)) {
1781 auto groupBox = *qstyleoption_cast<
const QStyleOptionGroupBox *>(option);
1782 groupBox.textAlignment |= Qt::AlignVCenter;
1784 const auto colorGroup = option->state.testFlag(QStyle::State_Enabled)
1786 : QPalette::Disabled;
1787 if (!groupBox.palette.isBrushSet(colorGroup, QPalette::WindowText))
1788 groupBox.textColor = groupBox.palette.color(QPalette::Text);
1790 const auto titleFont = getGroupBoxTitleFont(widget);
1791 painter->setFont(titleFont);
1793 QCommonStyle::drawComplexControl(control, &groupBox, painter, widget);
1798 if (qStyleOptionIs<QStyleOptionComboBox>(option)) {
1799 const auto comboBoxStyleOption = qstyleoption_cast<
const QStyleOptionComboBox *>(option);
1800 if (option->subControls.testFlag(SC_ComboBoxFrame)) {
1801 auto comboBoxStyleOptionCopy = *comboBoxStyleOption;
1802 comboBoxStyleOptionCopy.rect = subControlRect(control, option, SC_ComboBoxFrame, widget);
1803 drawComboBoxFrame(*painter, comboBoxStyleOptionCopy);
1806 if (option->subControls.testFlag(SC_ComboBoxArrow)) {
1807 auto optionCopy = *comboBoxStyleOption;
1808 auto comboBoxOptions =
static_cast<QStyleOption *>(&optionCopy);
1809 comboBoxOptions->rect = subControlRect(control, option, SC_ComboBoxArrow, widget);
1810 drawPrimitive(PE_IndicatorArrowDown, comboBoxOptions, painter, widget);
1813 QCommonStyle::drawComplexControl(control, option, painter, widget);
1818 QCommonStyle::drawComplexControl(control, option, painter, widget);
1822QRect QOhosStyle::subControlRect(
1823 ComplexControl control,
const QStyleOptionComplex *option, SubControl subControl,
const QWidget *widget)
const
1827 if (qStyleOptionIs<QStyleOptionSlider>(option)) {
1828 const auto sliderStyleOption = qstyleoption_cast<
const QStyleOptionSlider *>(option);
1829 switch (subControl) {
1830 case SC_SliderGroove: {
1831 const auto sliderLengthOffset = pixelMetric(PM_SliderLength, option, widget) * 0.5;
1832 auto grooveRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1834 if (sliderStyleOption->orientation == Qt::Horizontal) {
1835 grooveRect.adjust(sliderLengthOffset, 0, -sliderLengthOffset, 0);
1836 grooveRect.setHeight(sliderGrooveHeight);
1837 grooveRect.moveTop(option->rect.center().y() - sliderGrooveHeight * 0.5);
1839 grooveRect.adjust(0, sliderLengthOffset, 0, -sliderLengthOffset);
1840 grooveRect.setWidth(sliderGrooveHeight);
1841 grooveRect.moveLeft(option->rect.center().x() - sliderGrooveHeight * 0.5);
1846 case SC_SliderHandle: {
1847 auto handleRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1848 if (sliderStyleOption->orientation == Qt::Horizontal)
1849 handleRect.moveTop(option->rect.center().y() - handleRect.height() * 0.5);
1851 handleRect.moveLeft(option->rect.center().x() - handleRect.width() * 0.5);
1855 return QCommonStyle::subControlRect(control, option, subControl, widget);
1858 return QCommonStyle::subControlRect(control, option, subControl, widget);
1861 if (qStyleOptionIs<QStyleOptionSpinBox>(option)) {
1862 const auto spinBox = qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
1863 auto frameWidth = spinBox->frame ? pixelMetric(PM_SpinBoxFrameWidth, option, widget) : 0;
1865 switch (subControl) {
1866 case SC_SpinBoxFrame: {
1867 auto frameRect = spinBox->rect;
1868 frameRect.setHeight(spinBoxFrameHeight);
1869 frameRect.moveCenter(spinBox->rect.center());
1870 return visualRect(spinBox->direction, spinBox->rect, frameRect);
1872 case SC_SpinBoxDown:
1873 case SC_SpinBoxUp: {
1874 auto frameRect = subControlRect(CC_SpinBox, option, SC_SpinBoxFrame, widget);
1875 if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
1877 auto buttonRect = QRect(
1878 frameRect.left() + frameRect.width() - spinBoxButtonBoxWidth,
1879 frameRect.top() + (frameRect.height() - spinBoxFrameHeight) * 0.5,
1880 spinBoxButtonBoxWidth, spinBoxButtonBoxHeight);
1881 if (subControl == SC_SpinBoxDown)
1882 buttonRect.translate(0, spinBoxButtonBoxHeight);
1883 return visualRect(spinBox->direction, frameRect, buttonRect);
1885 case SC_SpinBoxEditField: {
1886 auto editRect = adjusted(spinBox->rect, -frameWidth);
1887 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
1888 editRect.setWidth(spinBox->rect.width() - frameWidth - spinBoxButtonBoxWidth);
1889 editRect = visualRect(spinBox->direction, spinBox->rect, editRect);
1894 return QCommonStyle::subControlRect(control, option, subControl, widget);
1897 return QCommonStyle::subControlRect(control, option, subControl, widget);
1900 if (qStyleOptionIs<QStyleOptionSlider>(option)) {
1901 auto scrollBoxStyleOption = qstyleoption_cast<
const QStyleOptionSlider *>(option);
1902 auto defaultUpButtonRect = QCommonStyle::subControlRect(control, option, SC_ScrollBarSubLine, widget);
1903 auto defaultDownButtonRect = QCommonStyle::subControlRect(control, option, SC_ScrollBarAddLine, widget);
1904 switch (subControl) {
1905 case SC_ScrollBarAddLine:
1906 case SC_ScrollBarSubLine:
1908 case SC_ScrollBarSubPage: {
1909 auto subPageRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1910 if (scrollBoxStyleOption->orientation == Qt::Vertical)
1911 subPageRect.moveTop(subPageRect.top() - defaultDownButtonRect.height());
1913 subPageRect.moveLeft(subPageRect.left() - defaultDownButtonRect.width());
1916 case SC_ScrollBarAddPage: {
1917 auto addPageRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1918 if (scrollBoxStyleOption->orientation == Qt::Vertical)
1919 addPageRect.moveTop(addPageRect.top() + defaultUpButtonRect.height());
1921 addPageRect.moveLeft(addPageRect.left() + defaultUpButtonRect.width());
1924 case SC_ScrollBarSlider: {
1925 const bool activeScrollBar =
1926 option->state.testFlag(QCommonStyle::State_Enabled)
1927 && option->state.testFlag(QCommonStyle::State_MouseOver);
1928 auto scrollBarExtent = activeScrollBar ? thickScrollBarSize : thinScrollBarSize;
1930 auto sliderRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1931 if (scrollBoxStyleOption->orientation == Qt::Vertical) {
1932 sliderRect.setWidth(scrollBarExtent);
1933 sliderRect.setHeight(sliderRect.height() + defaultUpButtonRect.height() + defaultDownButtonRect.height());
1934 sliderRect.moveTop(sliderRect.top() - defaultUpButtonRect.height());
1935 sliderRect.moveLeft((option->rect.width() - sliderRect.width()) * 0.5);
1937 sliderRect.setHeight(scrollBarExtent);
1938 sliderRect.setWidth(sliderRect.width() + defaultUpButtonRect.width() + defaultDownButtonRect.width());
1939 sliderRect.moveTop((option->rect.height() - sliderRect.height()) * 0.5);
1940 sliderRect.moveLeft(sliderRect.left() - defaultUpButtonRect.width());
1945 return QCommonStyle::subControlRect(control, option, subControl, widget);
1948 return QCommonStyle::subControlRect(control, option, subControl, widget);
1951 if (qStyleOptionIs<QStyleOptionGroupBox>(option)) {
1952 auto groupBox = *qstyleoption_cast<
const QStyleOptionGroupBox *>(option);
1953 groupBox.fontMetrics = QFontMetrics(getGroupBoxTitleFont(widget));
1956 QCommonStyle::subControlRect(control, &groupBox, SC_GroupBoxLabel, widget);
1957 if (groupBox.text.isEmpty()) {
1958 labelRect.moveTop(groupBox.rect.top() + groupBoxTopPadding);
1959 labelRect.moveBottom(labelRect.top());
1962 groupBox.rect.top() + groupBoxTopPadding + groupBox.fontMetrics.height() / 2);
1965 switch (subControl) {
1966 case SC_GroupBoxFrame:
1967 return QCommonStyle::subControlRect(control, &groupBox, subControl, widget);
1968 case SC_GroupBoxLabel: {
1971 case SC_GroupBoxCheckBox: {
1973 QCommonStyle::subControlRect(control, &groupBox, subControl, widget);
1974 checkBoxRect.moveTop(labelRect.center().y() - checkBoxRect.height() / 2);
1975 return checkBoxRect;
1977 case SC_GroupBoxContents: {
1979 QCommonStyle::subControlRect(control, &groupBox, SC_GroupBoxContents, widget);
1980 contentsRect.setTop(labelRect.bottom() + (groupBox.text.isEmpty() ? 0 : groupBoxTitleToContentSpacing));
1981 contentsRect.setBottom(groupBox.rect.bottom() - groupBoxBottomPadding);
1982 contentsRect.adjust(groupBoxHorizontalPadding, 0, -groupBoxHorizontalPadding, 0);
1983 return contentsRect;
1986 return QCommonStyle::subControlRect(control, option, subControl, widget);
1989 return QCommonStyle::subControlRect(control, option, subControl, widget);
1992 if (qStyleOptionIs<QStyleOptionComboBox>(option)) {
1993 auto comboBoxStyleOption = qstyleoption_cast<
const QStyleOptionComboBox *>(option);
1994 const auto arrowSize = pixelMetric(PM_MenuButtonIndicator, option, widget);
1995 switch (subControl) {
1996 case SC_ComboBoxFrame: {
1997 return adjusted(comboBoxStyleOption->rect, -comboBoxFocusFrameWidth);;
1999 case SC_ComboBoxEditField: {
2000 const auto editFieldRect = comboBoxStyleOption->rect.adjusted(
2001 comboBoxFrameLeftRightPadding, comboBoxVerticalMargin,
2002 -arrowSize - comboBoxFrameLeftRightPadding, -comboBoxVerticalMargin);
2003 return visualRect(comboBoxStyleOption->direction, comboBoxStyleOption->rect, editFieldRect);
2005 case SC_ComboBoxArrow: {
2006 auto arrowIconRect = comboBoxStyleOption->rect;
2007 arrowIconRect.setWidth(arrowSize);
2008 arrowIconRect.moveRight(comboBoxStyleOption->rect.right() - comboBoxFrameLeftRightPadding);
2009 return visualRect(comboBoxStyleOption->direction, comboBoxStyleOption->rect, arrowIconRect);
2012 return QCommonStyle::subControlRect(control, option, subControl, widget);
2015 return QCommonStyle::subControlRect(control, option, subControl, widget);
2018 if (qStyleOptionIs<QStyleOptionTitleBar>(option)) {
2019 auto titleBarOption = qstyleoption_cast<
const QStyleOptionTitleBar *>(option);
2021 titleBarOption->direction, titleBarOption->rect, titleBarSubControlRect(*titleBarOption, subControl));
2023 return QCommonStyle::subControlRect(control, option, subControl, widget);
2026 return QCommonStyle::subControlRect(control, option, subControl, widget);
2030QRect QOhosStyle::subElementRect(SubElement element,
const QStyleOption *option,
const QWidget *widget)
const
2033 case SE_PushButtonContents:
2034 return option->rect.adjusted(pushButtonHorizontalMargin, 0, -pushButtonHorizontalMargin, 0);
2035 case SE_ItemViewItemFocusRect:
2036 return option->rect.adjusted(focusFrameWidth, focusFrameWidth, -focusFrameWidth, -focusFrameWidth);
2037 case SE_ProgressBarGroove:
2038 case SE_ProgressBarContents:
2039 return option->rect;
2040 case SE_ProgressBarLabel:
2042 case SE_LineEditContents: {
2043 int horizontalMargin =
2044 widget !=
nullptr && qobjectIsInstanceOf<QAbstractSpinBox>(widget->parent())
2045 ? spinBoxEditHorizontalMargin
2046 : lineEditHorizontalMargin;
2047 return option->rect.adjusted(horizontalMargin, 0, -horizontalMargin, 0);
2049 case SE_CheckBoxFocusRect:
2050 case SE_RadioButtonFocusRect:
2052 checkBoxOrRadioButtonFocusStrokeWidth, (option->rect.height() - checkBoxOrRadioButtonHoverSize) * 0.5,
2053 checkBoxOrRadioButtonHoverSize, checkBoxOrRadioButtonHoverSize);
2054 case SE_CheckBoxClickRect:
2055 return subElementRect(SE_CheckBoxIndicator, option, widget)
2056 | subElementRect(SE_CheckBoxContents, option, widget);
2057 case SE_RadioButtonClickRect:
2058 return subElementRect(SE_RadioButtonIndicator, option, widget)
2059 | subElementRect(SE_RadioButtonContents, option, widget);
2061 return QCommonStyle::subElementRect(element, option, widget);;
2065QSize QOhosStyle::sizeFromContents(
2066 ContentsType contents,
const QStyleOption *option,
const QSize &contentsSize,
const QWidget *widget)
const
2069 case CT_ItemViewItem: {
2070 const auto viewItemStyleOption = qstyleoption_cast<
const QStyleOptionViewItem *>(option);
2071 if (viewItemStyleOption !=
nullptr) {
2072 if (isItemViewSeparator(viewItemStyleOption->index)) {
2073 return QSize(option->rect.width(), itemViewSeparatorHeight);
2075 auto verticalMargin = viewItemStyleOption->features.testFlag(QStyleOptionViewItem::HasDecoration)
2076 ? itemViewItemWithDecorationVerticalMargin
2077 : itemViewItemVerticalMargin;
2078 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget)
2079 + QSize(0, 2 * verticalMargin);
2082 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
2085 case CT_PushButton: {
2086 auto sizeAlignment = (2 * pushButtonFocusFrameGap) + (2 * pushButtonFocusFrameWidth);
2087 return contentsSize + QSize(
2088 (pushButtonHorizontalMargin * 2) + sizeAlignment, (pushButtonVerticalMargin * 2) + sizeAlignment);
2091 const auto arrowSize = pixelMetric(PM_MenuButtonIndicator, option, widget);
2092 auto comboBoxSize = qStyleOptionIs<QStyleOptionComboBox>(option)
2093 && qstyleoption_cast<
const QStyleOptionComboBox *>(option)->editable
2094 ? contentsSize + QSize(2 * lineEditHorizontalMargin, 0)
2096 const auto frameWidthCompensation = 2 * comboBoxFocusFrameWidth;
2097 comboBoxSize.rwidth() += (arrowSize + frameWidthCompensation + 2 * comboBoxFrameLeftRightPadding);
2098 comboBoxSize.rheight() += (frameWidthCompensation + 2 * comboBoxVerticalMargin + 2 * lineEditVerticalMargin);
2099 return comboBoxSize;
2101 case CT_ProgressBar: {
2102 const auto progressBarStyleOption = qstyleoption_cast<
const QStyleOptionProgressBar *>(option);
2103 if (progressBarStyleOption !=
nullptr) {
2104 const bool horizontal = progressBarStyleOption->state & QStyle::State_Horizontal;
2106 return QSize(contentsSize.width(), std::max(contentsSize.height(), progressBarMinHeight));
2108 return QSize(std::max(contentsSize.height(), progressBarMinHeight), contentsSize.height());
2110 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
2114 const auto defaultSize = QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
2115 const auto *menuItemStyleOption = qstyleoption_cast<
const QStyleOptionMenuItem *>(option);
2116 if (menuItemStyleOption !=
nullptr) {
2117 if (menuItemStyleOption->menuItemType == QStyleOptionMenuItem::Separator) {
2118 return QSize(defaultSize.width(), itemViewSeparatorHeight);
2120 const auto menuVMargin = pixelMetric(PM_MenuVMargin, option, widget);
2121 const auto arrowWidth = menuItemStyleOption->menuItemType == QStyleOptionMenuItem::SubMenu
2122 ? menuVMargin + pixelMetric(PM_SmallIconSize, option, widget)
2124 const auto checkboxWidth = menuItemStyleOption->checkType != QStyleOptionMenuItem::NotCheckable
2125 ? menuVMargin + pixelMetric(PM_IndicatorWidth, option, widget)
2129 + QSize(2 * itemViewItemHorizontalMargin, 2 * menuVMargin)
2130 + QSize(arrowWidth, 0)
2131 + QSize(checkboxWidth, 0);
2138 const auto groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(option);
2139 if (groupBox ==
nullptr)
2140 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
2142 const QFontMetrics titleMetrics(getGroupBoxTitleFont(widget));
2144 titleMetrics.horizontalAdvance(groupBox->text) + titleMetrics.horizontalAdvance(u' '),
2145 titleMetrics.height());
2146 if (groupBox->subControls.testFlag(SC_GroupBoxCheckBox)) {
2147 titleSize.rwidth() += pixelMetric(PM_IndicatorWidth, option, widget)
2148 + pixelMetric(PM_CheckBoxLabelSpacing, option, widget);
2149 titleSize.rheight() =
2150 std::max(titleSize.height(), pixelMetric(PM_IndicatorHeight, option, widget));
2153 return QCommonStyle::sizeFromContents(contents, option, titleSize, widget);
2156 int horizontalMargin;
2157 if (widget !=
nullptr && qobjectIsInstanceOf<QAbstractSpinBox>(widget->parent()))
2158 horizontalMargin = spinBoxEditHorizontalMargin;
2160 horizontalMargin = lineEditHorizontalMargin;
2161 return contentsSize + QSize(horizontalMargin * 2, lineEditVerticalMargin * 2);
2164 const auto spinBox = qstyleoption_cast<
const QStyleOptionSpinBox *>(option);
2165 if (spinBox !=
nullptr) {
2167 if (spinBox->subControls.testFlag(QStyle::SC_SpinBoxUp)
2168 && spinBox->subControls.testFlag(QStyle::SC_SpinBoxDown)) {
2169 buttonWidth = subControlRect(CC_SpinBox, spinBox, SC_SpinBoxDown, widget).width();
2173 const int frameWidth
2174 = spinBox->frame ? pixelMetric(PM_SpinBoxFrameWidth, option, widget) : 0;
2176 return QSize(contentsSize.width() + buttonWidth + 2 * frameWidth + spinBoxEditHorizontalMargin * 2,
2177 std::max(contentsSize.height() + 2 * frameWidth, spinBoxFrameHeight));
2180 return contentsSize;
2183 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
2187int QOhosStyle::pixelMetric(PixelMetric metric,
const QStyleOption *option,
const QWidget *widget)
const
2190 case PM_ButtonMargin:
2191 case PM_ButtonDefaultIndicator:
2192 case PM_ButtonShiftHorizontal:
2193 case PM_ButtonShiftVertical:
2195 case PM_IndicatorWidth:
2196 case PM_ExclusiveIndicatorWidth:
2197 return checkBoxOrRadioButtonSize;
2198 case PM_IndicatorHeight:
2199 case PM_ExclusiveIndicatorHeight:
2200 return checkBoxOrRadioButtonSize;
2201 case PM_FocusFrameHMargin:
2202 return qStyleOptionIs<QStyleOptionViewItem>(option)
2203 ? itemViewItemSpacing
2204 : QCommonStyle::pixelMetric(metric, option, widget);
2205 case PM_TextCursorWidth:
2206 return textCursorWidth;
2207 case PM_DefaultFrameWidth:
2208 if (qobjectIsInstanceOf<QLineEdit>(widget) || qobjectIsInstanceOf<QPushButton>(widget))
2211 return QCommonStyle::pixelMetric(metric, option, widget);
2212 case PM_MenuBarPanelWidth:
2214 case PM_MenuBarItemSpacing:
2215 return menuBarItemSpacing;
2216 case PM_MenuBarVMargin:
2217 return menuBarVerticalMargin;
2218 case PM_MenuBarHMargin:
2219 return menuBarHorizontalMargin;
2220 case PM_MenuPanelWidth:
2222 case PM_MenuHMargin:
2224 case PM_MenuVMargin:
2225 return menuItemVerticalMargin;
2226 case PM_ProgressBarChunkWidth:
2228 case PM_SliderThickness:
2229 return sliderThickness;
2230 case PM_SliderLength:
2231 case PM_SliderControlThickness:
2232 return sliderThumbSize + 2 * sliderHoverSize;
2233 case PM_SmallIconSize:
2234 return qStyleOptionIs<QStyleOptionMenuItem>(option) || qStyleOptionIs<QStyleOptionComboBox>(option)
2236 : QCommonStyle::pixelMetric(metric, option, widget);
2237 case PM_SplitterWidth:
2238 return splitterWidth;
2239 case PM_SpinBoxFrameWidth:
2240 return spinBoxFrameStroke;
2241 case PM_ScrollBarExtent:
2242 return maxScrollBarSize;
2243 case PM_TabBarTabShiftVertical:
2244 case PM_TabBarBaseOverlap:
2246 case PM_TabBarTabHSpace:
2247 return 2 * tabBarTabRadius + 2 * tabBarTabFrameWidth;
2248 case PM_TitleBarHeight:
2249 return titleBarHeight;
2250 case PM_HeaderDefaultSectionSizeVertical:
2251 return headerDefaultSectionSizeVertical;
2252 case PM_ToolTipLabelFrameWidth:
2253 return toolTipFrameWidth;
2254 case PM_MenuButtonIndicator: {
2255 const auto *toolButtonOption = qstyleoption_cast<
const QStyleOptionToolButton *>(option);
2256 const bool isToolButtonCornerIndicator = toolButtonOption !=
nullptr
2257 && toolButtonOption->features.testFlag(QStyleOptionToolButton::HasMenu)
2258 && !toolButtonOption->features.testFlag(QStyleOptionToolButton::MenuButtonPopup);
2259 if (isToolButtonCornerIndicator)
2260 return QCommonStyle::pixelMetric(metric, option, widget);
2261 return 2 * QCommonStyle::pixelMetric(metric, option, widget);
2264 return QCommonStyle::pixelMetric(metric, option, widget);
2268int QOhosStyle::styleHint(
2269 StyleHint hint,
const QStyleOption *option,
const QWidget *widget, QStyleHintReturn *hintReturn)
const
2272 case SH_Slider_AbsoluteSetButtons:
2273 return Qt::LeftButton | Qt::MiddleButton;
2274 case SH_Slider_PageSetButtons:
2276 case SH_ItemView_ShowDecorationSelected:
2277 return qobjectIsInstanceOf<QTreeView>(widget) ? 0 : 1;
2278 case SH_ToolTipLabel_Opacity:
2279 return toolTipBackgroundAlpha;
2280 case SH_Menu_MouseTracking:
2281 case SH_MenuBar_MouseTracking:
2284 return QCommonStyle::styleHint(hint, option, widget, hintReturn);
2288void QOhosStyle::polish(QWidget *widget)
2290 QCommonStyle::polish(widget);
2292 if (isHoverable(widget))
2293 widget->setAttribute(Qt::WA_Hover);
2295 if (qobjectIsInstanceOf<QPushButton>(widget)) {
2296 if (qobject_cast<QPushButton *>(widget)->isDefault()) {
2297 QPalette palette = widget->palette();
2298 auto textDisabledColor = palette.color(QPalette::Active, QPalette::Base);
2299 textDisabledColor.setAlphaF(ohos_id_alpha_disabled);
2300 palette.setColor(QPalette::All, QPalette::ButtonText, palette.color(QPalette::Active, QPalette::Base));
2301 palette.setColor(QPalette::Disabled, QPalette::ButtonText, textDisabledColor);
2302 widget->setPalette(palette);
2304 }
else if (qobjectIsInstanceOf<QScrollBar>(widget)) {
2305 widget->setAttribute(Qt::WA_NoSystemBackground);
2306 widget->setAttribute(Qt::WA_OpaquePaintEvent,
false);
2307 }
else if (qobjectIsInstanceOf<QListView>(widget)) {
2308 qobject_cast<QListView *>(widget)->viewport()->setAttribute(Qt::WA_Hover);
2309 }
else if (qobjectIsInstanceOf<QComboBox>(widget)) {
2310 auto comboBox = qobject_cast<QComboBox *>(widget);
2311 const char *delegateClassName = comboBox->itemDelegate()->metaObject()->className();
2312 bool isDefaultComboBoxDelegate =
2313 qstrcmp(delegateClassName,
"QComboBoxDelegate") == 0
2314 || qstrcmp(delegateClassName,
"QComboMenuDelegate") == 0;
2315 if (isDefaultComboBoxDelegate)
2316 comboBox->setItemDelegate(
new QStyledItemDelegate(comboBox->view()));
2317 }
else if (qobjectIsInstanceOf<QMdiSubWindow>(widget)) {
2318 widget->setAttribute(Qt::WA_TranslucentBackground);
2319 widget->setAutoFillBackground(
false);
2321 auto palette = widget->palette();
2322 palette.setColor(QPalette::Highlight, palette.color(QPalette::Active, QPalette::Base));
2323 palette.setColor(QPalette::Inactive, QPalette::Dark, palette.color(QPalette::Inactive, QPalette::Base));
2325 QPalette::Inactive, QPalette::Window,
2326 makeInactiveOrDisabledFromColor(palette.color(QPalette::Active, QPalette::AlternateBase)));
2327 palette.setColor(QPalette::HighlightedText, Qt::black);
2328 widget->setPalette(palette);
2332void QOhosStyle::unpolish(QWidget *widget)
2334 if (isHoverable(widget)) {
2335 widget->setAttribute(Qt::WA_Hover,
false);
2336 }
else if (qobjectIsInstanceOf<QScrollBar>(widget)) {
2337 widget->setAttribute(Qt::WA_NoSystemBackground,
false);
2338 widget->setAttribute(Qt::WA_OpaquePaintEvent);
2339 }
else if (qobjectIsInstanceOf<QListView>(widget)) {
2340 qobject_cast<QListView *>(widget)->viewport()->setAttribute(Qt::WA_Hover,
false);
2342 QCommonStyle::unpolish(widget);
2345QPalette QOhosStyle::standardPalette()
const
2347 return *QGuiApplicationPrivate::platformTheme()->palette();
2350QIcon QOhosStyle::standardIcon(
2351 StandardPixmap standardPixmap,
const QStyleOption *option,
const QWidget *widget)
const
2353 const QString iconName = ohosThemeIconName(standardPixmap);
2354 if (!iconName.isEmpty()) {
2355 const QIcon icon = QIcon::fromTheme(iconName);
2360 return QCommonStyle::standardIcon(standardPixmap, option, widget);