2 * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
17#include "MirSurfaceItem.h"
22#include <QGuiApplication>
24#include <QQmlProperty>
30MirSurfaceItem::MirSurfaceItem(const QString& name,
31 MirSurfaceItem::Type type,
32 MirSurfaceItem::State state,
33 const QUrl& screenshot,
34 const QString &qmlFilePath,
43 , m_screenshotUrl(screenshot)
45 qDebug() << "MirSurfaceItem::MirSurfaceItem() " << this->name();
47 QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
49 connect(this, &QQuickItem::focusChanged,
50 this, &MirSurfaceItem::onFocusChanged);
52 // The assumptions I make here really should hold.
53 QQuickView *quickView =
54 qobject_cast<QQuickView*>(QGuiApplication::topLevelWindows()[0]);
56 QString qmlComponentFilePath;
57 if (!qmlFilePath.isEmpty()) {
58 qmlComponentFilePath.append(qmlFilePath);
60 qmlComponentFilePath = QString("%1/Unity/Application/MirSurfaceItem.qml")
61 .arg(mockPluginsDir());
64 m_qmlContentComponent = new QQmlComponent(quickView->engine(), qmlComponentFilePath);
66 switch (m_qmlContentComponent->status()) {
67 case QQmlComponent::Ready:
68 createQmlContentItem();
70 case QQmlComponent::Loading:
71 connect(m_qmlContentComponent, &QQmlComponent::statusChanged,
72 this, &MirSurfaceItem::onComponentStatusChanged);
74 case QQmlComponent::Error:
75 printComponentErrors();
76 qFatal("MirSurfaceItem: failed to create content component.");
79 qFatal("MirSurfaceItem: Unhandled component status");
83MirSurfaceItem::~MirSurfaceItem()
85 qDebug() << "MirSurfaceItem::~MirSurfaceItem() " << name();
87 m_session->setSurface(nullptr);
91void MirSurfaceItem::printComponentErrors()
93 QList<QQmlError> errors = m_qmlContentComponent->errors();
94 for (int i = 0; i < errors.count(); ++i) {
95 qDebug() << errors[i];
99void MirSurfaceItem::release()
101 qDebug() << "MirSurfaceItem::release " << name();
104 m_session->setSurface(nullptr);
111void MirSurfaceItem::setSession(Session* session)
116void MirSurfaceItem::setScreenshot(const QUrl& screenshot)
118 m_screenshotUrl = screenshot;
120 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
121 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
125void MirSurfaceItem::setLive(bool live)
127 if (m_live != live) {
129 Q_EMIT liveChanged(m_live);
133void MirSurfaceItem::onQmlWantInputMethodChanged()
135 QQmlProperty prop(m_qmlItem, "wantInputMethod");
136 bool wantInputMethod = prop.read().toBool();
138 if (hasFocus() && wantInputMethod) {
139 Q_EMIT inputMethodRequested();
143void MirSurfaceItem::onFocusChanged()
145 QQmlProperty prop(m_qmlItem, "wantInputMethod");
146 bool wantInputMethod = prop.read().toBool();
148 if (!hasFocus() && wantInputMethod) {
149 Q_EMIT inputMethodDismissed();
150 prop.write(QVariant::fromValue(false));
154void MirSurfaceItem::setState(MirSurfaceItem::State newState)
156 if (newState != m_state) {
158 Q_EMIT stateChanged(newState);
162void MirSurfaceItem::onComponentStatusChanged(QQmlComponent::Status status)
164 if (status == QQmlComponent::Ready) {
165 createQmlContentItem();
169void MirSurfaceItem::createQmlContentItem()
171 qDebug() << "MirSurfaceItem::createQmlContentItem()";
173 m_qmlItem = qobject_cast<QQuickItem*>(m_qmlContentComponent->create());
174 m_qmlItem->setParentItem(this);
176 setImplicitWidth(m_qmlItem->implicitWidth());
177 setImplicitHeight(m_qmlItem->implicitHeight());
180 QQmlProperty screenshotSource(m_qmlItem, "screenshotSource");
181 screenshotSource.write(QVariant::fromValue(m_screenshotUrl));
185 QQmlProperty prop(m_qmlItem, "wantInputMethod");
186 if (prop.type() == QQmlProperty::Property) {
187 bool ok = prop.connectNotifySignal(this, SLOT(onQmlWantInputMethodChanged()));
188 if (!ok) qCritical("MirSurfaceItem: failed to connect to wantInputMethod notify signal");
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list