Merge lp:~mterry/ubuntu-keyboard/report-max-height into lp:ubuntu-keyboard

Proposed by Michael Terry
Status: Work in progress
Proposed branch: lp:~mterry/ubuntu-keyboard/report-max-height
Merge into: lp:ubuntu-keyboard
Diff against target: 336 lines (+110/-44)
8 files modified
qml/Keyboard.qml (+8/-11)
qml/keys/key_constants.js (+0/-8)
src/plugin/keyboardgeometry.cpp (+63/-9)
src/plugin/keyboardgeometry.h (+22/-1)
src/plugin/ubuntuapplicationapiwrapper.cpp (+13/-1)
src/plugin/ubuntuapplicationapiwrapper.h (+1/-0)
tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.cpp (+2/-13)
tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.pro (+1/-1)
To merge this branch: bzr merge lp:~mterry/ubuntu-keyboard/report-max-height
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Pending
Ubuntu Phablet Team Pending
Review via email: mp+294585@code.launchpad.net

Description of the change

Here's my first pass at reporting maximum keyboard height, for use by upper layers.

Unfortunately, it doesn't work. :( So I'm looking for advice.

In Keyboard.qml, fullScreenItem.height seems to only match the screen height when visible. Despite d->view->setGeometry, I guess Qml knows that when not visible, the height of the root item is 0.

Is there an obvious way to size the qml correctly even when not visible? (Or should I just save the ratio from Qml and have the cpp calculate it from screen size?)

This will need lp:~mterry/qtmir/report-osk-max-height to match.

To post a comment you must log in.
Revision history for this message
Michael Sheldon (michael-sheldon) wrote :

I think you're going to have to send the ratio through from QML I'm afraid; while it is possible to access the screen size in QML that's only available via the QtQuick.Window module, and I'm not sure how advisable it is to mix this in with Ubuntu Components usage

473. By Michael Terry

Move logic down a level and have c++ calculate canvasheight and ribbonheight

Revision history for this message
Michael Terry (mterry) wrote :

Heyo! Here's take 2. I took the ratio logic from Keyboard.qml and moved it down a layer into keyboardgeometry.cpp.

However... it still doesn't work. :)

Now my problem is that I relied on the existing calls to KeyboardGeometry::setOrientation to actually be functional. But it doesn't seem like it's every updated.

inputmethod.cpp does a lot of d->setLayoutOrientation() calls. But that only really gets updated when maliit calls handleAppOrientationChanged().

But at this point I'm out of my depth. But basically, the orientation never updated while I was rotating my phone. Which meant that the keyboard geometry never got to adjust its canvas ratio.

Pointers? Is the approach reasonable besides this bug?

Unmerged revisions

473. By Michael Terry

Move logic down a level and have c++ calculate canvasheight and ribbonheight

472. By Michael Terry

Never mind version bump, qtmir doesn't actually dep on us

471. By Michael Terry

Bump version

470. By Michael Terry

