1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qquickapplication_p.h"
41#include <private/qquickscreen_p.h>
42#include <private/qobject_p.h>
43#include <private/qguiapplication_p.h>
44#include <qpa/qplatformintegration.h>
45#include <QtGui/QGuiApplication>
46#include <QtCore/QDebug>
47#include <QtQml/private/qqmlglobal_p.h>
48
49QT_BEGIN_NAMESPACE
50
51/*
52 This object and its properties are documented as part of the Qt object,
53 in qqmlengine.cpp
54*/
55
56QQuickApplication::QQuickApplication(QObject *parent)
57 : QQmlApplication(parent)
58{
59 if (qApp) {
60 connect(qApp, SIGNAL(layoutDirectionChanged(Qt::LayoutDirection)),
61 receiver: this, SIGNAL(layoutDirectionChanged()));
62 connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
63 receiver: this, SIGNAL(stateChanged(Qt::ApplicationState)));
64 connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
65 receiver: this, SIGNAL(activeChanged()));
66 connect(qApp, SIGNAL(applicationDisplayNameChanged()),
67 receiver: this, SIGNAL(displayNameChanged()));
68
69 connect(qApp, signal: &QGuiApplication::screenAdded, receiver: this, slot: &QQuickApplication::updateScreens);
70 connect(qApp, signal: &QGuiApplication::screenRemoved, receiver: this, slot: &QQuickApplication::updateScreens);
71 updateScreens();
72 }
73}
74
75QQuickApplication::~QQuickApplication()
76{
77}
78
79bool QQuickApplication::active() const
80{
81 return QGuiApplication::applicationState() == Qt::ApplicationActive;
82}
83
84Qt::LayoutDirection QQuickApplication::layoutDirection() const
85{
86 return QGuiApplication::layoutDirection();
87}
88
89bool QQuickApplication::supportsMultipleWindows() const
90{
91 return QGuiApplicationPrivate::platformIntegration()->hasCapability(cap: QPlatformIntegration::MultipleWindows);
92}
93
94Qt::ApplicationState QQuickApplication::state() const
95{
96 return QGuiApplication::applicationState();
97}
98
99QFont QQuickApplication::font() const
100{
101 return QGuiApplication::font();
102}
103
104QString QQuickApplication::displayName() const
105{
106 return QGuiApplication::applicationDisplayName();
107}
108
109void QQuickApplication::setDisplayName(const QString &displayName)
110{
111 return QGuiApplication::setApplicationDisplayName(displayName);
112}
113
114int screens_count(QQmlListProperty<QQuickScreenInfo> *prop)
115{
116 return static_cast<QVector<QQuickScreenInfo *> *>(prop->data)->count();
117}
118
119QQuickScreenInfo *screens_at(QQmlListProperty<QQuickScreenInfo> *prop, int idx)
120{
121 return static_cast<QVector<QQuickScreenInfo *> *>(prop->data)->at(i: idx);
122}
123
124QQmlListProperty<QQuickScreenInfo> QQuickApplication::screens()
125{
126 return QQmlListProperty<QQuickScreenInfo>(this,
127 const_cast<QVector<QQuickScreenInfo *> *>(&m_screens), &screens_count, &screens_at);
128}
129
130void QQuickApplication::updateScreens()
131{
132 const QList<QScreen *> screenList = QGuiApplication::screens();
133 m_screens.resize(size: screenList.count());
134 for (int i = 0; i < screenList.count(); ++i) {
135 if (!m_screens[i])
136 m_screens[i] = new QQuickScreenInfo(this);
137 m_screens[i]->setWrappedScreen(screenList[i]);
138 }
139 emit screensChanged();
140}
141
142QT_END_NAMESPACE
143
144#include "moc_qquickapplication_p.cpp"
145

source code of qtdeclarative/src/quick/util/qquickapplication.cpp