on 2492425 help sign in
unity8/tests/mocks/Unity/Application/ApplicationImage.h
79 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#ifndef APPLICATION_IMAGE_H
18#define APPLICATION_IMAGE_H
20#include <QQuickItem>
22class ApplicationInfo;
24/* Fake implementation of ApplicationImage
26 That fake implementation is not made in QML just because we can only declare
27 enumerations in C++. We can't even make readonly properties to mimic an enum
28 because properties must begin with a lower case letter.
29*/
30class ApplicationImage : public QQuickItem {
31 Q_OBJECT
32 Q_ENUMS(FillMode)
33 Q_PROPERTY(ApplicationInfo* source READ source WRITE setSource NOTIFY sourceChanged)
34 Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
35 Q_PROPERTY(bool ready READ ready WRITE setReady NOTIFY readyChanged)
37public:
38 explicit ApplicationImage(QQuickItem* parent = 0);
39 virtual ~ApplicationImage() {}
41 enum FillMode { Stretch, PreserveAspectCrop };
43 ApplicationInfo* source() const { return m_source; }
44 void setSource(ApplicationInfo* source);
46 FillMode fillMode() const { return m_fillMode; }
47 void setFillMode(FillMode);
49 void setReady(bool value);
50 bool ready() const { return m_ready; }
52 Q_INVOKABLE void scheduleUpdate() {}
53 Q_INVOKABLE void updateFromCache() {}
55Q_SIGNALS:
56 void sourceChanged();
57 void fillModeChanged();
58 void readyChanged();
60private Q_SLOTS:
61 void updateImage();
62 void onImageComponentStatusChanged(QQmlComponent::Status status);
64private:
65 void createImageItem();
66 void createImageComponent();
67 void doCreateImageItem();
68 void destroyImage();
70 ApplicationInfo* m_source;
71 FillMode m_fillMode;
72 bool m_ready;
73 QQmlComponent *m_imageComponent;
74 QQuickItem* m_imageItem;
75 // the QML script used to create the current m_imageItem
76 QString m_qmlUsed;
77};
79#endif // APPLICATION_IMAGE_H