on d6bcfae help sign in
139 lines 3.6 kB history raw
1/*
2 * Copyright (C) 2015 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 MOCK_MIR_SURFACE_H
18#define MOCK_MIR_SURFACE_H
20#include <QObject>
21#include <QTimer>
22#include <QUrl>
23#include <QHash>
25// unity-api
26#include <unity/shell/application/MirSurfaceInterface.h>
28class MirSurface : public unity::shell::application::MirSurfaceInterface
30 Q_OBJECT
32 ////
33 // for use in qml tests
34 Q_PROPERTY(int width READ width NOTIFY widthChanged)
35 Q_PROPERTY(int height READ height NOTIFY heightChanged)
36 Q_PROPERTY(bool activeFocus READ activeFocus NOTIFY activeFocusChanged)
37 Q_PROPERTY(bool slowToResize READ isSlowToResize WRITE setSlowToResize NOTIFY slowToResizeChanged)
39public:
40 MirSurface(const QString& name,
41 Mir::Type type,
42 Mir::State state,
43 const QUrl& screenshot,
44 const QUrl &qmlFilePath = QUrl());
45 virtual ~MirSurface();
47 ////
48 // unity.shell.application.MirSurface
50 Mir::Type type() const override;
52 QString name() const override;
54 QSize size() const override { return QSize(width(),height()); }
55 void resize(int width, int height) override;
56 void resize(const QSize &size) override { resize(size.width(), size.height()); }
59 Mir::State state() const override;
60 Q_INVOKABLE void setState(Mir::State) override;
62 bool live() const override;
64 bool visible() const override;
66 Mir::OrientationAngle orientationAngle() const override;
67 void setOrientationAngle(Mir::OrientationAngle) override;
69 ////
70 // API for tests
72 Q_INVOKABLE void setLive(bool live);
74 void registerView(qintptr viewId);
75 void unregisterView(qintptr viewId);
76 void setViewVisibility(qintptr viewId, bool visible);
77 int viewCount() const { return m_views.count(); }
79 int width() const;
80 int height() const;
82 bool isSlowToResize() const;
83 void setSlowToResize(bool value);
85 /////
86 // internal mock stuff
88 QUrl qmlFilePath() const;
90 QUrl screenshotUrl() const;
91 void setScreenshotUrl(QUrl);
93 bool activeFocus() const;
94 void setActiveFocus(bool);
96Q_SIGNALS:
97 void stateChanged(Mir::State);
98 void liveChanged(bool live);
99 void orientationAngleChanged(Mir::OrientationAngle angle);
100 void widthChanged();
101 void heightChanged();
102 void slowToResizeChanged();
104 ////
105 // internal mock stuff
106 void screenshotUrlChanged(QUrl);
107 void activeFocusChanged(bool);
109private Q_SLOTS:
110 void applyDelayedResize();
112private:
113 void doResize(int width, int height);
114 void updateVisibility();
116 const QString m_name;
117 const Mir::Type m_type;
118 Mir::State m_state;
119 Mir::OrientationAngle m_orientationAngle;
120 QUrl m_screenshotUrl;
121 QUrl m_qmlFilePath;
122 bool m_live;
123 bool m_visible;
124 bool m_activeFocus;
125 int m_width;
126 int m_height;
128 bool m_slowToResize;
129 QTimer m_delayedResizeTimer;
130 QSize m_delayedResize;
131 QSize m_pendingResize;
133 struct View {
134 bool visible;
135 };
136 QHash<qintptr, View> m_views;
137};
139#endif // MOCK_MIR_SURFACE_H