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
Q_SLOT void initTestCase()
47
QVERIFY(qputenv("UBUNTU_KEYBOARD_DATA_DIR", TEST_MALIIT_KEYBOARD_DATADIR));
50
void connectUiConstToScreen(const MockScreen& mockScreen)
52
const QScreen* screen = qGuiApp->primaryScreen();
53
disconnect( screen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
54
disconnect( screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
55
disconnect( screen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
57
connect( &mockScreen, SIGNAL(primaryOrientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
58
connect( &mockScreen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), uiConst, SLOT(onPrimaryOrientationChanged(Qt::ScreenOrientation)) );
59
connect( &mockScreen, SIGNAL(geometryChanged(QRect)), uiConst, SLOT(onGeometryChanged(QRect)) );
62
Q_SLOT void dynamicLayout()
67
MockScreen mockScreen;
68
connectUiConstToScreen(mockScreen);
70
mockScreen.setGeometry(QRect(0,0, 300,400));
71
mockScreen.setOrientation(Qt::PortraitOrientation);
72
mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
74
uiConst->initDynamicLayout( "test-ui-constants.qml" );
75
QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 300 );
77
KeyboardLoader loader;
78
loader.setActiveId("en_us"); // TODO add a test layout
79
Keyboard kb = loader.keyboard();
81
QVERIFY(kb.keys.size() > 0);
82
QVERIFY2(kb.keys.size() == 33, "test if en_us layout contains 33 keys");
85
connectUiConstToScreen(mockScreen);
87
// this is important, so uiConst gets signals and changes internally
88
mockScreen.setGeometry( referenceScreenGeometry );
89
mockScreen.setOrientation(Qt::PortraitOrientation);
90
mockScreen.setPrimaryOrientation(Qt::PortraitOrientation);
92
uiConst->initDynamicLayout( "test-ui-constants.qml" );
94
QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
96
// this should remain the same even if we rotate the screen, as we depend on contentOrientation
97
mockScreen.setOrientation(Qt::LandscapeOrientation);
98
QCOMPARE( uiConst->windowGeometryRect(Qt::PortraitOrientation).width(), 720 );
100
// virtual width depending on contentOrientation
101
QCOMPARE( uiConst->windowWidth(LayoutHelper::Portrait), 720 );
102
QCOMPARE( uiConst->windowWidth(LayoutHelper::Landscape), 1280 );
104
// not sure if we need this in future
105
QVector<int> margins = uiConst->calculateMargins(LayoutHelper::Portrait, kb);
106
QVERIFY( margins[0] > 0 );
108
// TODO orientation argument not needed, qreal not needed
109
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Small), 10.0 );
110
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Medium), 12.0 );
111
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Large), 15.0 );
112
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XLarge), 18.0 );
113
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::XXLarge), 24.0 );
114
QCOMPARE( uiConst->keyWidth(LayoutHelper::Portrait, KeyDescription::Stretched), 30.0 );
116
// keyHeight() not tested, calculated
118
QCOMPARE( uiConst->fontSize(LayoutHelper::Portrait), 12.0 );
119
QCOMPARE( uiConst->fontSizeSmall(LayoutHelper::Portrait), 10.0 );
125
* background QByteArray
126
* backgroundBorders QMargins
133
* style Key::Style (normal, special, dead)
136
* has_extended_keys bool
138
* command_sequence QString
153
* flags: left|right spacer, rtl-icon
154
* width KeyDescription::Width (Small, Medium, ...)
155
* icon KeyDescription::Icon (no, return, backspace, shift, ...)
156
* font_group KeyDescription::FontGroup (normal, big)
161
* descriptions vector of KeyDescription
164
* keys vector of Keys
171
Q_SLOT void keyAreaConverter()
173
KeyboardLoader loader;
174
loader.setActiveId("en_us");
176
// this really seems overkill
177
Style* style = new Style;
178
style->setProfile("ubuntu");
180
KeyAreaConverter converter(style->attributes(), &loader);
181
converter.setLayoutOrientation(MaliitKeyboard::Logic::LayoutHelper::Portrait);
183
KeyArea area = converter.keyArea();
185
QVERIFY2( area.keys().size() == 33, "Make sure all keys are in keyarea" );
190
QTEST_MAIN(TestDynamicLayout)
191
#include "ut_dynamic-layout.moc"