Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qohosstyle.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qohosstyle_p.h"
5#include <QtGui/qicon.h>
6#include <QtGui/qpainter.h>
7#include <QtGui/qpainterpath.h>
8#include <QtWidgets/qcheckbox.h>
9#include <QtWidgets/qcombobox.h>
10#include <QtWidgets/qlineedit.h>
11#include <QtWidgets/qlistview.h>
12#include <QtWidgets/qmdisubwindow.h>
13#include <QtWidgets/qpushbutton.h>
14#include <QtWidgets/qradiobutton.h>
15#include <QtWidgets/qscrollbar.h>
16#include <QtWidgets/qspinbox.h>
17#include <QtWidgets/qstyleditemdelegate.h>
18#include <QtWidgets/qstyleoption.h>
19#include <QtWidgets/qtoolbutton.h>
20#include <QtWidgets/qtreeview.h>
21#include "qpa/qplatformtheme.h"
22#include "private/qguiapplication_p.h"
23#include "private/qstylehelper_p.h"
24#include <algorithm>
25
26namespace {
27
28// Map a standard pixmap to the XDG icon-theme name that QAbstractFileIconProvider
29// uses for the same QFileIconProvider type, so the widgets path resolves through the
30// platform theme's icon engine exactly as the gui path does.
31QString ohosThemeIconName(QStyle::StandardPixmap standardPixmap)
32{
33 switch (standardPixmap) {
34 case QStyle::SP_ComputerIcon: return QStringLiteral("computer");
35 case QStyle::SP_DesktopIcon: return QStringLiteral("user-desktop");
36 case QStyle::SP_TrashIcon: return QStringLiteral("user-trash");
37 case QStyle::SP_DriveNetIcon: return QStringLiteral("network-workgroup");
38 case QStyle::SP_DriveHDIcon: return QStringLiteral("drive-harddisk");
39 case QStyle::SP_DirClosedIcon: return QStringLiteral("folder");
40 case QStyle::SP_DirIcon: return QStringLiteral("folder");
41 case QStyle::SP_FileIcon: return QStringLiteral("text-x-generic");
42 default: break;
43 }
44
45 return QString();
46}
47
48constexpr int checkBoxOrRadioButtonIndicatorSize = 24;
49constexpr int checkBoxOrRadioButtonIndicatorStrokeWidth = 1;
50constexpr int checkBoxOrRadioButtonIndicatorGap = 2;
51constexpr int checkBoxOrRadioButtonHoverSize =
52 checkBoxOrRadioButtonIndicatorSize + (2 * checkBoxOrRadioButtonIndicatorGap);
53constexpr int checkBoxOrRadioButtonFocusStrokeWidth = 2;
54constexpr int checkBoxOrRadioButtonSize =
55 checkBoxOrRadioButtonIndicatorSize + (2 * checkBoxOrRadioButtonIndicatorGap)
56 + (2 * checkBoxOrRadioButtonFocusStrokeWidth);
57constexpr int radioButtonIndicatorStrokeWidth = 6;
58
59constexpr int textCursorWidth = 1;
60
61constexpr int itemViewItemHorizontalMargin = 16;
62constexpr int itemViewItemVerticalMargin = 8;
63constexpr int itemViewItemWithDecorationVerticalMargin = 10;
64constexpr int itemViewItemSpacing = 8;
65constexpr int itemViewSeparatorHeight = 5;
66
67constexpr int focusFrameWidth = 2;
68constexpr int focusFrameCornerRadius = 16;
69
70constexpr int headerMargin = 16;
71constexpr int headerDefaultSectionSizeVertical = 48;
72
73constexpr double lineEditCornerRadius = 32.0;
74constexpr int lineEditHorizontalMargin = 16;
75constexpr int lineEditVerticalMargin = 9;
76
77constexpr int menuBarItemSpacing = 16;
78constexpr int menuBarVerticalMargin = 8;
79constexpr int menuBarHorizontalMargin = 8;
80
81constexpr int menuItemVerticalMargin = 8;
82constexpr int menuItemCornerRadius = 4;
83constexpr int menuItemHoverHorizontalMargin = 4;
84
85constexpr int pushButtonHorizontalMargin = 16;
86constexpr int pushButtonVerticalMargin = 8;
87constexpr int pushButtonCornerRadius = 8;
88constexpr int pushButtonFocusFrameGap = 2;
89constexpr int pushButtonFocusFrameWidth = 2;
90
91constexpr int progressBarMinHeight = 24;
92constexpr int progressBarGrooveHeight = 4;
93constexpr int progressBarCornerRadius = 2;
94
95constexpr int shadowXSRadius = 22;
96
97constexpr int sliderThickness = 40;
98constexpr int sliderGrooveHeight = 4;
99constexpr int sliderCornerRadius = 2;
100constexpr int sliderThumbSize = 16;
101constexpr int sliderHoverSize = 4;
102constexpr int sliderFocusStrokeWidth = 2;
103
104constexpr int smallIconSize = 12;
105
106constexpr int splitterHandleWidth = 6;
107constexpr int splitterWidth = 12;
108
109constexpr int titleBarHeight = 46;
110
111constexpr int toolButtonCornerRadius = 4;
112constexpr int toolButtonFocusFrameWidth = 2;
113
114constexpr int toolTipCornerRadius = 8;
115constexpr int toolTipFrameWidth = 8;
116constexpr int toolTipBackgroundAlpha = 204;
117
118constexpr int spinBoxFrameHeight = 32;
119constexpr int spinBoxButtonBoxWidth = 32;
120constexpr int spinBoxButtonBoxHeight = 16;
121constexpr int spinBoxEditHorizontalMargin = 4;
122constexpr double spinBoxFrameRadius = 12.0;
123constexpr int spinBoxFrameStroke = 2;
124
125constexpr int maxScrollBarSize = 9;
126constexpr int thinScrollBarSize = 3;
127constexpr int thickScrollBarSize = 6;
128
129constexpr int tabBarTabRadius = 8;
130constexpr int tabBarTabFrameWidth = 2;
131constexpr int tabBarTabUnderLineWidth = 2;
132
133constexpr int groupBoxBottomPadding = 8;
134constexpr int groupBoxFrameCornerRadius = 8;
135constexpr int groupBoxHorizontalPadding = 12;
136constexpr int groupBoxTitleToContentSpacing = 8;
137constexpr int groupBoxTopPadding = 24;
138
139constexpr int comboBoxVerticalMargin = 4;
140constexpr int comboBoxFrameRadius = 8;
141constexpr int comboBoxFrameLeftRightPadding = 16;
142constexpr int comboBoxFocusFrameWidth = 2;
143
144constexpr int tabWidgetFrameWidth = 1;
145
146constexpr double ohos_id_alpha_disabled = 0.4;
147constexpr double ohos_id_alpha_content_tertiary = 0.4;
148
149QColor makeInactiveOrDisabledFromColor(const QColor &color)
150{
151 auto disabledColor = color;
152 disabledColor.setAlphaF(ohos_id_alpha_disabled);
153
154 return disabledColor;
155}
156
157template<typename T>
158bool qobjectIsInstanceOf(const QObject *obj)
159{
160 return qobject_cast<const T *>(obj) != nullptr;
161}
162
163template<typename T>
164bool qStyleOptionIs(const QStyleOption *option)
165{
166 return qstyleoption_cast<const T *>(option) != nullptr;
167}
168
169bool isItemViewSeparator(const QModelIndex &index)
170{
171 return index.data(Qt::AccessibleDescriptionRole).toString() == QLatin1String("separator");
172}
173
174bool isFirstItem(const QModelIndex &index)
175{
176 return index.isValid() && index.row() == 0 && index.column() == 0;
177}
178
179bool isLastItem(const QModelIndex &index)
180{
181 return index.isValid()
182 && index.row() == index.model()->rowCount(index.parent()) - 1
183 && index.column() == index.model()->columnCount(index.parent()) - 1;
184}
185
186bool isHoverable(const QWidget *widget)
187{
188 static bool (* const hoverTypeCheckFuncs[])(const QObject *obj) = {
189 &qobjectIsInstanceOf<QCheckBox>,
190 &qobjectIsInstanceOf<QPushButton>,
191 &qobjectIsInstanceOf<QRadioButton>,
192 &qobjectIsInstanceOf<QSlider>,
193 &qobjectIsInstanceOf<QToolButton>,
194 &qobjectIsInstanceOf<QComboBox>,
195 &qobjectIsInstanceOf<QScrollBar>,
196 };
197
198 return std::any_of(
199 std::begin(hoverTypeCheckFuncs), std::end(hoverTypeCheckFuncs),
200 [&](const auto &typeCheckFunc) {
201 return typeCheckFunc(widget);
202 });
203}
204
205QRect adjusted(const QRect &rect, int growth)
206{
207 return rect.adjusted(-growth, -growth, growth, growth);
208}
209
210QFont getGroupBoxTitleFont(const QWidget *widget)
211{
212 const bool widgetHasItsOwnFont = widget != nullptr && widget->testAttribute(Qt::WA_SetFont);
213 if (widgetHasItsOwnFont)
214 return widget->font();
215
216 const auto *themeFont =
217 QGuiApplicationPrivate::platformTheme()->font(QPlatformTheme::GroupBoxTitleFont);
218 return themeFont != nullptr ? *themeFont : QFont();
219}
220
221QColor getSunkenOrHoverColor(bool isSunken, const QPalette &palette)
222{
223 return isSunken
224 ? palette.color(QPalette::Active, QPalette::Dark)
225 : palette.color(QPalette::Active, QPalette::Light);
226}
227
228void paintOnStackTop(QPainter &painter, const std::function<void(QPainter &painter)> &paint)
229{
230 painter.save();
231 paint(painter);
232 painter.restore();
233}
234
235void drawLine(QPainter &painter, const QPen &pen, const QPoint &aPoint, const QPoint &bPoint)
236{
237 paintOnStackTop(painter, [&](QPainter &painter) {
238 painter.setRenderHints(QPainter::Antialiasing);
239 painter.setPen(pen);
240 painter.drawLine(aPoint, bPoint);
241 });
242}
243
244void drawEllipse(QPainter &painter, const QPen &pen, const QBrush &brush, const QRect &rect)
245{
246 painter.save();
247 painter.setRenderHints(QPainter::Antialiasing);
248 painter.setPen(pen);
249 painter.setBrush(brush);
250 painter.drawEllipse(rect);
251 painter.restore();
252}
253
254void drawRect(QPainter &painter, const QPen &pen, const QBrush &brush, const QRect &rect)
255{
256 paintOnStackTop(painter, [&](QPainter &painter) {
257 painter.setRenderHints(QPainter::Antialiasing);
258 painter.setPen(pen);
259 painter.setBrush(brush);
260 painter.drawRect(rect);
261 });
262}
263
264void drawRoundedRect(
265 QPainter &painter, const QPen &pen, const QBrush &brush, const QRect &rect, qreal xRadius, qreal yRadius)
266{
267 paintOnStackTop(painter, [&](QPainter &painter) {
268 painter.setRenderHints(QPainter::Antialiasing);
269 painter.setPen(pen);
270 painter.setBrush(brush);
271 painter.drawRoundedRect(rect, xRadius, yRadius);
272 });
273}
274
275QPainterPath roundedPathInRect(
276 const QRect &rect, qreal topLeftCornerRadius, qreal topRightCornerRadius, qreal bottomLeftCornerRadius,
277 qreal bottomRightCornerRadius)
278{
279 QPainterPath path;
280
281 const auto bottom = rect.y() + rect.height();
282 const auto right = rect.x() + rect.width();
283
284 const auto topLeftDiameter = 2 * topLeftCornerRadius;
285 path.moveTo(rect.x() + topLeftCornerRadius, rect.y());
286 path.arcTo(rect.x(), rect.y(), topLeftDiameter, topLeftDiameter, 90.0, 90.0);
287
288 const auto bottomLeftDiameter = 2 * bottomLeftCornerRadius;
289 path.lineTo(rect.x(), bottom - bottomLeftCornerRadius);
290 path.arcTo(rect.x(), bottom - bottomLeftDiameter, bottomLeftDiameter, bottomLeftDiameter, 180.0, 90.0);
291
292 const auto bottomRightDiameter = 2 * bottomRightCornerRadius;
293 path.lineTo(right - bottomRightCornerRadius, bottom);
294 path.arcTo(
295 right - bottomRightDiameter, bottom - bottomRightDiameter, bottomRightDiameter, bottomRightDiameter, 270.0,
296 90.0);
297
298 const auto topRightDiameter = 2 * topRightCornerRadius;
299 path.lineTo(right, rect.y() + topRightCornerRadius);
300 path.arcTo(right - topRightDiameter, rect.y(), topRightDiameter, topRightDiameter, 360.0, 90.0);
301
302 path.closeSubpath();
303
304 return path;
305}
306
307void drawPath(QPainter &painter, const QPen &pen, const QBrush &brush, const QPainterPath& path)
308{
309 paintOnStackTop(painter, [&](QPainter &painter) {
310 painter.setRenderHints(QPainter::Antialiasing);
311 painter.setPen(pen);
312 painter.setBrush(brush);
313 painter.drawPath(path);
314 });
315}
316
317void drawRoundedRect(
318 QPainter &painter, const QPen &pen, const QBrush brush, const QRect &rect, qreal topLeftCornerRadius,
319 qreal topRightCornerRadius, qreal bottomLeftCornerRadius, qreal bottomRightCornerRadius)
320{
321 drawPath(
322 painter, pen, brush, roundedPathInRect(rect, topLeftCornerRadius, topRightCornerRadius, bottomLeftCornerRadius,
323 bottomRightCornerRadius));
324}
325
326void drawPolyline(
327 QPainter &painter, const QPen &pen, const QBrush &brush, const std::vector<QPointF> &polygonPoints)
328{
329 paintOnStackTop(painter, [&](auto &p) {
330 p.setRenderHint(QPainter::Antialiasing);
331 p.setPen(pen);
332 p.setBrush(brush);
333 p.drawPolyline(polygonPoints.data(), polygonPoints.size());
334 });
335}
336
337void drawCheckBoxOrRadioButtonIndicator(QPainter &painter, const QStyleOption &option, bool isCheckBox)
338{
339 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
340 const auto isOn = option.state.testFlag(QStyle::State_On);
341 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
342 const auto isSunken = option.state.testFlag(QStyle::State_Sunken);
343
344 painter.save();
345 painter.setRenderHints(QPainter::Antialiasing);
346
347 painter.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
348
349 QRect hoverRect(0, 0, checkBoxOrRadioButtonHoverSize, checkBoxOrRadioButtonHoverSize);
350 hoverRect.moveCenter(option.rect.center());
351 if (isMouseOver || isSunken)
352 drawEllipse(painter, Qt::NoPen, getSunkenOrHoverColor(isSunken, option.palette), hoverRect);
353
354 QRect indicatorRect(0, 0, checkBoxOrRadioButtonIndicatorSize, checkBoxOrRadioButtonIndicatorSize);
355 indicatorRect.moveCenter(option.rect.center());
356
357 auto activeColor = option.palette.color(QPalette::Active, QPalette::Button);
358 if (isOn) {
359 if (isCheckBox) {
360 drawEllipse(painter, Qt::NoPen, activeColor, indicatorRect);
361
362 QPixmap svgPixmap(indicatorRect.size());
363 if (svgPixmap.load(QString::fromStdString(":/resources/ic_gallery_material_select_checkbo.svg"))) {
364 painter.drawPixmap(indicatorRect.topLeft(), svgPixmap);
365 }
366 } else {
367 drawEllipse(
368 painter, QPen(activeColor, radioButtonIndicatorStrokeWidth), Qt::NoBrush,
369 adjusted(indicatorRect, -radioButtonIndicatorStrokeWidth / 2));
370 }
371 } else {
372 drawEllipse(
373 painter, QPen(option.palette.color(QPalette::Inactive, QPalette::Button),
374 checkBoxOrRadioButtonIndicatorStrokeWidth), option.palette.color(QPalette::Inactive, QPalette::Base),
375 adjusted(indicatorRect, -checkBoxOrRadioButtonIndicatorStrokeWidth));
376 }
377
378 painter.restore();
379}
380
381void drawLineEditBackground(QPainter &painter, const QStyleOption &option)
382{
383 auto radius = std::min(
384 std::min(option.rect.size().width(), option.rect.size().height()) * 0.5, lineEditCornerRadius);
385 drawRoundedRect(painter, Qt::NoPen, option.palette.brush(QPalette::Base), option.rect, radius, radius);
386}
387
388QBrush getPushButtonBackgroundBrush(const QStyleOptionButton &option)
389{
390 const auto isDefaultButton = option.features.testFlag(QStyleOptionButton::DefaultButton);
391 const auto isAutoDefaultButton = option.features.testFlag(QStyleOptionButton::AutoDefaultButton);
392 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
393 const auto isOn = option.state.testFlag(QStyle::State_On);
394
395 const auto defaultButtonBackgroundColor = isEnabled
396 ? option.palette.color(QPalette::Active, QPalette::AlternateBase)
397 : makeInactiveOrDisabledFromColor(option.palette.color(QPalette::Active, QPalette::AlternateBase));
398
399 return isOn
400 ? isDefaultButton || isAutoDefaultButton
401 ? defaultButtonBackgroundColor
402 : option.palette.color(QPalette::Active, QPalette::Dark)
403 : isDefaultButton
404 ? defaultButtonBackgroundColor
405 : option.palette.brush(
406 isEnabled
407 ? QPalette::Active
408 : QPalette::Inactive,
409 QPalette::Button);
410}
411
412QColor getPushButtonTextColor(const QStyleOptionButton &option)
413{
414 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
415 const auto isDefaultButton = option.features.testFlag(QStyleOptionButton::DefaultButton);
416 const auto isOn = option.state.testFlag(QStyle::State_On);
417 const QPalette *themePalette =
418 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ButtonPalette);
419
420 return isDefaultButton || isOn
421 ? themePalette->color(QPalette::Active, QPalette::BrightText)
422 : themePalette->color(
423 isEnabled
424 ? QPalette::Active
425 : QPalette::Disabled,
426 QPalette::ButtonText);
427}
428
429void drawPushButtonBackground(QPainter &painter, const QStyleOptionButton &option)
430{
431 paintOnStackTop(painter, [&](QPainter &painter) {
432 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
433 const auto isSunken = option.state.testFlag(QStyle::State_Sunken);
434
435 painter.setRenderHints(QPainter::Antialiasing);
436 painter.setPen(Qt::NoPen);
437
438 auto adjustment = pushButtonFocusFrameGap + pushButtonFocusFrameWidth;
439 auto rect = option.rect.adjusted(adjustment, adjustment, -adjustment, -adjustment);
440
441 painter.setBrush(getPushButtonBackgroundBrush(option));
442 painter.drawRoundedRect(rect, pushButtonCornerRadius, pushButtonCornerRadius);
443
444 if (isMouseOver || isSunken) {
445 painter.setBrush(getSunkenOrHoverColor(isSunken, option.palette));
446 painter.drawRoundedRect(rect, pushButtonCornerRadius, pushButtonCornerRadius);
447 }
448 });
449}
450
451void drawPushButtonFocus(QPainter &painter, const QStyleOption &option)
452{
453 paintOnStackTop(painter, [&](QPainter &painter) {
454 painter.setRenderHints(QPainter::Antialiasing);
455 painter.setBrush(Qt::NoBrush);
456 painter.setPen(QPen(option.palette.color(QPalette::Active, QPalette::Highlight), pushButtonFocusFrameWidth));
457 auto cornerRadius = pushButtonCornerRadius + pushButtonFocusFrameGap;
458 painter.drawRoundedRect(option.rect, cornerRadius, cornerRadius);
459 });
460}
461
462QRect getProgressBarGrooveRect(const QStyleOptionProgressBar &option)
463{
464 auto rect = option.rect;
465 const bool horizontal = option.state & QStyle::State_Horizontal;
466 if (horizontal) {
467 rect.setHeight(progressBarGrooveHeight);
468 rect.moveTop(option.rect.center().y());
469 } else {
470 rect.setWidth(progressBarGrooveHeight);
471 rect.moveRight(option.rect.center().x());
472 }
473
474 return rect;
475}
476
477void drawProgressBarContent(QPainter &painter, const QStyleOptionProgressBar &option)
478{
479 auto rect = getProgressBarGrooveRect(option);
480 const bool horizontal = option.state & QStyle::State_Horizontal;
481
482 const bool isIndeterminate = option.maximum == 0 && option.minimum == 0;
483 if (isIndeterminate) {
484 // TODO: proper busy indicator pending UI spec. Fill groove as a placeholder.
485 drawRoundedRect(painter, Qt::NoPen, option.palette.brush(QPalette::Highlight),
486 rect, progressBarCornerRadius, progressBarCornerRadius);
487 return;
488 }
489
490 const qint64 totalSteps = std::max(qint64(1), qint64(option.maximum) - option.minimum);
491 const double fraction = static_cast<double>(qint64(option.progress) - option.minimum)
492 / static_cast<double>(totalSteps);
493
494 if (horizontal) {
495 rect.setWidth(fraction * rect.width());
496 rect.moveLeft(option.invertedAppearance ? option.rect.width() - rect.width() : 0);
497 } else {
498 rect.setHeight(fraction * rect.height());
499 rect.moveTop(option.invertedAppearance ? 0 : option.rect.height() - rect.height());
500 }
501
502 drawRoundedRect(
503 painter, Qt::NoPen, option.palette.brush(QPalette::Highlight), rect, progressBarCornerRadius,
504 progressBarCornerRadius);
505}
506
507void drawSliderGroove(QPainter &painter, const QStyleOptionSlider &option)
508{
509 drawRoundedRect(
510 painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Mid),
511 option.rect, sliderCornerRadius, sliderCornerRadius);
512
513 QRect fillRect;
514 if (option.orientation == Qt::Horizontal) {
515 const auto sliderPosition = QStyle::sliderPositionFromValue(
516 option.minimum, option.maximum, option.sliderPosition, option.rect.width(), option.upsideDown);
517 fillRect = QRect(option.rect.topLeft(), QSize(sliderPosition, option.rect.height()));
518 } else {
519 const auto sliderPosition = QStyle::sliderPositionFromValue(
520 option.minimum, option.maximum, option.sliderPosition, option.rect.height(), option.upsideDown);
521 fillRect = QRect(
522 option.rect.x(), option.rect.y() + sliderPosition, option.rect.width(), option.rect.height() - sliderPosition);
523 }
524 drawRoundedRect(
525 painter, Qt::NoPen, option.palette.brush(QPalette::Highlight), fillRect, sliderCornerRadius,
526 sliderCornerRadius);
527}
528
529void drawSliderThumb(QPainter &painter, const QStyleOptionSlider &option)
530{
531 QRect shadowRect(0, 0, shadowXSRadius, shadowXSRadius);
532 shadowRect.moveCenter(option.rect.center());
533
534 QRadialGradient radialGrad(shadowRect.center(), shadowXSRadius * 1.0);
535 radialGrad.setColorAt(0.0, Qt::transparent);
536 radialGrad.setColorAt(1.0, option.palette.color(QPalette::Active, QPalette::Shadow));
537
538 drawEllipse(painter, Qt::NoPen, QBrush(radialGrad), shadowRect);
539
540 if (option.state.testFlag(QStyle::State_MouseOver))
541 drawEllipse(painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Light), option.rect);
542
543 auto adjustedRect = option.rect.adjusted(sliderHoverSize, sliderHoverSize, -sliderHoverSize, -sliderHoverSize);
544 drawEllipse(painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::AlternateBase), adjustedRect);
545
546 if (option.state.testFlag(QStyle::State_Sunken))
547 drawEllipse(painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Dark), adjustedRect);
548
549 if (option.state.testFlag(QStyle::State_HasFocus)) {
550 drawEllipse(
551 painter, QPen(option.palette.color(QPalette::Active, QPalette::Highlight), sliderFocusStrokeWidth),
552 Qt::NoBrush, adjusted(option.rect, -1));
553 }
554}
555
556void drawToolButton(QPainter &painter, const QStyleOption &option)
557{
558 const auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
559 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
560 const auto isSunken = option.state.testFlag(QStyle::State_Sunken);
561
562 drawRoundedRect(
563 painter, Qt::NoPen, option.palette.brush(isEnabled ? QPalette::Active : QPalette::Disabled, QPalette::Button),
564 option.rect, toolButtonCornerRadius, toolButtonCornerRadius);
565
566 if (isMouseOver || isSunken) {
567 drawRoundedRect(
568 painter, Qt::NoPen, getSunkenOrHoverColor(isSunken, option.palette), option.rect, toolButtonCornerRadius,
569 toolButtonCornerRadius);
570 }
571}
572
573void drawToolBarbackground(QPainter &painter, const QStyleOption &option)
574{
575 paintOnStackTop(painter, [&](QPainter &painter) {
576 painter.setRenderHints(QPainter::Antialiasing);
577 painter.fillRect(option.rect, option.palette.brush(QPalette::Active, QPalette::Window));
578 });
579}
580
581void drawMenuBarBarbackground(QPainter &painter, const QStyleOption &option)
582{
583 paintOnStackTop(painter, [&](QPainter &painter) {
584 painter.setRenderHints(QPainter::Antialiasing);
585 painter.fillRect(option.rect, option.palette.brush(QPalette::Active, QPalette::Window));
586 });
587}
588
589void drawListItemSeparator(QPainter &painter, const QStyleOption &option)
590{
591 QPoint center = option.rect.center();
592 drawLine(
593 painter, option.palette.color(QPalette::Active, QPalette::Mid),
594 QPoint(option.rect.left(), center.y()), QPoint(option.rect.right(), center.y()));
595}
596
597void drawMenuItem(QPainter &painter, const QStyleOptionMenuItem &option, int checkMarkSize, int iconSize)
598{
599 const auto contentRect = option.rect.adjusted(itemViewItemHorizontalMargin, 0, -itemViewItemHorizontalMargin, 0);
600 if (option.menuItemType == QStyleOptionMenuItem::Separator) {
601 auto copyOption = option;
602 copyOption.rect = contentRect;
603 drawListItemSeparator(painter, copyOption);
604 } else {
605 const bool isSelected = option.state.testFlag(QStyle::State_Selected);
606 const bool isSunken = option.state.testFlag(QStyle::State_Sunken);
607
608 if (isSelected || isSunken) {
609 drawRoundedRect(
610 painter, Qt::NoPen, getSunkenOrHoverColor(isSunken, option.palette),
611 option.rect.adjusted(menuItemHoverHorizontalMargin, 0, -menuItemHoverHorizontalMargin, 0),
612 menuItemCornerRadius, menuItemCornerRadius);
613 }
614
615 const bool isCheckable = option.checkType != QStyleOptionMenuItem::NotCheckable;
616 QRect checkMarkRect;
617 if (isCheckable) {
618 checkMarkRect = contentRect;
619 checkMarkRect.setWidth(checkMarkSize);
620
621 auto copyOption = option;
622 copyOption.rect = checkMarkRect;
623 if (option.checked)
624 copyOption.state |= QStyle::State_On;
625
626 drawCheckBoxOrRadioButtonIndicator(painter, copyOption, true);
627 }
628
629 const bool hasIcon = !option.icon.isNull();
630 QRect iconRect;
631 if (hasIcon) {
632 iconRect = QRect(contentRect.x(), contentRect.center().y() - iconSize * 0.5, iconSize, iconSize);
633 iconRect.moveLeft(checkMarkRect.right() + itemViewItemHorizontalMargin);
634
635 option.icon.paint(
636 &painter, iconRect, Qt::AlignCenter,
637 option.state.testFlag(QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled,
638 option.checked ? QIcon::On : QIcon::Off);
639 }
640
641 QRect textRect = contentRect;
642 if (isCheckable)
643 textRect.setLeft(checkMarkRect.right() + itemViewItemHorizontalMargin);
644 if (hasIcon)
645 textRect.setLeft(iconRect.right() + itemViewItemHorizontalMargin);
646 paintOnStackTop(painter, [&](QPainter &painter) {
647 painter.setPen(option.palette.color(QPalette::Text));
648 painter.drawText(
649 textRect, (Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic), option.text);
650 });
651 }
652}
653
654void drawMenuTearOff(QPainter &painter, const QStyleOption &option)
655{
656 const auto pointY = option.rect.y() + option.rect.height() / 2;
657 drawLine(
658 painter, QPen(option.palette.color(QPalette::Text), 1, Qt::DashLine), QPoint(option.rect.x(), pointY),
659 QPoint(option.rect.x() + option.rect.width(), pointY)
660 );
661}
662
663void drawSplitter(QPainter &painter, const QStyleOption &option)
664{
665 constexpr int splitterAvailableSizeDivider = 12;
666 const bool isHorizontal = option.state.testFlag(QStyle::State_Horizontal);
667
668 if (option.rect.width() > 1 && option.rect.height() > 1) {
669 const auto handleSize = isHorizontal
670 ? QSize(splitterHandleWidth, option.rect.height() / splitterAvailableSizeDivider)
671 : QSize(option.rect.width() / splitterAvailableSizeDivider, splitterHandleWidth);
672 const auto handleRect = QRect(
673 QPoint(
674 (option.rect.width() - handleSize.width()) * 0.5,
675 (option.rect.height() - handleSize.height()) * 0.5),
676 handleSize);
677 const auto cornerRadius = std::min(handleSize.width(), handleSize.height()) * 0.5;
678 drawRoundedRect(
679 painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Mid),
680 handleRect, cornerRadius, cornerRadius);
681 } else {
682 auto endPoint = isHorizontal ? option.rect.bottomLeft() : option.rect.topRight();
683 drawLine(painter, option.palette.dark().color(), option.rect.topLeft(), endPoint);
684 }
685}
686
687void drawSpinBoxFrame(
688 QPainter &painter, const QStyleOptionSpinBox &option, const QRect &frameRect, int frameWidth)
689{
690 auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
691
692 QPen pen =
693 option.frame && option.subControls.testFlag(QStyle::SC_SpinBoxFrame)
694 ? QPen(option.palette.color(QPalette::Active, QPalette::Mid), frameWidth)
695 : Qt::NoPen;
696
697 paintOnStackTop(painter, [&](auto &p) {
698 p.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
699 drawRoundedRect(
700 p, pen, option.palette.window(), frameRect, spinBoxFrameRadius, spinBoxFrameRadius);
701 });
702}
703
704void drawSpinBoxButton(QPainter &painter, const QStyleOptionSpinBox &option, int penWidth)
705{
706 auto rect = option.rect;
707 auto isEnabled = option.state.testFlag(QStyle::State_Enabled);
708 auto isPressed = option.state.testFlag(QStyle::State_Sunken);
709
710 QPen pen(option.palette.color(QPalette::Active, QPalette::Mid), penWidth);
711 QBrush brush(option.palette.window());
712
713 if (isPressed)
714 brush = QBrush(option.palette.highlight());
715
716 qreal rectX = rect.x();
717 qreal rectY = rect.y();
718 qreal rectWidth = rect.width();
719 qreal rectHeight = rect.height();
720 qreal cornerRadius = static_cast<qreal>(spinBoxFrameRadius);
721
722 QPainterPath path;
723 path.moveTo(rectX, rectY);
724 path.lineTo(rectX, rectY + rectHeight);
725 if (option.subControls == QStyle::SC_SpinBoxDown) {
726 path.lineTo(rectX + rectWidth - cornerRadius, rectY + rectHeight);
727 path.arcTo(
728 rectX + rectWidth - 2 * cornerRadius, rectY + rectHeight - 2 * cornerRadius,
729 2 * cornerRadius, 2 * cornerRadius, 270, 90);
730 path.lineTo(rectX + rectWidth, rectY);
731 } else {
732 path.lineTo(rectX + rectWidth, rectY + rectHeight);
733 path.lineTo(rectX + rectWidth, rectY + cornerRadius);
734 path.arcTo(rectX + rectWidth - 2 * cornerRadius, rectY, 2 * cornerRadius, 2 * cornerRadius, 0, 90);
735 }
736 path.closeSubpath();
737
738 paintOnStackTop(painter, [&](auto &p) {
739 p.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
740 drawPath(p, pen, brush, path);
741 });
742}
743
744void drawScrollBarSlider(QPainter &painter, const QStyleOptionSlider &option)
745{
746 int scrollBarRadius =
747 option.orientation == Qt::Vertical
748 ? option.rect.width() * 0.5
749 : option.rect.height() * 0.5;
750
751 paintOnStackTop(painter, [&](QPainter &painter) {
752 painter.setOpacity(ohos_id_alpha_content_tertiary);
753 drawRoundedRect(
754 painter, Qt::NoPen, option.palette.color(QPalette::Active, QPalette::Midlight),
755 option.rect, scrollBarRadius, scrollBarRadius);
756 });
757}
758
759Qt::Orientation tabBarShapeToOrientation(QTabBar::Shape shape)
760{
761 switch (shape) {
762 case QTabBar::RoundedNorth:
763 case QTabBar::RoundedSouth:
764 case QTabBar::TriangularNorth:
765 case QTabBar::TriangularSouth:
766 return Qt::Horizontal;
767 case QTabBar::RoundedWest:
768 case QTabBar::TriangularWest:
769 case QTabBar::RoundedEast:
770 case QTabBar::TriangularEast:
771 return Qt::Vertical;
772 }
773}
774
775void drawTabBarTabShape(QPainter &painter, const QStyleOptionTab &option)
776{
777 auto isSelected = option.state.testFlag(QStyle::State_Selected);
778 auto isFocused = option.state.testFlag(QStyle::State_HasFocus);
779 QRect rect(option.rect);
780 adjusted(rect, -tabBarTabFrameWidth - 1);
781
782 QPoint underLineStart, underLineEnd;
783 if (tabBarShapeToOrientation(option.shape) == Qt::Horizontal) {
784 int lineY = rect.y() + rect.height() - tabBarTabUnderLineWidth;
785 underLineStart = QPoint(rect.x() + tabBarTabRadius, lineY);
786 underLineEnd = QPoint(rect.x() + rect.width() - tabBarTabRadius, lineY);
787 } else {
788 int lineX = rect.x();
789
790 if (option.shape == QTabBar::RoundedWest || option.shape == QTabBar::TriangularWest)
791 lineX += rect.width() - tabBarTabUnderLineWidth;
792 else
793 lineX += tabBarTabUnderLineWidth;
794
795 underLineStart = QPoint(lineX, rect.y() + tabBarTabRadius);
796 underLineEnd = QPoint(lineX, rect.y() + rect.height() - tabBarTabRadius);
797 }
798
799 drawRoundedRect(painter, Qt::NoPen, option.palette.window(), rect, tabBarTabRadius, tabBarTabRadius);
800 if (!isFocused && isSelected)
801 drawLine(painter, QPen(option.palette.highlight(), tabBarTabUnderLineWidth), underLineStart, underLineEnd);
802}
803
804void drawComboBoxFrame(QPainter &painter, const QStyleOptionComboBox &option)
805{
806 const auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
807 const auto isOpened = option.state.testFlag(QStyle::State_On);
808 const auto isFocused = option.state.testFlag(QStyle::State_HasFocus);
809
810 auto focusedPen = QPen(
811 option.palette.color(QPalette::Active, QPalette::AlternateBase),
812 comboBoxFocusFrameWidth);
813
814 drawRoundedRect(
815 painter, isFocused ? focusedPen : Qt::NoPen, option.palette.brush(QPalette::Window), option.rect,
816 comboBoxFrameRadius, comboBoxFrameRadius);
817
818 if (isMouseOver || isOpened) {
819 auto pen = isOpened ? focusedPen : Qt::NoPen;
820 auto brush = getSunkenOrHoverColor(isOpened, option.palette);
821 drawRoundedRect(painter, pen, brush, option.rect, comboBoxFrameRadius, comboBoxFrameRadius);
822 }
823}
824
825void drawComboBoxListViewItem(QPainter &painter, const QStyleOptionViewItem &option, const QBrush &brush)
826{
827 if (isFirstItem(option.index)) {
828 drawRoundedRect(
829 painter, Qt::NoPen, brush, option.rect, focusFrameCornerRadius, focusFrameCornerRadius, 0, 0);
830 } else if (isLastItem(option.index)) {
831 drawRoundedRect(
832 painter, Qt::NoPen, brush, option.rect, 0, 0, focusFrameCornerRadius, focusFrameCornerRadius);
833 } else {
834 drawRect(painter, Qt::NoPen, brush, option.rect);
835 }
836}
837
838void drawTreeViewHighlightItem(QPainter &painter, const QStyleOptionViewItem &option, const QBrush &brush)
839{
840 switch (option.viewItemPosition) {
841 case QStyleOptionViewItem::OnlyOne:
842 drawRoundedRect(
843 painter, Qt::NoPen, brush, option.rect, focusFrameCornerRadius, focusFrameCornerRadius);
844 break;
845 case QStyleOptionViewItem::Beginning:
846 drawRoundedRect(
847 painter, Qt::NoPen, brush, option.rect, focusFrameCornerRadius, 0, focusFrameCornerRadius, 0);
848 break;
849 case QStyleOptionViewItem::Invalid:
850 case QStyleOptionViewItem::Middle:
851 drawRect(painter, Qt::NoPen, brush, option.rect);
852 break;
853 case QStyleOptionViewItem::End:
854 drawRoundedRect(
855 painter, Qt::NoPen, brush, option.rect, 0, focusFrameCornerRadius, 0, focusFrameCornerRadius);
856 break;
857 }
858}
859
860void drawPanelItemViewItem(QPainter &painter, const QStyleOptionViewItem &option, bool isComboBoxListViewItem)
861{
862 if (isItemViewSeparator(option.index)) {
863 auto copyOption = option;
864 copyOption.rect = option.rect.adjusted(itemViewItemHorizontalMargin, 0, -itemViewItemHorizontalMargin, 0);
865 drawListItemSeparator(painter, copyOption);
866 } else {
867 auto isSelected = option.state.testFlag(QStyle::State_Selected);
868 auto isMouseOver = option.state.testFlag(QStyle::State_MouseOver);
869
870 auto colorGroup = option.state.testFlag(QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled;
871 if (colorGroup == QPalette::Normal && !option.state.testFlag(QStyle::State_Active))
872 colorGroup = QPalette::Inactive;
873
874 const QBrush brush =
875 isSelected
876 ? option.palette.brush(colorGroup, QPalette::Highlight)
877 : isMouseOver
878 ? option.palette.color(QPalette::Active, QPalette::Light)
879 : option.backgroundBrush.style() == Qt::NoBrush
880 ? Qt::NoBrush
881 : option.backgroundBrush;
882
883 if (isComboBoxListViewItem)
884 drawComboBoxListViewItem(painter, option, brush);
885 else
886 drawTreeViewHighlightItem(painter, option, brush);
887 }
888}
889
890void drawHeaderSection(QPainter &painter, const QStyleOptionHeader &option)
891{
892 QRect rect =
893 option.position == QStyleOptionHeader::OnlyOneSection
894 ? option.rect
895 : option.orientation == Qt::Horizontal
896 ? option.rect.adjusted(-1, 0, 0, 0)
897 : option.rect.adjusted(0, -1, 0, 0);
898
899 drawRect(painter, QPen(Qt::black), option.palette.brush(QPalette::Button), rect);
900}
901
902void drawWindowBackgroundAndFrame(
903 QPainter &painter, const QStyleOptionFrame &option, QFlags<Qt::WindowState> state, int titleBarHeight)
904{
905 const auto offset = option.lineWidth * 0.5;
906 const auto windowFrameColor =
907 state.testFlag(Qt::WindowActive)
908 ? option.palette.color(QPalette::Active, QPalette::Base)
909 : option.palette.color(QPalette::Inactive, QPalette::Base);
910 if (state.testFlag(Qt::WindowMinimized)) {
911 drawRoundedRect(
912 painter, QPen(windowFrameColor, option.lineWidth), Qt::NoBrush,
913 option.rect.adjusted(offset, offset, -offset, -offset), focusFrameCornerRadius, focusFrameCornerRadius, 0,
914 0);
915 drawRect(
916 painter, Qt::NoPen, option.palette.brush(QPalette::Window),
917 option.rect.adjusted(option.lineWidth, titleBarHeight, -option.lineWidth, 0));
918 } else {
919 drawRoundedRect(
920 painter, Qt::NoPen, windowFrameColor, option.rect.adjusted(0, titleBarHeight, 0, 0), 0, 0,
921 focusFrameCornerRadius, focusFrameCornerRadius);
922 drawRoundedRect(
923 painter, Qt::NoPen, option.palette.brush(QPalette::Window),
924 option.rect.adjusted(option.lineWidth, titleBarHeight, -option.lineWidth, -option.lineWidth),
925 focusFrameCornerRadius, focusFrameCornerRadius);
926 drawRoundedRect(
927 painter, QPen(windowFrameColor, option.lineWidth), Qt::NoBrush,
928 option.rect.adjusted(offset, offset, -offset, -offset), focusFrameCornerRadius, focusFrameCornerRadius);
929 }
930}
931
932void drawToolTip(QPainter &painter, const QStyleOptionFrame &option)
933{
934 drawRoundedRect(
935 painter, option.palette.color(QPalette::Active, QPalette::Base),
936 option.palette.toolTipBase(), option.rect, toolTipCornerRadius,
937 toolTipCornerRadius);
938}
939
940QRect titleBarSubControlRect(const QStyleOptionTitleBar &option, QCommonStyle::SubControl subControl)
941{
942 const bool isMinimized = (option.titleBarState & Qt::WindowMinimized) != 0;
943 const bool isMaximized = (option.titleBarState & Qt::WindowMaximized) != 0;
944
945 const bool hasTitle = option.titleBarFlags.testFlag(Qt::WindowTitleHint);
946 const bool hasSystemMenuButton = option.titleBarFlags.testFlag(Qt::WindowSystemMenuHint);
947 const bool hasShadeButton = option.titleBarFlags.testFlag(Qt::WindowShadeButtonHint);
948 const bool hasContextHelpButton = option.titleBarFlags.testFlag(Qt::WindowContextHelpButtonHint);
949 const bool hasMinimizeButton = option.titleBarFlags.testFlag(Qt::WindowMinimizeButtonHint);
950 const bool hasMaximizeButton = option.titleBarFlags.testFlag(Qt::WindowMaximizeButtonHint);
951
952 const auto controlSize = QSize(30, 30);
953 const int titleBarHorizontalMargin = 25;
954 const int titleBarControlVerticalMargin = 15;
955
956 const auto titleBarContentRect = QRect(
957 option.rect.x() + titleBarHorizontalMargin, (option.rect.height() - controlSize.height()) / 2,
958 option.rect.width() - 2 * titleBarHorizontalMargin, controlSize.height());
959 const auto titleBarContentRectRight = titleBarContentRect.x() + titleBarContentRect.width();
960 const auto delta = controlSize.width() + titleBarControlVerticalMargin;
961
962 QRect result;
963 switch (subControl) {
964 case QCommonStyle::SC_TitleBarSysMenu:
965 if (hasSystemMenuButton)
966 result = QRect(titleBarContentRect.topLeft(), controlSize);
967 break;
968 case QCommonStyle::SC_TitleBarLabel:
969 if (hasTitle) {
970 result = titleBarContentRect;
971 if (hasSystemMenuButton)
972 result.adjust(delta, 0, -delta, 0);
973 if (hasMinimizeButton)
974 result.adjust(0, 0, -delta, 0);
975 if (hasMaximizeButton)
976 result.adjust(0, 0, -delta, 0);
977 if (hasShadeButton)
978 result.adjust(0, 0, -delta, 0);
979 if (hasContextHelpButton)
980 result.adjust(0, 0, -delta, 0);
981 }
982 break;
983 case QCommonStyle::SC_TitleBarMaxButton:
984 if (!isMaximized && hasMaximizeButton) {
985 result = QRect(
986 QPoint(titleBarContentRectRight - 3 * delta + titleBarControlVerticalMargin,
987 titleBarContentRect.y()), controlSize);
988 }
989 break;
990 case QCommonStyle::SC_TitleBarNormalButton:
991 if (isMinimized && hasMinimizeButton) {
992 result = QRect(
993 QPoint(titleBarContentRectRight - 2 * delta + titleBarControlVerticalMargin,
994 titleBarContentRect.y()), controlSize);
995 } else if (isMaximized && hasMaximizeButton) {
996 result = QRect(
997 QPoint(titleBarContentRectRight - 3 * delta + titleBarControlVerticalMargin,
998 titleBarContentRect.y()), controlSize);
999 }
1000 break;
1001 case QCommonStyle::SC_TitleBarMinButton:
1002 if (!isMinimized && hasMinimizeButton) {
1003 result = QRect(
1004 QPoint(titleBarContentRectRight - 2 * delta + titleBarControlVerticalMargin,
1005 titleBarContentRect.y()), controlSize);
1006 }
1007 break;
1008 case QCommonStyle::SC_TitleBarCloseButton:
1009 result = QRect(
1010 QPoint(titleBarContentRectRight - controlSize.width(), titleBarContentRect.y()), controlSize);
1011 break;
1012 case QCommonStyle::SC_TitleBarShadeButton:
1013 case QCommonStyle::SC_TitleBarUnshadeButton:
1014 result = QRect(
1015 QPoint(titleBarContentRectRight - 4 * delta + titleBarControlVerticalMargin,
1016 titleBarContentRect.y()), controlSize);
1017 break;
1018 case QCommonStyle::SC_TitleBarContextHelpButton:
1019 result = QRect(
1020 QPoint(titleBarContentRectRight - (hasShadeButton ? 5 : 4) * delta + titleBarControlVerticalMargin,
1021 titleBarContentRect.y()), controlSize);
1022 break;
1023 default:
1024 break;
1025 }
1026
1027 return result;
1028}
1029
1030}
1031
1032QOhosStyle::QOhosStyle()
1033 : QCommonStyle()
1034{
1035}
1036
1037void QOhosStyle::drawPrimitive(
1038 PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
1039{
1040 switch (element) {
1041 case PE_Frame: {
1042 if (widget != nullptr && qobjectIsInstanceOf<QComboBox>(widget->parent()))
1043 break;
1044 QCommonStyle::drawPrimitive(element, option, painter, widget);
1045 break;
1046 }
1047 case PE_FrameWindow:
1048 if (qStyleOptionIs<QStyleOptionFrame>(option)) {
1049 drawWindowBackgroundAndFrame(
1050 *painter, *qstyleoption_cast<const QStyleOptionFrame *>(option), widget->windowState(),
1051 pixelMetric(PM_TitleBarHeight, option, widget));
1052 }
1053 break;
1054 case PE_FrameFocusRect:
1055 if (qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
1056 if (qobjectIsInstanceOf<QPushButton>(widget)) {
1057 drawPushButtonFocus(*painter, *option);
1058 } else if (qobjectIsInstanceOf<QToolButton>(widget)) {
1059 const auto menuButtonIndicatorSize =
1060 qobject_cast<const QToolButton *>(widget)->popupMode() == QToolButton::MenuButtonPopup
1061 ? pixelMetric(PM_MenuButtonIndicator, option, widget)
1062 : 0;
1063 drawRoundedRect(
1064 *painter,
1065 QPen(option->palette.color(QPalette::Active, QPalette::Highlight), toolButtonFocusFrameWidth),
1066 Qt::NoBrush, option->rect.adjusted(-1, -1, 1 + menuButtonIndicatorSize, 1),
1067 toolButtonCornerRadius, toolButtonCornerRadius);
1068 } else if (qobjectIsInstanceOf<QCheckBox>(widget) || qobjectIsInstanceOf<QRadioButton>(widget)) {
1069 drawEllipse(
1070 *painter, QPen(option->palette.color(QPalette::Active, QPalette::Button),
1071 checkBoxOrRadioButtonFocusStrokeWidth), Qt::NoBrush, option->rect);
1072 } else if (qobjectIsInstanceOf<QTabBar>(widget)) {
1073 drawRoundedRect(
1074 *painter, QPen(option->palette.highlight(), tabBarTabFrameWidth), Qt::NoBrush,
1075 option->rect, tabBarTabRadius, tabBarTabRadius);
1076 } else {
1077 drawRoundedRect(
1078 *painter, QPen(option->palette.color(QPalette::Active, QPalette::Highlight), focusFrameWidth),
1079 Qt::NoBrush, option->rect, focusFrameCornerRadius, focusFrameCornerRadius);
1080 }
1081 }
1082 break;
1083 case PE_PanelButtonCommand:
1084 if (qStyleOptionIs<QStyleOptionButton>(option))
1085 drawPushButtonBackground(*painter, *qstyleoption_cast<const QStyleOptionButton *>(option));
1086 break;
1087 case PE_PanelButtonTool:
1088 if (qobjectIsInstanceOf<QMdiSubWindow>(widget)) {
1089 const QPalette *toolButtonThemePalette =
1090 QGuiApplicationPrivate::platformTheme()->palette(QPlatformTheme::Palette::ToolButtonPalette);
1091 const auto panelButtonColor =
1092 toolButtonThemePalette->color(QPalette::Active, QPalette::AlternateBase);
1093 drawEllipse(
1094 *painter, Qt::NoPen,
1095 widget->windowState().testFlag(Qt::WindowActive)
1096 ? panelButtonColor
1097 : makeInactiveOrDisabledFromColor(panelButtonColor),
1098 option->rect);
1099 } else {
1100 const QToolButton *toolButton = qobject_cast<const QToolButton *>(widget);
1101 const auto menuButtonIndicatorSize =
1102 toolButton != nullptr && toolButton->popupMode() == QToolButton::MenuButtonPopup
1103 ? pixelMetric(PM_MenuButtonIndicator, option, widget)
1104 : 0;
1105 auto optionCopy = *option;
1106 optionCopy.rect.setWidth(option->rect.width() + menuButtonIndicatorSize);
1107 drawToolButton(*painter, optionCopy);
1108 }
1109 break;
1110 case PE_PanelMenuBar:
1111 drawMenuBarBarbackground(*painter, *option);
1112 break;
1113 case PE_IndicatorCheckBox:
1114 drawCheckBoxOrRadioButtonIndicator(*painter, *option, true);
1115 break;
1116 case PE_IndicatorRadioButton:
1117 drawCheckBoxOrRadioButtonIndicator(*painter, *option, false);
1118 break;
1119 case PE_PanelLineEdit: {
1120 // HACK: Q(Abstrace)SpinBox contains a QLineEdit inside, which is painted separately from
1121 // the QSpinBox itself. We will be drawing the whole QSpinBox in the drawComplexControl.
1122 if (widget != nullptr && qobjectIsInstanceOf<QAbstractSpinBox>(widget->parentWidget()))
1123 break;
1124
1125 // HACK: QComboBox in editable mode presents line edit in the center. This line edit is drawn
1126 // above QComboBox. There are two issues here: QComboBox has different base color than line edit.
1127 // Second, line edit and QComboBox has the same size - so drawing a line edit overlays a frame border.
1128 // To fix above, do not draw line edit background.
1129 if (widget != nullptr && qobjectIsInstanceOf<QComboBox>(widget->parentWidget()))
1130 break;
1131
1132 // HACK: while editing Tree View/Widget item - line edit component is presented above it. If the line edit has
1133 // some opacity in background content below it (item content) is visible. This causes an effect that original
1134 // text is still visible while editing. To fix it, override background (base) color and use solid color value.
1135 auto optionCopy = *option;
1136 if (widget != nullptr && qstrcmp(widget->metaObject()->className(), "QExpandingLineEdit") == 0) {
1137 optionCopy.palette.setColor(
1138 QPalette::Base,
1139 option->palette.color(QPalette::Active, QPalette::AlternateBase));
1140 }
1141
1142 drawLineEditBackground(*painter, optionCopy);
1143 break;
1144 }
1145 case PE_PanelButtonBevel:
1146 if (qStyleOptionIs<QStyleOptionSpinBox>(option)) {
1147 drawSpinBoxButton(
1148 *painter, *qstyleoption_cast<const QStyleOptionSpinBox *>(option),
1149 pixelMetric(PM_SpinBoxFrameWidth, option, widget));
1150 }
1151 break;
1152 case PE_IndicatorSpinDown:
1153 case PE_IndicatorSpinUp: {
1154 // HACK: QCommonStyle adjusts the indicator left as follows: copy.rect.adjust(3, 0, -4, 0);
1155 // However, Ohos requires 4 pixels of horizontal margin and 2 pixels of vertical margin
1156 QRect indicatorRect = option->rect.adjusted(1, 2, 0, -2);
1157 constexpr int arrowWidth = 2;
1158 auto x = indicatorRect.x();
1159 auto y = indicatorRect.y();
1160 auto width = indicatorRect.width();
1161 auto height = indicatorRect.height();
1162 auto verticalSpacing = 4;
1163 auto horizontalSpacing = 7;
1164
1165 qreal x1 = x + horizontalSpacing;
1166 qreal x2 = x + width * 0.5;
1167 qreal x3 = x + width - horizontalSpacing;
1168
1169 qreal y1, y2;
1170 if (element == PE_IndicatorSpinDown) {
1171 y1 = y + verticalSpacing;
1172 y2 = y + height - verticalSpacing;
1173 } else {
1174 y1 = y + height - verticalSpacing;
1175 y2 = y + verticalSpacing;
1176 }
1177 auto y3 = y1;
1178
1179 QPen indicatorPen(option->palette.color(QPalette::Active, QPalette::Text), arrowWidth);
1180 indicatorPen.setCapStyle(Qt::RoundCap);
1181 indicatorPen.setJoinStyle(Qt::RoundJoin);
1182
1183 paintOnStackTop(*painter, [&](auto &p) {
1184 p.setOpacity(option->state.testFlag(State_Enabled) ? 1.0 : ohos_id_alpha_disabled);
1185 p.setRenderHint(QPainter::Antialiasing);
1186 p.setPen(indicatorPen);
1187 p.setBrush(Qt::NoBrush);
1188 p.drawLine(x1, y1, x2, y2);
1189 p.drawLine(x2, y2, x3, y3);
1190 });
1191 break;
1192 }
1193 case PE_FrameGroupBox: {
1194 const auto frame = qstyleoption_cast<const QStyleOptionFrame *>(option);
1195 if (frame != nullptr) {
1196 QPen pen;
1197 pen.setColor(frame->palette.alternateBase().color());
1198 pen.setStyle(
1199 frame->features.testFlag(QStyleOptionFrame::FrameFeature::Flat)
1200 ? Qt::NoPen : Qt::SolidLine);
1201
1202 painter->setClipRegion(frame->rect);
1203 drawRoundedRect(
1204 *painter, pen, option->palette.window(), frame->rect, groupBoxFrameCornerRadius,
1205 groupBoxFrameCornerRadius);
1206 }
1207 break;
1208 }
1209 case PE_IndicatorArrowUp:
1210 case PE_IndicatorArrowDown:
1211 case PE_IndicatorArrowLeft:
1212 case PE_IndicatorArrowRight: {
1213 QRect availableRect;
1214 int maxArrowSize = 0;
1215 if (qobjectIsInstanceOf<QToolButton>(widget) || qobjectIsInstanceOf<QPushButton>(widget)
1216 || qobjectIsInstanceOf<QComboBox>(widget)) {
1217 const auto menuButtonIndicatorSize = pixelMetric(PM_MenuButtonIndicator, option, widget);
1218 availableRect = QRect(
1219 widget->size().width() - menuButtonIndicatorSize, 0, menuButtonIndicatorSize, widget->size().height());
1220 maxArrowSize = std::min(availableRect.width(), availableRect.height()) * 0.5;
1221 } else {
1222 availableRect = option->rect;
1223 maxArrowSize = std::min(availableRect.width(), availableRect.height());
1224 }
1225
1226 const auto arrowWidth = 2;
1227 auto arrowRect = QRect(0, 0, maxArrowSize, maxArrowSize * 0.5);
1228 arrowRect.moveCenter(availableRect.center());
1229 arrowRect = adjusted(arrowRect, -arrowWidth * 0.5);
1230
1231 const std::vector<QPointF> polygonPoints = {
1232 QPointF(arrowRect.x(), arrowRect.y()),
1233 QPointF(arrowRect.x() + arrowRect.width() * 0.5, arrowRect.y() + arrowRect.height()),
1234 QPointF(arrowRect.x() + arrowRect.width(), arrowRect.y())
1235 };
1236 const auto isEnabled = option->state.testFlag(QStyle::State_Enabled);
1237
1238 paintOnStackTop(*painter, [&](auto &p) {
1239 p.translate(option->rect.center());
1240 switch (element) {
1241 default:
1242 case PE_IndicatorArrowDown:
1243 break;
1244 case PE_IndicatorArrowUp:
1245 p.rotate(180);
1246 break;
1247 case PE_IndicatorArrowLeft:
1248 p.rotate(90);
1249 break;
1250 case PE_IndicatorArrowRight:
1251 p.rotate(-90);
1252 break;
1253 }
1254 p.translate(-option->rect.center());
1255
1256 p.setOpacity(isEnabled ? 1.0 : ohos_id_alpha_disabled);
1257 drawPolyline(
1258 p,
1259 QPen(
1260 option->palette.color(QPalette::Active, QPalette::WindowText),
1261 arrowWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin), Qt::NoBrush,
1262 polygonPoints);
1263 });
1264 break;
1265 }
1266 case PE_IndicatorButtonDropDown: {
1267 if (qobjectIsInstanceOf<QToolButton>(widget))
1268 break;
1269 QCommonStyle::drawPrimitive(element, option, painter, widget);
1270 break;
1271 }
1272 case PE_PanelItemViewItem:
1273 if (qStyleOptionIs<QStyleOptionViewItem>(option)) {
1274 drawPanelItemViewItem(
1275 *painter, *qstyleoption_cast<const QStyleOptionViewItem *>(option),
1276 widget != nullptr && qstrcmp(widget->metaObject()->className(), "QComboBoxListView") == 0);
1277 }
1278 break;
1279 case PE_FrameTabWidget:
1280 if (qStyleOptionIs<QStyleOptionTabWidgetFrame>(option)) {
1281 QRect rect = option->rect;
1282
1283 switch (qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)->shape) {
1284 case QTabBar::RoundedNorth:
1285 case QTabBar::TriangularNorth:
1286 rect.adjust(0, tabWidgetFrameWidth, 0, 0);
1287 break;
1288 case QTabBar::RoundedWest:
1289 case QTabBar::TriangularWest:
1290 rect.adjust(tabWidgetFrameWidth, 0, 0, 0);
1291 break;
1292 case QTabBar::RoundedSouth:
1293 case QTabBar::TriangularSouth:
1294 rect.adjust(0, 0, 0, -(tabWidgetFrameWidth * 2));
1295 break;
1296 case QTabBar::RoundedEast:
1297 case QTabBar::TriangularEast:
1298 rect.adjust(0, 0, -(tabWidgetFrameWidth * 2), 0);
1299 break;
1300 }
1301
1302 drawRect(
1303 *painter, QPen(option->palette.color(QPalette::Dark), tabWidgetFrameWidth),
1304 Qt::NoBrush, rect);
1305 }
1306 break;
1307 case PE_PanelTipLabel:
1308 if (qStyleOptionIs<QStyleOptionFrame>(option))
1309 drawToolTip(*painter, *qstyleoption_cast<const QStyleOptionFrame *>(option));
1310 break;
1311 default:
1312 QCommonStyle::drawPrimitive(element, option, painter, widget);
1313 break;
1314 }
1315}
1316
1317void QOhosStyle::drawControl(
1318 ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
1319{
1320 switch (element) {
1321 case CE_HeaderSection:
1322 if (qStyleOptionIs<QStyleOptionHeader>(option))
1323 drawHeaderSection(*painter, *qstyleoption_cast<const QStyleOptionHeader *>(option));
1324 break;
1325 case CE_MenuBarEmptyArea:
1326 break;
1327 case CE_MenuItem:
1328 if (qStyleOptionIs<QStyleOptionMenuItem>(option)) {
1329 const auto *menuItemStyleOption = qstyleoption_cast<const QStyleOptionMenuItem *>(option);
1330 drawMenuItem(
1331 *painter, *menuItemStyleOption, pixelMetric(PM_IndicatorWidth, option, widget),
1332 pixelMetric(PM_SmallIconSize, option, widget));
1333 if (menuItemStyleOption->menuItemType == QStyleOptionMenuItem::SubMenu) {
1334 const auto iconSize = pixelMetric(PM_SmallIconSize, option, widget);
1335 const auto menuItemRect = menuItemStyleOption->rect;
1336
1337 QStyleOptionMenuItem menuArrowStyleOption = *menuItemStyleOption;
1338 menuArrowStyleOption.rect = QRect(
1339 menuItemRect.right() - itemViewItemHorizontalMargin - iconSize,
1340 menuItemRect.top() + (menuItemRect.height() - iconSize) / 2, iconSize, iconSize);
1341 QColor arrowColor = menuItemStyleOption->palette.color(QPalette::Active, QPalette::Text);
1342 menuArrowStyleOption.palette.setColor(
1343 QPalette::Active, QPalette::WindowText, arrowColor);
1344 drawPrimitive(
1345 menuArrowStyleOption.direction == Qt::RightToLeft ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight,
1346 &menuArrowStyleOption, painter, widget);
1347 }
1348 }
1349 break;
1350 case CE_MenuTearoff:
1351 drawMenuTearOff(*painter, *option);
1352 break;
1353 case CE_ProgressBarGroove:
1354 if (qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
1355 drawRoundedRect(
1356 *painter, Qt::NoPen, option->palette.color(QPalette::Active, QPalette::Mid),
1357 getProgressBarGrooveRect(*qstyleoption_cast<const QStyleOptionProgressBar *>(option)),
1358 progressBarCornerRadius, progressBarCornerRadius);
1359 }
1360 break;
1361 case CE_ProgressBarContents:
1362 if (qstyleoption_cast<const QStyleOptionProgressBar *>(option))
1363 drawProgressBarContent(*painter, *qstyleoption_cast<const QStyleOptionProgressBar *>(option));
1364 break;
1365 case CE_ProgressBarLabel:
1366 break;
1367 case CE_Splitter:
1368 drawSplitter(*painter, *option);
1369 break;
1370 case CE_ToolBar:
1371 drawToolBarbackground(*painter, *option);
1372 break;
1373 case CE_ScrollBarSlider:
1374 if (qStyleOptionIs<QStyleOptionSlider>(option))
1375 drawScrollBarSlider(*painter, *qstyleoption_cast<const QStyleOptionSlider *>(option));
1376 break;
1377 case CE_TabBarTabShape: {
1378 auto tabOption = qstyleoption_cast<const QStyleOptionTab *>(option);
1379 if (tabOption != nullptr)
1380 drawTabBarTabShape(*painter, *tabOption);
1381 break;
1382 }
1383 case CE_TabBarTabLabel: {
1384 auto tabOption = qstyleoption_cast<const QStyleOptionTab *>(option);
1385 if (tabOption != nullptr) {
1386 auto copy = *tabOption;
1387 if (!option->state.testFlag(State_Selected))
1388 copy.palette.setCurrentColorGroup(QPalette::Inactive);
1389 QCommonStyle::drawControl(element, &copy, painter, widget);
1390 }
1391 break;
1392 }
1393 case CE_PushButtonLabel: {
1394 if (qStyleOptionIs<QStyleOptionButton>(option)) {
1395 auto buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option);
1396
1397 auto buttonOptionCopy = *buttonOption;
1398 buttonOptionCopy.palette.setColor(QPalette::ButtonText, getPushButtonTextColor(*buttonOption));
1399
1400 QCommonStyle::drawControl(element, &buttonOptionCopy, painter, widget);
1401 }
1402 break;
1403 }
1404 case CE_DockWidgetTitle: {
1405 const auto *dockWidgetOption = qstyleoption_cast<const QStyleOptionDockWidget *>(option);
1406 if (dockWidgetOption == nullptr)
1407 break;
1408 auto dockWidgetOptionCopy = *dockWidgetOption;
1409 if (!dockWidgetOptionCopy.title.isEmpty()) {
1410 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, option, widget);
1411 if (dockWidgetOptionCopy.verticalTitleBar) {
1412 QRect rect = dockWidgetOptionCopy.rect;
1413 QRect verticalRect = rect.transposed();
1414 titleRect = QRect(
1415 verticalRect.left() + rect.bottom() - titleRect.bottom(),
1416 verticalRect.top() + titleRect.left() - rect.left(),
1417 titleRect.height(),
1418 titleRect.width());
1419 }
1420 dockWidgetOptionCopy.title = painter->fontMetrics().elidedText(
1421 dockWidgetOptionCopy.title, Qt::ElideRight, titleRect.width());
1422 }
1423 QCommonStyle::drawControl(element, &dockWidgetOptionCopy, painter, widget);
1424 break;
1425 }
1426 default:
1427 QCommonStyle::drawControl(element, option, painter, widget);
1428 }
1429}
1430
1431void QOhosStyle::drawComplexControl(
1432 ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
1433{
1434 switch (control) {
1435 case CC_Slider: {
1436 const auto sliderStyleOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
1437 if (sliderStyleOption != nullptr) {
1438 if (option->subControls.testFlag(SC_SliderGroove)) {
1439 auto sliderStyleOptionCopy = *sliderStyleOption;
1440 sliderStyleOptionCopy.rect = subControlRect(control, option, SC_SliderGroove, widget);
1441 drawSliderGroove(*painter, sliderStyleOptionCopy);
1442 }
1443 if (option->subControls.testFlag(SC_SliderHandle)) {
1444 auto sliderStyleOptionCopy = *sliderStyleOption;
1445 sliderStyleOptionCopy.rect = subControlRect(control, option, SC_SliderHandle, widget);
1446 drawSliderThumb(*painter, sliderStyleOptionCopy);
1447 }
1448 }
1449 break;
1450 }
1451 case CC_SpinBox:
1452 if (qStyleOptionIs<QStyleOptionSpinBox>(option)) {
1453 auto spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option);
1454 auto frameRect = subControlRect(control, spinBox, SC_SpinBoxFrame, widget);
1455 auto frameWidth = pixelMetric(PM_SpinBoxFrameWidth, spinBox, widget);
1456 drawSpinBoxFrame(*painter, *spinBox, frameRect, frameWidth);
1457
1458 auto copy = *spinBox;
1459 copy.frame = false;
1460
1461 QCommonStyle::drawComplexControl(control, &copy, painter, widget);
1462 }
1463 break;
1464 case CC_ScrollBar: {
1465 const auto scrollBarStyleOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
1466 if (scrollBarStyleOption != nullptr) {
1467 if (option->subControls.testFlag(SC_ScrollBarSlider)) {
1468 auto scrollBarStyleOptionCopy = *scrollBarStyleOption;
1469 scrollBarStyleOptionCopy.rect = subControlRect(control, option, SC_ScrollBarSlider, widget);
1470 drawControl(CE_ScrollBarSlider, &scrollBarStyleOptionCopy, painter, widget);
1471 }
1472 }
1473 break;
1474 }
1475 case CC_GroupBox: {
1476 if (qStyleOptionIs<QStyleOptionGroupBox>(option)) {
1477 auto groupBox = *qstyleoption_cast<const QStyleOptionGroupBox *>(option);
1478 groupBox.textAlignment |= Qt::AlignVCenter;
1479
1480 const auto colorGroup = option->state.testFlag(QStyle::State_Enabled)
1481 ? QPalette::Active
1482 : QPalette::Disabled;
1483 if (!groupBox.palette.isBrushSet(colorGroup, QPalette::WindowText))
1484 groupBox.textColor = groupBox.palette.color(QPalette::Text);
1485
1486 const auto titleFont = getGroupBoxTitleFont(widget);
1487 painter->setFont(titleFont);
1488
1489 QCommonStyle::drawComplexControl(control, &groupBox, painter, widget);
1490 }
1491 break;
1492 }
1493 case CC_ComboBox: {
1494 if (qStyleOptionIs<QStyleOptionComboBox>(option)) {
1495 const auto comboBoxStyleOption = qstyleoption_cast<const QStyleOptionComboBox *>(option);
1496 if (option->subControls.testFlag(SC_ComboBoxFrame)) {
1497 auto comboBoxStyleOptionCopy = *comboBoxStyleOption;
1498 comboBoxStyleOptionCopy.rect = subControlRect(control, option, SC_ComboBoxFrame, widget);
1499 drawComboBoxFrame(*painter, comboBoxStyleOptionCopy);
1500 }
1501
1502 if (option->subControls.testFlag(SC_ComboBoxArrow)) {
1503 auto optionCopy = *option;
1504 auto comboBoxOptions = static_cast<QStyleOption *>(&optionCopy);
1505 comboBoxOptions->rect = subControlRect(control, option, SC_ComboBoxArrow, widget);
1506 drawPrimitive(PE_IndicatorArrowDown, comboBoxOptions, painter, widget);
1507 }
1508 } else {
1509 QCommonStyle::drawComplexControl(control, option, painter, widget);
1510 }
1511 break;
1512 }
1513 default:
1514 QCommonStyle::drawComplexControl(control, option, painter, widget);
1515 }
1516}
1517
1518QRect QOhosStyle::subControlRect(
1519 ComplexControl control, const QStyleOptionComplex *option, SubControl subControl, const QWidget *widget) const
1520{
1521 switch (control) {
1522 case CC_Slider:
1523 if (qStyleOptionIs<QStyleOptionSlider>(option)) {
1524 const auto sliderStyleOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
1525 switch (subControl) {
1526 case SC_SliderGroove: {
1527 const auto sliderLengthOffset = pixelMetric(PM_SliderLength, option, widget) * 0.5;
1528 auto grooveRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1529
1530 if (sliderStyleOption->orientation == Qt::Horizontal) {
1531 grooveRect.adjust(sliderLengthOffset, 0, -sliderLengthOffset, 0);
1532 grooveRect.setHeight(sliderGrooveHeight);
1533 grooveRect.moveTop(option->rect.center().y() - sliderGrooveHeight * 0.5);
1534 } else {
1535 grooveRect.adjust(0, sliderLengthOffset, 0, -sliderLengthOffset);
1536 grooveRect.setWidth(sliderGrooveHeight);
1537 grooveRect.moveLeft(option->rect.center().x() - sliderGrooveHeight * 0.5);
1538 }
1539
1540 return grooveRect;
1541 }
1542 case SC_SliderHandle: {
1543 auto handleRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1544 if (sliderStyleOption->orientation == Qt::Horizontal)
1545 handleRect.moveTop(option->rect.center().y() - handleRect.height() * 0.5);
1546 else
1547 handleRect.moveLeft(option->rect.center().x() - handleRect.width() * 0.5);
1548 return handleRect;
1549 }
1550 default:
1551 return QCommonStyle::subControlRect(control, option, subControl, widget);
1552 }
1553 } else {
1554 return QCommonStyle::subControlRect(control, option, subControl, widget);
1555 }
1556 case CC_SpinBox:
1557 if (qStyleOptionIs<QStyleOptionSpinBox>(option)) {
1558 const auto spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option);
1559 auto frameWidth = spinBox->frame ? pixelMetric(PM_SpinBoxFrameWidth, option, widget) : 0;
1560
1561 switch (subControl) {
1562 case SC_SpinBoxFrame: {
1563 auto frameRect = spinBox->rect;
1564 frameRect.setHeight(spinBoxFrameHeight);
1565 frameRect.moveCenter(spinBox->rect.center());
1566 return visualRect(spinBox->direction, spinBox->rect, frameRect);
1567 }
1568 case SC_SpinBoxDown:
1569 case SC_SpinBoxUp: {
1570 auto frameRect = subControlRect(CC_SpinBox, option, SC_SpinBoxFrame, widget);
1571 if (spinBox->buttonSymbols == QAbstractSpinBox::NoButtons)
1572 return QRect();
1573 auto buttonRect = QRect(
1574 frameRect.left() + frameRect.width() - spinBoxButtonBoxWidth,
1575 frameRect.top() + (frameRect.height() - spinBoxFrameHeight) * 0.5,
1576 spinBoxButtonBoxWidth, spinBoxButtonBoxHeight);
1577 if (subControl == SC_SpinBoxDown)
1578 buttonRect.translate(0, spinBoxButtonBoxHeight);
1579 return visualRect(spinBox->direction, frameRect, buttonRect);
1580 }
1581 case SC_SpinBoxEditField: {
1582 auto editRect = adjusted(spinBox->rect, -frameWidth);
1583 if (spinBox->buttonSymbols != QAbstractSpinBox::NoButtons) {
1584 editRect.setWidth(spinBox->rect.width() - frameWidth - spinBoxButtonBoxWidth);
1585 editRect = visualRect(spinBox->direction, spinBox->rect, editRect);
1586 }
1587 return editRect;
1588 }
1589 default:
1590 return QCommonStyle::subControlRect(control, option, subControl, widget);
1591 }
1592 } else {
1593 return QCommonStyle::subControlRect(control, option, subControl, widget);
1594 }
1595 case CC_ScrollBar:
1596 if (qStyleOptionIs<QStyleOptionSlider>(option)) {
1597 auto scrollBoxStyleOption = qstyleoption_cast<const QStyleOptionSlider *>(option);
1598 auto defaultUpButtonRect = QCommonStyle::subControlRect(control, option, SC_ScrollBarSubLine, widget);
1599 auto defaultDownButtonRect = QCommonStyle::subControlRect(control, option, SC_ScrollBarAddLine, widget);
1600 switch (subControl) {
1601 case SC_ScrollBarAddLine:
1602 case SC_ScrollBarSubLine:
1603 return QRect();
1604 case SC_ScrollBarSubPage: {
1605 auto subPageRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1606 if (scrollBoxStyleOption->orientation == Qt::Vertical)
1607 subPageRect.moveTop(subPageRect.top() - defaultDownButtonRect.height());
1608 else
1609 subPageRect.moveLeft(subPageRect.left() - defaultDownButtonRect.width());
1610 return subPageRect;
1611 }
1612 case SC_ScrollBarAddPage: {
1613 auto addPageRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1614 if (scrollBoxStyleOption->orientation == Qt::Vertical)
1615 addPageRect.moveTop(addPageRect.top() + defaultUpButtonRect.height());
1616 else
1617 addPageRect.moveLeft(addPageRect.left() + defaultUpButtonRect.width());
1618 return addPageRect;
1619 }
1620 case SC_ScrollBarSlider: {
1621 const bool activeScrollBar =
1622 option->state.testFlag(QCommonStyle::State_Enabled)
1623 && option->state.testFlag(QCommonStyle::State_MouseOver);
1624 auto scrollBarExtent = activeScrollBar ? thickScrollBarSize : thinScrollBarSize;
1625
1626 auto sliderRect = QCommonStyle::subControlRect(control, option, subControl, widget);
1627 if (scrollBoxStyleOption->orientation == Qt::Vertical) {
1628 sliderRect.setWidth(scrollBarExtent);
1629 sliderRect.setHeight(sliderRect.height() + defaultUpButtonRect.height() + defaultDownButtonRect.height());
1630 sliderRect.moveTop(sliderRect.top() - defaultUpButtonRect.height());
1631 sliderRect.moveLeft((option->rect.width() - sliderRect.width()) * 0.5);
1632 } else {
1633 sliderRect.setHeight(scrollBarExtent);
1634 sliderRect.setWidth(sliderRect.width() + defaultUpButtonRect.width() + defaultDownButtonRect.width());
1635 sliderRect.moveTop((option->rect.height() - sliderRect.height()) * 0.5);
1636 sliderRect.moveLeft(sliderRect.left() - defaultUpButtonRect.width());
1637 }
1638 return sliderRect;
1639 }
1640 default:
1641 return QCommonStyle::subControlRect(control, option, subControl, widget);
1642 }
1643 } else {
1644 return QCommonStyle::subControlRect(control, option, subControl, widget);
1645 }
1646 case CC_GroupBox:
1647 if (qStyleOptionIs<QStyleOptionGroupBox>(option)) {
1648 auto groupBox = *qstyleoption_cast<const QStyleOptionGroupBox *>(option);
1649 groupBox.fontMetrics = QFontMetrics(getGroupBoxTitleFont(widget));
1650
1651 auto labelRect =
1652 QCommonStyle::subControlRect(control, &groupBox, SC_GroupBoxLabel, widget);
1653 if (groupBox.text.isEmpty()) {
1654 labelRect.moveTop(groupBox.rect.top() + groupBoxTopPadding);
1655 labelRect.moveBottom(labelRect.top());
1656 } else {
1657 labelRect.moveTop(
1658 groupBox.rect.top() + groupBoxTopPadding + groupBox.fontMetrics.height() / 2);
1659 }
1660
1661 switch (subControl) {
1662 case SC_GroupBoxFrame:
1663 return QCommonStyle::subControlRect(control, &groupBox, subControl, widget);
1664 case SC_GroupBoxLabel: {
1665 return labelRect;
1666 }
1667 case SC_GroupBoxCheckBox: {
1668 auto checkBoxRect =
1669 QCommonStyle::subControlRect(control, &groupBox, subControl, widget);
1670 checkBoxRect.moveTop(labelRect.center().y() - checkBoxRect.height() / 2);
1671 return checkBoxRect;
1672 }
1673 case SC_GroupBoxContents: {
1674 auto contentsRect =
1675 QCommonStyle::subControlRect(control, &groupBox, SC_GroupBoxContents, widget);
1676 contentsRect.setTop(labelRect.bottom() + (groupBox.text.isEmpty() ? 0 : groupBoxTitleToContentSpacing));
1677 contentsRect.setBottom(groupBox.rect.bottom() - groupBoxBottomPadding);
1678 contentsRect.adjust(groupBoxHorizontalPadding, 0, -groupBoxHorizontalPadding, 0);
1679 return contentsRect;
1680 }
1681 default:
1682 return QCommonStyle::subControlRect(control, option, subControl, widget);
1683 }
1684 } else {
1685 return QCommonStyle::subControlRect(control, option, subControl, widget);
1686 }
1687 case CC_ComboBox:
1688 if (qStyleOptionIs<QStyleOptionComboBox>(option)) {
1689 auto comboBoxStyleOption = qstyleoption_cast<const QStyleOptionComboBox *>(option);
1690 const auto arrowSize = pixelMetric(PM_MenuButtonIndicator, option, widget);
1691 switch (subControl) {
1692 case SC_ComboBoxFrame: {
1693 return adjusted(comboBoxStyleOption->rect, -comboBoxFocusFrameWidth);;
1694 }
1695 case SC_ComboBoxEditField: {
1696 return comboBoxStyleOption->rect.adjusted(
1697 comboBoxFrameLeftRightPadding, comboBoxVerticalMargin,
1698 -arrowSize - comboBoxFrameLeftRightPadding, -comboBoxVerticalMargin);
1699 }
1700 case SC_ComboBoxArrow: {
1701 auto arrowIconRect = comboBoxStyleOption->rect;
1702 arrowIconRect.setWidth(arrowSize);
1703 arrowIconRect.moveRight(comboBoxStyleOption->rect.right());
1704 return visualRect(comboBoxStyleOption->direction, comboBoxStyleOption->rect, arrowIconRect);
1705 }
1706 default:
1707 return QCommonStyle::subControlRect(control, option, subControl, widget);
1708 }
1709 } else {
1710 return QCommonStyle::subControlRect(control, option, subControl, widget);
1711 }
1712 case CC_TitleBar:
1713 if (qStyleOptionIs<QStyleOptionTitleBar>(option)) {
1714 auto titleBarOption = qstyleoption_cast<const QStyleOptionTitleBar *>(option);
1715 return visualRect(
1716 titleBarOption->direction, titleBarOption->rect, titleBarSubControlRect(*titleBarOption, subControl));
1717 } else {
1718 return QCommonStyle::subControlRect(control, option, subControl, widget);
1719 }
1720 default:
1721 return QCommonStyle::subControlRect(control, option, subControl, widget);
1722 }
1723}
1724
1725QRect QOhosStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const
1726{
1727 switch (element) {
1728 case SE_PushButtonContents:
1729 return option->rect.adjusted(pushButtonHorizontalMargin, 0, -pushButtonHorizontalMargin, 0);
1730 case SE_ItemViewItemFocusRect:
1731 return option->rect.adjusted(focusFrameWidth, focusFrameWidth, -focusFrameWidth, -focusFrameWidth);
1732 case SE_ProgressBarGroove:
1733 case SE_ProgressBarContents:
1734 return option->rect;
1735 case SE_ProgressBarLabel:
1736 return QRect();
1737 case SE_LineEditContents: {
1738 int horizontalMargin =
1739 widget != nullptr && qobjectIsInstanceOf<QAbstractSpinBox>(widget->parent())
1740 ? spinBoxEditHorizontalMargin
1741 : lineEditHorizontalMargin;
1742 return option->rect.adjusted(
1743 horizontalMargin, lineEditVerticalMargin, -horizontalMargin, -lineEditVerticalMargin);
1744 }
1745 case SE_CheckBoxFocusRect:
1746 case SE_RadioButtonFocusRect:
1747 return QRect(
1748 checkBoxOrRadioButtonFocusStrokeWidth, (option->rect.height() - checkBoxOrRadioButtonHoverSize) * 0.5,
1749 checkBoxOrRadioButtonHoverSize, checkBoxOrRadioButtonHoverSize);
1750 case SE_CheckBoxClickRect:
1751 return subElementRect(SE_CheckBoxIndicator, option, widget)
1752 | subElementRect(SE_CheckBoxContents, option, widget);
1753 case SE_RadioButtonClickRect:
1754 return subElementRect(SE_RadioButtonIndicator, option, widget)
1755 | subElementRect(SE_RadioButtonContents, option, widget);
1756 default:
1757 return QCommonStyle::subElementRect(element, option, widget);;
1758 }
1759}
1760
1761QSize QOhosStyle::sizeFromContents(
1762 ContentsType contents, const QStyleOption *option, const QSize &contentsSize, const QWidget *widget) const
1763{
1764 switch (contents) {
1765 case CT_ItemViewItem: {
1766 const auto viewItemStyleOption = qstyleoption_cast<const QStyleOptionViewItem *>(option);
1767 if (viewItemStyleOption != nullptr) {
1768 if (isItemViewSeparator(viewItemStyleOption->index)) {
1769 return QSize(option->rect.width(), itemViewSeparatorHeight);
1770 } else {
1771 auto verticalMargin = viewItemStyleOption->features.testFlag(QStyleOptionViewItem::HasDecoration)
1772 ? itemViewItemWithDecorationVerticalMargin
1773 : itemViewItemVerticalMargin;
1774 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget)
1775 + QSize(0, 2 * verticalMargin);
1776 }
1777 } else {
1778 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
1779 }
1780 }
1781 case CT_PushButton: {
1782 auto sizeAlignment = (2 * pushButtonFocusFrameGap) + (2 * pushButtonFocusFrameWidth);
1783 return contentsSize + QSize(
1784 (pushButtonHorizontalMargin * 2) + sizeAlignment, (pushButtonVerticalMargin * 2) + sizeAlignment);
1785 }
1786 case CT_ComboBox: {
1787 const auto arrowSize = pixelMetric(PM_MenuButtonIndicator, option, widget);
1788 auto comboBoxSize = qStyleOptionIs<QStyleOptionComboBox>(option)
1789 && qstyleoption_cast<const QStyleOptionComboBox *>(option)->editable
1790 ? contentsSize + QSize(2 * lineEditHorizontalMargin, 0)
1791 : contentsSize;
1792 const auto frameWidthCompensation = 2 * comboBoxFocusFrameWidth;
1793 comboBoxSize.rwidth() += (arrowSize + frameWidthCompensation + 2 * comboBoxFrameLeftRightPadding);
1794 comboBoxSize.rheight() += (frameWidthCompensation + 2 * comboBoxVerticalMargin + 2 * lineEditVerticalMargin);
1795 return comboBoxSize;
1796 }
1797 case CT_ProgressBar: {
1798 const auto progressBarStyleOption = qstyleoption_cast<const QStyleOptionProgressBar *>(option);
1799 if (progressBarStyleOption != nullptr) {
1800 const bool horizontal = progressBarStyleOption->state & QStyle::State_Horizontal;
1801 if (horizontal)
1802 return QSize(contentsSize.width(), std::max(contentsSize.height(), progressBarMinHeight));
1803 else
1804 return QSize(std::max(contentsSize.height(), progressBarMinHeight), contentsSize.height());
1805 } else {
1806 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
1807 }
1808 }
1809 case CT_MenuItem: {
1810 const auto defaultSize = QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
1811 const auto *menuItemStyleOption = qstyleoption_cast<const QStyleOptionMenuItem *>(option);
1812 if (menuItemStyleOption != nullptr) {
1813 if (menuItemStyleOption->menuItemType == QStyleOptionMenuItem::Separator) {
1814 return QSize(defaultSize.width(), itemViewSeparatorHeight);
1815 } else {
1816 const auto menuVMargin = pixelMetric(PM_MenuVMargin, option, widget);
1817 const auto arrowWidth = menuItemStyleOption->menuItemType == QStyleOptionMenuItem::SubMenu
1818 ? menuVMargin + pixelMetric(PM_SmallIconSize, option, widget)
1819 : 0;
1820 const auto checkboxWidth = menuItemStyleOption->checkType != QStyleOptionMenuItem::NotCheckable
1821 ? menuVMargin + pixelMetric(PM_IndicatorWidth, option, widget)
1822 : 0;
1823
1824 return defaultSize
1825 + QSize(2 * itemViewItemHorizontalMargin, 2 * menuVMargin)
1826 + QSize(arrowWidth, 0)
1827 + QSize(checkboxWidth, 0);
1828 }
1829 } else {
1830 return defaultSize;
1831 }
1832 }
1833 case CT_GroupBox: {
1834 const auto groupBox = qstyleoption_cast<const QStyleOptionGroupBox *>(option);
1835 if (groupBox == nullptr)
1836 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
1837
1838 const QFontMetrics titleMetrics(getGroupBoxTitleFont(widget));
1839 QSize titleSize(
1840 titleMetrics.horizontalAdvance(groupBox->text) + titleMetrics.horizontalAdvance(u' '),
1841 titleMetrics.height());
1842 if (groupBox->subControls.testFlag(SC_GroupBoxCheckBox)) {
1843 titleSize.rwidth() += pixelMetric(PM_IndicatorWidth, option, widget)
1844 + pixelMetric(PM_CheckBoxLabelSpacing, option, widget);
1845 titleSize.rheight() =
1846 std::max(titleSize.height(), pixelMetric(PM_IndicatorHeight, option, widget));
1847 }
1848
1849 return QCommonStyle::sizeFromContents(contents, option, titleSize, widget);
1850 }
1851 case CT_LineEdit: {
1852 int horizontalMargin;
1853 if (widget != nullptr && qobjectIsInstanceOf<QAbstractSpinBox>(widget->parent()))
1854 horizontalMargin = spinBoxEditHorizontalMargin;
1855 else
1856 horizontalMargin = lineEditHorizontalMargin;
1857 return contentsSize + QSize(horizontalMargin * 2, lineEditVerticalMargin * 2);
1858 }
1859 case CT_SpinBox: {
1860 const auto spinBox = qstyleoption_cast<const QStyleOptionSpinBox *>(option);
1861 if (spinBox != nullptr) {
1862 int buttonWidth;
1863 if (spinBox->subControls.testFlag(QStyle::SC_SpinBoxUp)
1864 && spinBox->subControls.testFlag(QStyle::SC_SpinBoxDown)) {
1865 buttonWidth = subControlRect(CC_SpinBox, spinBox, SC_SpinBoxDown, widget).width();
1866 } else {
1867 buttonWidth = 0;
1868 }
1869 const int frameWidth
1870 = spinBox->frame ? pixelMetric(PM_SpinBoxFrameWidth, option, widget) : 0;
1871
1872 return QSize(contentsSize.width() + buttonWidth + 2 * frameWidth + spinBoxEditHorizontalMargin * 2,
1873 std::max(contentsSize.height() + 2 * frameWidth, spinBoxFrameHeight));
1874 }
1875
1876 return contentsSize;
1877 }
1878 default:
1879 return QCommonStyle::sizeFromContents(contents, option, contentsSize, widget);
1880 }
1881}
1882
1883int QOhosStyle::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
1884{
1885 switch (metric) {
1886 case PM_ButtonMargin:
1887 case PM_ButtonDefaultIndicator:
1888 case PM_ButtonShiftHorizontal:
1889 case PM_ButtonShiftVertical:
1890 return 0;
1891 case PM_IndicatorWidth:
1892 case PM_ExclusiveIndicatorWidth:
1893 return checkBoxOrRadioButtonSize;
1894 case PM_IndicatorHeight:
1895 case PM_ExclusiveIndicatorHeight:
1896 return checkBoxOrRadioButtonSize;
1897 case PM_FocusFrameHMargin:
1898 return qStyleOptionIs<QStyleOptionViewItem>(option)
1899 ? itemViewItemSpacing
1900 : QCommonStyle::pixelMetric(metric, option, widget);
1901 case PM_TextCursorWidth:
1902 return textCursorWidth;
1903 case PM_DefaultFrameWidth:
1904 if (qobjectIsInstanceOf<QLineEdit>(widget) || qobjectIsInstanceOf<QPushButton>(widget))
1905 return 0;
1906 else
1907 return QCommonStyle::pixelMetric(metric, option, widget);
1908 case PM_MenuBarPanelWidth:
1909 return 0;
1910 case PM_MenuBarItemSpacing:
1911 return menuBarItemSpacing;
1912 case PM_MenuBarVMargin:
1913 return menuBarVerticalMargin;
1914 case PM_MenuBarHMargin:
1915 return menuBarHorizontalMargin;
1916 case PM_MenuPanelWidth:
1917 return 0;
1918 case PM_MenuHMargin:
1919 return 0;
1920 case PM_MenuVMargin:
1921 return menuItemVerticalMargin;
1922 case PM_ProgressBarChunkWidth:
1923 return 0;
1924 case PM_SliderThickness:
1925 return sliderThickness;
1926 case PM_SliderLength:
1927 case PM_SliderControlThickness:
1928 return sliderThumbSize + 2 * sliderHoverSize;
1929 case PM_SmallIconSize:
1930 return qStyleOptionIs<QStyleOptionMenuItem>(option) || qStyleOptionIs<QStyleOptionComboBox>(option)
1931 ? smallIconSize
1932 : QCommonStyle::pixelMetric(metric, option, widget);
1933 case PM_SplitterWidth:
1934 return splitterWidth;
1935 case PM_SpinBoxFrameWidth:
1936 return spinBoxFrameStroke;
1937 case PM_ScrollBarExtent:
1938 return maxScrollBarSize;
1939 case PM_TabBarTabShiftVertical:
1940 case PM_TabBarBaseOverlap:
1941 return 0;
1942 case PM_TabBarTabHSpace:
1943 return 2 * tabBarTabRadius + 2 * tabBarTabFrameWidth;
1944 case PM_TitleBarHeight:
1945 return titleBarHeight;
1946 case PM_HeaderMargin:
1947 return headerMargin;
1948 case PM_HeaderDefaultSectionSizeVertical:
1949 return headerDefaultSectionSizeVertical;
1950 case PM_ToolTipLabelFrameWidth:
1951 return toolTipFrameWidth;
1952 case PM_MenuButtonIndicator:
1953 return 2 * QCommonStyle::pixelMetric(metric, option, widget);
1954 default:
1955 return QCommonStyle::pixelMetric(metric, option, widget);
1956 }
1957}
1958
1959int QOhosStyle::styleHint(
1960 StyleHint hint, const QStyleOption *option, const QWidget *widget, QStyleHintReturn *hintReturn) const
1961{
1962 switch (hint) {
1963 case SH_Slider_AbsoluteSetButtons:
1964 return Qt::LeftButton | Qt::MiddleButton;
1965 case SH_Slider_PageSetButtons:
1966 return 0;
1967 case SH_ItemView_ShowDecorationSelected:
1968 return qobjectIsInstanceOf<QTreeView>(widget) ? 0 : 1;
1969 case SH_ToolTipLabel_Opacity:
1970 return toolTipBackgroundAlpha;
1971 case SH_Menu_MouseTracking:
1972 case SH_MenuBar_MouseTracking:
1973 return 1;
1974 default:
1975 return QCommonStyle::styleHint(hint, option, widget, hintReturn);
1976 }
1977}
1978
1979void QOhosStyle::polish(QWidget *widget)
1980{
1981 QCommonStyle::polish(widget);
1982
1983 if (isHoverable(widget))
1984 widget->setAttribute(Qt::WA_Hover);
1985
1986 if (qobjectIsInstanceOf<QPushButton>(widget)) {
1987 if (qobject_cast<QPushButton *>(widget)->isDefault()) {
1988 QPalette palette = widget->palette();
1989 auto textDisabledColor = palette.color(QPalette::Active, QPalette::Base);
1990 textDisabledColor.setAlphaF(ohos_id_alpha_disabled);
1991 palette.setColor(QPalette::All, QPalette::ButtonText, palette.color(QPalette::Active, QPalette::Base));
1992 palette.setColor(QPalette::Disabled, QPalette::ButtonText, textDisabledColor);
1993 widget->setPalette(palette);
1994 }
1995 } else if (qobjectIsInstanceOf<QScrollBar>(widget)) {
1996 widget->setAttribute(Qt::WA_NoSystemBackground);
1997 widget->setAttribute(Qt::WA_OpaquePaintEvent, false);
1998 } else if (qobjectIsInstanceOf<QListView>(widget)) {
1999 qobject_cast<QListView *>(widget)->viewport()->setAttribute(Qt::WA_Hover);
2000 } else if (qobjectIsInstanceOf<QComboBox>(widget)) {
2001 auto comboBox = qobject_cast<QComboBox *>(widget);
2002 const char *delegateClassName = comboBox->itemDelegate()->metaObject()->className();
2003 bool isDefaultComboBoxDelegate =
2004 qstrcmp(delegateClassName, "QComboBoxDelegate") == 0
2005 || qstrcmp(delegateClassName, "QComboMenuDelegate") == 0;
2006 if (isDefaultComboBoxDelegate)
2007 comboBox->setItemDelegate(new QStyledItemDelegate(comboBox->view()));
2008 } else if (qobjectIsInstanceOf<QMdiSubWindow>(widget)) {
2009 widget->setAttribute(Qt::WA_TranslucentBackground);
2010 widget->setAutoFillBackground(false);
2011
2012 auto palette = widget->palette();
2013 palette.setColor(QPalette::Highlight, palette.color(QPalette::Active, QPalette::Base));
2014 palette.setColor(QPalette::Inactive, QPalette::Dark, palette.color(QPalette::Inactive, QPalette::Base));
2015 palette.setColor(
2016 QPalette::Inactive, QPalette::Window,
2017 makeInactiveOrDisabledFromColor(palette.color(QPalette::Active, QPalette::AlternateBase)));
2018 palette.setColor(QPalette::HighlightedText, Qt::black);
2019 widget->setPalette(palette);
2020 }
2021}
2022
2023void QOhosStyle::unpolish(QWidget *widget)
2024{
2025 if (isHoverable(widget)) {
2026 widget->setAttribute(Qt::WA_Hover, false);
2027 } else if (qobjectIsInstanceOf<QScrollBar>(widget)) {
2028 widget->setAttribute(Qt::WA_NoSystemBackground, false);
2029 widget->setAttribute(Qt::WA_OpaquePaintEvent);
2030 } else if (qobjectIsInstanceOf<QListView>(widget)) {
2031 qobject_cast<QListView *>(widget)->viewport()->setAttribute(Qt::WA_Hover, false);
2032 }
2033 QCommonStyle::unpolish(widget);
2034}
2035
2036QPalette QOhosStyle::standardPalette() const
2037{
2038 return *QGuiApplicationPrivate::platformTheme()->palette();
2039}
2040
2041QIcon QOhosStyle::standardIcon(
2042 StandardPixmap standardPixmap, const QStyleOption *option, const QWidget *widget) const
2043{
2044 const QString iconName = ohosThemeIconName(standardPixmap);
2045 if (!iconName.isEmpty()) {
2046 const QIcon icon = QIcon::fromTheme(iconName);
2047 if (!icon.isNull())
2048 return icon;
2049 }
2050
2051 return QCommonStyle::standardIcon(standardPixmap, option, widget);
2052}