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
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
14 : QQuickPaintedItem(parent)
15{
16 connect(this, &QQuickItem::paletteChanged, this, [this](){ update(); });
17}
18
19// extracted from QStyleHelper::drawDial()
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
48 painter->setBrush(gradient);
49 painter->setPen(QColor(255, 255, 255, 150));
51 painter->setPen(QColor(0, 0, 0, 80));
52 painter->drawEllipse(rect.adjusted(1, 1, -1, -1));
53}
54
56
57#include "moc_qquickfusionknob_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
void setColorAt(qreal pos, const QColor &color)
Creates a stop point at the given position with the given color.
Definition qbrush.cpp:1563
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
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 setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint.
\inmodule QtCore\reentrant
Definition qpoint.h:217
void paint(QPainter *painter) override
This function, which is usually called by the QML Scene Graph, paints the contents of an item in loca...
QQuickFusionKnob(QQuickItem *parent=nullptr)
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
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
rect
[4]
Combined button and popup list for selecting options.
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
GLfloat GLfloat GLfloat w
[0]
GLuint color
[2]
GLfloat GLfloat GLfloat GLfloat h
double qreal
Definition qtypes.h:187
QPainter painter(this)
[7]