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
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
12
13QQuickFusionKnob::QQuickFusionKnob(QQuickItem *parent)
15{
16 connect(this, &QQuickItem::paletteChanged, this, [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(this)->palette()->button().toHsv();
28 color.setHsv(color.hue(),
29 qMin(140, color .saturation()),
30 qMax(180, color.value()));
31 color = color.lighter(104);
32 color.setAlphaF(0.8f);
33
34 const qreal sz = qMin(w, h);
35 QRectF rect(0, 0, sz, sz);
36 rect.moveCenter(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(1, color.darker(140));
44 gradient.setColorAt(qreal(0.4), color.darker(120));
45 gradient.setColorAt(0, color.darker(110));
46
47 painter->setRenderHint(QPainter::Antialiasing);
48 painter->setBrush(gradient);
49 painter->setPen(QColor(255, 255, 255, 150));
50 painter->drawEllipse(rect);
51 painter->setPen(QColor(0, 0, 0, 80));
52 painter->drawEllipse(rect.adjusted(1, 1, -1, -1));
53}
54
55QT_END_NAMESPACE
56
57#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:63
Combined button and popup list for selecting options.