1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtQuick/private/qquickapplication_p.h>
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformintegration.h>
#include <QtGui/qguiapplication.h>
#include <QtQml/private/qqmlglobal_p.h>
#include <QtCore/private/qobject_p.h>
#include <QtCore/qdebug.h>
QT_BEGIN_NAMESPACE
/*!
\qmltype Application
\instantiates QQuickApplication
\inqmlmodule QtQuick
//! once exposed: \inherits CoreApplication?
//! TODO: \ingroup ?
\brief Provides access to global application
state properties shared by many QML components.
The Application singleton exposes a subset of QApplication's properties to
QML applications.
It also provides an aboutToQuit() signal, which is the same as
QCoreApplication::aboutToQuit().
\qml
import QtQuick
Window {
id: root
visible: true
width: 800
height: 680
title: `${Application.name} (${Application.version})`
Connections {
target: Application
function onAboutToQuit() {
console.log("Bye!")
}
}
}
\endqml
\sa SystemPalette
*/
/*!
\qmlproperty bool Application::active
\deprecated [5.2]
Returns whether the application is active.
Use Application.state == Qt.ApplicationActive instead
*/
/*!
\qmlproperty Qt::ApplicationState Application::state
This property represents the current state of the application.
\qml
Timer {
interval: 1000; repeat: true
active: Application.state === Qt.Qt.ApplicationActive
onTriggered: imageFetcher.fetchLatestImages()
}
\endqml
*/
/*!
\qmlproperty Qt::LayoutDirection Application::layoutDirection
This read-only property can be used to query the default layout
direction of the application. On system start-up, the default layout
direction depends on the application's language. The property has a
value of \c Qt.RightToLeft in locales where text and graphic elements
are read from right to left, and \c Qt.LeftToRight where the reading
direction flows from left to right. You can bind to this property to
customize your application layouts to support both layout directions.
\qml
RowLayout {
layoutDirection: Application.layoutDirection
}
\endqml
*/
/*!
\qmlproperty bool Application::supportsMultipleWindows
Returns \c true if the platform supports multiple windows. Some embedded
platforms do not support multiple windows, for example.
*/
/*!
\qmlproperty QFont Application::font
Returns the default application font as returned by
\l QGuiApplication::font().
*/
/*!
\qmlproperty QString Application::displayName
This property represents the application display name set on the
QGuiApplication instance. This property can be written to in order to set
the application display name.
\qml
Binding {
target: Application
property: "displayName"
value: "My Awesome Application"
}
\endqml
*/
/*!
\qmlproperty QQmlListProperty<QQuickScreenInfo> Application::screens
An array containing the descriptions of all connected screens. The
elements of the array are objects with the same properties as the
\l{Screen} attached object. In practice the array corresponds to the screen
list returned by QGuiApplication::screens(). In addition to examining
properties like name, width, height, etc., the array elements can also be
assigned to the screen property of Window items, thus serving as an
alternative to the C++ side's QWindow::setScreen().
\sa Screen, Window, {Window::screen}{Window.screen}
*/
/* The following properties are from QQmlApplication.
### Document those in QQmlApplication instead once it is exposed
*/
/*!
\qmlproperty QStringList Application::arguments
This is a string list of the arguments the executable was invoked with.
*/
/*!
\qmlproperty QString Application::name
This is the application name set on the QCoreApplication instance. This
property can be written to in order to set the application name.
*/
/*!
\qmlproperty QString Application::version
This is the application version set on the QCoreApplication instance. This
property can be written to in order to set the application version.
*/
/*!
\qmlproperty QString Application::organization
This is the organization name set on the QCoreApplication instance.
This property can be written to in order to set the organization name.
*/
/*!
\qmlproperty QString Application::domain
This is the organization domain set on the QCoreApplication instance.
This property can be written to in order to set the organization domain.
*/
/*!
\qmlproperty StyleHints Application::styleHints
The \c styleHints property provides platform-specific style hints and settings.
See the \l QStyleHints documentation for further details.
The following example uses \c styleHints to determine whether an
item should gain focus on mouse press or touch release:
\code
import QtQuick
MouseArea {
id: button
onPressed: {
if (!Application.styleHints.setFocusOnTouchRelease)
button.forceActiveFocus()
}
onReleased: {
if (Application.styleHints.setFocusOnTouchRelease)
button.forceActiveFocus()
}
}
\endcode
*/
/*!
\qmlsignal Application::aboutToQuit()
This signal is emitted when the application is about to quit the main
event loop. The signal is particularly useful if your application has to
do some last-second cleanup. User interaction is not possible in this state.
For more information, see \l {Window::closing()}{Window.closing}.
\sa QCoreApplication::aboutToQuit
*/
QQuickApplication::QQuickApplication(QObject *parent)
: QQmlApplication(parent)
{
QCoreApplication *app = QCoreApplication::instance();
if (QGuiApplication *guiApp = qobject_cast<QGuiApplication *>(app)) {
connect(guiApp, &QGuiApplication::layoutDirectionChanged,
this, &QQuickApplication::layoutDirectionChanged);
connect(guiApp, &QGuiApplication::applicationStateChanged,
this, &QQuickApplication::stateChanged);
connect(guiApp, &QGuiApplication::applicationStateChanged,
this, &QQuickApplication::activeChanged);
connect(guiApp, &QGuiApplication::applicationDisplayNameChanged,
this, &QQuickApplication::displayNameChanged);
connect(guiApp, &QGuiApplication::primaryScreenChanged, this, &QQuickApplication::updateScreens);
connect(guiApp, &QGuiApplication::screenAdded, this, &QQuickApplication::updateScreens);
connect(guiApp, &QGuiApplication::screenRemoved, this, &QQuickApplication::updateScreens);
updateScreens();
}
}
QQuickApplication::~QQuickApplication()
{
}
bool QQuickApplication::active() const
{
return QGuiApplication::applicationState() == Qt::ApplicationActive;
}
Qt::LayoutDirection QQuickApplication::layoutDirection() const
{
return QGuiApplication::layoutDirection();
}
bool QQuickApplication::supportsMultipleWindows() const
{
return QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::MultipleWindows);
}
Qt::ApplicationState QQuickApplication::state() const
{
return QGuiApplication::applicationState();
}
QFont QQuickApplication::font() const
{
return QGuiApplication::font();
}
QString QQuickApplication::displayName() const
{
return QGuiApplication::applicationDisplayName();
}
QStyleHints *QQuickApplication::styleHints()
{
return QGuiApplication::styleHints();
}
void QQuickApplication::setDisplayName(const QString &displayName)
{
return QGuiApplication::setApplicationDisplayName(displayName);
}
qsizetype screens_count(QQmlListProperty<QQuickScreenInfo> *prop)
{
return static_cast<QVector<QQuickScreenInfo *> *>(prop->data)->size();
}
QQuickScreenInfo *screens_at(QQmlListProperty<QQuickScreenInfo> *prop, qsizetype idx)
{
return static_cast<QVector<QQuickScreenInfo *> *>(prop->data)->at(idx);
}
QQmlListProperty<QQuickScreenInfo> QQuickApplication::screens()
{
return QQmlListProperty<QQuickScreenInfo>(this,
const_cast<QVector<QQuickScreenInfo *> *>(&m_screens), &screens_count, &screens_at);
}
void QQuickApplication::updateScreens()
{
const QList<QScreen *> screenList = QGuiApplication::screens();
m_screens.resize(screenList.size());
for (int i = 0; i < screenList.size(); ++i) {
if (!m_screens[i])
m_screens[i] = new QQuickScreenInfo(this);
m_screens[i]->setWrappedScreen(screenList[i]);
}
emit screensChanged();
}
QT_END_NAMESPACE
#include "moc_qquickapplication_p.cpp"
|