on a7ea6aa help sign in
unity8/tests/mocks/Ubuntu/Application/ApplicationInfo.cpp
92 lines 2.4 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "ApplicationInfo.h"
19#include <QGuiApplication>
20#include <QQuickItem>
21#include <QQuickView>
22#include <QQmlComponent>
24ApplicationInfo::ApplicationInfo(QObject *parent)
25 : QObject(parent)
26 ,m_handle(0)
27 ,m_stage(MainStage)
28 ,m_state(Starting)
29 ,m_fullscreen(false)
30 ,m_windowItem(0)
31 ,m_windowComponent(0)
32 ,m_parentItem(0)
36void ApplicationInfo::onWindowComponentStatusChanged(QQmlComponent::Status status)
38 if (status == QQmlComponent::Ready && !m_windowItem)
39 doCreateWindowItem();
42void ApplicationInfo::createWindowComponent()
44 // The assumptions I make here really should hold.
45 QQuickView *quickView =
46 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
48 QQmlEngine *engine = quickView->engine();
50 m_windowComponent = new QQmlComponent(engine, this);
51 m_windowComponent->setData(m_windowQml.toLatin1(), QUrl());
54void ApplicationInfo::doCreateWindowItem()
56 m_windowItem = qobject_cast<QQuickItem *>(m_windowComponent->create());
57 m_windowItem->setParentItem(m_parentItem);
60void ApplicationInfo::createWindowItem()
62 if (!m_windowComponent)
63 createWindowComponent();
65 // only create the windowItem once the component is ready
66 if (!m_windowComponent->isReady()) {
67 connect(m_windowComponent, &QQmlComponent::statusChanged,
68 this, &ApplicationInfo::onWindowComponentStatusChanged);
69 } else {
70 doCreateWindowItem();
71 }
74void ApplicationInfo::showWindow(QQuickItem *parent)
76 m_parentItem = parent;
78 if (!m_windowItem)
79 createWindowItem();
81 if (m_windowItem) {
82 m_windowItem->setVisible(true);
83 }
86void ApplicationInfo::hideWindow()
88 if (!m_windowItem)
89 return;
91 m_windowItem->setVisible(false);