Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
17
19{
20 return m_highlight;
21}
22
24{
25 if (m_highlight == highlight)
26 return;
27
28 m_highlight = highlight;
29 update();
30}
31
32// based on QStyleHelper::drawDial()
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
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);
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 {
86 }
87
88 painter->setPen(QPen(buttonColor.darker(280)));
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);
102 painter->drawEllipse(br.adjusted(-1, -1, 1, 1));
103 }
104}
105
107
108#include "moc_qquickfusiondial_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
QColor darker(int f=200) const noexcept
Definition qcolor.cpp:2857
void setHsv(int h, int s, int v, int a=255)
Sets a HSV color value; h is the hue, s is the saturation, v is the value and a is the alpha componen...
Definition qcolor.cpp:1099
int value() const noexcept
Returns the value color component of this color.
Definition qcolor.cpp:1756
QColor lighter(int f=150) const noexcept
Definition qcolor.cpp:2812
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
Definition qbrush.cpp:1563
The QPainter class performs low-level painting on widgets and other paint devices.
Definition qpainter.h:46
void setPen(const QColor &color)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void drawEllipse(const QRectF &r)
Draws the ellipse defined by the given rectangle.
void setBrush(const QBrush &brush)
Sets the painter's brush to the given brush.
@ Antialiasing
Definition qpainter.h:52
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
\inmodule QtGui
Definition qpen.h:28
QQuickFusionDial(QQuickItem *parent=nullptr)
void setHighlight(bool highlight)
void paint(QPainter *painter) override
This function, which is usually called by the QML Scene Graph, paints the contents of an item in loca...
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
bool isVisible() const
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
bool isEnabled() const
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
void update()
Schedules a call to updatePaintNode() for this item.
The QQuickPaintedItem class provides a way to use the QPainter API in the QML Scene Graph.
\inmodule QtGui
Definition qbrush.h:412
\inmodule QtCore\reentrant
Definition qrect.h:484
Combined button and popup list for selecting options.
@ transparent
Definition qnamespace.h:47
@ NoPen
@ NoBrush
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
GLint GLsizei GLsizei height
GLboolean r
[2]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei width
double qreal
Definition qtypes.h:187
QPainter painter(this)
[7]