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#include <QtQuick/private/qquickpalette_p.h>
10#include <QtQuick/private/qquickitem_p.h>
11
13
14QQuickFusionKnob::QQuickFusionKnob(QQuickItem *parent)
16{
17 connect(this, &QQuickItem::paletteChanged, this, [this](){ update(); });
18}
19
20// extracted from QStyleHelper::drawDial()
21void QQuickFusionKnob::paint(QPainter *painter)
22{
23 const qreal w = width();
24 const qreal h = height();
25 if (w <= 0 || h <= 0)
26 return;
27
28 QColor color = QQuickItemPrivate::get(this)->palette()->button().toHsv();
29 color.setHsv(color.hue(),
30 qMin(140, color .saturation()),
31 qMax(180, color.value()));
32 color = color.lighter(104);
33 color.setAlphaF(0.8f);
34
35 const qreal sz = qMin(w, h);
36 QRectF rect(0, 0, sz, sz);
37 rect.moveCenter(QPointF(w / 2.0, h / 2.0));
38 const QPointF center = rect.center();
39
40 QRadialGradient gradient(center.x() + rect.width() / 2,
41 center.y() + rect.width(),
42 rect.width() * 2,
43 center.x(), center.y());
44 gradient.setColorAt(1, color.darker(140));
45 gradient.setColorAt(qreal(0.4), color.darker(120));
46 gradient.setColorAt(0, color.darker(110));
47
48 painter->setRenderHint(QPainter::Antialiasing);
49 painter->setBrush(gradient);
50 painter->setPen(QColor(255, 255, 255, 150));
51 painter->drawEllipse(rect);
52 painter->setPen(QColor(0, 0, 0, 80));
53 painter->drawEllipse(rect.adjusted(1, 1, -1, -1));
54}
55
56QT_END_NAMESPACE
57
58#include "moc_qquickfusionknob_p.cpp"
QObject * parent
Definition qobject.h:73
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64