on xenial help sign in
merge prereq
commit9a47628f840d580ef5bb7132172089ac16c5bfa7 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 22 Jul 2014, 13:52 (12 years ago) parentd50312218c4b89
9 files changed+186−5
qml/Dash/graphics/phone/screenshots/vkb_portrait.png tests/mocks/Unity/Application/ApplicationInfo.cpp+2−2 tests/mocks/Unity/Application/CMakeLists.txt+1 tests/mocks/Unity/Application/MirSurfaceItem.cpp+31−1 tests/mocks/Unity/Application/MirSurfaceItem.h+16−1 tests/mocks/Unity/Application/SurfaceManager.cpp+36 tests/mocks/Unity/Application/SurfaceManager.h+10−1 tests/mocks/Unity/Application/VirtualKeyboard.cpp+55 tests/mocks/Unity/Application/VirtualKeyboard.h+35
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()
8585 fullscreen() ? MirSurfaceItem::Fullscreen : MirSurfaceItem::Maximized,
8686 screenshot());
8787 Q_EMIT surfaceChanged(m_surface);
88− Q_EMIT SurfaceManager::singleton()->surfaceCreated(m_surface);
88+ SurfaceManager::singleton()->registerSurface(m_surface);
8989}
9090
9191void ApplicationInfo::destroySurface()
@@ -95,7 +95,7 @@ void ApplicationInfo::destroySurface()
9595 m_surface = nullptr;
9696
9797 Q_EMIT surfaceChanged(nullptr);
98− Q_EMIT SurfaceManager::singleton()->surfaceDestroyed(oldSurface);
98+ SurfaceManager::singleton()->unregisterSurface(m_surface);
9999 oldSurface->deleteLater();
100100}
101101
tests/mocks/Unity/Application/CMakeLists.txt+1
@@ -8,6 +8,7 @@ set(FakeUnityApplicationQml_SOURCES
88 ApplicationScreenshotProvider.cpp
99 MirSurfaceItem.cpp
1010 SurfaceManager.cpp
11+ VirtualKeyboard.cpp
1112 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationInfoInterface.h
1213 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
1314)
tests/mocks/Unity/Application/MirSurfaceItem.cpp+31−1
@@ -28,8 +28,14 @@ MirSurfaceItem::MirSurfaceItem(const QString& name,
2828 , m_type(type)
2929 , m_state(state)
3030 , m_img(screenshot.isLocalFile() ? screenshot.toLocalFile() : screenshot.toString())
31+ , m_haveInputMethod(false)
3132{
32− setFillColor(Qt::white);
33+ // The virtual keyboard (input method) has a big transparent area so that
34+ // content behind it show through
35+ setFillColor(Qt::transparent);
36+
37+ connect(this, &QQuickItem::focusChanged,
38+ this, &MirSurfaceItem::onFocusChanged);
3339}
3440
3541void MirSurfaceItem::paint(QPainter * painter)
@@ -38,3 +44,27 @@ void MirSurfaceItem::paint(QPainter * painter)
3844 painter->drawImage(contentsBoundingRect(), m_img, QRect(QPoint(0,0), m_img.size()));
3945 }
4046}
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:
6262 State state() const { return m_state; }
6363 QString name() const { return m_name; }
6464
65+ void setState(State newState);
66+
6567 Q_INVOKABLE void release() {}
6668
6769 void paint(QPainter * painter) override;
6870
71+ void touchEvent(QTouchEvent * event) override;
72+
6973Q_SIGNALS:
7074 void typeChanged(Type);
7175 void stateChanged(State);
7276 void nameChanged(QString);
7377
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+
7487private:
7588
7689 const QString m_name;
7790 const Type m_type;
78− const State m_state;
91+ State m_state;
7992 const QImage m_img;
93+
94+ bool m_haveInputMethod;
8095};
8196
8297Q_DECLARE_METATYPE(MirSurfaceItem*)
tests/mocks/Unity/Application/SurfaceManager.cpp+36
@@ -15,6 +15,10 @@
1515 */
1616#include "SurfaceManager.h"
1717
18+#include "MirSurfaceItem.h"
19+#include "VirtualKeyboard.h"
20+
21+
1822SurfaceManager *SurfaceManager::the_surface_manager = nullptr;
1923
2024SurfaceManager *SurfaceManager::singleton()
@@ -27,5 +31,37 @@ SurfaceManager *SurfaceManager::singleton()
2731
2832SurfaceManager::SurfaceManager(QObject *parent) :
2933 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)
3048{
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+ }
3167}
tests/mocks/Unity/Application/SurfaceManager.h+10−1
@@ -20,6 +20,7 @@
2020#include <QObject>
2121
2222class MirSurfaceItem;
23+class VirtualKeyboard;
2324
2425class SurfaceManager : public QObject
2526{
@@ -29,14 +30,22 @@ public:
2930
3031 static SurfaceManager *singleton();
3132
33+ // Internal mock use
34+ void registerSurface(MirSurfaceItem *surface);
35+ void unregisterSurface(MirSurfaceItem *surface);
36+
3237Q_SIGNALS:
3338 void countChanged();
3439 void surfaceCreated(MirSurfaceItem *surface);
3540 void surfaceDestroyed(MirSurfaceItem *surface);
3641
42+private Q_SLOTS:
43+ void showInputMethod();
44+ void hideInputMethod();
45+
3746private:
3847 static SurfaceManager *the_surface_manager;
39−
48+ VirtualKeyboard *m_virtualKeyboard;
4049};
4150
4251#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