Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickfusiondial.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// Qt-Security score:significant reason:default
4
6
7#include <QtGui/qpainter.h>
8#include <QtGui/private/qmath_p.h>
9
11
12QQuickFusionDial::QQuickFusionDial(QQuickItem *parent)
14{
15}
16
17bool QQuickFusionDial::highlight() const
18{
19 return m_highlight;
20}
21
22void QQuickFusionDial::setHighlight(bool highlight)
23{
24 if (m_highlight == highlight)
25 return;
26
27 m_highlight = highlight;
28 update();
29}
30
31QColor QQuickFusionDial::buttonColor() const
32{
33 return m_buttonColor;
34}
35
36void QQuickFusionDial::setButtonColor(const QColor &color)
37{
38 if (m_buttonColor == color)
39 return;
40
41 m_buttonColor = color;
42 update();
43}
44
45QColor QQuickFusionDial::highlightColor() const
46{
47 return m_highlightColor;
48}
49
50void QQuickFusionDial::setHighlightColor(const QColor &color)
51{
52 if (m_highlightColor == color)
53 return;
54
55 m_highlightColor = color;
56 update();
57}
58
59// based on QStyleHelper::drawDial()
60void QQuickFusionDial::paint(QPainter *painter)
61{
62 const int width = QQuickItem::width();
63 const int height = QQuickItem::height();
64 if (width <= 0 || height <= 0 || !isVisible())
65 return;
66
67 const bool enabled = isEnabled();
68 qreal r = qMin(width, height) / 2.0;
69 r -= r/50;
70 const qreal penSize = r/20.0;
71
72 painter->setRenderHint(QPainter::Antialiasing);
73
74 const qreal d_ = r / 6;
75 const qreal dx = d_ + (width - 2 * r) / 2 + 1;
76 const qreal dy = d_ + (height - 2 * r) / 2 + 1;
77
78 QRectF br = QRectF(dx + 0.5, dy + 0.5,
79 int(r * 2 - 2 * d_ - 2),
80 int(r * 2 - 2 * d_ - 2));
81 QColor buttonColor = m_buttonColor.toHsv();
82 buttonColor.setHsv(buttonColor .hue(),
83 qMin(140, buttonColor .saturation()),
84 qMax(180, buttonColor.value()));
85
86 if (enabled) {
87 // Drop shadow
88 qreal shadowSize = qMax(1.0, penSize/2.0);
89 QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
90 2*shadowSize, 2*shadowSize);
91 QRadialGradient shadowGradient(shadowRect.center().x(),
92 shadowRect.center().y(), shadowRect.width()/2.0,
93 shadowRect.center().x(), shadowRect.center().y());
94 shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40));
95 shadowGradient.setColorAt(qreal(1.0), Qt::transparent);
96 painter->setBrush(shadowGradient);
97 painter->setPen(Qt::NoPen);
98 painter->translate(shadowSize, shadowSize);
99 painter->drawEllipse(shadowRect);
100 painter->translate(-shadowSize, -shadowSize);
101
102 // Main gradient
103 QRadialGradient gradient(br.center().x() - br.width()/3, dy,
104 br.width()*1.3, br.center().x(),
105 br.center().y() - br.height()/2);
106 gradient.setColorAt(0, buttonColor.lighter(110));
107 gradient.setColorAt(qreal(0.5), buttonColor);
108 gradient.setColorAt(qreal(0.501), buttonColor.darker(102));
109 gradient.setColorAt(1, buttonColor.darker(115));
110 painter->setBrush(gradient);
111 } else {
112 painter->setBrush(Qt::NoBrush);
113 }
114
115 painter->setPen(QPen(buttonColor.darker(280)));
116 painter->drawEllipse(br);
117 painter->setBrush(Qt::NoBrush);
118 painter->setPen(buttonColor.lighter(110));
119 painter->drawEllipse(br.adjusted(1, 1, -1, -1));
120
121 if (m_highlight) {
122 QColor highlight = m_highlightColor.toHsv();
123 highlight.setHsv(highlight.hue(),
124 qMin(160, highlight.saturation()),
125 qMax(230, highlight.value()));
126 highlight.setAlpha(127);
127 painter->setPen(QPen(highlight, 2.0));
128 painter->setBrush(Qt::NoBrush);
129 painter->drawEllipse(br.adjusted(-1, -1, 1, 1));
130 }
131}
132
133QT_END_NAMESPACE
134
135#include "moc_qquickfusiondial_p.cpp"
QObject * parent
Definition qobject.h:74
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
Combined button and popup list for selecting options.