2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "plugin/inputmethod.h"
19
#include "lib/models/wordribbon.h"
20
#include "lib/models/styleattributes.h"
22
#include "lib/logic/dynamiclayout.h"
23
#include "lib/logic/keyboardloader.h"
24
#include "lib/logic/layouthelper.h"
25
#include "lib/logic/keyareaconverter.h"
26
#include "lib/logic/style.h"
28
#include "common/inputmethodhostprobe.h"
29
#include "common/mockscreen.h"
31
#include <maliit/plugins/abstractinputmethodhost.h>
33
#include <QtTest/QtTest>
35
using namespace MaliitKeyboard;
36
using namespace MaliitKeyboard::Logic;
38
const QRect referenceScreenGeometry(0,0,720,1280);
40
class TestDynamicLayout: public QObject
45
void connectUiConstToScreen(const MockScreen& mockScreen)
47
const QScreen* screen = qGuiApp->primaryScreen();
48
disconnect( screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
49
disconnect( screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
50
disconnect( screen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
52
connect( &mockScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
53
connect( &mockScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
54
connect( &mockScreen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
57
Q_SLOT void dynamicLayout()
62
MockScreen mockScreen;
63
connectUiConstToScreen(mockScreen);
65
mockScreen.setGeometry(QRect(0,0, 300,400));
66
mockScreen.setOrientation(Qt::PortraitOrientation);
67
mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
69
uiConst->initDynamicLayout( "maliit-keyboard/tests/unittests/dynamic-layout/test-ui-constants.qml" );
70
QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 300 );
72
KeyboardLoader loader;
73
loader.setActiveId("en_us"); // TODO add a test layout
74
Keyboard kb = loader.keyboard();
76
QVERIFY(kb.keys.size() > 0);
77
QVERIFY2(kb.keys.size() == 33, "test if en_us layout contains 33 keys");
80
connectUiConstToScreen(mockScreen);
82
// this is important, so uiConst gets signals and changes internally
83
mockScreen.setGeometry( referenceScreenGeometry );
84
mockScreen.setOrientation(Qt::PortraitOrientation);
85
mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
87
uiConst->initDynamicLayout( "maliit-keyboard/tests/dynamic-layout/test-ui-constants.qml" );
89
QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
91
// this should remain the same even if we rotate the screen, as we depend on contentOrientation
92
mockScreen.setOrientation(Qt::LandscapeOrientation);
93
QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
95
// virtual width depending on contentOrientation
96
QCOMPARE( uiConst->windowWidth(LayoutHelper::Portrait), 720 );
97
QCOMPARE( uiConst->windowWidth(LayoutHelper::Landscape), 1280 );
99
// not sure if we need this in future
100
QVector<int> margins = uiConst->calculateMargins(LayoutHelper::Portrait, kb);
101
QVERIFY( margins[0] > 0 );
103
// TODO orientation argument not needed, qreal not needed
104
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Small), 10.0 );
105
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Medium), 12.0 );
106
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Large), 15.0 );
107
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XLarge), 18.0 );
108
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XXLarge), 24.0 );
109
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Stretched), 30.0 );
111
// keyHeight() not tested, calculated
113
QCOMPARE( uiConst->fontSize(LayoutHelper::Portrait), 12.0 );
114
QCOMPARE( uiConst->fontSizeSmall(LayoutHelper::Portrait), 10.0 );
120
* background QByteArray
121
* backgroundBorders QMargins
128
* style Key::Style (normal, special, dead)
131
* has_extended_keys bool
133
* command_sequence QString
148
* flags: left|right spacer, rtl-icon
149
* width KeyDescription::Width (Small, Medium, ...)
150
* icon KeyDescription::Icon (no, return, backspace, shift, ...)
151
* font_group KeyDescription::FontGroup (normal, big)
156
* descriptions vector of KeyDescription
159
* keys vector of Keys
166
Q_SLOT void keyAreaConverter()
168
KeyboardLoader loader;
169
loader.setActiveId("en_us");
171
// this really seems overkill
172
Style* style = new Style;
173
style->setProfile("ubuntu");
175
KeyAreaConverter converter(style->attributes(), &loader);
176
converter.setLayoutOrientation(MaliitKeyboard::Logic::LayoutHelper::Portrait);
178
KeyArea area = converter.keyArea();
180
QVERIFY2( area.keys().size() == 33, "Make sure all keys are in keyarea" );
185
QTEST_MAIN(TestDynamicLayout)
186
#include "ut_dynamic-layout.moc"