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#include "qquickstyleoption.h"
5
6#include <QtGui/private/qguiapplication_p.h>
7#include <QtCore/qdebug.h>
8#include <QtCore/qmath.h>
9
10QT_BEGIN_NAMESPACE
11
12namespace QQC2 {
13
14QStyleOption::QStyleOption(int version, int type)
15 : version(version), type(type), state(QStyle::State_None),
16 direction(QGuiApplication::layoutDirection()), fontMetrics(QFont()),
17 styleObject(nullptr), control(nullptr), window(nullptr)
18{
19}
20
21/*!
22 Destroys this style option object.
23*/
24QStyleOption::~QStyleOption()
25{
26}
27
28/*!
29 Constructs a copy of \a other.
30*/
31QStyleOption::QStyleOption(const QStyleOption &other)
32 : version(Version), type(Type), state(other.state),
33 direction(other.direction), rect(other.rect), fontMetrics(other.fontMetrics),
34 palette(other.palette), styleObject(other.styleObject),
35 control(other.control), window(other.window)
36{
37}
38
39/*!
40 Assign \a other to this QStyleOption.
41*/
42QStyleOption &QStyleOption::operator=(const QStyleOption &other)
43{
44 control = other.control;
45 window = other.window;
46 state = other.state;
47 direction = other.direction;
48 rect = other.rect;
49 fontMetrics = other.fontMetrics;
50 palette = other.palette;
51 styleObject = other.styleObject;
52 return *this;
53}
54
55/*!
56 Constructs a QStyleOptionFocusRect, initializing the members
57 variables to their default values.
58*/
59QStyleOptionFocusRect::QStyleOptionFocusRect()
60 : QStyleOption(Version, SO_FocusRect)
61{
62 state |= QStyle::State_KeyboardFocusChange; // assume we had one, will be corrected in initFrom()
63}
64
65/*!
66 \internal
67*/
68QStyleOptionFocusRect::QStyleOptionFocusRect(int versionIn)
69 : QStyleOption(versionIn, SO_FocusRect)
70{
71 state |= QStyle::State_KeyboardFocusChange; // assume we had one, will be corrected in initFrom()
72}
73
74/*!
75 Constructs a QStyleOptionFrame, initializing the members
76 variables to their default values.
77*/
78QStyleOptionFrame::QStyleOptionFrame()
79 : QStyleOption(Version, SO_Frame), lineWidth(0), midLineWidth(0),
80 features(None), frameShape(NoFrame)
81{
82}
83
84/*!
85 \internal
86*/
87QStyleOptionFrame::QStyleOptionFrame(int versionIn)
88 : QStyleOption(versionIn, SO_Frame), lineWidth(0), midLineWidth(0),
89 features(None)
90{
91}
92
93/*!
94 Constructs a QStyleOptionGroupBox, initializing the members
95 variables to their default values.
96*/
97QStyleOptionGroupBox::QStyleOptionGroupBox()
98 : QStyleOptionComplex(Version, Type), features(QStyleOptionFrame::None),
99 textAlignment(Qt::AlignLeft), lineWidth(0), midLineWidth(0)
100{
101}
102
103QStyleOptionGroupBox::QStyleOptionGroupBox(int versionIn)
104 : QStyleOptionComplex(versionIn, Type), features(QStyleOptionFrame::None),
105 textAlignment(Qt::AlignLeft), lineWidth(0), midLineWidth(0)
106{
107}
108
109/*!
110 Constructs a QStyleOptionHeader, initializing the members
111 variables to their default values.
112*/
113QStyleOptionHeader::QStyleOptionHeader()
114 : QStyleOption(QStyleOptionHeader::Version, SO_Header),
115 section(0), textAlignment(Qt::AlignLeft), iconAlignment(Qt::AlignLeft),
116 position(QStyleOptionHeader::Beginning),
117 selectedPosition(QStyleOptionHeader::NotAdjacent), sortIndicator(None),
118 orientation(Qt::Horizontal)
119{
120}
121
122/*!
123 \internal
124*/
125QStyleOptionHeader::QStyleOptionHeader(int versionIn)
126 : QStyleOption(versionIn, SO_Header),
127 section(0), textAlignment(Qt::AlignLeft), iconAlignment(Qt::AlignLeft),
128 position(QStyleOptionHeader::Beginning),
129 selectedPosition(QStyleOptionHeader::NotAdjacent), sortIndicator(None),
130 orientation(Qt::Horizontal)
131{
132}
133
134/*!
135 Constructs a QStyleOptionButton, initializing the members
136 variables to their default values.
137*/
138QStyleOptionButton::QStyleOptionButton()
139 : QStyleOption(QStyleOptionButton::Version, SO_Button), features(None)
140{
141}
142
143/*!
144 \internal
145*/
146QStyleOptionButton::QStyleOptionButton(int versionIn)
147 : QStyleOption(versionIn, SO_Button), features(None)
148{
149}
150
151/*!
152 Constructs a QStyleOptionToolBar, initializing the members
153 variables to their default values.
154*/
155QStyleOptionToolBar::QStyleOptionToolBar()
156 : QStyleOption(Version, SO_ToolBar), positionOfLine(OnlyOne), positionWithinLine(OnlyOne),
157 toolBarArea(Qt::TopToolBarArea), features(None), lineWidth(0), midLineWidth(0)
158{
159}
160
161/*!
162 \fn QStyleOptionToolBar::QStyleOptionToolBar(const QStyleOptionToolBar &other)
163
164 Constructs a copy of the \a other style option.
165*/
166QStyleOptionToolBar::QStyleOptionToolBar(int versionIn)
167: QStyleOption(versionIn, SO_ToolBar), positionOfLine(OnlyOne), positionWithinLine(OnlyOne),
168 toolBarArea(Qt::TopToolBarArea), features(None), lineWidth(0), midLineWidth(0)
169{
170
171}
172
173/*!
174 Constructs a QStyleOptionTab object, initializing the members
175 variables to their default values.
176*/
177QStyleOptionTab::QStyleOptionTab()
178 : QStyleOption(QStyleOptionTab::Version, SO_Tab),
179 row(0),
180 position(Beginning),
181 selectedPosition(NotAdjacent), cornerWidgets(QStyleOptionTab::NoCornerWidgets),
182 documentMode(false),
183 features(QStyleOptionTab::None)
184{
185}
186
187QStyleOptionTab::QStyleOptionTab(int versionIn)
188 : QStyleOption(versionIn, SO_Tab),
189 row(0),
190 position(Beginning),
191 selectedPosition(NotAdjacent), cornerWidgets(QStyleOptionTab::NoCornerWidgets),
192 documentMode(false),
193 features(QStyleOptionTab::None)
194{
195}
196
197/*!
198 Constructs a QStyleOptionTabV4 object, initializing the members
199 variables to their default values.
200 */
201QStyleOptionTabV4::QStyleOptionTabV4() : QStyleOptionTab(QStyleOptionTabV4::Version)
202{
203}
204
205/*!
206 Constructs a QStyleOptionProgressBar, initializing the members
207 variables to their default values.
208*/
209QStyleOptionProgressBar::QStyleOptionProgressBar()
210 : QStyleOption(QStyleOptionProgressBar::Version, SO_ProgressBar),
211 minimum(0), maximum(0), progress(0), textAlignment(Qt::AlignLeft), textVisible(false),
212 invertedAppearance(false), bottomToTop(false)
213{
214}
215
216QStyleOptionProgressBar::QStyleOptionProgressBar(int versionIn)
217 : QStyleOption(versionIn, SO_ProgressBar),
218 minimum(0), maximum(0), progress(0), textAlignment(Qt::AlignLeft), textVisible(false),
219 invertedAppearance(false), bottomToTop(false)
220{
221}
222
223/*!
224 Constructs a QStyleOptionMenuItem, initializing the members
225 variables to their default values.
226*/
227QStyleOptionMenuItem::QStyleOptionMenuItem()
228 : QStyleOption(QStyleOptionMenuItem::Version, SO_MenuItem), menuItemType(Normal),
229 checkType(NotCheckable), checked(false), menuHasCheckableItems(true), maxIconWidth(0), tabWidth(0)
230{
231}
232
233/*!
234 \internal
235*/
236QStyleOptionMenuItem::QStyleOptionMenuItem(int versionIn)
237 : QStyleOption(versionIn, SO_MenuItem), menuItemType(Normal),
238 checkType(NotCheckable), checked(false), menuHasCheckableItems(true), maxIconWidth(0), tabWidth(0)
239{
240}
241
242/*!
243 Constructs a QStyleOptionComplex of the specified \a type and \a
244 version, initializing the member variables to their default
245 values. This constructor is usually called by subclasses.
246*/
247QStyleOptionComplex::QStyleOptionComplex(int versionIn, int typeIn)
248 : QStyleOption(versionIn, typeIn), subControls(QStyle::SC_All), activeSubControls(QStyle::SC_None)
249{
250}
251
252
253/*!
254 Constructs a QStyleOptionSlider, initializing the members
255 variables to their default values.
256*/
257QStyleOptionSlider::QStyleOptionSlider()
258 : QStyleOptionComplex(Version, SO_Slider), orientation(Qt::Horizontal), minimum(0), maximum(0),
259 tickPosition(NoTicks), tickInterval(0), upsideDown(false),
260 sliderPosition(0), sliderValue(0), singleStep(0), pageStep(0), notchTarget(0.0),
261 dialWrapping(false)
262{
263}
264
265/*!
266 \internal
267*/
268QStyleOptionSlider::QStyleOptionSlider(int versionIn)
269 : QStyleOptionComplex(versionIn, SO_Slider), orientation(Qt::Horizontal), minimum(0), maximum(0),
270 tickPosition(NoTicks), tickInterval(0), upsideDown(false),
271 sliderPosition(0), sliderValue(0), singleStep(0), pageStep(0), notchTarget(0.0),
272 dialWrapping(false)
273{
274}
275
276/*!
277 Constructs a QStyleOptionSpinBox, initializing the members
278 variables to their default values.
279*/
280QStyleOptionSpinBox::QStyleOptionSpinBox()
281 : QStyleOptionComplex(Version, SO_SpinBox), buttonSymbols(UpDownArrows),
282 stepEnabled(StepNone), frame(false)
283{
284}
285
286/*!
287 \internal
288*/
289QStyleOptionSpinBox::QStyleOptionSpinBox(int versionIn)
290 : QStyleOptionComplex(versionIn, SO_SpinBox), buttonSymbols(UpDownArrows),
291 stepEnabled(StepNone), frame(false)
292{
293}
294
295/*!
296 Constructs a QStyleOptionDockWidget, initializing the member
297 variables to their default values.
298*/
299QStyleOptionDockWidget::QStyleOptionDockWidget()
300 : QStyleOption(Version, SO_DockWidget), closable(false),
301 movable(false), floatable(false), verticalTitleBar(false)
302{
303}
304
305/*!
306 \internal
307*/
308QStyleOptionDockWidget::QStyleOptionDockWidget(int versionIn)
309 : QStyleOption(versionIn, SO_DockWidget), closable(false),
310 movable(false), floatable(false), verticalTitleBar(false)
311{
312}
313
314/*!
315 Constructs a QStyleOptionToolButton, initializing the members
316 variables to their default values.
317*/
318QStyleOptionToolButton::QStyleOptionToolButton()
319 : QStyleOptionComplex(Version, SO_ToolButton), features(None), arrowType(Qt::DownArrow)
320 , toolButtonStyle(Qt::ToolButtonIconOnly)
321{
322}
323
324QStyleOptionToolButton::QStyleOptionToolButton(int versionIn)
325 : QStyleOptionComplex(versionIn, SO_ToolButton), features(None), arrowType(Qt::DownArrow)
326 , toolButtonStyle(Qt::ToolButtonIconOnly)
327
328{
329}
330
331/*!
332 Creates a QStyleOptionComboBox, initializing the members variables
333 to their default values.
334*/
335QStyleOptionComboBox::QStyleOptionComboBox()
336 : QStyleOptionComplex(Version, SO_ComboBox), editable(false), frame(true)
337{
338}
339
340QStyleOptionComboBox::QStyleOptionComboBox(int versionIn)
341 : QStyleOptionComplex(versionIn, SO_ComboBox), editable(false), frame(true)
342{
343}
344
345/*!
346 Creates a QStyleOptionToolBox, initializing the members variables
347 to their default values.
348*/
349QStyleOptionToolBox::QStyleOptionToolBox()
350 : QStyleOption(Version, SO_ToolBox), position(Beginning), selectedPosition(NotAdjacent)
351{
352}
353
354QStyleOptionToolBox::QStyleOptionToolBox(int versionIn)
355 : QStyleOption(versionIn, SO_ToolBox), position(Beginning), selectedPosition(NotAdjacent)
356{
357}
358
359
360/*!
361 Creates a QStyleOptionRubberBand, initializing the members
362 variables to their default values.
363*/
364QStyleOptionRubberBand::QStyleOptionRubberBand()
365 : QStyleOption(Version, SO_RubberBand), opaque(false), shape(Line)
366{
367}
368
369QStyleOptionRubberBand::QStyleOptionRubberBand(int versionIn)
370 : QStyleOption(versionIn, SO_RubberBand), opaque(false)
371{
372}
373
374/*!
375 Constructs a QStyleOptionTitleBar, initializing the members
376 variables to their default values.
377*/
378QStyleOptionTitleBar::QStyleOptionTitleBar()
379 : QStyleOptionComplex(Version, SO_TitleBar), titleBarState(0)
380{
381}
382
383QStyleOptionTitleBar::QStyleOptionTitleBar(int versionIn)
384 : QStyleOptionComplex(versionIn, SO_TitleBar), titleBarState(0)
385{
386}
387
388/*!
389 Constructs a QStyleOptionViewItem, initializing the members
390 variables to their default values.
391*/
392QStyleOptionViewItem::QStyleOptionViewItem()
393 : QStyleOption(Version, SO_ViewItem),
394 displayAlignment(Qt::AlignLeft), decorationAlignment(Qt::AlignLeft),
395 textElideMode(Qt::ElideMiddle), decorationPosition(Left),
396 showDecorationSelected(false), features(None),
397 checkState(Qt::Unchecked), viewItemPosition(QStyleOptionViewItem::Invalid)
398{
399}
400
401QStyleOptionViewItem::QStyleOptionViewItem(int versionIn)
402 : QStyleOption(versionIn, SO_ViewItem),
403 displayAlignment(Qt::AlignLeft), decorationAlignment(Qt::AlignLeft),
404 textElideMode(Qt::ElideMiddle), decorationPosition(Left),
405 showDecorationSelected(false), features(None),
406 checkState(Qt::Unchecked), viewItemPosition(QStyleOptionViewItem::Invalid)
407{
408}
409
410/*!
411 Constructs a QStyleOptionTabWidgetFrame, initializing the members
412 variables to their default values.
413*/
414QStyleOptionTabWidgetFrame::QStyleOptionTabWidgetFrame()
415 : QStyleOption(Version, SO_TabWidgetFrame), lineWidth(0), midLineWidth(0), shape(QStyleOptionTab::RoundedNorth)
416{
417}
418
419QStyleOptionTabWidgetFrame::QStyleOptionTabWidgetFrame(int versionIn)
420 : QStyleOption(versionIn, SO_TabWidgetFrame), lineWidth(0), midLineWidth(0)
421{
422}
423
424/*!
425 Construct a QStyleOptionTabBarBase, initializing the members
426 vaiables to their default values.
427*/
428QStyleOptionTabBarBase::QStyleOptionTabBarBase()
429 : QStyleOption(Version, SO_TabBarBase), documentMode(false), shape(QStyleOptionTab::RoundedNorth)
430{
431}
432
433QStyleOptionTabBarBase::QStyleOptionTabBarBase(int versionIn)
434 : QStyleOption(versionIn, SO_TabBarBase), documentMode(false)
435{
436}
437
438/*!
439 Constructs a QStyleOptionSizeGrip.
440*/
441QStyleOptionSizeGrip::QStyleOptionSizeGrip()
442 : QStyleOptionComplex(Version, Type), corner(Qt::BottomRightCorner)
443{
444}
445
446QStyleOptionSizeGrip::QStyleOptionSizeGrip(int versionIn)
447 : QStyleOptionComplex(versionIn, Type), corner(Qt::BottomRightCorner)
448{
449}
450
451/*!
452 Constructs a QStyleOptionGraphicsItem.
453*/
454QStyleOptionGraphicsItem::QStyleOptionGraphicsItem()
455 : QStyleOption(Version, Type), levelOfDetail(1)
456{
457}
458
459QStyleOptionGraphicsItem::QStyleOptionGraphicsItem(int versionIn)
460 : QStyleOption(versionIn, Type), levelOfDetail(1)
461{
462}
463
464/*!
465 \since 4.6
466
467 Returns the level of detail from the \a worldTransform.
468
469 Its value represents the maximum value of the height and
470 width of a unity rectangle, mapped using the \a worldTransform
471 of the painter used to draw the item. By default, if no
472 transformations are applied, its value is 1. If zoomed out 1:2, the level
473 of detail will be 0.5, and if zoomed in 2:1, its value is 2.
474
475 \sa QGraphicsScene::minimumRenderSize()
476*/
477qreal QStyleOptionGraphicsItem::levelOfDetailFromTransform(const QTransform &worldTransform)
478{
479 if (worldTransform.type() <= QTransform::TxTranslate)
480 return 1; // Translation only? The LOD is 1.
481
482 // Two unit vectors.
483 QLineF v1(0, 0, 1, 0);
484 QLineF v2(0, 0, 0, 1);
485 // LOD is the transformed area of a 1x1 rectangle.
486 return qSqrt(v: worldTransform.map(l: v1).length() * worldTransform.map(l: v2).length());
487}
488
489/*!
490 Constructs a QStyleHintReturn with version \a version and type \a
491 type.
492
493 The version has no special meaning for QStyleHintReturn; it can be
494 used by subclasses to distinguish between different version of
495 the same hint type.
496
497 \sa QStyleOption::version, QStyleOption::type
498*/
499QStyleHintReturn::QStyleHintReturn(int versionIn, int type)
500 : version(versionIn), type(type)
501{
502}
503
504/*!
505 \internal
506*/
507
508QStyleHintReturn::~QStyleHintReturn()
509{
510}
511
512/*!
513 Constructs a QStyleHintReturnMask. The member variables are
514 initialized to default values.
515*/
516QStyleHintReturnMask::QStyleHintReturnMask() : QStyleHintReturn(Version, Type)
517{
518}
519
520QStyleHintReturnMask::~QStyleHintReturnMask()
521{
522}
523
524/*!
525 Constructs a QStyleHintReturnVariant. The member variables are
526 initialized to default values.
527*/
528QStyleHintReturnVariant::QStyleHintReturnVariant() : QStyleHintReturn(Version, Type)
529{
530}
531
532QStyleHintReturnVariant::~QStyleHintReturnVariant()
533{
534}
535
536#if !defined(QT_NO_DEBUG_STREAM)
537QDebug operator<<(QDebug debug, const QStyleOption::OptionType &optionType)
538{
539#if !defined(QT_NO_DEBUG)
540 switch (optionType) {
541 case QStyleOption::SO_Default:
542 debug << "SO_Default"; break;
543 case QStyleOption::SO_FocusRect:
544 debug << "SO_FocusRect"; break;
545 case QStyleOption::SO_Button:
546 debug << "SO_Button"; break;
547 case QStyleOption::SO_Tab:
548 debug << "SO_Tab"; break;
549 case QStyleOption::SO_MenuItem:
550 debug << "SO_MenuItem"; break;
551 case QStyleOption::SO_Frame:
552 debug << "SO_Frame"; break;
553 case QStyleOption::SO_ProgressBar:
554 debug << "SO_ProgressBar"; break;
555 case QStyleOption::SO_ToolBox:
556 debug << "SO_ToolBox"; break;
557 case QStyleOption::SO_Header:
558 debug << "SO_Header"; break;
559 case QStyleOption::SO_DockWidget:
560 debug << "SO_DockWidget"; break;
561 case QStyleOption::SO_ViewItem:
562 debug << "SO_ViewItem"; break;
563 case QStyleOption::SO_TabWidgetFrame:
564 debug << "SO_TabWidgetFrame"; break;
565 case QStyleOption::SO_TabBarBase:
566 debug << "SO_TabBarBase"; break;
567 case QStyleOption::SO_RubberBand:
568 debug << "SO_RubberBand"; break;
569 case QStyleOption::SO_Complex:
570 debug << "SO_Complex"; break;
571 case QStyleOption::SO_Slider:
572 debug << "SO_Slider"; break;
573 case QStyleOption::SO_SpinBox:
574 debug << "SO_SpinBox"; break;
575 case QStyleOption::SO_ToolButton:
576 debug << "SO_ToolButton"; break;
577 case QStyleOption::SO_ComboBox:
578 debug << "SO_ComboBox"; break;
579 case QStyleOption::SO_TitleBar:
580 debug << "SO_TitleBar"; break;
581 case QStyleOption::SO_CustomBase:
582 debug << "SO_CustomBase"; break;
583 case QStyleOption::SO_GroupBox:
584 debug << "SO_GroupBox"; break;
585 case QStyleOption::SO_ToolBar:
586 debug << "SO_ToolBar"; break;
587 case QStyleOption::SO_ComplexCustomBase:
588 debug << "SO_ComplexCustomBase"; break;
589 case QStyleOption::SO_SizeGrip:
590 debug << "SO_SizeGrip"; break;
591 case QStyleOption::SO_GraphicsItem:
592 debug << "SO_GraphicsItem"; break;
593 }
594#else
595 Q_UNUSED(optionType);
596#endif
597 return debug;
598}
599
600QDebug operator<<(QDebug debug, const QStyleOption &option)
601{
602#if !defined(QT_NO_DEBUG)
603 debug << "QStyleOption(";
604 debug << QStyleOption::OptionType(option.type);
605 debug << ',' << (option.direction == Qt::RightToLeft ? "RightToLeft" : "LeftToRight");
606 debug << ',' << option.state;
607 debug << ',' << option.rect;
608 debug << ',' << option.styleObject;
609 debug << ')';
610#else
611 Q_UNUSED(option);
612#endif
613 return debug;
614}
615#endif
616
617} // namespace QQC2
618
619QT_END_NAMESPACE
620

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