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
qquickbasicdial.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 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 "qquickbasicdial_p.h"
5
6#include <QtCore/qmath.h>
7#include <QtGui/qpainter.h>
8#include <QtGui/qpainterpath.h>
9#include <QtQuick/private/qquickitem_p.h>
10
12
17
19{
20 return m_progress;
21}
22
24{
25 if (progress == m_progress)
26 return;
27
28 m_progress = progress;
29 update();
30}
31
33{
34 return m_startAngle;
35}
36
38{
39 if (startAngle == m_startAngle)
40 return;
41
42 m_startAngle = startAngle;
43 update();
44}
45
47{
48 return m_endAngle;
49}
50
52{
53 if (endAngle == m_endAngle)
54 return;
55
56 m_endAngle = endAngle;
57 update();
58}
59
61{
62 return m_color;
63}
64
66{
67 if (color == m_color)
68 return;
69
70 m_color = color;
71 update();
72}
73
75{
76 if (width() <= 0 || height() <= 0)
77 return;
78
79 QPen pen(m_color);
80 pen.setWidth(8);
82 painter->setPen(pen);
83
84 const QRectF bounds = boundingRect();
85 const qreal smallest = qMin(bounds.width(), bounds.height());
86 QRectF rect = QRectF(pen.widthF() / 2.0 + 1, pen.widthF() / 2.0 + 1, smallest - pen.widthF() - 2, smallest - pen.widthF() - 2);
87 rect.moveCenter(bounds.center());
88
89 // Make sure the arc is aligned to whole pixels.
90 if (rect.x() - int(rect.x()) > 0)
91 rect.setX(qCeil(rect.x()));
92 if (rect.y() - int(rect.y()) > 0)
93 rect.setY(qCeil(rect.y()));
94 if (rect.width() - int(rect.width()) > 0)
95 rect.setWidth(qFloor(rect.width()));
96 if (rect.height() - int(rect.height()) > 0)
97 rect.setHeight(qFloor(rect.height()));
98
100
101 const qreal startAngle = 90. - m_startAngle;
102 const qreal spanAngle = m_progress * (m_startAngle - m_endAngle);
104 path.arcMoveTo(rect, startAngle);
105 path.arcTo(rect, startAngle, spanAngle);
107
108 rect.adjust(-pen.widthF() / 2.0, -pen.widthF() / 2.0, pen.widthF() / 2.0, pen.widthF() / 2.0);
109 pen.setWidth(1);
110 painter->setPen(pen);
111
112 path = QPainterPath();
113 path.arcMoveTo(rect, 0);
114 path.arcTo(rect, 0, 360);
116}
117
119
120#include "moc_qquickbasicdial_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
\inmodule QtGui
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void drawPath(const QPainterPath &path)
Draws the given painter path using the current pen for outline and the current brush for filling.
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ Antialiasing
Definition qpainter.h:52
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
\inmodule QtGui
Definition qpen.h:28
void setCapStyle(Qt::PenCapStyle pcs)
Sets the pen's cap style to the given style.
Definition qpen.cpp:650
qreal widthF() const
Returns the pen width with floating point precision.
Definition qpen.cpp:572
void setWidth(int width)
Sets the pen width to the given width in pixels with integer precision.
Definition qpen.cpp:592
void setColor(const QColor &color)
void setStartAngle(qreal startAngle)
void setProgress(qreal progress)
QQuickBasicDial(QQuickItem *parent=nullptr)
void paint(QPainter *painter) override
This function, which is usually called by the QML Scene Graph, paints the contents of an item in loca...
void setEndAngle(qreal endAngle)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
virtual QRectF boundingRect() const
Returns the extents of the item in its own coordinate system: a rectangle from {0,...
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
void update()
Schedules a call to updatePaintNode() for this item.
The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.
\inmodule QtCore\reentrant
Definition qrect.h:484
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:732
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:729
constexpr QPointF center() const noexcept
Returns the center point of the rectangle.
Definition qrect.h:699
rect
[4]
Combined button and popup list for selecting options.
@ FlatCap
int qFloor(T v)
Definition qmath.h:42
int qCeil(T v)
Definition qmath.h:36
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
GLuint color
[2]
GLsizei const GLchar *const * path
double qreal
Definition qtypes.h:187
QPainter painter(this)
[7]