74
69
LayoutHelper::Orientation orientation,
75
70
ActivationPolicy policy)
77
if (not candidate || not attributes) {
81
Label &label(candidate->rLabel());
83
f.setSize(attributes->candidateFontSize(orientation));
84
f.setStretch(attributes->candidateFontStretch(orientation));
89
color = QByteArray("#fff");
92
case DeactivateElement:
93
color = QByteArray("#ddd");
74
Q_UNUSED(orientation);
101
78
// FIXME: Make word candidates fit word ribbon also after orientation change.
130
107
for (int index = 0; index < candidates.count(); ++index) {
131
108
WordCandidate ¤t(candidates[index]);
133
if (current.label().text() == candidate.label().text()) {
110
if (current.label() == candidate.label()) {
134
111
// in qml we don´t care about ( current.rect() == candidate.rect() )
135
112
applyStyleToCandidate(¤t, attributes, layout->orientation(), policy);
136
113
layout->setWordRibbon(layout->wordRibbon());
189
161
magnifier.rArea().setBackground(attributes->magnifierKeyBackground());
190
162
magnifier.rArea().setSize(magnifier_rect.size());
191
163
magnifier.rArea().setBackgroundBorders(attributes->magnifierKeyBackgroundBorders());
192
magnifier.rLabel().setFont(magnifier_font);
194
// Compute label rectangle, contains the text:
195
const qreal label_offset(attributes->magnifierKeyLabelVerticalOffset(orientation));
196
const QSize &magnifier_size(magnifier.area().size());
197
const QRect label_rect(0, 0,
198
magnifier_size.width(),
199
magnifier_size.height() - label_offset);
200
magnifier.rLabel().setRect(label_rect);
201
165
magnifier.setMargins(QMargins());
203
167
return magnifier;
231
189
bool inShiftedState() const
233
return (shift_machine.inState(ShiftMachine::shift_state) or
234
shift_machine.inState(ShiftMachine::caps_lock_state) or
235
shift_machine.inState(ShiftMachine::latched_shift_state));
238
194
bool arePrimarySymbolsShown() const
240
return view_machine.inState(ViewMachine::symbols0_state);
243
199
bool areSecondarySymbolsShown() const
245
return view_machine.inState(ViewMachine::symbols1_state);
248
204
bool areSymbolsShown() const
323
273
void LayoutUpdater::setOrientation(LayoutHelper::Orientation orientation)
327
if (d->layout && d->style && d->layout->orientation() != orientation) {
328
d->layout->setOrientation(orientation);
330
KeyAreaConverter converter(d->style->attributes(), &d->loader);
331
converter.setLayoutOrientation(orientation);
332
d->layout->setCenterPanel(d->inShiftedState() ? converter.shiftedKeyArea()
333
: converter.keyArea());
335
if (isWordRibbonVisible())
336
applyStyleToWordRibbon(d->layout->wordRibbon(), d->style, orientation);
338
clearActiveKeysAndMagnifier();
275
Q_UNUSED(orientation);
342
278
void LayoutUpdater::setStyle(const SharedStyle &style)
413
348
void LayoutUpdater::onKeyLongPressed(const Key &key)
418
if (not d->layout || d->style.isNull()) {
422
clearActiveKeysAndMagnifier();
424
const LayoutHelper::Orientation orientation(d->layout->orientation());
425
StyleAttributes * const extended_attributes(d->style->extendedKeysAttributes());
426
const qreal vertical_offset(d->style->attributes()->verticalOffset(orientation));
427
KeyAreaConverter converter(extended_attributes, &d->loader);
428
converter.setLayoutOrientation(orientation);
429
KeyArea ext_ka(converter.extendedKeyArea(key));
431
if (not ext_ka.hasKeys()) {
432
if (key.action() == Key::ActionSpace) {
433
Q_EMIT addToUserDictionary();
438
const QSize &ext_panel_size(ext_ka.area().size());
439
const QSize ¢er_panel_size(d->layout->centerPanel().area().size());
440
const QPointF &key_center(key.rect().center());
441
const qreal safety_margin(extended_attributes->safetyMargin(orientation));
443
QPoint offset(qMax<int>(safety_margin, key_center.x() - ext_panel_size.width() / 2),
444
key.rect().top() - vertical_offset);
446
if (offset.x() + ext_panel_size.width() > center_panel_size.width()) {
447
offset.rx() = center_panel_size.width() - ext_panel_size.width() - safety_margin;
450
ext_ka.setOrigin(offset);
451
d->layout->setExtendedPanel(ext_ka);
452
d->layout->setActivePanel(LayoutHelper::ExtendedPanel);
455
353
void LayoutUpdater::onKeyReleased(const Key &key)
457
Q_D(const LayoutUpdater);
463
d->layout->removeActiveKey(key);
464
d->layout->clearMagnifierKey();
466
if (d->layout->activePanel() == LayoutHelper::ExtendedPanel) {
467
d->layout->clearActiveKeys();
468
d->layout->setExtendedPanel(KeyArea());
469
d->layout->setActivePanel(LayoutHelper::CenterPanel);
473
switch (key.action()) {
474
case Key::ActionShift:
475
Q_EMIT shiftReleased();
478
case Key::ActionInsert:
479
if (d->shift_machine.inState(ShiftMachine::latched_shift_state)) {
480
Q_EMIT shiftCancelled();
483
if (d->deadkey_machine.inState(DeadkeyMachine::latched_deadkey_state)) {
484
Q_EMIT deadkeyCancelled();
490
Q_EMIT symKeyReleased();
493
case Key::ActionSwitch:
494
Q_EMIT symSwitcherReleased();
497
case Key::ActionDead:
498
Q_EMIT deadkeyReleased();
506
358
void LayoutUpdater::onKeyAreaPressed(LayoutHelper::Panel panel)
615
467
void LayoutUpdater::onExtendedKeysShown(const Key &main_key)
619
if (not d->layout || d->style.isNull()) {
623
clearActiveKeysAndMagnifier();
625
const LayoutHelper::Orientation orientation(d->layout->orientation());
626
StyleAttributes * const extended_attributes(d->style->extendedKeysAttributes());
627
const qreal vertical_offset(d->style->attributes()->verticalOffset(orientation));
628
KeyAreaConverter converter(extended_attributes, &d->loader);
629
converter.setLayoutOrientation(orientation);
630
KeyArea ext_ka(converter.extendedKeyArea(main_key));
632
if (not ext_ka.hasKeys()) {
633
if (main_key.action() == Key::ActionSpace) {
634
Q_EMIT addToUserDictionary();
639
const QSize &ext_panel_size(ext_ka.area().size());
640
const QSize ¢er_panel_size(d->layout->centerPanel().area().size());
641
const QPointF &key_center(main_key.rect().center());
642
const qreal safety_margin(extended_attributes->safetyMargin(orientation));
644
QPoint offset(qMax<int>(safety_margin, key_center.x() - ext_panel_size.width() / 2),
645
main_key.rect().top() - vertical_offset);
647
if (offset.x() + ext_panel_size.width() > center_panel_size.width()) {
648
offset.rx() = center_panel_size.width() - ext_panel_size.width() - safety_margin;
651
ext_ka.setOrigin(offset);
652
d->layout->setExtendedPanel(ext_ka);
653
d->layout->setActivePanel(LayoutHelper::ExtendedPanel);
656
472
void LayoutUpdater::onWordCandidatePressed(const WordCandidate &candidate)
704
520
Q_D(LayoutUpdater);
706
// Resetting state machines should reset layout also.
707
// FIXME: Most probably reloading will happen three
708
// times, which is not what we want.
709
d->shift_machine.restart();
710
d->deadkey_machine.restart();
711
d->view_machine.restart();
713
522
Q_EMIT keyboardTitleChanged(d->loader.title(d->loader.activeId()));
716
525
void LayoutUpdater::switchToMainView()
720
if (not d->layout || d->style.isNull()) {
724
d->layout->clearActiveKeys();
725
d->layout->clearMagnifierKey();
727
const LayoutHelper::Orientation orientation(d->layout->orientation());
729
if (d->word_ribbon_visible)
730
applyStyleToWordRibbon(d->layout->wordRibbon(), d->style, orientation);
732
KeyAreaConverter converter(d->style->attributes(), &d->loader);
733
converter.setLayoutOrientation(orientation);
734
d->layout->setCenterPanel(d->inShiftedState() ? converter.shiftedKeyArea()
735
: converter.keyArea());
737
if (d->inShiftedState())
738
Q_EMIT d->layout->stateChanged(Model::Layout::ShiftedState);
739
else if (d->inDeadkeyState())
740
Q_EMIT d->layout->stateChanged(Model::Layout::DeadkeyState);
742
Q_EMIT d->layout->stateChanged(Model::Layout::DefaultState);
745
529
void LayoutUpdater::switchToPrimarySymView()
749
if (not d->layout || d->style.isNull()) {
753
const LayoutHelper::Orientation orientation(d->layout->orientation());
754
KeyAreaConverter converter(d->style->attributes(), &d->loader);
755
converter.setLayoutOrientation(orientation);
756
d->layout->setCenterPanel(converter.symbolsKeyArea(0));
758
// Reset shift state machine, also see switchToMainView.
759
d->shift_machine.restart();
761
Q_EMIT d->layout->stateChanged(Model::Layout::PrimarySymbolState);
764
533
void LayoutUpdater::switchToSecondarySymView()
768
if (not d->layout || d->style.isNull()) {
772
const LayoutHelper::Orientation orientation(d->layout->orientation());
773
KeyAreaConverter converter(d->style->attributes(), &d->loader);
774
converter.setLayoutOrientation(orientation);
775
d->layout->setCenterPanel(converter.symbolsKeyArea(1));
777
Q_EMIT d->layout->stateChanged(Model::Layout::SecondarySymbolState);
780
537
void LayoutUpdater::switchToAccentedView()
784
if (not d->layout || d->style.isNull()) {
789
const LayoutHelper::Orientation orientation(d->layout->orientation());
790
KeyAreaConverter converter(d->style->attributes(), &d->loader);
791
converter.setLayoutOrientation(orientation);
792
const Key accent(d->deadkey_machine.accentKey());
793
d->layout->setCenterPanel(d->inShiftedState() ? converter.shiftedDeadKeyArea(accent)
794
: converter.deadKeyArea(accent));
797
541
}} // namespace Logic, MaliitKeyboard