Initial maxHeight support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'qml/Keyboard.qml'
2--- qml/Keyboard.qml 2016-01-28 18:50:10 +0000
3+++ qml/Keyboard.qml 2016-05-20 20:41:32 +0000
4@@ -39,9 +39,6 @@
5 id: fullScreenItem
6 objectName: "fullScreenItem"
7
8- property bool landscape: width > height
9- readonly property bool tablet: landscape ? width >= units.gu(90) : height >= units.gu(90)
10-
11 property variant input_method: maliit_input_method
12 property variant event_handler: maliit_event_handler
13
14@@ -50,6 +47,12 @@
15 onWidthChanged: fullScreenItem.reportKeyboardVisibleRect();
16 onHeightChanged: fullScreenItem.reportKeyboardVisibleRect();
17
18+ Binding {
19+ target: maliit_geometry
20+ property: "gridUnit"
21+ value: units.gu(1)
22+ }
23+
24 Item {
25 id: canvas
26 objectName: "ubuntuKeyboard" // Allow us to specify a specific keyboard within autopilot.
27@@ -58,11 +61,7 @@
28 anchors.left: parent.left
29
30 width: parent.width
31- height: fullScreenItem.height * (fullScreenItem.landscape ? fullScreenItem.tablet ? UI.tabletKeyboardHeightLandscape
32- : UI.phoneKeyboardHeightLandscape
33- : fullScreenItem.tablet ? UI.tabletKeyboardHeightPortrait
34- : UI.phoneKeyboardHeightPortrait)
35- + wordRibbon.height + borderTop.height
36+ height: maliit_geometry.canvasHeight + wordRibbon.height + borderTop.height
37
38 property int keypadHeight: height;
39
40@@ -144,9 +143,7 @@
41 anchors.bottom: keyboardComp.top
42 width: parent.width;
43
44- height: canvas.wordribbon_visible ? (fullScreenItem.tablet ? units.gu(UI.tabletWordribbonHeight)
45- : units.gu(UI.phoneWordribbonHeight))
46- : 0
47+ height: canvas.wordribbon_visible ? maliit_geometry.wordRibbonHeight : 0
48 onHeightChanged: fullScreenItem.reportKeyboardVisibleRect();
49 }
50
51
52=== modified file 'qml/keys/key_constants.js'
53--- qml/keys/key_constants.js 2016-01-28 19:06:37 +0000
54+++ qml/keys/key_constants.js 2016-05-20 20:41:32 +0000
55@@ -73,13 +73,5 @@
56 /* language menu */
57 var languageMenuListViewPadding = 2.22; // gu
58
59-var tabletWordribbonHeight = 6; // gu
60-var phoneWordribbonHeight = 4; // gu
61 var tabletWordRibbonFontSize = 17 // dp
62 var phoneWordRibbonFontSize = 14 // dp
63-
64-var phoneKeyboardHeightPortrait = 0.40; // percent of screen
65-var phoneKeyboardHeightLandscape = 0.49; // percent of screen
66-
67-var tabletKeyboardHeightPortrait = 0.39; // percent of screen
68-var tabletKeyboardHeightLandscape = 0.42; // percent of screen
69
70=== modified file 'src/plugin/keyboardgeometry.cpp'
71--- src/plugin/keyboardgeometry.cpp 2013-11-06 09:31:37 +0000
72+++ src/plugin/keyboardgeometry.cpp 2016-05-20 20:41:32 +0000
73@@ -28,11 +28,15 @@
74 #include "keyboardgeometry.h"
75
76 #include <QDebug>
77+#include <QGuiApplication>
78+#include <QScreen>
79
80 KeyboardGeometry::KeyboardGeometry(QObject *parent) :
81 QObject(parent)
82 , m_keypadHeight(0)
83 , m_canvasHeight(0)
84+ , m_wordRibbonHeight(0)
85+ , m_gridUnit(0)
86 , m_visibleRect()
87 , m_orientation(Qt::PrimaryOrientation)
88 , m_shown(false)
89@@ -62,23 +66,38 @@
90 }
91
92 //! \brief KeyboardGeometry::canvasHeight height for the canvas item
93-//! FIXME this should not be needed, and calculated in QML directly
94 //! \return
95 int KeyboardGeometry::canvasHeight() const
96 {
97 return m_canvasHeight;
98 }
99
100-//! \brief KeyboardGeometry::setCanvasHeight
101-//! FIXME this should not be needed, and calculated in QML directly
102-//! \param height
103-void KeyboardGeometry::setCanvasHeight(int height)
104-{
105- if (height == m_canvasHeight)
106+//! \brief KeyboardGeometry::wordRibbonHeight height of the word ribbon
107+//! \return
108+int KeyboardGeometry::wordRibbonHeight() const
109+{
110+ return m_wordRibbonHeight;
111+}
112+
113+//! \brief KeyboardGeometry::gridUnit size in pixels of one grid unit
114+//! \return
115+double KeyboardGeometry::gridUnit() const
116+{
117+ return m_gridUnit;
118+}
119+
120+//! \brief KeyboardGeometry::setKeypadHeight
121+//! \param height height of the keypad in pixel
122+void KeyboardGeometry::setGridUnit(double gridUnit)
123+{
124+ if (gridUnit == m_gridUnit)
125 return;
126
127- m_canvasHeight = height;
128- Q_EMIT canvasHeightChanged();
129+ m_gridUnit = gridUnit;
130+ Q_EMIT gridUnitChanged();
131+
132+ calculateCanvasHeight();
133+ calculateWordRibbonHeight();
134 }
135
136 //! \brief KeyboardGeometry::visibleRect returns the size and position of the total
137@@ -117,6 +136,8 @@
138
139 m_orientation = orient;
140 Q_EMIT orientationChanged();
141+
142+ calculateCanvasHeight();
143 }
144
145 //! \brief KeyboardGeometry::shown property to indicate if the OSK is visible
146@@ -136,3 +157,36 @@
147 m_shown = show;
148 Q_EMIT shownChanged();
149 }
150+
151+void KeyboardGeometry::calculateCanvasHeight()
152+{
153+ QRect geometry = QGuiApplication::primaryScreen()->geometry();
154+ bool tablet = std::max(geometry.height(), geometry.width()) >= 90 * m_gridUnit;
155+ bool landscape = (m_orientation == Qt::LandscapeOrientation ||
156+ m_orientation == Qt::InvertedLandscapeOrientation);
157+
158+ int height = landscape ? geometry.width() : geometry.height();
159+ height *= landscape ? tablet ? TABLET_KEYBOARD_HEIGHT_LANDSCAPE
160+ : PHONE_KEYBOARD_HEIGHT_LANDSCAPE
161+ : tablet ? TABLET_KEYBOARD_HEIGHT_PORTRAIT
162+ : PHONE_KEYBOARD_HEIGHT_PORTRAIT;
163+
164+ if (m_canvasHeight != height) {
165+ m_canvasHeight = height;
166+ Q_EMIT canvasHeightChanged();
167+ }
168+}
169+
170+void KeyboardGeometry::calculateWordRibbonHeight()
171+{
172+ QRect geometry = QGuiApplication::primaryScreen()->geometry();
173+ bool tablet = std::max(geometry.height(), geometry.width()) >= 90 * m_gridUnit;
174+
175+ int height = (tablet ? TABLET_WORD_RIBBON_HEIGHT
176+ : PHONE_WORD_RIBBON_HEIGHT) * m_gridUnit;
177+
178+ if (m_wordRibbonHeight != height) {
179+ m_wordRibbonHeight = height;
180+ Q_EMIT wordRibbonHeightChanged();
181+ }
182+}
183
184=== modified file 'src/plugin/keyboardgeometry.h'
185--- src/plugin/keyboardgeometry.h 2013-11-05 18:08:40 +0000
186+++ src/plugin/keyboardgeometry.h 2016-05-20 20:41:32 +0000
187@@ -38,6 +38,8 @@
188 Q_OBJECT
189 Q_PROPERTY(int keypadHeight READ keypadHeight NOTIFY keypadHeightChanged)
190 Q_PROPERTY(int canvasHeight READ canvasHeight NOTIFY canvasHeightChanged)
191+ Q_PROPERTY(int wordRibbonHeight READ wordRibbonHeight NOTIFY wordRibbonHeightChanged)
192+ Q_PROPERTY(double gridUnit READ gridUnit WRITE setGridUnit NOTIFY gridUnitChanged)
193 Q_PROPERTY(QRectF visibleRect READ visibleRect WRITE setVisibleRect NOTIFY visibleRectChanged)
194 Q_PROPERTY(Qt::ScreenOrientation orientation READ orientation NOTIFY orientationChanged)
195 Q_PROPERTY(bool shown READ shown WRITE setShown NOTIFY shownChanged)
196@@ -49,7 +51,11 @@
197 void setKeypadHeight(int height);
198
199 int canvasHeight() const;
200- void setCanvasHeight(int height);
201+
202+ int wordRibbonHeight() const;
203+
204+ double gridUnit() const;
205+ void setGridUnit(double gridUnit);
206
207 const QRectF &visibleRect() const;
208 Q_SLOT void setVisibleRect(const QRectF &rect);
209@@ -63,13 +69,28 @@
210 Q_SIGNALS:
211 void keypadHeightChanged();
212 void canvasHeightChanged();
213+ void wordRibbonHeightChanged();
214+ void gridUnitChanged();
215 void visibleRectChanged();
216 void orientationChanged();
217 void shownChanged();
218
219 private:
220+ void calculateCanvasHeight();
221+ void calculateWordRibbonHeight();
222+
223+ static const double TABLET_KEYBOARD_HEIGHT_LANDSCAPE = 0.42; // percent of screen
224+ static const double TABLET_KEYBOARD_HEIGHT_PORTRAIT = 0.39; // percent of screen
225+ static const double PHONE_KEYBOARD_HEIGHT_LANDSCAPE = 0.49; // percent of screen
226+ static const double PHONE_KEYBOARD_HEIGHT_PORTRAIT = 0.40; // percent of screen
227+
228+ static const double TABLET_WORD_RIBBON_HEIGHT = 6; // gu
229+ static const double PHONE_WORD_RIBBON_HEIGHT = 4; // gu
230+
231 int m_keypadHeight;
232 int m_canvasHeight;
233+ int m_wordRibbonHeight;
234+ double m_gridUnit;
235 QRectF m_visibleRect;
236 Qt::ScreenOrientation m_orientation;
237 bool m_shown;
238
239=== modified file 'src/plugin/ubuntuapplicationapiwrapper.cpp'
240--- src/plugin/ubuntuapplicationapiwrapper.cpp 2015-07-17 10:18:28 +0000
241+++ src/plugin/ubuntuapplicationapiwrapper.cpp 2016-05-20 20:41:32 +0000
242@@ -163,6 +163,7 @@
243 m_sharedInfo.keyboardY = keyboardSceneRect.y();
244 m_sharedInfo.keyboardWidth = keyboardSceneRect.width();
245 m_sharedInfo.keyboardHeight = keyboardSceneRect.height();
246+ m_sharedInfo.keyboardMaxHeight = m_geometry->canvasHeight() + m_geometry->wordRibbonHeight();
247
248 sendInfoToClientConnection();
249 }
250@@ -187,9 +188,18 @@
251 if (m_geometry) {
252 QObject::disconnect(m_geometry, SIGNAL(visibleRectChanged()),
253 this, SLOT(delayedGeometryUpdate()));
254+ QObject::disconnect(m_geometry, SIGNAL(canvasHeightChanged()),
255+ this, SLOT(delayedGeometryUpdate()));
256+ QObject::disconnect(m_geometry, SIGNAL(wordRibbonHeightChanged()),
257+ this, SLOT(delayedGeometryUpdate()));
258 }
259
260 m_geometry = geometry;
261+ QObject::connect(m_geometry, SIGNAL(canvasHeightChanged()),
262+ this, SLOT(delayedGeometryUpdate()));
263+ QObject::connect(m_geometry, SIGNAL(wordRibbonHeightChanged()),
264+ this, SLOT(delayedGeometryUpdate()));
265+ updateSharedInfo();
266 }
267
268 // ------------------------------- SharedInfo ----------------------------
269@@ -199,7 +209,8 @@
270 return keyboardX == other.keyboardX
271 && keyboardY == other.keyboardY
272 && keyboardWidth == other.keyboardWidth
273- && keyboardHeight == other.keyboardHeight;
274+ && keyboardHeight == other.keyboardHeight
275+ && keyboardMaxHeight == other.keyboardMaxHeight;
276 }
277
278 void UbuntuApplicationApiWrapper::SharedInfo::reset()
279@@ -208,4 +219,5 @@
280 keyboardY = -1;
281 keyboardWidth = 0;
282 keyboardHeight = 0;
283+ keyboardMaxHeight = 0;
284 }
285
286=== modified file 'src/plugin/ubuntuapplicationapiwrapper.h'
287--- src/plugin/ubuntuapplicationapiwrapper.h 2014-04-16 13:12:34 +0000
288+++ src/plugin/ubuntuapplicationapiwrapper.h 2016-05-20 20:41:32 +0000
289@@ -62,6 +62,7 @@
290 qint32 keyboardY;
291 qint32 keyboardWidth;
292 qint32 keyboardHeight;
293+ qint32 keyboardMaxHeight;
294
295 bool operator ==(const struct SharedInfo &other);
296 void reset();
297
298=== modified file 'tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.cpp'
299--- tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.cpp 2013-11-06 09:31:37 +0000
300+++ tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.cpp 2016-05-20 20:41:32 +0000
301@@ -76,20 +76,9 @@
302
303 Q_SLOT void testCanvasHeight()
304 {
305- QSignalSpy spy(m_geometry, SIGNAL(canvasHeightChanged()));
306-
307 QCOMPARE(m_geometry->canvasHeight(), 0);
308- int height = 123;
309-
310- // normal set
311- m_geometry->setCanvasHeight(height);
312- QCOMPARE(m_geometry->canvasHeight(), height);
313- QCOMPARE(spy.count(), 1);
314-
315- // setting same again does not emit the changed signal
316- m_geometry->setCanvasHeight(height);
317- QCOMPARE(m_geometry->canvasHeight(), height);
318- QCOMPARE(spy.count(), 1);
319+
320+ // TODO
321 }
322
323 Q_SLOT void testVisibleRect()
324
325=== modified file 'tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.pro'
326--- tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.pro 2013-11-06 09:44:17 +0000
327+++ tests/unittests/ut_keyboardgeometry/ut_keyboardgeometry.pro 2016-05-20 20:41:32 +0000
328@@ -6,7 +6,7 @@
329
330 CONFIG += testcase
331 TARGET = ut_keyboardgeometry
332-QT = core testlib
333+QT = core gui testlib
334
335 HEADERS += \
336 $${TOP_SRCDIR}/src/plugin/keyboardgeometry.h

Subscribers

People subscribed via source and target branches