on 42301fa help sign in
161 lines 4.5 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 QObject *parent = nullptr);
46 virtual ~MirSurface();
48 ////
49 // unity.shell.application.MirSurface
51 Mir::Type type() const override;
53 QString name() const override;
55 QSize size() const override { return QSize(width(),height()); }
56 void resize(int width, int height) override;
57 void resize(const QSize &size) override { resize(size.width(), size.height()); }
60 Mir::State state() const override;
61 Q_INVOKABLE void setState(Mir::State) override;
63 bool live() const override;
65 bool visible() const override;
67 Mir::OrientationAngle orientationAngle() const override;
68 void setOrientationAngle(Mir::OrientationAngle) override;
70 int minimumWidth() const override { return m_minimumWidth; }
71 int minimumHeight() const override { return m_minimumHeight; }
72 int maximumWidth() const override { return m_maximumWidth; }
73 int maximumHeight() const override { return m_maximumHeight; }
74 int widthIncrement() const override { return m_widthIncrement; }
75 int heightIncrement() const override { return m_heightIncrement; }
77 ////
78 // API for tests
80 Q_INVOKABLE void setLive(bool live);
82 void registerView(qintptr viewId);
83 void unregisterView(qintptr viewId);
84 void setViewVisibility(qintptr viewId, bool visible);
85 int viewCount() const { return m_views.count(); }
87 int width() const;
88 int height() const;
90 bool isSlowToResize() const;
91 void setSlowToResize(bool value);
93 Q_INVOKABLE void setMinimumWidth(int);
94 Q_INVOKABLE void setMaximumWidth(int);
95 Q_INVOKABLE void setMinimumHeight(int);
96 Q_INVOKABLE void setMaximumHeight(int);
97 Q_INVOKABLE void setWidthIncrement(int);
98 Q_INVOKABLE void setHeightIncrement(int);
100 /////
101 // internal mock stuff
103 QUrl qmlFilePath() const;
105 QUrl screenshotUrl() const;
106 void setScreenshotUrl(QUrl);
108 bool activeFocus() const;
109 void setActiveFocus(bool);
111Q_SIGNALS:
112 void stateChanged(Mir::State);
113 void liveChanged(bool live);
114 void orientationAngleChanged(Mir::OrientationAngle angle);
115 void widthChanged();
116 void heightChanged();
117 void slowToResizeChanged();
119 ////
120 // internal mock stuff
121 void screenshotUrlChanged(QUrl);
122 void activeFocusChanged(bool);
124private Q_SLOTS:
125 void applyDelayedResize();
127private:
128 void doResize(int width, int height);
129 void updateVisibility();
131 const QString m_name;
132 const Mir::Type m_type;
133 Mir::State m_state;
134 Mir::OrientationAngle m_orientationAngle;
135 QUrl m_screenshotUrl;
136 QUrl m_qmlFilePath;
137 bool m_live;
138 bool m_visible;
139 bool m_activeFocus;
140 int m_width;
141 int m_height;
143 int m_minimumWidth{0};
144 int m_minimumHeight{0};
145 int m_maximumWidth{0};
146 int m_maximumHeight{0};
147 int m_widthIncrement{0};
148 int m_heightIncrement{0};
150 bool m_slowToResize;
151 QTimer m_delayedResizeTimer;
152 QSize m_delayedResize;
153 QSize m_pendingResize;
155 struct View {
156 bool visible;
157 };
158 QHash<qintptr, View> m_views;
159};
161#endif // MOCK_MIR_SURFACE_H