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
qquickfusionknob.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 <QtCore/qmath.h>
8#include <QtGui/qpainter.h>
9
11
12QQuickFusionKnob::QQuickFusionKnob(QQuickItem *parent)
14{
15}
16
17QColor QQuickFusionKnob::color() const
18{
19 return m_color;
20}
21
22void QQuickFusionKnob::setColor(const QColor &color)
23{
24 if (m_color == color)
25 return;
26
27 m_color = color;
28 update();
29}
30
31// extracted from QStyleHelper::drawDial()
32void QQuickFusionKnob::paint(QPainter *painter)
33{
34 const qreal w = width();
35 const qreal h = height();
36 if (w <= 0 || h <= 0)
37 return;
38
39 QColor color = m_color.toHsv();
40 color.setHsv(color.hue(),
41 qMin(140, color .saturation()),
42 qMax(180, color.value()));
43 color = color.lighter(104);
44 color.setAlphaF(0.8f);
45
46 const qreal sz = qMin(w, h);
47 QRectF rect(0, 0, sz, sz);
48 rect.moveCenter(QPointF(w / 2.0, h / 2.0));
49 const QPointF center = rect.center();
50
51 QRadialGradient gradient(center.x() + rect.width() / 2,
52 center.y() + rect.width(),
53 rect.width() * 2,
54 center.x(), center.y());
55 gradient.setColorAt(1, color.darker(140));
56 gradient.setColorAt(qreal(0.4), color.darker(120));
57 gradient.setColorAt(0, color.darker(110));
58
59 painter->setRenderHint(QPainter::Antialiasing);
60 painter->setBrush(gradient);
61 painter->setPen(QColor(255, 255, 255, 150));
62 painter->drawEllipse(rect);
63 painter->setPen(QColor(0, 0, 0, 80));
64 painter->drawEllipse(rect.adjusted(1, 1, -1, -1));
65}
66
67QT_END_NAMESPACE
68
69#include "moc_qquickfusionknob_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.