on xenial help sign in
merge prereq
9a47628Michael Zanetti
qml/Dash/graphics/phone/screenshots/vkb_portrait.pngnew file

Binary file not shown.

tests/mocks/Unity/Application/ApplicationInfo.cpp+2−2
@@ -85,7 +85,7 @@ void ApplicationInfo::createSurface()
85 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
85 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
86 screenshot());
86 screenshot());
87 Q_EMIT surfaceChanged(m_surface);
87 Q_EMIT surfaceChanged(m_surface);
88− Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface);
88+ SurfaceManager::singleton()->registerSurface(m_surface);
89}
89}
90
90
91void ApplicationInfo::destroySurface()
91void ApplicationInfo::destroySurface()
@@ -95,7 +95,7 @@ void ApplicationInfo::destroySurface()
95 m_surface = nullptr;
95 m_surface = nullptr;
96
96
97 Q_EMIT surfaceChanged(nullptr);
97 Q_EMIT surfaceChanged(nullptr);
98− Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(oldSurface);
98+ SurfaceManager::singleton()->unregisterSurface(m_surface);
99 oldSurface->deleteLater();
99 oldSurface->deleteLater();
100}
100}
101
101
tests/mocks/Unity/Application/CMakeLists.txt+1
@@ -8,6 +8,7 @@ set(FakeUnityApplicationQml_SOURCES
8 ApplicationScreenshotProvider.cpp
8 ApplicationScreenshotProvider.cpp
9 MirSurfaceItem.cpp
9 MirSurfaceItem.cpp
10 SurfaceManager.cpp
10 SurfaceManager.cpp
11+ VirtualKeyboard.cpp
11 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
12 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
12 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
13 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
13)
14)
tests/mocks/Unity/Application/MirSurfaceItem.cpp+31−1
@@ -28,8 +28,14 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
28 , m_type(type)
28 , m_type(type)
29 , m_state(state)
29 , m_state(state)
30 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
30 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
31+ , m_haveInputMethod(false)
31{
32{
33+ // The virtual keyboard (input method) has a big transparent area so that
34+ // content behind it show through
32− setFillColor(Qt::white);
35+ setFillColor(Qt::transparent);
36+
37+ connect(this, &QQuickItem::focusChanged,
38+ this, &MirSurfaceItem::onFocusChanged);
33}
39}
34
40
35void MirSurfaceItem::paint(QPainter * painter)
41void MirSurfaceItem::paint(QPainter * painter)
@@ -38,3 +44,27 @@ void MirSurfaceItem::paint(QPainter * painter)
38 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
44 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
39 }
45 }
40}
46}
47+
48+void MirSurfaceItem::touchEvent(QTouchEvent * event)
49+{
50+ if (event->type() == QEvent::TouchBegin && hasFocus()) {
51+ Q_EMIT inputMethodRequested();
52+ m_haveInputMethod = true;
53+ }
54+}
55+
56+void MirSurfaceItem::onFocusChanged()
57+{
58+ if (!hasFocus() && m_haveInputMethod) {
59+ Q_EMIT inputMethodDismissed();
60+ m_haveInputMethod = false;
61+ }
62+}
63+
64+void MirSurfaceItem::setState(MirSurfaceItem::State newState)
65+{
66+ if (newState != m_state) {
67+ m_state = newState;
68+ Q_EMIT stateChanged(newState);
69+ }
70+}
tests/mocks/Unity/Application/MirSurfaceItem.h+16−1
@@ -62,21 +62,36 @@ public:
62 State state() const { return m_state; }
62 State state() const { return m_state; }
63 QString name() const { return m_name; }
63 QString name() const { return m_name; }
64
64
65+ void setState(State newState);
66+
65 Q_INVOKABLE void release() {}
67 Q_INVOKABLE void release() {}
66
68
67 void paint(QPainter * painter) override;
69 void paint(QPainter * painter) override;
68
70
71+ void touchEvent(QTouchEvent * event) override;
72+
69Q_SIGNALS:
73Q_SIGNALS:
70 void typeChanged(Type);
74 void typeChanged(Type);
71 void stateChanged(State);
75 void stateChanged(State);
72 void nameChanged(QString);
76 void nameChanged(QString);
73
77
78+ void inputMethodRequested();
79+ void inputMethodDismissed();
80+
81+private Q_SLOTS:
82+ void onFocusChanged();
83+
84+protected:
85+ const QImage &screenshotImage() { return m_img; }
86+
74private:
87private:
75
88
76 const QString m_name;
89 const QString m_name;
77 const Type m_type;
90 const Type m_type;
78− const State m_state;
91+ State m_state;
79 const QImage m_img;
92 const QImage m_img;
93+
94+ bool m_haveInputMethod;
80};
95};
81
96
82Q_DECLARE_METATYPE(MirSurfaceItem*)
97Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/SurfaceManager.cpp+36
@@ -15,6 +15,10 @@
15 */
15 */
16#include "SurfaceManager.h"
16#include "SurfaceManager.h"
17
17
18+#include "MirSurfaceItem.h"
19+#include "VirtualKeyboard.h"
20+
21+
18SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
22SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
19
23
20SurfaceManager *SurfaceManager::singleton()
24SurfaceManager *SurfaceManager::singleton()
@@ -27,5 +31,37 @@ SurfaceManager *SurfaceManager::singleton()
27
31
28SurfaceManager::SurfaceManager(QObject *parent) :
32SurfaceManager::SurfaceManager(QObject *parent) :
29 QObject(parent)
33 QObject(parent)
34+ , m_virtualKeyboard(nullptr)
35+{
36+}
37+
38+void SurfaceManager::registerSurface(MirSurfaceItem *surface)
39+{
40+ connect(surface, &MirSurfaceItem::inputMethodRequested,
41+ this, &SurfaceManager::showInputMethod);
42+ connect(surface, &MirSurfaceItem::inputMethodDismissed,
43+ this, &SurfaceManager::hideInputMethod);
44+ Q_EMIT surfaceCreated(surface);
45+}
46+
47+void SurfaceManager::unregisterSurface(MirSurfaceItem *surface)
30{
48{
49+ disconnect(surface, 0, this, 0);
50+ Q_EMIT surfaceDestroyed(surface);
51+}
52+
53+void SurfaceManager::showInputMethod()
54+{
55+ if (!m_virtualKeyboard) {
56+ m_virtualKeyboard = new VirtualKeyboard(MirSurfaceItem::Minimized);
57+ Q_EMIT surfaceCreated(m_virtualKeyboard);
58+ }
59+ m_virtualKeyboard->setState(MirSurfaceItem::Restored);
60+}
61+
62+void SurfaceManager::hideInputMethod()
63+{
64+ if (m_virtualKeyboard) {
65+ m_virtualKeyboard->setState(MirSurfaceItem::Minimized);
66+ }
31}
67}
tests/mocks/Unity/Application/SurfaceManager.h+10−1
@@ -20,6 +20,7 @@
20#include <QObject>
20#include <QObject>
21
21
22class MirSurfaceItem;
22class MirSurfaceItem;
23+class VirtualKeyboard;
23
24
24class SurfaceManager : public QObject
25class SurfaceManager : public QObject
25{
26{
@@ -29,14 +30,22 @@ public:
29
30
30 static SurfaceManager *singleton();
31 static SurfaceManager *singleton();
31
32
33+ // Internal mock use
34+ void registerSurface(MirSurfaceItem *surface);
35+ void unregisterSurface(MirSurfaceItem *surface);
36+
32Q_SIGNALS:
37Q_SIGNALS:
33 void countChanged();
38 void countChanged();
34 void surfaceCreated(MirSurfaceItem *surface);
39 void surfaceCreated(MirSurfaceItem *surface);
35 void surfaceDestroyed(MirSurfaceItem *surface);
40 void surfaceDestroyed(MirSurfaceItem *surface);
36
41
42+private Q_SLOTS:
43+ void showInputMethod();
44+ void hideInputMethod();
45+
37private:
46private:
38 static SurfaceManager *the_surface_manager;
47 static SurfaceManager *the_surface_manager;
39−
48+ VirtualKeyboard *m_virtualKeyboard;
40};
49};
41
50
42#endif // SURFACEMANAGER_H
51#endif // SURFACEMANAGER_H
tests/mocks/Unity/Application/VirtualKeyboard.cppnew file+55
@@ -0,0 +1,55 @@
1+/*
2+ * Copyright (C) 2014 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+ */
16+
17+#include "VirtualKeyboard.h"
18+
19+#include <paths.h>
20+
21+VirtualKeyboard::VirtualKeyboard(State state, QQuickItem *parent)
22+ : MirSurfaceItem("input-method",
23+ MirSurfaceItem::InputMethod,
24+ state,
25+ QString("file://%1/Dash/graphics/phone/screenshots/vkb_portrait.png").arg(qmlDirectory()),
26+ parent)
27+{
28+}
29+
30+void VirtualKeyboard::touchEvent(QTouchEvent *event)
31+{
32+ if (event->type() == QEvent::TouchBegin && !hasTouchInsideKeyboard(event)) {
33+ event->ignore();
34+ }
35+}
36+
37+bool VirtualKeyboard::hasTouchInsideKeyboard(QTouchEvent *event)
38+{
39+ const QList<QTouchEvent::TouchPoint> &touchPoints = event->touchPoints();
40+ for (int i = 0; i < touchPoints.count(); ++i) {
41+ QPoint pos = touchPoints.at(i).pos().toPoint();
42+
43+ // Map to image coords
44+ int imageX = (int)( ( ((qreal)pos.x()) / width() ) * ((qreal)screenshotImage().size().width()) );
45+ int imageY = (int)( ( ((qreal)pos.y()) / height() ) * ((qreal)screenshotImage().size().height()) );
46+
47+ QRgb pixelHit = screenshotImage().pixel(imageX, imageY);
48+
49+ // The keyboard depicted in the image is in its opaque part.
50+ if (qAlpha(pixelHit) != 0) {
51+ return true;
52+ }
53+ }
54+ return false;
55+}
tests/mocks/Unity/Application/VirtualKeyboard.hnew file+35
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright (C) 2014 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+ */
16+
17+#ifndef VIRTUALKEYBOARD_H
18+#define VIRTUALKEYBOARD_H
19+
20+#include "MirSurfaceItem.h"
21+
22+class VirtualKeyboard : public MirSurfaceItem
23+{
24+ Q_OBJECT
25+public:
26+ VirtualKeyboard(State state,
27+ QQuickItem *parent = 0);
28+
29+ void touchEvent(QTouchEvent * event) override;
30+
31+private:
32+ bool hasTouchInsideKeyboard(QTouchEvent *event);
33+};
34+
35+#endif // VIRTUALKEYBOARD_H