Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qquickglobal.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2016 BasysKom GmbH.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include <QtQuick/private/qquickvaluetypes_p.h>
6#include <QtQuick/private/qquickapplication_p.h>
7#include <QtQuick/private/qquickstate_p.h>
8#include <QtQuick/private/qquickpropertychanges_p.h>
9#include <QtQuick/private/qquickitemsmodule_p.h>
10#if QT_CONFIG(accessibility)
11# include <QtQuick/private/qquickaccessiblefactory_p.h>
12#endif
13#include <QtGui/QGuiApplication>
14#include <QtGui/qdesktopservices.h>
15#include <QtGui/qfontdatabase.h>
16#include <QtGui/qstylehints.h>
17
18#include <QtQml/private/qqmlbinding_p.h>
19#include <QtQml/private/qqmldebugserviceinterfaces_p.h>
20#include <QtQml/private/qqmldebugstatesdelegate_p.h>
21#include <QtQml/private/qqmlglobal_p.h>
22#include <QtQml/private/qv4engine_p.h>
23#include <QtQml/private/qv4object_p.h>
24#include <QtQml/private/qqmlanybinding_p.h>
25
26#include <QtCore/qiterable.h>
27
28#ifdef Q_CC_MSVC
29// MSVC2010 warns about 'unused variable t', even if it's used in t->~T()
30# pragma warning( disable : 4189 )
31#endif
32
34
35#if QT_CONFIG(qml_debug)
36
37class QQmlQtQuick2DebugStatesDelegate : public QQmlDebugStatesDelegate
38{
39public:
40 QQmlQtQuick2DebugStatesDelegate();
41 ~QQmlQtQuick2DebugStatesDelegate();
42 void buildStatesList(bool cleanList, const QList<QPointer<QObject> > &instances) override;
43 void updateBinding(QQmlContext *context,
45 const QVariant &expression, bool isLiteralValue,
46 const QString &fileName, int line, int column,
47 bool *isBaseState) override;
48 bool setBindingForInvalidProperty(QObject *object,
49 const QString &propertyName,
50 const QVariant &expression,
51 bool isLiteralValue) override;
52 void resetBindingForInvalidProperty(QObject *object,
53 const QString &propertyName) override;
54
55private:
56 void buildStatesList(QObject *obj);
57
58 QList<QPointer<QQuickState> > m_allStates;
59};
60
61QQmlQtQuick2DebugStatesDelegate::QQmlQtQuick2DebugStatesDelegate()
62{
63}
64
65QQmlQtQuick2DebugStatesDelegate::~QQmlQtQuick2DebugStatesDelegate()
66{
67}
68
69void QQmlQtQuick2DebugStatesDelegate::buildStatesList(bool cleanList,
70 const QList<QPointer<QObject> > &instances)
71{
72 if (cleanList)
73 m_allStates.clear();
74
75 //only root context has all instances
76 for (int ii = 0; ii < instances.size(); ++ii) {
77 buildStatesList(instances.at(ii));
78 }
79}
80
81void QQmlQtQuick2DebugStatesDelegate::buildStatesList(QObject *obj)
82{
83 if (QQuickState *state = qobject_cast<QQuickState *>(obj)) {
84 m_allStates.append(state);
85 }
86
87 QObjectList children = obj->children();
88 for (int ii = 0; ii < children.size(); ++ii) {
89 buildStatesList(children.at(ii));
90 }
91}
92
93void QQmlQtQuick2DebugStatesDelegate::updateBinding(QQmlContext *context,
95 const QVariant &expression, bool isLiteralValue,
96 const QString &fileName, int line, int column,
97 bool *inBaseState)
98{
100 typedef QPointer<QQuickState> QuickStatePointer;
101 QObject *object = property.object();
102 QString propertyName = property.name();
103 for (const QuickStatePointer& statePointer : std::as_const(m_allStates)) {
104 if (QQuickState *state = statePointer.data()) {
105 // here we assume that the revert list on itself defines the base state
106 if (state->isStateActive() && state->containsPropertyInRevertList(object, propertyName)) {
107 *inBaseState = false;
108
109 QQmlAnyBinding newBinding;
110 if (!isLiteralValue) {
112 expression.toString(), object,
114 line);
115 }
116 state->changeBindingInRevertList(object, propertyName, newBinding);
117
118 if (isLiteralValue)
119 state->changeValueInRevertList(object, propertyName, expression);
120 }
121 }
122 }
123}
124
125bool QQmlQtQuick2DebugStatesDelegate::setBindingForInvalidProperty(QObject *object,
126 const QString &propertyName,
127 const QVariant &expression,
128 bool isLiteralValue)
129{
130 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
131 if (isLiteralValue)
132 propertyChanges->changeValue(propertyName, expression);
133 else
134 propertyChanges->changeExpression(propertyName, expression.toString());
135 return true;
136 } else {
137 return false;
138 }
139}
140
141void QQmlQtQuick2DebugStatesDelegate::resetBindingForInvalidProperty(QObject *object, const QString &propertyName)
142{
143 if (QQuickPropertyChanges *propertyChanges = qobject_cast<QQuickPropertyChanges *>(object)) {
144 propertyChanges->removeProperty(propertyName);
145 }
146}
147
149{
150 return new QQmlQtQuick2DebugStatesDelegate;
151}
152
153#endif // QT_CONFIG(qml_debug)
154
156{
157public:
158 QVariant colorFromString(const QString &s, bool *ok) override
159 {
161 if (c.isValid()) {
162 if (ok) *ok = true;
163 return QVariant(c);
164 }
165
166 if (ok) *ok = false;
167 return QVariant();
168 }
169
170 unsigned rgbaFromString(const QString &s, bool *ok) override
171 {
173 if (c.isValid()) {
174 if (ok) *ok = true;
175 return c.rgba();
176 }
177
178 if (ok) *ok = false;
179 return 0;
180 }
181
182 QString stringFromRgba(unsigned rgba)
183 {
185 if (c.isValid()) {
186 return QVariant(c).toString();
187 }
188
189 return QString();
190 }
191
192 QVariant fromRgbF(double r, double g, double b, double a) override
193 {
194 return QVariant(QColor::fromRgbF(r, g, b, a));
195 }
196
197 QVariant fromHslF(double h, double s, double l, double a) override
198 {
199 return QVariant(QColor::fromHslF(h, s, l, a));
200 }
201
202 QVariant fromHsvF(double h, double s, double v, double a) override
203 {
204 return QVariant(QColor::fromHsvF(h, s, v, a));
205 }
206
207 QVariant lighter(const QVariant &var, qreal factor) override
208 {
210 color = color.lighter(int(qRound(factor*100.)));
212 }
213
214 QVariant darker(const QVariant &var, qreal factor) override
215 {
217 color = color.darker(int(qRound(factor*100.)));
219 }
220
222 {
224 color.setAlphaF(value);
226 }
227
228 QVariant tint(const QVariant &baseVar, const QVariant &tintVar) override
229 {
230 QColor tintColor = tintVar.value<QColor>().toRgb();
231
232 int tintAlpha = tintColor.alpha();
233 if (tintAlpha == 0xFF) {
234 return tintVar;
235 } else if (tintAlpha == 0x00) {
236 return baseVar;
237 }
238
239 // tint the base color and return the final color
240 QColor baseColor = baseVar.value<QColor>().toRgb();
241 qreal a = tintColor.alphaF();
242 qreal inv_a = 1.0 - a;
243
244 qreal r = tintColor.redF() * a + baseColor.redF() * inv_a;
245 qreal g = tintColor.greenF() * a + baseColor.greenF() * inv_a;
246 qreal b = tintColor.blueF() * a + baseColor.blueF() * inv_a;
247
248 return QVariant::fromValue(QColor::fromRgbF(r, g, b, a + inv_a * baseColor.alphaF()));
249 }
250};
251
253{
254public:
256 {
257 return new QQuickApplication(parent);
258 }
259
260#if QT_CONFIG(im)
261 QInputMethod *inputMethod() override
262 {
263 QInputMethod *im = qGuiApp->inputMethod();
265 return im;
266 }
267#endif
268
270 {
271 QStyleHints *sh = qGuiApp->styleHints();
273 return sh;
274 }
275
277 {
279 }
280
281 bool openUrlExternally(const QUrl &url) override
282 {
283#ifndef QT_NO_DESKTOPSERVICES
285#else
286 Q_UNUSED(url);
287 return false;
288#endif
289 }
290
291 QString pluginName() const override
292 {
294 }
295};
296
298{
300 return &colorProvider;
301}
302
304{
306 return &guiProvider;
307}
308
310{
311 // This is used by QQuickPath, and on macOS it fails to automatically register.
312 qRegisterMetaType<QVector<QVector<QPointF>>>();
313
316
318
319#if QT_CONFIG(accessibility)
320 QAccessible::installFactory(&qQuickAccessibleFactory);
321#endif
322
323#if QT_CONFIG(qml_debug)
325#endif
326}
327
329
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
static QColor fromHslF(float h, float s, float l, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcolor.cpp:2594
float greenF() const noexcept
Returns the green color component of this color.
Definition qcolor.cpp:1643
static QColor fromRgba(QRgb rgba) noexcept
Static convenience function that returns a QColor constructed from the given QRgb value rgba.
Definition qcolor.cpp:2385
int alpha() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1466
static QColor fromString(QAnyStringView name) noexcept
Definition qcolor.cpp:980
float redF() const noexcept
Returns the red color component of this color.
Definition qcolor.cpp:1611
static QColor fromHsvF(float h, float s, float v, float a=1.0)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qcolor.cpp:2530
float alphaF() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1497
float blueF() const noexcept
Returns the blue color component of this color.
Definition qcolor.cpp:1675
static QColor fromRgbF(float r, float g, float b, float a=1.0)
Static convenience function that returns a QColor constructed from the RGB color values,...
Definition qcolor.cpp:2427
static bool openUrl(const QUrl &url)
Opens the given url in the appropriate Web browser for the user's desktop environment,...
static QStringList families(WritingSystem writingSystem=Any)
Returns a sorted list of the available font families which support the writingSystem.
QString platformName
The name of the underlying platform plugin.
The QInputMethod class provides access to the active text input method.
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
Definition qlist.h:74
qsizetype size() const noexcept
Definition qlist.h:386
const_reference at(qsizetype i) const noexcept
Definition qlist.h:429
void clear()
Definition qlist.h:417
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore
Definition qpointer.h:18
QQmlAnyBinding is an abstraction over the various bindings in QML.
static QQmlAnyBinding createFromCodeString(const QQmlProperty &prop, const QString &code, QObject *obj, const QQmlRefPointer< QQmlContextData > &ctxt, const QString &url, quint16 lineNumber)
static QQmlRefPointer< QQmlContextData > get(QQmlContext *context)
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
static void setStatesDelegateFactory(QQmlDebugStatesDelegate *(*)())
virtual QObject * inputMethod()
The QQmlProperty class abstracts accessing properties on objects created from QML.
QVariant lighter(const QVariant &var, qreal factor) override
QVariant fromRgbF(double r, double g, double b, double a) override
QString stringFromRgba(unsigned rgba)
QVariant tint(const QVariant &baseVar, const QVariant &tintVar) override
QVariant fromHsvF(double h, double s, double v, double a) override
unsigned rgbaFromString(const QString &s, bool *ok) override
QVariant darker(const QVariant &var, qreal factor) override
QVariant fromHslF(double h, double s, double l, double a) override
QVariant colorFromString(const QString &s, bool *ok) override
QVariant alpha(const QVariant &var, qreal value) override
QQuickApplication * application(QObject *parent) override
bool openUrlExternally(const QUrl &url) override
QString pluginName() const override
QStyleHints * styleHints() override
QStringList fontFamilies() override
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
The QStyleHints class contains platform specific hints and settings. \inmodule QtGui.
Definition qstylehints.h:17
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:64
T value() const &
Definition qvariant.h:511
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:531
else opt state
[0]
Combined button and popup list for selecting options.
static void * context
Q_CONSTRUCTOR_FUNCTION(initializeStandardUserDefaults)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
Definition qfloat16.h:281
#define qGuiApp
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLboolean r
[2]
GLboolean GLboolean g
GLfloat GLfloat GLfloat GLfloat h
GLenum GLenum GLsizei void GLsizei void * column
GLhandleARB obj
[2]
const GLubyte * c
GLdouble s
[6]
Definition qopenglext.h:235
static QQmlDebugStatesDelegate *(* statesDelegateFactory)()
static QQmlGuiProvider * guiProvider
Q_QML_PRIVATE_EXPORT QQmlColorProvider * QQml_setColorProvider(QQmlColorProvider *newProvider)
static QQmlColorProvider * colorProvider
Q_QML_PRIVATE_EXPORT QQmlGuiProvider * QQml_setGuiProvider(QQmlGuiProvider *newProvider)
static QQuickColorProvider * getColorProvider()
static QQuickGuiProvider * getGuiProvider()
void QQuick_initializeModule()
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:92
const char property[13]
Definition qwizard.cpp:101
QUrl url("example.com")
[constructor-url-reference]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent