1// Copyright (C) 2020 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#ifndef QSTYLEOPTION_H
5#define QSTYLEOPTION_H
6
7#include "qquickstyle.h"
8
9#include <QtCore/qlocale.h>
10#include <QtCore/qvariant.h>
11#include <QtCore/qdebug.h>
12#include <QtCore/qabstractitemmodel.h>
13
14#include <QtGui/qicon.h>
15#include <QtGui/qfontmetrics.h>
16
17QT_BEGIN_NAMESPACE
18
19class QQuickItem;
20
21namespace QQC2 {
22
23class QStyleOption
24{
25public:
26 enum OptionType {
27 SO_Default, SO_FocusRect, SO_Button, SO_Tab, SO_MenuItem,
28 SO_Frame, SO_ProgressBar, SO_ToolBox, SO_Header,
29 SO_DockWidget, SO_ViewItem, SO_TabWidgetFrame,
30 SO_TabBarBase, SO_RubberBand, SO_ToolBar, SO_GraphicsItem,
31
32 SO_Complex = 0xf0000, SO_Slider, SO_SpinBox, SO_ToolButton, SO_ComboBox,
33 SO_TitleBar, SO_GroupBox, SO_SizeGrip,
34
35 SO_CustomBase = 0xf00,
36 SO_ComplexCustomBase = 0xf000000
37 };
38
39 enum StyleOptionType { Type = SO_Default };
40 enum StyleOptionVersion { Version = 1 };
41
42 int version; // TODO: Remove version information
43 int type;
44 QStyle::State state;
45 Qt::LayoutDirection direction;
46 QRect rect;
47 QFontMetrics fontMetrics;
48 QPalette palette;
49 QObject *styleObject;
50
51 // QQC2 additions. Remember to also update copy
52 // constructor and assignment operator when adding
53 // new variables here.
54 QQuickItem *control;
55 QWindow *window;
56
57 QStyleOption(int version = QStyleOption::Version, int type = SO_Default);
58 QStyleOption(const QStyleOption &other);
59 ~QStyleOption();
60
61 QStyleOption &operator=(const QStyleOption &other);
62};
63
64class QStyleOptionFocusRect : public QStyleOption
65{
66public:
67 enum StyleOptionType { Type = SO_FocusRect };
68 enum StyleOptionVersion { Version = 1 };
69
70 QColor backgroundColor;
71
72 QStyleOptionFocusRect();
73 QStyleOptionFocusRect(const QStyleOptionFocusRect &other) : QStyleOption(Version, Type) { *this = other; }
74 QStyleOptionFocusRect &operator=(const QStyleOptionFocusRect &) = default;
75
76protected:
77 QStyleOptionFocusRect(int version);
78};
79
80class QStyleOptionFrame : public QStyleOption
81{
82public:
83 enum StyleOptionType { Type = SO_Frame };
84 enum StyleOptionVersion { Version = 3 };
85 enum FrameFeature {
86 None = 0x00,
87 Flat = 0x01,
88 Rounded = 0x02
89 };
90 Q_DECLARE_FLAGS(FrameFeatures, FrameFeature)
91 enum Shape {
92 NoFrame = 0, // no frame
93 Box = 0x0001, // rectangular box
94 Panel = 0x0002, // rectangular panel
95 WinPanel = 0x0003, // rectangular panel (Windows)
96 HLine = 0x0004, // horizontal line
97 VLine = 0x0005, // vertical line
98 StyledPanel = 0x0006 // rectangular panel depending on the GUI style
99 };
100 enum Shadow {
101 Plain = 0x0010, // plain line
102 Raised = 0x0020, // raised shadow effect
103 Sunken = 0x0030 // sunken shadow effect
104 };
105
106 int lineWidth;
107 int midLineWidth;
108 FrameFeatures features;
109 Shape frameShape;
110
111 QStyleOptionFrame();
112 QStyleOptionFrame(const QStyleOptionFrame &other) : QStyleOption(Version, Type) { *this = other; }
113 QStyleOptionFrame &operator=(const QStyleOptionFrame &) = default;
114
115protected:
116 QStyleOptionFrame(int version);
117};
118
119Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionFrame::FrameFeatures)
120Q_DECLARE_MIXED_ENUM_OPERATORS_SYMMETRIC(int, QStyleOptionFrame::Shape, QStyleOptionFrame::Shadow)
121
122Q_DECL_DEPRECATED typedef QStyleOptionFrame QStyleOptionFrameV2;
123Q_DECL_DEPRECATED typedef QStyleOptionFrame QStyleOptionFrameV3;
124
125class QStyleOptionTab : public QStyleOption
126{
127public:
128 enum StyleOptionType { Type = SO_Tab };
129 enum StyleOptionVersion { Version = 3 };
130
131 enum TabPosition { Beginning, Middle, End, OnlyOneTab };
132 enum SelectedPosition { NotAdjacent, NextIsSelected, PreviousIsSelected };
133 enum CornerWidget { NoCornerWidgets = 0x00, LeftCornerWidget = 0x01,
134 RightCornerWidget = 0x02 };
135 enum TabFeature { None = 0x00, HasFrame = 0x01 };
136 enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
137 TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
138 };
139 Q_DECLARE_FLAGS(CornerWidgets, CornerWidget)
140 Q_DECLARE_FLAGS(TabFeatures, TabFeature)
141
142 QString text;
143 QIcon icon;
144 int row;
145 TabPosition position;
146 Shape shape = RoundedNorth;
147 SelectedPosition selectedPosition;
148 CornerWidgets cornerWidgets;
149 QSize iconSize;
150 bool documentMode;
151 QSize leftButtonSize;
152 QSize rightButtonSize;
153 TabFeatures features;
154
155 QStyleOptionTab();
156 QStyleOptionTab(const QStyleOptionTab &other) : QStyleOption(Version, Type) { *this = other; }
157 QStyleOptionTab &operator=(const QStyleOptionTab &) = default;
158
159protected:
160 QStyleOptionTab(int version);
161};
162
163class QStyleOptionTabWidgetFrame : public QStyleOption
164{
165public:
166 enum StyleOptionType { Type = SO_TabWidgetFrame };
167 enum StyleOptionVersion { Version = 2 };
168
169 int lineWidth;
170 int midLineWidth;
171 QStyleOptionTab::Shape shape;
172 QSize tabBarSize;
173 QSize rightCornerWidgetSize;
174 QSize leftCornerWidgetSize;
175 QRect tabBarRect;
176 QRect selectedTabRect;
177
178 QStyleOptionTabWidgetFrame();
179 inline QStyleOptionTabWidgetFrame(const QStyleOptionTabWidgetFrame &other)
180 : QStyleOption(Version, Type) { *this = other; }
181 QStyleOptionTabWidgetFrame &operator=(const QStyleOptionTabWidgetFrame &) = default;
182
183protected:
184 QStyleOptionTabWidgetFrame(int version);
185};
186
187Q_DECL_DEPRECATED typedef QStyleOptionTabWidgetFrame QStyleOptionTabWidgetFrameV2;
188
189
190class QStyleOptionTabBarBase : public QStyleOption
191{
192public:
193 enum StyleOptionType { Type = SO_TabBarBase };
194
195 enum TabBarPosition { North, South, West, East };
196 enum ButtonPosition { LeftSide, RightSide };
197
198 QRect tabBarRect;
199 QRect selectedTabRect;
200 bool documentMode;
201 QStyleOptionTab::Shape shape;
202
203 QStyleOptionTabBarBase();
204 QStyleOptionTabBarBase(const QStyleOptionTabBarBase &other) : QStyleOption(Version, Type) { *this = other; }
205 QStyleOptionTabBarBase &operator=(const QStyleOptionTabBarBase &) = default;
206
207protected:
208 QStyleOptionTabBarBase(int version);
209};
210
211class QStyleOptionHeader : public QStyleOption
212{
213public:
214 enum StyleOptionType { Type = SO_Header };
215 enum StyleOptionVersion { Version = 1 };
216 enum SectionPosition { Beginning, Middle, End, OnlyOneSection };
217 enum SelectedPosition { NotAdjacent, NextIsSelected, PreviousIsSelected,
218 NextAndPreviousAreSelected };
219 enum SortIndicator { None, SortUp, SortDown };
220
221 int section;
222 QString text;
223 Qt::Alignment textAlignment;
224 QIcon icon;
225 Qt::Alignment iconAlignment;
226 SectionPosition position;
227 SelectedPosition selectedPosition;
228 SortIndicator sortIndicator;
229 Qt::Orientation orientation;
230
231 QStyleOptionHeader();
232 QStyleOptionHeader(const QStyleOptionHeader &other) : QStyleOption(Version, Type) { *this = other; }
233 QStyleOptionHeader &operator=(const QStyleOptionHeader &) = default;
234
235protected:
236 QStyleOptionHeader(int version);
237};
238
239class QStyleOptionButton : public QStyleOption
240{
241public:
242 enum StyleOptionType { Type = SO_Button };
243 enum StyleOptionVersion { Version = 1 };
244
245 enum ButtonFeature { None = 0x00, Flat = 0x01, HasMenu = 0x02, DefaultButton = 0x04,
246 AutoDefaultButton = 0x08, CommandLinkButton = 0x10 };
247 Q_DECLARE_FLAGS(ButtonFeatures, ButtonFeature)
248
249 ButtonFeatures features;
250 QString text;
251 QIcon icon;
252 QSize iconSize;
253
254 QStyleOptionButton();
255 QStyleOptionButton(const QStyleOptionButton &other) : QStyleOption(Version, Type) { *this = other; }
256 QStyleOptionButton &operator=(const QStyleOptionButton &) = default;
257
258protected:
259 QStyleOptionButton(int version);
260};
261
262Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionButton::ButtonFeatures)
263
264class QStyleOptionTabV4 : public QStyleOptionTab
265{
266public:
267 enum StyleOptionVersion { Version = 4 };
268 QStyleOptionTabV4();
269 int tabIndex = -1;
270};
271
272Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionTab::CornerWidgets)
273
274Q_DECL_DEPRECATED typedef QStyleOptionTab QStyleOptionTabV2;
275Q_DECL_DEPRECATED typedef QStyleOptionTab QStyleOptionTabV3;
276
277
278class QStyleOptionToolBar : public QStyleOption
279{
280public:
281 enum StyleOptionType { Type = SO_ToolBar };
282 enum StyleOptionVersion { Version = 1 };
283 enum ToolBarPosition { Beginning, Middle, End, OnlyOne };
284 enum ToolBarFeature { None = 0x0, Movable = 0x1 };
285 Q_DECLARE_FLAGS(ToolBarFeatures, ToolBarFeature)
286
287 ToolBarPosition positionOfLine; // The toolbar line position
288 ToolBarPosition positionWithinLine; // The position within a toolbar
289 Qt::ToolBarArea toolBarArea; // The toolbar docking area
290 ToolBarFeatures features;
291 int lineWidth;
292 int midLineWidth;
293
294 QStyleOptionToolBar();
295 QStyleOptionToolBar(const QStyleOptionToolBar &other) : QStyleOption(Version, Type) { *this = other; }
296 QStyleOptionToolBar &operator=(const QStyleOptionToolBar &) = default;
297
298protected:
299 QStyleOptionToolBar(int version);
300};
301
302Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionToolBar::ToolBarFeatures)
303
304class QStyleOptionProgressBar : public QStyleOption
305{
306public:
307 enum StyleOptionType { Type = SO_ProgressBar };
308 enum StyleOptionVersion { Version = 2 };
309
310 int minimum;
311 int maximum;
312 int progress;
313 QString text;
314 Qt::Alignment textAlignment;
315 bool textVisible;
316 bool invertedAppearance;
317 bool bottomToTop;
318
319 QStyleOptionProgressBar();
320 QStyleOptionProgressBar(const QStyleOptionProgressBar &other) : QStyleOption(Version, Type) { *this = other; }
321 QStyleOptionProgressBar &operator=(const QStyleOptionProgressBar &) = default;
322
323protected:
324 QStyleOptionProgressBar(int version);
325};
326
327class QStyleOptionMenuItem : public QStyleOption
328{
329public:
330 enum StyleOptionType { Type = SO_MenuItem };
331 enum StyleOptionVersion { Version = 1 };
332
333 enum MenuItemType { Normal, DefaultItem, Separator, SubMenu, Scroller, TearOff, Margin,
334 EmptyArea };
335 enum CheckType { NotCheckable, Exclusive, NonExclusive };
336
337 MenuItemType menuItemType;
338 CheckType checkType;
339 bool checked;
340 bool menuHasCheckableItems;
341 QRect menuRect;
342 QString text;
343 QIcon icon;
344 int maxIconWidth;
345 int tabWidth; // ### Qt 6: rename to reservedShortcutWidth
346 QFont font;
347
348 QStyleOptionMenuItem();
349 QStyleOptionMenuItem(const QStyleOptionMenuItem &other) : QStyleOption(Version, Type) { *this = other; }
350 QStyleOptionMenuItem &operator=(const QStyleOptionMenuItem &) = default;
351
352protected:
353 QStyleOptionMenuItem(int version);
354};
355
356class QStyleOptionDockWidget : public QStyleOption
357{
358public:
359 enum StyleOptionType { Type = SO_DockWidget };
360 enum StyleOptionVersion { Version = 2 };
361
362 QString title;
363 bool closable;
364 bool movable;
365 bool floatable;
366 bool verticalTitleBar;
367
368 QStyleOptionDockWidget();
369 QStyleOptionDockWidget(const QStyleOptionDockWidget &other) : QStyleOption(Version, Type) { *this = other; }
370 QStyleOptionDockWidget &operator=(const QStyleOptionDockWidget &) = default;
371
372protected:
373 QStyleOptionDockWidget(int version);
374};
375
376Q_DECL_DEPRECATED typedef QStyleOptionDockWidget QStyleOptionDockWidgetV2;
377
378class QStyleOptionViewItem : public QStyleOption
379{
380public:
381 enum StyleOptionType { Type = SO_ViewItem };
382 enum StyleOptionVersion { Version = 4 };
383
384 enum Position { Left, Right, Top, Bottom };
385 enum ScrollMode { ScrollPerItem, ScrollPerPixel }; // Doesn't really belong in this class.
386
387 Qt::Alignment displayAlignment;
388 Qt::Alignment decorationAlignment;
389 Qt::TextElideMode textElideMode;
390 Position decorationPosition;
391 QSize decorationSize;
392 QFont font;
393 bool showDecorationSelected;
394
395 enum ViewItemFeature {
396 None = 0x00,
397 WrapText = 0x01,
398 Alternate = 0x02,
399 HasCheckIndicator = 0x04,
400 HasDisplay = 0x08,
401 HasDecoration = 0x10
402 };
403 Q_DECLARE_FLAGS(ViewItemFeatures, ViewItemFeature)
404
405 ViewItemFeatures features;
406
407 QLocale locale;
408
409 enum ViewItemPosition { Invalid, Beginning, Middle, End, OnlyOne };
410
411 QModelIndex index;
412 Qt::CheckState checkState;
413 QIcon icon;
414 QString text;
415 ViewItemPosition viewItemPosition;
416 QBrush backgroundBrush;
417
418 QStyleOptionViewItem();
419 QStyleOptionViewItem(const QStyleOptionViewItem &other) : QStyleOption(Version, Type) { *this = other; }
420 QStyleOptionViewItem &operator=(const QStyleOptionViewItem &) = default;
421
422protected:
423 QStyleOptionViewItem(int version);
424};
425
426Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionViewItem::ViewItemFeatures)
427
428Q_DECL_DEPRECATED typedef QStyleOptionViewItem QStyleOptionViewItemV2;
429Q_DECL_DEPRECATED typedef QStyleOptionViewItem QStyleOptionViewItemV3;
430Q_DECL_DEPRECATED typedef QStyleOptionViewItem QStyleOptionViewItemV4;
431
432class QStyleOptionToolBox : public QStyleOption
433{
434public:
435 enum StyleOptionType { Type = SO_ToolBox };
436 enum StyleOptionVersion { Version = 2 };
437
438 QString text;
439 QIcon icon;
440
441 enum TabPosition { Beginning, Middle, End, OnlyOneTab };
442 enum SelectedPosition { NotAdjacent, NextIsSelected, PreviousIsSelected };
443
444 TabPosition position;
445 SelectedPosition selectedPosition;
446
447 QStyleOptionToolBox();
448 QStyleOptionToolBox(const QStyleOptionToolBox &other) : QStyleOption(Version, Type) { *this = other; }
449 QStyleOptionToolBox &operator=(const QStyleOptionToolBox &) = default;
450
451protected:
452 QStyleOptionToolBox(int version);
453};
454
455Q_DECL_DEPRECATED typedef QStyleOptionToolBox QStyleOptionToolBoxV2;
456
457class QStyleOptionRubberBand : public QStyleOption
458{
459public:
460 enum StyleOptionType { Type = SO_RubberBand };
461 enum StyleOptionVersion { Version = 1 };
462 enum Shape { Line, Rectangle };
463
464 bool opaque;
465 Shape shape;
466
467 QStyleOptionRubberBand();
468 QStyleOptionRubberBand(const QStyleOptionRubberBand &other) : QStyleOption(Version, Type) { *this = other; }
469 QStyleOptionRubberBand &operator=(const QStyleOptionRubberBand &) = default;
470
471protected:
472 QStyleOptionRubberBand(int version);
473};
474
475// -------------------------- Complex style options -------------------------------
476class QStyleOptionComplex : public QStyleOption
477{
478public:
479 enum StyleOptionType { Type = SO_Complex };
480 enum StyleOptionVersion { Version = 1 };
481
482 QStyle::SubControls subControls;
483 QStyle::SubControls activeSubControls;
484
485 QStyleOptionComplex(int version = QStyleOptionComplex::Version, int type = SO_Complex);
486 QStyleOptionComplex(const QStyleOptionComplex &other) : QStyleOption(Version, Type) { *this = other; }
487 QStyleOptionComplex &operator=(const QStyleOptionComplex &) = default;
488};
489
490class QStyleOptionSlider : public QStyleOptionComplex
491{
492public:
493 enum StyleOptionType { Type = SO_Slider };
494 enum StyleOptionVersion { Version = 1 };
495 enum TickPosition {
496 NoTicks = 0,
497 TicksAbove = 1,
498 TicksLeft = TicksAbove,
499 TicksBelow = 2,
500 TicksRight = TicksBelow,
501 TicksBothSides = 3
502 };
503
504 Qt::Orientation orientation;
505 int minimum;
506 int maximum;
507 TickPosition tickPosition;
508 int tickInterval;
509 bool upsideDown;
510 int sliderPosition;
511 int sliderValue;
512 int singleStep;
513 int pageStep;
514 qreal notchTarget;
515 bool dialWrapping;
516 qreal startAngle;
517 qreal endAngle;
518
519 QStyleOptionSlider();
520 QStyleOptionSlider(const QStyleOptionSlider &other) : QStyleOptionComplex(Version, Type) { *this = other; }
521 QStyleOptionSlider &operator=(const QStyleOptionSlider &) = default;
522
523protected:
524 QStyleOptionSlider(int version);
525};
526
527class QStyleOptionSpinBox : public QStyleOptionComplex
528{
529public:
530 enum StyleOptionType { Type = SO_SpinBox };
531 enum StyleOptionVersion { Version = 1 };
532 enum StepEnabledFlag { StepNone = 0x00, StepUpEnabled = 0x01, StepDownEnabled = 0x02, StepEnabled = 0xFF };
533 enum ButtonSymbols { UpDownArrows, PlusMinus, NoButtons };
534
535 ButtonSymbols buttonSymbols;
536 StepEnabledFlag stepEnabled;
537 bool frame;
538
539 QStyleOptionSpinBox();
540 QStyleOptionSpinBox(const QStyleOptionSpinBox &other) : QStyleOptionComplex(Version, Type) { *this = other; }
541 QStyleOptionSpinBox &operator=(const QStyleOptionSpinBox &) = default;
542
543protected:
544 QStyleOptionSpinBox(int version);
545};
546
547class QStyleOptionToolButton : public QStyleOptionComplex
548{
549public:
550 enum StyleOptionType { Type = SO_ToolButton };
551 enum StyleOptionVersion { Version = 1 };
552
553 enum ToolButtonFeature { None = 0x00, Arrow = 0x01, Menu = 0x04, MenuButtonPopup = Menu, PopupDelay = 0x08,
554 HasMenu = 0x10 };
555 Q_DECLARE_FLAGS(ToolButtonFeatures, ToolButtonFeature)
556
557 ToolButtonFeatures features;
558 QIcon icon;
559 QSize iconSize;
560 QString text;
561 Qt::ArrowType arrowType;
562 Qt::ToolButtonStyle toolButtonStyle;
563 QPoint pos;
564 QFont font;
565
566 QStyleOptionToolButton();
567 QStyleOptionToolButton(const QStyleOptionToolButton &other) : QStyleOptionComplex(Version, Type) { *this = other; }
568 QStyleOptionToolButton &operator=(const QStyleOptionToolButton &) = default;
569
570protected:
571 QStyleOptionToolButton(int version);
572};
573
574Q_DECLARE_OPERATORS_FOR_FLAGS(QStyleOptionToolButton::ToolButtonFeatures)
575
576class QStyleOptionComboBox : public QStyleOptionComplex
577{
578public:
579 enum StyleOptionType { Type = SO_ComboBox };
580 enum StyleOptionVersion { Version = 1 };
581
582 bool editable;
583 QRect popupRect;
584 bool frame;
585 QString currentText;
586 QIcon currentIcon;
587 QSize iconSize;
588
589 QStyleOptionComboBox();
590 QStyleOptionComboBox(const QStyleOptionComboBox &other) : QStyleOptionComplex(Version, Type) { *this = other; }
591 QStyleOptionComboBox &operator=(const QStyleOptionComboBox &) = default;
592
593protected:
594 QStyleOptionComboBox(int version);
595};
596
597class QStyleOptionTitleBar : public QStyleOptionComplex
598{
599public:
600 enum StyleOptionType { Type = SO_TitleBar };
601 enum StyleOptionVersion { Version = 1 };
602
603 QString text;
604 QIcon icon;
605 int titleBarState;
606 Qt::WindowFlags titleBarFlags;
607
608 QStyleOptionTitleBar();
609 QStyleOptionTitleBar(const QStyleOptionTitleBar &other) : QStyleOptionComplex(Version, Type) { *this = other; }
610 QStyleOptionTitleBar &operator=(const QStyleOptionTitleBar &) = default;
611
612protected:
613 QStyleOptionTitleBar(int version);
614};
615
616class QStyleOptionGroupBox : public QStyleOptionComplex
617{
618public:
619 enum StyleOptionType { Type = SO_GroupBox };
620 enum StyleOptionVersion { Version = 1 };
621
622 QStyleOptionFrame::FrameFeatures features;
623 QString text;
624 Qt::Alignment textAlignment;
625 QColor textColor;
626 int lineWidth;
627 int midLineWidth;
628
629 QStyleOptionGroupBox();
630 QStyleOptionGroupBox(const QStyleOptionGroupBox &other) : QStyleOptionComplex(Version, Type) { *this = other; }
631 QStyleOptionGroupBox &operator=(const QStyleOptionGroupBox &) = default;
632protected:
633 QStyleOptionGroupBox(int version);
634};
635
636class QStyleOptionSizeGrip : public QStyleOptionComplex
637{
638public:
639 enum StyleOptionType { Type = SO_SizeGrip };
640 enum StyleOptionVersion { Version = 1 };
641
642 Qt::Corner corner;
643
644 QStyleOptionSizeGrip();
645 QStyleOptionSizeGrip(const QStyleOptionSizeGrip &other) : QStyleOptionComplex(Version, Type) { *this = other; }
646 QStyleOptionSizeGrip &operator=(const QStyleOptionSizeGrip &) = default;
647protected:
648 QStyleOptionSizeGrip(int version);
649};
650
651class QStyleOptionGraphicsItem : public QStyleOption
652{
653public:
654 enum StyleOptionType { Type = SO_GraphicsItem };
655 enum StyleOptionVersion { Version = 1 };
656
657 QRectF exposedRect;
658 qreal levelOfDetail;
659
660 QStyleOptionGraphicsItem();
661 QStyleOptionGraphicsItem(const QStyleOptionGraphicsItem &other) : QStyleOption(Version, Type) { *this = other; }
662 QStyleOptionGraphicsItem &operator=(const QStyleOptionGraphicsItem &) = default;
663 static qreal levelOfDetailFromTransform(const QTransform &worldTransform);
664protected:
665 QStyleOptionGraphicsItem(int version);
666};
667
668template <typename T>
669T qstyleoption_cast(const QStyleOption *opt)
670{
671 typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Opt;
672 if (opt && opt->version >= Opt::Version && (opt->type == Opt::Type
673 || int(Opt::Type) == QStyleOption::SO_Default
674 || (int(Opt::Type) == QStyleOption::SO_Complex
675 && opt->type > QStyleOption::SO_Complex)))
676 return static_cast<T>(opt);
677 return nullptr;
678}
679
680template <typename T>
681T qstyleoption_cast(QStyleOption *opt)
682{
683 typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Opt;
684 if (opt && opt->version >= Opt::Version && (opt->type == Opt::Type
685 || int(Opt::Type) == QStyleOption::SO_Default
686 || (int(Opt::Type) == QStyleOption::SO_Complex
687 && opt->type > QStyleOption::SO_Complex)))
688 return static_cast<T>(opt);
689 return nullptr;
690}
691
692// -------------------------- QStyleHintReturn -------------------------------
693
694class QStyleHintReturn
695{
696public:
697 enum HintReturnType {
698 SH_Default=0xf000, SH_Mask, SH_Variant
699 };
700
701 enum StyleOptionType { Type = SH_Default };
702 enum StyleOptionVersion { Version = 1 };
703
704 QStyleHintReturn(int version = QStyleOption::Version, int type = SH_Default);
705 ~QStyleHintReturn();
706
707 int version;
708 int type;
709};
710
711class QStyleHintReturnMask : public QStyleHintReturn
712{
713public:
714 enum StyleOptionType { Type = SH_Mask };
715 enum StyleOptionVersion { Version = 1 };
716
717 QStyleHintReturnMask();
718 ~QStyleHintReturnMask();
719
720 QRegion region;
721};
722
723class QStyleHintReturnVariant : public QStyleHintReturn
724{
725public:
726 enum StyleOptionType { Type = SH_Variant };
727 enum StyleOptionVersion { Version = 1 };
728
729 QStyleHintReturnVariant();
730 ~QStyleHintReturnVariant();
731
732 QVariant variant;
733};
734
735template <typename T>
736T qstyleoption_cast(const QStyleHintReturn *hint)
737{
738 typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Opt;
739 if (hint && hint->version <= Opt::Version &&
740 (hint->type == Opt::Type || int(Opt::Type) == QStyleHintReturn::SH_Default))
741 return static_cast<T>(hint);
742 return nullptr;
743}
744
745template <typename T>
746T qstyleoption_cast(QStyleHintReturn *hint)
747{
748 typedef typename std::remove_cv<typename std::remove_pointer<T>::type>::type Opt;
749 if (hint && hint->version <= Opt::Version &&
750 (hint->type == Opt::Type || int(Opt::Type) == QStyleHintReturn::SH_Default))
751 return static_cast<T>(hint);
752 return nullptr;
753}
754
755#if !defined(QT_NO_DEBUG_STREAM)
756QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType);
757QDebug operator<<(QDebug debug, const QStyleOption &option);
758#endif
759
760} // namespace QQC2
761
762QT_END_NAMESPACE
763
764#endif // QSTYLEOPTION_H
765

source code of qtdeclarative/src/quicknativestyle/qstyle/qquickstyleoption.h