~iamsylvie/ubuntu-keyboard/ubuntu-keyboard

« back to all changes in this revision

Viewing changes to src/view/abstracttexteditor.cpp

  • Committer: CI Train Bot
  • Author(s): Mitsuya Shibata
  • Date: 2016-02-22 11:04:18 UTC
  • mfrom: (402.2.16 japanese-keyboard-rebooted)
  • Revision ID: ci-train-bot@canonical.com-20160222110418-1hn0utyw7pj0gsqf
Implement Japanese keyboard layout Fixes: #1290031
Approved by: Ken VanDine

Show diffs side-by-side

added added

removed removed

Lines of Context:
126
126
//! \brief Emitted when preedit setting changes.
127
127
//! \param enabled New setting.
128
128
 
 
129
//! \fn void AbstractTextEditor::preeditChanged(const QString &preedit)
 
130
//! \brief Emitted when preedit string changes.
 
131
//! \param enabled New string.
 
132
 
 
133
//! \fn void AbstractTextEditor::cursorPositionChanged(int pos)
 
134
//! \brief Emitted when preedit cusor position changes.
 
135
//! \param enabled New position.
 
136
 
129
137
//! \fn void AbstractTextEditor::wordCandidatesChanged(const WordCandidateList &word_candidates)
130
138
//! \brief Emitted when new word candidates are generated.
131
139
//! \param word_candidates New word candidates.
373
381
        const bool isSymbol = d->word_engine->languageFeature()->isSymbol(text);
374
382
        const bool replace_preedit = d->auto_correct_enabled && not d->text->primaryCandidate().isEmpty() && 
375
383
                    not d->text->preedit().isEmpty() && isSeparator;
 
384
        const bool enablePreeditAtInsertion = d->word_engine->languageFeature()->enablePreeditAtInsertion();
376
385
 
377
386
        d->previous_preedit = "";
378
387
 
379
388
        if (d->preedit_enabled) {
380
 
            if (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]")) || email_detected) {
 
389
            if (!enablePreeditAtInsertion &&
 
390
                    (d->text->surroundingRight().left(1).contains(QRegExp("[\\w]")) || email_detected)) {
381
391
                // We're editing in the middle of a word or entering an email address, so just insert characters directly
382
392
                d->text->appendToPreedit(text);
383
393
                commitPreedit();
429
439
            // standard input (like certain separators, e.g. '.' in western languages) can also trigger autoCaps
430
440
            Q_EMIT autoCapsActivated();
431
441
        }
 
442
 
 
443
        Q_EMIT preeditChanged(d->text->preedit());
 
444
        Q_EMIT cursorPositionChanged(d->text->cursorPosition());
432
445
    } break;
433
446
 
434
447
    case Key::ActionBackspace: {
505
518
        d->text->appendToPreedit(space);
506
519
        commitPreedit();
507
520
 
 
521
        Q_EMIT preeditChanged(d->text->preedit());
 
522
        Q_EMIT cursorPositionChanged(d->text->cursorPosition());
 
523
 
508
524
        if (auto_caps_activated && d->auto_caps_enabled) {
509
525
            Q_EMIT autoCapsActivated();
510
526
        }
515
531
        keyText = QString("\r");
516
532
    } break;
517
533
 
 
534
    case Key::ActionCommit: {
 
535
        commitPreedit();
 
536
 
 
537
        Q_EMIT preeditChanged(d->text->preedit());
 
538
        Q_EMIT cursorPositionChanged(d->text->cursorPosition());
 
539
    } break;
 
540
 
518
541
    case Key::ActionClose:
519
542
        Q_EMIT keyboardClosed();
520
543
        break;
561
584
    if (event_key != Qt::Key_unknown) {
562
585
        commitPreedit();
563
586
        sendKeyPressAndReleaseEvents(event_key, Qt::NoModifier, keyText);
 
587
 
 
588
        Q_EMIT preeditChanged(d->text->preedit());
 
589
        Q_EMIT cursorPositionChanged(d->text->cursorPosition());
564
590
    }
