summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2015-10-15 09:07:54 +0200
committerMontel Laurent <[email protected]>2015-10-15 09:07:54 +0200
commitf186e367200a763f05135bcd02a01492f72d99f8 (patch)
tree7a20d3d2a16f229ee9acab43df6994404103f1ce
parentf6594db71b639d3e01749d912c4443609efb8496 (diff)
Move autocorrection code in own method
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposer.cpp84
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposer.h2
2 files changed, 45 insertions, 41 deletions
diff --git a/messagecomposer/src/composer-ng/richtextcomposer.cpp b/messagecomposer/src/composer-ng/richtextcomposer.cpp
index 41ee480..7eff315 100644
--- a/messagecomposer/src/composer-ng/richtextcomposer.cpp
+++ b/messagecomposer/src/composer-ng/richtextcomposer.cpp
@@ -405,6 +405,49 @@ static bool isSpecial(const QTextCharFormat &charFormat)
charFormat.isListFormat() || charFormat.isTableFormat() || charFormat.isTableCellFormat();
}
+void RichTextComposer::processAutoCorrection(QKeyEvent *e)
+{
+ if (d->autoCorrection && d->autoCorrection->isEnabledAutoCorrection()) {
+ if ((e->key() == Qt::Key_Space) || (e->key() == Qt::Key_Enter) || (e->key() == Qt::Key_Return)) {
+ if (!isLineQuoted(textCursor().block().text()) && !textCursor().hasSelection()) {
+ const QTextCharFormat initialTextFormat = textCursor().charFormat();
+ const bool richText = (textMode() == RichTextComposer::Rich);
+ int position = textCursor().position();
+ const bool addSpace = d->autoCorrection->autocorrect(richText, *document(), position);
+ QTextCursor cur = textCursor();
+ cur.setPosition(position);
+ if (overwriteMode() && e->key() == Qt::Key_Space) {
+ if (addSpace) {
+ const QChar insertChar = QLatin1Char(' ');
+ if (!cur.atBlockEnd()) {
+ cur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 1);
+ }
+ if (richText && !isSpecial(initialTextFormat)) {
+ cur.insertText(insertChar, initialTextFormat);
+ } else {
+ cur.insertText(insertChar);
+ }
+ setTextCursor(cur);
+ }
+ } else {
+ const bool spacePressed = (e->key() == Qt::Key_Space);
+ const QChar insertChar = spacePressed ? QLatin1Char(' ') : QLatin1Char('\n');
+ if (richText && !isSpecial(initialTextFormat)) {
+ if ((spacePressed && addSpace) || !spacePressed) {
+ cur.insertText(insertChar, initialTextFormat);
+ }
+ } else {
+ if ((spacePressed && addSpace) || !spacePressed) {
+ cur.insertText(insertChar);
+ }
+ }
+ setTextCursor(cur);
+ }
+ }
+ }
+ }
+}
+
bool RichTextComposer::processKeyEvent(QKeyEvent *e)
{
if (d->externalComposer->useExternalEditor() &&
@@ -431,46 +474,7 @@ bool RichTextComposer::processKeyEvent(QKeyEvent *e)
textCursor().clearSelection();
Q_EMIT focusUp();
} else {
- if (d->autoCorrection && d->autoCorrection->isEnabledAutoCorrection()) {
- if ((e->key() == Qt::Key_Space) || (e->key() == Qt::Key_Enter) || (e->key() == Qt::Key_Return)) {
- if (!isLineQuoted(textCursor().block().text()) && !textCursor().hasSelection()) {
- const QTextCharFormat initialTextFormat = textCursor().charFormat();
- const bool richText = (textMode() == RichTextComposer::Rich);
- int position = textCursor().position();
- const bool addSpace = d->autoCorrection->autocorrect(richText, *document(), position);
- QTextCursor cur = textCursor();
- cur.setPosition(position);
- if (overwriteMode() && e->key() == Qt::Key_Space) {
- if (addSpace) {
- const QChar insertChar = QLatin1Char(' ');
- if (!cur.atBlockEnd()) {
- cur.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, 1);
- }
- if (richText && !isSpecial(initialTextFormat)) {
- cur.insertText(insertChar, initialTextFormat);
- } else {
- cur.insertText(insertChar);
- }
- setTextCursor(cur);
- }
- } else {
- const bool spacePressed = (e->key() == Qt::Key_Space);
- const QChar insertChar = spacePressed ? QLatin1Char(' ') : QLatin1Char('\n');
- if (richText && !isSpecial(initialTextFormat)) {
- if ((spacePressed && addSpace) || !spacePressed) {
- cur.insertText(insertChar, initialTextFormat);
- }
- } else {
- if ((spacePressed && addSpace) || !spacePressed) {
- cur.insertText(insertChar);
- }
- }
- setTextCursor(cur);
- }
- return true;
- }
- }
- }
+ processAutoCorrection(e);
evaluateReturnKeySupport(e);
}
return true;
diff --git a/messagecomposer/src/composer-ng/richtextcomposer.h b/messagecomposer/src/composer-ng/richtextcomposer.h
index aeceff2..5ee1c9c 100644
--- a/messagecomposer/src/composer-ng/richtextcomposer.h
+++ b/messagecomposer/src/composer-ng/richtextcomposer.h
@@ -146,7 +146,7 @@ protected:
void updateHighLighter() Q_DECL_OVERRIDE;
bool processKeyEvent(QKeyEvent *e);
void evaluateReturnKeySupport(QKeyEvent *event);
-
+ void processAutoCorrection(QKeyEvent *e);
private Q_SLOTS:
void slotTextModeChanged(MessageComposer::RichTextComposer::Mode mode);