on xenial help sign in
Clean up Unity.Application mocks regarging input method
d43eea3Daniel d'Andrada
tests/mocks/Unity/Application/GenericApp.cpp−24
@@ -32,42 +32,18 @@ GenericApp::GenericApp(const QString& name,
32 : MirSurfaceItem(name, type, state, screenshot, qmlFilePath, parent)
32 : MirSurfaceItem(name, type, state, screenshot, qmlFilePath, parent)
33 , m_touchPressCount(0)
33 , m_touchPressCount(0)
34 , m_touchReleaseCount(0)
34 , m_touchReleaseCount(0)
35− , m_requestedInputMethod(false)
36{
35{
37− connect(this, &QQuickItem::activeFocusChanged,
38− this, &GenericApp::onActiveFocusChanged);
39}
36}
40
37
41GenericApp::~GenericApp()
38GenericApp::~GenericApp()
42{
39{
43}
40}
44
41
45−void GenericApp::onActiveFocusChanged()
46−{
47− if (hasActiveFocus()) {
48− if (m_requestedInputMethod) {
49− Q_EMIT inputMethodRequested();
50− }
51− } else {
52− Q_EMIT inputMethodDismissed();
53− }
54−}
55−
56void GenericApp::touchEvent(QTouchEvent * event)
42void GenericApp::touchEvent(QTouchEvent * event)
57{
43{
58 if (event->touchPointStates() & Qt::TouchPointPressed) {
44 if (event->touchPointStates() & Qt::TouchPointPressed) {
59 ++m_touchPressCount;
45 ++m_touchPressCount;
60 Q_EMIT touchPressCountChanged(m_touchPressCount);
46 Q_EMIT touchPressCountChanged(m_touchPressCount);
61−
62− if (hasActiveFocus()) {
63− if (m_requestedInputMethod) {
64− Q_EMIT inputMethodDismissed();
65− } else {
66− Q_EMIT inputMethodRequested();
67− }
68− m_requestedInputMethod = !m_requestedInputMethod;
69− }
70−
71 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
47 } else if (event->touchPointStates() & Qt::TouchPointReleased) {
72 ++m_touchReleaseCount;
48 ++m_touchReleaseCount;
73 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
49 Q_EMIT touchReleaseCountChanged(m_touchReleaseCount);
tests/mocks/Unity/Application/GenericApp.h−18
@@ -44,18 +44,9 @@ Q_SIGNALS:
44 void touchPressCountChanged(int count);
44 void touchPressCountChanged(int count);
45 void touchReleaseCountChanged(int count);
45 void touchReleaseCountChanged(int count);
46
46
47− void inputMethodRequested();
48− void inputMethodDismissed();
49−
50− // internal mock use
51− void deregister();
52−
53protected:
47protected:
54 void touchEvent(QTouchEvent * event) override;
48 void touchEvent(QTouchEvent * event) override;
55
49
56−private Q_SLOTS:
57− void onActiveFocusChanged();
58−
59private:
50private:
60 explicit GenericApp(const QString& name,
51 explicit GenericApp(const QString& name,
61 Type type,
52 Type type,
@@ -64,18 +55,9 @@ private:
64 const QString &qmlFilePath = QString(),
55 const QString &qmlFilePath = QString(),
65 QQuickItem *parent = 0);
56 QQuickItem *parent = 0);
66
57
67− void createQmlContentItem();
68− void printComponentErrors();
69−
70 int m_touchPressCount;
58 int m_touchPressCount;
71 int m_touchReleaseCount;
59 int m_touchReleaseCount;
72
60
73− QQmlComponent *m_qmlContentComponent;
74− QQuickItem *m_qmlItem;
75− QUrl m_screenshotUrl;
76−
77− bool m_requestedInputMethod;
78−
79 friend class SurfaceManager;
61 friend class SurfaceManager;
80};
62};
81
63
tests/mocks/Unity/Application/SurfaceManager.cpp−20
@@ -59,26 +59,6 @@ void SurfaceManager::registerSurface(MirSurfaceItem *surface)
59 surface->setLive(false);
59 surface->setLive(false);
60 Q_EMIT surfaceDestroyed(surface);
60 Q_EMIT surfaceDestroyed(surface);
61 });
61 });
62−
63− GenericApp *genericApp = qobject_cast<GenericApp*>(surface);
64− if (genericApp) {
65− connect(genericApp, &GenericApp::inputMethodRequested,
66− this, &SurfaceManager::showInputMethod, Qt::QueuedConnection);
67− connect(genericApp, &GenericApp::inputMethodDismissed,
68− this, &SurfaceManager::hideInputMethod, Qt::QueuedConnection);
69− }
70−}
71−
72−void SurfaceManager::showInputMethod()
73−{
74− inputMethodSurface()->setState(MirSurfaceItem::Restored);
75−}
76−
77−void SurfaceManager::hideInputMethod()
78−{
79− if (m_virtualKeyboard) {
80− m_virtualKeyboard->setState(MirSurfaceItem::Minimized);
81− }
82}
62}
83
63
84MirSurfaceItem *SurfaceManager::inputMethodSurface()
64MirSurfaceItem *SurfaceManager::inputMethodSurface()
tests/mocks/Unity/Application/SurfaceManager.h−4
@@ -46,10 +46,6 @@ Q_SIGNALS:
46 void surfaceCreated(MirSurfaceItem *surface);
46 void surfaceCreated(MirSurfaceItem *surface);
47 void surfaceDestroyed(MirSurfaceItem *surface);
47 void surfaceDestroyed(MirSurfaceItem *surface);
48
48
49−private Q_SLOTS:
50− void showInputMethod();
51− void hideInputMethod();
52−
53private:
49private:
54 static SurfaceManager *the_surface_manager;
50 static SurfaceManager *the_surface_manager;
55 VirtualKeyboard *m_virtualKeyboard;
51 VirtualKeyboard *m_virtualKeyboard;
tests/qmltests/tst_OrientedShell.qml+19
@@ -262,6 +262,25 @@ Rectangle {
262 app.fullscreen = !app.fullscreen;
262 app.fullscreen = !app.fullscreen;
263 }
263 }
264 }
264 }
265+ RowLayout {
266+ Layout.fillWidth: true
267+ CheckBox {
268+ checked: false
269+ activeFocusOnPress: false
270+ onCheckedChanged: {
271+ var surface = SurfaceManager.inputMethodSurface();
272+ if (checked) {
273+ surface.setState(MirSurfaceItem.Restored);
274+ } else {
275+ surface.setState(MirSurfaceItem.Minimized);
276+ }
277+ }
278+ }
279+ Label {
280+ text: "Input Method"
281+ anchors.verticalCenter: parent.verticalCenter
282+ }
283+ }
265 }
284 }
266 }
285 }
267
286