565
591
}
566
592
 
614
640
    // before sending preedit:
615
641
    d->word_engine->computeCandidates(d->text.data());
616
642
    sendPreeditString(d->text->preedit(), d->text->preeditFace());
 
643
 
 
644
    Q_EMIT preeditChanged(d->text->preedit());
 
645
    Q_EMIT cursorPositionChanged(d->text->cursorPosition());
617
646
}
618
647
 
619
648
void AbstractTextEditor::replaceTextWithPreedit(const QString &replacement, int start, int len, int pos)
629
658
    Replacement word_r(start, len, pos);
630
659
    sendPreeditString(d->text->preedit(), d->text->preeditFace(),
631
660
                      word_r);
 
661
 
 
662
    Q_EMIT preeditChanged(d->text->preedit());
 
663
    Q_EMIT cursorPositionChanged(d->text->cursorPosition());
632
664
}
633
665
 
634
666
//! \brief Replaces current preedit with given replacement and then
662
694
            Q_EMIT autoCapsDeactivated();
663
695
        }
664
696
    }
 
697
 
 
698
    Q_EMIT preeditChanged(d->text->preedit());
 
699
    Q_EMIT cursorPositionChanged(d->text->cursorPosition());
665
700
}
666
701
 
667
702
//! \brief Clears preedit.
702
737
    }
703
738
}
704
739
 
 
740
//! \brief Set cursor position of preedit.
 
741
void AbstractTextEditor::setCursorPosition(int pos)
 
742
{
 
743
    Q_D(AbstractTextEditor);
 
744
 
 
745
    if (not d->valid()) {
 
746
        return;
 
747
    }
 
748
 
 
749
    if (pos == d->text->cursorPosition()) {
 
750
        return;
 
751
    }
 
752
 
 
753
    d->text->setCursorPosition(pos);
 
754
 
 
755
    sendPreeditString(d->text->preedit(), d->text->preeditFace(),
 
756
                      Replacement(d->text->cursorPosition()));
 
757
    Q_EMIT preeditChanged(d->text->preedit());
 
758
    Q_EMIT cursorPositionChanged(d->text->cursorPosition());
 
759
}
 
760
 
705
761
//! \brief Returns whether auto-correct functionality is enabled.
706
762
//! \sa autoCorrectEnabled
707
763
bool AbstractTextEditor::isAutoCorrectEnabled() const
906
962
        // Clear previous word candidates
907
963
        Q_EMIT wordCandidatesChanged(WordCandidateList());
908
964
        sendPreeditString(d->text->preedit(), d->text->preeditFace(),
909
 
                          Replacement());
 
965
                          Replacement(d->text->cursorPosition()));
 
966
 
 
967
        Q_EMIT preeditChanged(d->text->preedit());
 
968
        Q_EMIT cursorPositionChanged(d->text->cursorPosition());
910
969
 
911
970
        if (d->text->preedit().isEmpty()) {
912
971
            d->word_engine->clearCandidates();
983
1042
        return;
984
1043
    }
985
1044
 
 
1045
    if(!d->word_engine->languageFeature()->restorePreedit()) {
 
1046
        return;
 
1047
    }
 
1048
 
986
1049
    int currentOffset = text()->surroundingOffset();
987
1050
    if(currentOffset > 1 && currentOffset <= text()->surrounding().size()) {
988
1051
        QString lastChar;
1023
1086
                }
1024
1087
                d->previous_preedit = "";
1025
1088
            }
1026
 
 
1027
1089
            replaceTextWithPreedit(recreatedPreedit, 0, 0, recreatedPreedit.size());
1028
1090
        }
1029
 
 
1030
1091
    }
1031
1092
 
1032
1093
    d->word_engine->computeCandidates(d->text.data());