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
5
6#include <QtGui/qpainter.h>
7#include <QtGui/private/qmath_p.h>
8#include <QtQuick/private/qquickpalette_p.h>
9#include <QtQuick/private/qquickitem_p.h>
10
12
13QQuickFusionDial::QQuickFusionDial(QQuickItem *parent)
15{
16}
17
18bool QQuickFusionDial::highlight() const
19{
20 return m_highlight;
21}
22
23void QQuickFusionDial::setHighlight(bool highlight)
24{
25 if (m_highlight == highlight)
26 return;
27
28 m_highlight = highlight;
29 update();
30}
31
32// based on QStyleHelper::drawDial()
33void QQuickFusionDial::paint(QPainter *painter)
34{
35 const int width = QQuickItem::width();
36 const int height = QQuickItem::height();
37 if (width <= 0 || height <= 0 || !isVisible())
38 return;
39
40 const bool enabled = isEnabled();
41 qreal r = qMin(width, height) / 2.0;
42 r -= r/50;
43 const qreal penSize = r/20.0;
44
45 painter->setRenderHint(QPainter::Antialiasing);
46
47 const qreal d_ = r / 6;
48 const qreal dx = d_ + (width - 2 * r) / 2 + 1;
49 const qreal dy = d_ + (height - 2 * r) / 2 + 1;
50
51 QRectF br = QRectF(dx + 0.5, dy + 0.5,
52 int(r * 2 - 2 * d_ - 2),
53 int(r * 2 - 2 * d_ - 2));
54 QColor buttonColor = QQuickItemPrivate::get(this)->palette()->button().toHsv();
55 buttonColor.setHsv(buttonColor .hue(),
56 qMin(140, buttonColor .saturation()),
57 qMax(180, buttonColor.value()));
58
59 if (enabled) {
60 // Drop shadow
61 qreal shadowSize = qMax(1.0, penSize/2.0);
62 QRectF shadowRect= br.adjusted(-2*shadowSize, -2*shadowSize,
63 2*shadowSize, 2*shadowSize);
64 QRadialGradient shadowGradient(shadowRect.center().x(),
65 shadowRect.center().y(), shadowRect.width()/2.0,
66 shadowRect.center().x(), shadowRect.center().y());
67 shadowGradient.setColorAt(qreal(0.91), QColor(0, 0, 0, 40));
68 shadowGradient.setColorAt(qreal(1.0), Qt::transparent);
69 painter->setBrush(shadowGradient);
70 painter->setPen(Qt::NoPen);
71 painter->translate(shadowSize, shadowSize);
72 painter->drawEllipse(shadowRect);
73 painter->translate(-shadowSize, -shadowSize);
74
75 // Main gradient
76 QRadialGradient gradient(br.center().x() - br.width()/3, dy,
77 br.width()*1.3, br.center().x(),
78 br.center().y() - br.height()/2);
79 gradient.setColorAt(0, buttonColor.lighter(110));
80 gradient.setColorAt(qreal(0.5), buttonColor);
81 gradient.setColorAt(qreal(0.501), buttonColor.darker(102));
82 gradient.setColorAt(1, buttonColor.darker(115));
83 painter->setBrush(gradient);
84 } else {
85 painter->setBrush(Qt::NoBrush);
86 }
87
88 painter->setPen(QPen(buttonColor.darker(280)));
89 painter->drawEllipse(br);
90 painter->setBrush(Qt::NoBrush);
91 painter->setPen(buttonColor.lighter(110));
92 painter->drawEllipse(br.adjusted(1, 1, -1, -1));
93
94 if (m_highlight) {
95 QColor highlight = QQuickItemPrivate::get(this)->palette()->highlight().toHsv();
96 highlight.setHsv(highlight.hue(),
97 qMin(160, highlight.saturation()),
98 qMax(230, highlight.value()));
99 highlight.setAlpha(127);
100 painter->setPen(QPen(highlight, 2.0));
101 painter->setBrush(Qt::NoBrush);
102 painter->drawEllipse(br.adjusted(-1, -1, 1, 1));
103 }
104}
105
106QT_END_NAMESPACE
107
108#include "moc_qquickfusiondial_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.