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
qquickstyleitemprogressbar.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
21
23{
24 QStyleOptionProgressBar styleOption;
25 initStyleOption(styleOption);
26
27 StyleItemGeometry geometry;
28 geometry.minimumSize = style()->sizeFromContents(QStyle::CT_ProgressBar, &styleOption, QSize(0, 0));
29
30 // From qprogressbar.cpp in qtbase:
31 const int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &styleOption);
32 QFontMetrics fm(control<QQuickProgressBar>()->font());
33 QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8);
34 if (!(styleOption.state & QStyle::State_Horizontal))
35 size = size.transposed();
36
37 geometry.implicitSize = style()->sizeFromContents(QStyle::CT_ProgressBar, &styleOption, size);
38 styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
39 geometry.contentRect = style()->subElementRect(QStyle::SE_ProgressBarContents, &styleOption);
40 geometry.layoutRect = style()->subElementRect(QStyle::SE_ProgressBarLayoutItem, &styleOption);
41 geometry.ninePatchMargins = style()->ninePatchMargins(QStyle::CE_ProgressBar, &styleOption, geometry.minimumSize);
42
43 return geometry;
44}
45
47{
48 QStyleOptionProgressBar styleOption;
49 initStyleOption(styleOption);
50#ifndef Q_OS_MACOS
51 const QRect r = styleOption.rect;
52#endif
53 // Note: on macOS, the groove will paint both the background and the contents
54 styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarGroove, &styleOption);
55 style()->drawControl(QStyle::CE_ProgressBarGroove, &styleOption, painter);
56#ifndef Q_OS_MACOS
57 styleOption.rect = r;
58 styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarContents, &styleOption);
59 style()->drawControl(QStyle::CE_ProgressBarContents, &styleOption, painter);
60#endif
61}
62
63void QQuickStyleItemProgressBar::initStyleOption(QStyleOptionProgressBar &styleOption) const
64{
65 initStyleOptionBase(styleOption);
66 auto progressBar = control<QQuickProgressBar>();
67
68 styleOption.state = QStyle::State_Horizontal;
69
70 if (progressBar->isIndeterminate()) {
71 styleOption.minimum = 0;
72 styleOption.maximum = 0;
73 } else if (progressBar->to() - progressBar->from() < 100) {
74 // Add some range to support float numbers
75 styleOption.minimum = 0;
76 styleOption.maximum = (progressBar->to() - progressBar->from()) * 100;
77 styleOption.progress = (progressBar->value() - progressBar->from()) * 100;
78 } else {
79 styleOption.minimum = progressBar->from();
80 styleOption.maximum = progressBar->to();
81 styleOption.progress = progressBar->value();
82 }
83}
84
86
87#include "moc_qquickstyleitemprogressbar.cpp"
\reentrant \inmodule QtGui
\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
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
StyleItemGeometry calculateGeometry() override
QFont styleFont(QQuickItem *control) const override
void paintEvent(QPainter *painter) 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
\variable QStyleOptionButton::features
QStyle::State state
@ State_Horizontal
Definition qstyle.h:74
@ CT_ProgressBar
Definition qstyle.h:553
@ CE_ProgressBarLabel
Definition qstyle.h:188
@ CE_ProgressBarContents
Definition qstyle.h:187
@ CE_ProgressBar
Definition qstyle.h:185
@ CE_ProgressBarGroove
Definition qstyle.h:186
@ PM_ProgressBarChunkWidth
Definition qstyle.h:445
@ SE_ProgressBarGroove
Definition qstyle.h:260
@ SE_ProgressBarLayoutItem
Definition qstyle.h:293
@ SE_ProgressBarContents
Definition qstyle.h:261
Combined button and popup list for selecting options.
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLboolean r
[2]
static const struct TessellationWindingOrderTab cw[]
QPainter painter(this)
[7]
\inmodule QtCore \reentrant
Definition qchar.h:18