~thomas-moenicke/phablet-extras/maliit-plugins-fix-1199150

« back to all changes in this revision

Viewing changes to maliit-keyboard/lib/logic/keyareaconverter.cpp

orientation changes.

Approved by PS Jenkins bot, Bill Filler.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
namespace Helper {
48
48
int calculateVerticalMargin(LayoutHelper::Orientation orientation, Keyboard& kb)
49
49
{
 
50
    Q_UNUSED(kb);
 
51
 
50
52
    const int freeSpace = uiConst->keyboardVisibleHeight(orientation)
51
 
                            - (uiConst->keyHeight(orientation) * uiConst->numberOfRows());
 
53
                            - (uiConst->keyHeight(orientation) * uiConst->numberOfRows())
52
54
                            - uiConst->keyboardTopMargin(orientation);
53
55
 
54
56
    const int vMargin = (freeSpace / (uiConst->numberOfRows()-1)) / 2;
59
61
QVector<int> calculateMargins(LayoutHelper::Orientation orientation,
60
62
                              Keyboard& kb)
61
63
{
62
 
    const qreal keyboardWidth = uiConst->keyboardSurfaceRect(orientation).size().width();
 
64
    const qreal keyboardWidth = uiConst->keyboardSurfaceRect(qGuiApp->primaryScreen()->orientation()).size().width();
63
65
 
64
66
    QVector<int> margins;
65
67
 
115
117
        uiConstantsHelperView.setSource(QUrl::fromLocalFile(g_maliit_ui_constants_qml));
116
118
        QQuickItem* uiConstantsHelper = uiConstantsHelperView.rootObject();
117
119
 
118
 
        const int screenWidth = QGuiApplication::primaryScreen()->size().width();
119
 
        const int screenHeight = QGuiApplication::primaryScreen()->size().height();
 
120
        const QRect rLandscape = qGuiApp->primaryScreen()->mapBetween(
 
121
                    qGuiApp->primaryScreen()->primaryOrientation(),
 
122
                    Qt::LandscapeOrientation,
 
123
                    QGuiApplication::primaryScreen()->geometry());
 
124
 
 
125
        const QRect rInvertedLandscape = qGuiApp->primaryScreen()->mapBetween(
 
126
                    qGuiApp->primaryScreen()->primaryOrientation(),
 
127
                    Qt::InvertedLandscapeOrientation,
 
128
                    QGuiApplication::primaryScreen()->geometry());
 
129
 
 
130
        const QRect rPortrait = qGuiApp->primaryScreen()->mapBetween(
 
131
                    qGuiApp->primaryScreen()->primaryOrientation(),
 
132
                    Qt::PortraitOrientation,
 
133
                    QGuiApplication::primaryScreen()->geometry());
 
134
 
 
135
        const QRect rInvertedPortrait = qGuiApp->primaryScreen()->mapBetween(
 
136
                    qGuiApp->primaryScreen()->primaryOrientation(),
 
137
                    Qt::InvertedPortraitOrientation,
 
138
                    QGuiApplication::primaryScreen()->geometry());
 
139
 
120
140
 
121
141
        // generic
122
142
 
130
150
        m_genericStorage->fontFamily = uiConstantsHelper->property("font_family").toByteArray();
131
151
 
132
152
        // portrait
133
 
        m_portraitStorage->keyboardTotalHeight = uiConstantsHelper->property("portrait_keyboard_total_height").toInt();
134
 
        m_portraitStorage->keyboardVisibleHeight = uiConstantsHelper->property("portrait_keyboard_visible_height").toInt();
 
153
 
 
154
        qreal portraitHeightRatio = uiConstantsHelper->property("phone_keyboard_height_portrait").toReal();
 
155
        if (qGuiApp->primaryScreen()->primaryOrientation() == Qt::LandscapeOrientation)
 
156
            portraitHeightRatio = uiConstantsHelper->property("tablet_keyboard_height_portrait").toReal();
 
157
 
 
158
        m_portraitStorage->keyboardVisibleHeight = rPortrait.height() * portraitHeightRatio;
 
159
        m_portraitStorage->keyboardTotalHeight = m_portraitStorage->keyboardVisibleHeight
 
160
                                                + uiConstantsHelper->property("portrait_invisible_dismiss_helper").toInt();
135
161
        m_portraitStorage->keyboardScreenWidthRatio = uiConstantsHelper->property("portrait_keyboard_screen_width_ratio").toReal();
136
162
 
137
 
        const int portraitKeyboardWidth = screenWidth * m_portraitStorage->keyboardScreenWidthRatio;
138
 
        const int xp = (screenWidth - (portraitKeyboardWidth)) / 2;
139
 
        const int yp = screenHeight - m_portraitStorage->keyboardVisibleHeight;
 
163
        const int portraitKeyboardWidth = rPortrait.width() * m_portraitStorage->keyboardScreenWidthRatio;
 
164
        const int xp = (rPortrait.width() - (portraitKeyboardWidth)) / 2;
 
165
 
 
166
        // point of origin differs when primary orientation is different
 
167
        int yp = 0;
 
168
        if(qGuiApp->primaryScreen()->primaryOrientation() == Qt::PortraitOrientation)
 
169
            yp = rPortrait.height() - m_portraitStorage->keyboardVisibleHeight;
140
170
 
141
171
        m_portraitStorage->keyboardSurfaceRect = QRect(xp, yp, portraitKeyboardWidth,  m_portraitStorage->keyboardVisibleHeight);
142
172
 
 
173
        const int invertedPortraitKeyboardWidth = rInvertedPortrait.width() * m_portraitStorage->keyboardScreenWidthRatio;
 
174
        const int xpi = (rInvertedPortrait.width() - (portraitKeyboardWidth)) / 2;
 
175
 
 
176
        // point of origin differs when primary orientation is different
 
177
        int ypi = 0;
 
178
        if(qGuiApp->primaryScreen()->primaryOrientation() == Qt::LandscapeOrientation)
 
179
            ypi = rInvertedPortrait.height() - m_portraitStorage->keyboardVisibleHeight;
 
180
 
 
181
        m_portraitStorage->keyboardSurfaceRectInverted = QRect(xpi, ypi, invertedPortraitKeyboardWidth,  m_portraitStorage->keyboardVisibleHeight);
 
182
 
143
183
        m_portraitStorage->keyboardTopMargin = uiConstantsHelper->property("portrait_top_margin").toInt();
144
 
        m_landscapeStorage->keyboardTopMargin = uiConstantsHelper->property("landscape_top_margin").toInt();
 
184
        m_landscapeStorage->keyboardTopMargin = 0.02 * rLandscape.height(); //uiConstantsHelper->property("landscape_top_margin").toInt();
145
185
 
146
186
        m_portraitStorage->keyboardBottomMargin = uiConstantsHelper->property("portrait_bottom_margin").toInt();
147
 
        m_landscapeStorage->keyboardBottomMargin = uiConstantsHelper->property("landscape_bottom_margin").toInt();
148
 
 
 
187
        m_landscapeStorage->keyboardBottomMargin = 0.02 * rLandscape.height();//uiConstantsHelper->property("landscape_bottom_margin").toInt();
149
188
 
150
189
        // landscape
151
 
        m_landscapeStorage->keyboardTotalHeight = uiConstantsHelper->property("landscape_keyboard_total_height").toInt();
152
 
        m_landscapeStorage->keyboardVisibleHeight = uiConstantsHelper->property("landscape_keyboard_visible_height").toInt();
 
190
 
 
191
        qreal landscapeHeightRatio = uiConstantsHelper->property("phone_keyboard_height_landscape").toReal();
 
192
        if (qGuiApp->primaryScreen()->primaryOrientation() == Qt::LandscapeOrientation)
 
193
            landscapeHeightRatio = uiConstantsHelper->property("tablet_keyboard_height_landscape").toReal();
 
194
 
 
195
        m_landscapeStorage->keyboardVisibleHeight = rLandscape.height() * landscapeHeightRatio;
 
196
        m_landscapeStorage->keyboardTotalHeight = m_landscapeStorage->keyboardVisibleHeight
 
197
                                                + uiConstantsHelper->property("landscape_invisible_dismiss_helper").toInt();
 
198
 
153
199
        m_landscapeStorage->keyboardScreenWidthRatio = uiConstantsHelper->property("landscape_keyboard_screen_width_ratio").toReal();
154
200
 
155
 
        const int landscapeKeyboardWidth = screenWidth * m_landscapeStorage->keyboardScreenWidthRatio;
156
 
        const int xl = (screenWidth - (landscapeKeyboardWidth)) / 2;
157
 
        const int yl = screenHeight - m_landscapeStorage->keyboardVisibleHeight;
 
201
        const int landscapeKeyboardWidth = rLandscape.width() * m_landscapeStorage->keyboardScreenWidthRatio;
 
202
        const int xl = (rLandscape.width() - (landscapeKeyboardWidth)) / 2;
 
203
        const int yl = rLandscape.height() - m_landscapeStorage->keyboardVisibleHeight;
158
204
 
159
205
        m_landscapeStorage->keyboardSurfaceRect = QRect(xl, yl, landscapeKeyboardWidth,  m_landscapeStorage->keyboardVisibleHeight);
160
206
 
 
207
        const int invertedLandscapeKeyboardWidth = rInvertedLandscape.width() * m_landscapeStorage->keyboardScreenWidthRatio;
 
208
        const int xli = (rInvertedLandscape.width() - (invertedLandscapeKeyboardWidth)) / 2;
 
209
        const int yli = 0;
 
210
 
 
211
        m_landscapeStorage->keyboardSurfaceRectInverted = QRect(xli, yli, invertedLandscapeKeyboardWidth,  m_landscapeStorage->keyboardVisibleHeight);
 
212
 
 
213
 
161
214
        // reference
162
215
        const QSize referenceSize(
163
216
                    uiConstantsHelper->property("reference_width").toInt(),
189
242
        m_genericStorage->keyBackgroundDead = uiConstantsHelper->property("key_background_deadkey").toByteArray();
190
243
 
191
244
        m_initialized = true;
 
245
 
 
246
        qDebug() << "landscape         " << rLandscape << m_landscapeStorage->keyboardSurfaceRect;
 
247
        qDebug() << "landscape inverted" << rInvertedLandscape << m_landscapeStorage->keyboardSurfaceRectInverted;
 
248
 
 
249
        qDebug() << "portrait          " << rPortrait << m_portraitStorage->keyboardSurfaceRect;
 
250
        qDebug() << "portrait inverted " << rInvertedPortrait << m_portraitStorage->keyboardSurfaceRectInverted;
192
251
    }
193
252
}
194
253
 
 
254
QRect& UiConstants::keyboardSurfaceRect(Qt::ScreenOrientation orientation)
 
255
{
 
256
    LayoutHelper::Orientation maliitOrientation = LayoutHelper::Landscape;
 
257
 
 
258
    if (orientation == Qt::PortraitOrientation || orientation == Qt::InvertedPortraitOrientation)
 
259
            maliitOrientation = LayoutHelper::Portrait;
 
260
 
 
261
    if (orientation == Qt::InvertedLandscapeOrientation || orientation == Qt::InvertedPortraitOrientation)
 
262
        return storage(maliitOrientation)->keyboardSurfaceRectInverted;
 
263
 
 
264
    return storage(maliitOrientation)->keyboardSurfaceRect;
 
265
}
 
266
 
195
267
qreal UiConstants::keyWidth(LayoutHelper::Orientation orientation, KeyDescription::Width requestedSize)
196
268
{
197
269
    qreal width = 1.0;
326
398
 
327
399
    static const QMargins bg_margins( uiConst->keyAreaBorders() );
328
400
 
329
 
    const qreal max_width( uiConst->keyboardSurfaceRect(orientation).width() );
 
401
    const qreal max_width( uiConst->keyboardSurfaceRect(qGuiApp->primaryScreen()->orientation()).width() );
330
402
    const qreal key_height(uiConst->keyHeight(orientation));
331
403
    const qreal keyboard_visible_height = uiConst->keyboardVisibleHeight(orientation);
332
404