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
qquickstyleitemscrollbar.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
9 : QQuickStyleItem(parent)
10{
11#ifdef QT_DEBUG
12 setObjectName("styleItemScrollBar");
13#endif
14}
15
20
28
30{
31 QStyleOptionSlider styleOption;
32 initStyleOption(styleOption);
33
34 StyleItemGeometry geometry;
35 geometry.minimumSize = style()->sizeFromContents(QStyle::CT_ScrollBar, &styleOption, QSize(0, 0));
36 if (m_subControl == SubLine || m_subControl == AddLine) {
37 // So far, we know that only the windows style uses these subcontrols,
38 // so we can use hardcoded sizes...
39 QSize sz(16, 17);
40 if (styleOption.orientation == Qt::Vertical)
41 sz.transpose();
42 geometry.minimumSize = sz;
43 }
44 geometry.implicitSize = geometry.minimumSize;
45 styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
46 geometry.layoutRect = style()->subElementRect(QStyle::SE_ScrollBarLayoutItem, &styleOption);
47 geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CC_ScrollBar, &styleOption, geometry.minimumSize);
48
49 return geometry;
50}
51
53{
54 QStyleOptionSlider styleOption;
55 initStyleOption(styleOption);
56 if (m_subControl == SubLine || m_subControl == AddLine) {
58 QStyleOptionSlider opt = styleOption;
62
63 const qreal scale = window()->effectiveDevicePixelRatio();
64 const QSize scrollBarMinSize = style()->sizeFromContents(QStyle::CT_ScrollBar, &opt, QSize(0, 0));
65 const QSize sz = scrollBarMinSize * scale;
67 scrollBarImage.setDevicePixelRatio(scale);
68 QPainter p(&scrollBarImage);
69 opt.rect = QRect(QPoint(0, 0), scrollBarMinSize);
70 style()->drawComplexControl(QStyle::CC_ScrollBar, &opt, &p);
71 QRect sourceImageRect = style()->subControlRect(QStyle::CC_ScrollBar, &opt, sc);
72 sourceImageRect = QRect(sourceImageRect.topLeft() * scale, sourceImageRect.size() * scale);
73 painter->drawImage(QPoint(0, 0), scrollBarImage, sourceImageRect);
74 } else {
75 style()->drawComplexControl(QStyle::CC_ScrollBar, &styleOption, painter);
76 }
77}
78
79void QQuickStyleItemScrollBar::initStyleOption(QStyleOptionSlider &styleOption) const
80{
81 initStyleOptionBase(styleOption);
82 auto scrollBar = control<QQuickScrollBar>();
83
84 switch (m_subControl) {
85 case Groove:
87 break;
88 case Handle:
90 break;
91 case AddLine:
93 break;
94 case SubLine:
96 break;
97 }
98
100 styleOption.orientation = scrollBar->orientation();
101 if (styleOption.orientation == Qt::Horizontal)
102 styleOption.state |= QStyle::State_Horizontal;
103
104 if (scrollBar->isPressed())
105 styleOption.state |= QStyle::State_Sunken;
106
107 if (m_overrideState != None) {
108 // In ScrollBar.qml we fade between two versions of
109 // the handle, depending on if it's hovered or not
110
112 styleOption.state &= ~QStyle::State_Sunken;
114 } else if (m_overrideState == NeverHovered) {
115 styleOption.state &= ~QStyle::State_Sunken;
117 } else if (m_overrideState == AlwaysSunken) {
118 styleOption.state |= QStyle::State_Sunken;
120 }
121 }
122
123 // The following values will let the handle fill 100% of the
124 // groove / imageSize. But when the handle is resized by
125 // QQuickScrollBar, it will end up with the correct size visually.
126 styleOption.pageStep = 1000;
127 styleOption.minimum = 0;
128 styleOption.maximum = 1;
129 styleOption.sliderValue = 0;
130}
131
133
134#include "moc_qquickstyleitemscrollbar.cpp"
Qt::Orientation orientation
the orientation of the slider
\reentrant
Definition qfont.h:22
\inmodule QtGui
Definition qimage.h:37
@ Format_ARGB32_Premultiplied
Definition qimage.h:48
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
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
\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
QQuickWindow * window() const
Returns the window in which this item is rendered.
qreal scale
\qmlproperty real QtQuick::Item::scale This property holds the scale factor for this item.
Definition qquickitem.h:107
void pressedChanged()
void orientationChanged()
void connectToControl() const override
void paintEvent(QPainter *painter) const override
QFont styleFont(QQuickItem *control) const override
StyleItemGeometry calculateGeometry() override
QQuickStyleItemScrollBar(QQuickItem *parent=nullptr)
virtual void connectToControl() const
OverrideState m_overrideState
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
void transpose() noexcept
Swaps the width and height values.
Definition qsize.cpp:130
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI.
Definition qstyle.h:29
@ State_Sunken
Definition qstyle.h:69
@ State_Horizontal
Definition qstyle.h:74
@ CT_ScrollBar
Definition qstyle.h:560
@ CE_ProgressBarLabel
Definition qstyle.h:188
@ CC_ScrollBar
Definition qstyle.h:334
SubControl
This enum describes the available sub controls.
Definition qstyle.h:347
@ SC_ScrollBarSubLine
Definition qstyle.h:351
@ SC_ScrollBarAddLine
Definition qstyle.h:350
@ SC_ScrollBarGroove
Definition qstyle.h:357
@ SC_ScrollBarSlider
Definition qstyle.h:356
@ SC_None
Definition qstyle.h:348
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
GLfloat GLfloat p
[1]
GLenum GLenum GLenum GLenum GLenum scale
double qreal
Definition qtypes.h:187
QScrollBar * scrollBar
QPainter painter(this)
[7]