2
* Copyright (C) 2013 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 "ApplicationImage.h"
18
#include "ApplicationInfo.h"
21
#include <QQmlComponent>
22
#include <QQmlContext>
24
ApplicationImage::ApplicationImage(QQuickItem* parent)
34
void ApplicationImage::setSource(ApplicationInfo* source)
36
if (m_source != source) {
38
disconnect(m_source, &ApplicationInfo::imageQmlChanged,
39
this, &ApplicationImage::updateImage);
44
connect(m_source, &ApplicationInfo::imageQmlChanged,
45
this, &ApplicationImage::updateImage);
49
Q_EMIT sourceChanged();
53
void ApplicationImage::setFillMode(FillMode newFillMode)
55
if (m_fillMode != newFillMode) {
56
m_fillMode = newFillMode;
57
Q_EMIT fillModeChanged();
61
void ApplicationImage::setReady(bool value)
63
if (value != m_ready) {
65
Q_EMIT readyChanged();
69
void ApplicationImage::destroyImage()
73
delete m_imageComponent;
79
void ApplicationImage::updateImage()
81
if (!m_source || m_source->imageQml().isEmpty()) {
83
} else if (m_source->imageQml() != m_qmlUsed) {
89
void ApplicationImage::createImageItem()
92
if (!m_imageComponent)
93
createImageComponent();
95
// only create the windowItem one the component is ready
96
if (!m_imageComponent->isReady()) {
97
connect(m_imageComponent, &QQmlComponent::statusChanged,
98
this, &ApplicationImage::onImageComponentStatusChanged);
105
void ApplicationImage::createImageComponent()
107
QQmlEngine *engine = QQmlEngine::contextForObject(this)->engine();
108
m_imageComponent = new QQmlComponent(engine, this);
109
m_imageComponent->setData(m_source->imageQml().toLatin1(), QUrl());
112
void ApplicationImage::doCreateImageItem()
114
m_imageItem = qobject_cast<QQuickItem *>(m_imageComponent->create());
115
m_imageItem->setParentItem(this);
119
void ApplicationImage::onImageComponentStatusChanged(QQmlComponent::Status status)
121
if (status == QQmlComponent::Ready && !m_imageItem)