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 "qquickfusionknob_p.h"
5
6#include <QtCore/qmath.h>
7#include <QtGui/qpainter.h>
8#include <QtQuick/private/qquickpalette_p.h>
9#include <QtQuick/private/qquickitem_p.h>
10
11QT_BEGIN_NAMESPACE
12
13QQuickFusionKnob::QQuickFusionKnob(QQuickItem *parent)
14 : QQuickPaintedItem(parent)
15{
16 connect(sender: this, signal: &QQuickItem::paletteChanged, context: this, slot: [this](){ update(); });
17}
18
19// extracted from QStyleHelper::drawDial()
20void QQuickFusionKnob::paint(QPainter *painter)
21{
22 const qreal w = width();
23 const qreal h = height();
24 if (w <= 0 || h <= 0)
25 return;
26
27 QColor color = QQuickItemPrivate::get(item: this)->palette()->button().toHsv();
28 color.setHsv(h: color.hue(),
29 s: qMin(a: 140, b: color .saturation()),
30 v: qMax(a: 180, b: color.value()));
31 color = color.lighter(f: 104);
32 color.setAlphaF(0.8f);
33
34 const qreal sz = qMin(a: w, b: h);
35 QRectF rect(0, 0, sz, sz);
36 rect.moveCenter(p: QPointF(w / 2.0, h / 2.0));
37 const QPointF center = rect.center();
38
39 QRadialGradient gradient(center.x() + rect.width() / 2,
40 center.y() + rect.width(),
41 rect.width() * 2,
42 center.x(), center.y());
43 gradient.setColorAt(pos: 1, color: color.darker(f: 140));
44 gradient.setColorAt(pos: qreal(0.4), color: color.darker(f: 120));
45 gradient.setColorAt(pos: 0, color: color.darker(f: 110));
46
47 painter->setRenderHint(hint: QPainter::Antialiasing);
48 painter->setBrush(gradient);
49 painter->setPen(QColor(255, 255, 255, 150));
50 painter->drawEllipse(r: rect);
51 painter->setPen(QColor(0, 0, 0, 80));
52 painter->drawEllipse(r: rect.adjusted(xp1: 1, yp1: 1, xp2: -1, yp2: -1));
53}
54
55QT_END_NAMESPACE
56
57#include "moc_qquickfusionknob_p.cpp"
58

source code of qtdeclarative/src/quickcontrols/fusion/impl/qquickfusionknob.cpp