Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickstyleitemslider.cpp
Go to the documentation of this file.
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
5
7
12
25
27{
28 QStyleOptionSlider styleOption;
29 initStyleOption(styleOption);
30
31 StyleItemGeometry geometry;
32 geometry.minimumSize = style()->sizeFromContents(QStyle::CT_Slider, &styleOption, QSize(0, 0));
33 geometry.implicitSize = geometry.minimumSize;
34 styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
35 geometry.layoutRect = style()->subElementRect(QStyle::SE_SliderLayoutItem, &styleOption);
36 geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CC_Slider, &styleOption, geometry.minimumSize);
37 geometry.focusFrameRadius = style()->pixelMetric(QStyle::PM_SliderFocusFrameRadius, &styleOption);
38
39 return geometry;
40}
41
43{
44 QStyleOptionSlider styleOption;
45 initStyleOption(styleOption);
46 style()->drawComplexControl(QStyle::CC_Slider, &styleOption, painter);
47}
48
49void QQuickStyleItemSlider::initStyleOption(QStyleOptionSlider &styleOption) const
50{
51 initStyleOptionBase(styleOption);
52 auto slider = control<QQuickSlider>();
53
54 styleOption.subControls = QStyle::SC_None;
55 if (m_subControl & Groove)
57 if (m_subControl & Handle)
60 styleOption.orientation = slider->orientation();
61
62 if (slider->isPressed())
63 styleOption.state |= QStyle::State_Sunken;
64
65 qreal min = 0;
66 qreal max = 1;
67 if (!qFuzzyIsNull(slider->stepSize())) {
68 min = slider->from();
69 max = slider->to();
70
71 // TODO: add proper API for tickmarks
72 const int index = slider->metaObject()->indexOfProperty("qqc2_style_tickPosition");
73 if (index != -1) {
74 const int tickPosition = slider->metaObject()->property(index).read(slider).toInt();
75 styleOption.tickPosition = QStyleOptionSlider::TickPosition(tickPosition);
78 }
79 }
80
81 // Since the [from, to] interval in QQuickSlider is floating point, users can
82 // specify very small ranges and step sizes, (e.g. [0.., 0.25], step size 0.05).
83 // Since the style operates on ints, we cannot pass these values directly to the style,
84 // so we normalize all values to the range [0, 10000]
85 static const qreal Scale = 10000;
86 const qreal normalizeMultiplier = Scale/(max - min);
87 styleOption.tickInterval = int(slider->stepSize() * normalizeMultiplier);
88 styleOption.minimum = 0;
89 styleOption.maximum = int(Scale);
90 styleOption.sliderValue = int((slider->value() - min) * normalizeMultiplier);
91 styleOption.sliderPosition = int(slider->position() * styleOption.maximum);
92}
93
95
96#include "moc_qquickstyleitemslider.cpp"
\reentrant
Definition qfont.h:22
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
\inmodule QtCore\reentrant
Definition qpoint.h:25
QStyle::SubControls subControls
QStyle::SubControls activeSubControls
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void stepSizeChanged()
void positionChanged()
void pressedChanged()
void fromChanged()
void orientationChanged()
void valueChanged()
void toChanged()
void connectToControl() const override
StyleItemGeometry calculateGeometry() override
void paintEvent(QPainter *painter) const override
QFont styleFont(QQuickItem *control) const override
virtual void connectToControl() const
static QStyle::State controlSize(QQuickItem *item)
void initStyleOptionBase(QStyleOption &styleOption) const
QQuickItem * control
static QStyle * style()
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
Definition qsize.h:25
@ State_Sunken
Definition qstyle.h:69
@ CT_Slider
Definition qstyle.h:559
@ CE_ProgressBarLabel
Definition qstyle.h:188
@ CC_Slider
Definition qstyle.h:335
@ SE_SliderLayoutItem
Definition qstyle.h:296
@ SC_SliderGroove
Definition qstyle.h:369
@ SC_None
Definition qstyle.h:348
@ SC_SliderTickmarks
Definition qstyle.h:371
@ SC_SliderHandle
Definition qstyle.h:370
Combined button and popup list for selecting options.
constexpr const T & min(const T &a, const T &b)
Definition qnumeric.h:366
bool qFuzzyIsNull(qfloat16 f) noexcept
Definition qfloat16.h:349
GLuint index
[2]
double qreal
Definition qtypes.h:187
QPainter painter(this)
[7]