38
38
#include "logic/keyboardloader.h"
41
#include <QtGui/QGuiApplication>
42
#include <QtGui/QScreen>
42
45
namespace MaliitKeyboard {
48
QVector<int> calculateMargins(LayoutHelper::Orientation orientation,
51
const qreal screenWidth = QGuiApplication::primaryScreen()->size().width();
55
int spaceTakenByKeys = 0;
56
int numberOfKeysInRow = 0;
57
for (int index = 0; index < kb.keys.count(); ++index) {
58
const KeyDescription &desc(kb.key_descriptions.at(index));
59
int width = uiConst->keyWidth(orientation);
60
spaceTakenByKeys += width;
63
bool at_row_end((index + 1 == kb.keys.count())
64
|| (index + 1 < kb.keys.count()
65
&& kb.key_descriptions.at(index + 1).row > desc.row));
68
int marginThisRow = ( (screenWidth - spaceTakenByKeys) / (numberOfKeysInRow-1) ) / 2;
69
margins.append(marginThisRow);
77
UiConstants* UiConstants::self = 0;
79
void UiConstants::initUiConstants()
84
const QString g_maliit_ui_constants_qml(MALIIT_KEYBOARD_DATA_DIR "/maliit-ui-constants.qml");
86
QQuickView uiConstantsHelperView;
87
uiConstantsHelperView.setSource(QUrl::fromLocalFile(g_maliit_ui_constants_qml));
88
QQuickItem* portraitConstantsHelper = uiConstantsHelperView.rootObject();
90
const int screenWidth = QGuiApplication::primaryScreen()->size().width();
91
const int screenHeight = QGuiApplication::primaryScreen()->size().height();
95
m_genericStorage->keyAreaBorders = QMargins(portraitConstantsHelper->property("key_area_borders").toInt(),
96
portraitConstantsHelper->property("key_area_borders").toInt(),
97
portraitConstantsHelper->property("key_area_borders").toInt(),
98
portraitConstantsHelper->property("key_area_borders").toInt()
101
m_genericStorage->fontColor = portraitConstantsHelper->property("font_color").toByteArray();
102
m_genericStorage->fontFamily = portraitConstantsHelper->property("font_family").toByteArray();
106
m_portraitStorage->keyboardTotalHeight = portraitConstantsHelper->property("portrait_keyboard_total_height").toInt();
107
m_portraitStorage->keyboardVisibleHeight = portraitConstantsHelper->property("portrait_keyboard_visible_height").toInt();
108
m_portraitStorage->keyboardScreenWidthRatio = portraitConstantsHelper->property("portrait_keyboard_screen_width_ratio").toReal();
110
const int xp = (screenWidth - (screenWidth * m_portraitStorage->keyboardScreenWidthRatio)) / 2;
111
const int yp = screenHeight - m_portraitStorage->keyboardVisibleHeight;
113
m_portraitStorage->keyboardSurfaceRect = QRect(xp, yp, screenWidth, m_portraitStorage->keyboardTotalHeight);
115
m_portraitStorage->keyHeight = portraitConstantsHelper->property("portrait_key_height").toReal();
116
m_portraitStorage->keyWidth = portraitConstantsHelper->property("portrait_key_width").toReal();
118
m_portraitStorage->fontSize = portraitConstantsHelper->property("portrait_font_size").toReal();
123
m_landscapeStorage->keyboardTotalHeight = portraitConstantsHelper->property("landscape_keyboard_total_height").toInt();
124
m_landscapeStorage->keyboardVisibleHeight = portraitConstantsHelper->property("landscape_keyboard_visible_height").toInt();
125
m_landscapeStorage->keyboardScreenWidthRatio = portraitConstantsHelper->property("landscape_keyboard_screen_width_ratio").toReal();
127
const int xl = (screenWidth - (screenWidth * m_landscapeStorage->keyboardScreenWidthRatio)) / 2;
128
const int yl = screenHeight - m_landscapeStorage->keyboardVisibleHeight;
130
m_landscapeStorage->keyboardSurfaceRect = QRect(xl, yl, screenWidth, m_landscapeStorage->keyboardTotalHeight);
132
m_landscapeStorage->keyHeight = portraitConstantsHelper->property("landscape_key_height").toReal();
133
m_landscapeStorage->keyWidth = portraitConstantsHelper->property("landscape_key_width").toReal();
135
m_landscapeStorage->fontSize = portraitConstantsHelper->property("landscape_font_size").toReal();
138
m_initialized = true;
142
} // namespace Helper
45
144
//! \class KeyAreaConverter
46
145
//! Reads keyboard layouts and converts them into key areas. It can apply
74
175
attributes->setStyleName(kb.style_name);
77
font.setName(attributes->fontName(orientation));
78
font.setSize(attributes->fontSize(orientation));
79
font.setColor(attributes->fontColor(orientation));
178
font.setName(uiConst->fontFamily());
179
font.setSize(uiConst->fontSize(orientation));
180
font.setColor(uiConst->fontColor());
81
182
Font small_font(font);
82
183
small_font.setSize(attributes->smallFontSize(orientation));
84
static const QMargins bg_margins(attributes->keyBackgroundBorders());
86
const qreal max_width(attributes->keyAreaWidth(orientation));
87
const qreal key_height(attributes->keyHeight(orientation));
88
const qreal margin = attributes->keyMargin(orientation);
185
static const QMargins bg_margins( uiConst->keyAreaBorders() );
187
const qreal max_width( uiConst->keyboardSurfaceRect(orientation).width() );
188
const qreal key_height(uiConst->keyHeight(orientation));
189
const qreal keyboard_visible_height = uiConst->keyboardVisibleHeight(orientation);
89
191
const qreal padding = attributes->keyAreaPadding(orientation);
92
195
QVector<int> row_indices;
93
196
int spacer_count = 0;
94
197
qreal consumed_width = 0;
199
QVector<int> margins = Helper::calculateMargins(orientation, kb);
97
202
for (int index = 0; index < kb.keys.count(); ++index) {
98
203
row_indices.append(index);
99
204
Key &key(kb.keys[index]);
100
205
const KeyDescription &desc(kb.key_descriptions.at(index));
102
208
pos.setY(key_height * desc.row);
107
213
|| (index + 1 < kb.keys.count()
108
214
&& kb.key_descriptions.at(index + 1).row > desc.row));
216
qreal margin = margins[row];
110
221
if (desc.left_spacer || desc.right_spacer) {
114
width = attributes->keyWidth(orientation, desc.width);
225
width = uiConst->keyWidth(orientation);
226
//attributes->keyWidth(orientation, desc.width);
116
228
const qreal key_margin((at_row_start || at_row_end) ? margin + padding : margin * 2);