diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-11-11 15:59:37 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-11-11 16:02:17 (GMT) |
commit | fab1ce65da8bacfce92b1df7656780e729d31b74 (patch) | |
tree | 5a18285c4a506ba778b018f52f8f8500ee0b4456 /src/gui/text/qtextcontrol.cpp | |
parent | 06baf7f173b0331a5192616b8ecf9611130f278b (diff) | |
download | Qt-fab1ce65da8bacfce92b1df7656780e729d31b74.zip Qt-fab1ce65da8bacfce92b1df7656780e729d31b74.tar.gz Qt-fab1ce65da8bacfce92b1df7656780e729d31b74.tar.bz2 |
Add option to ingore unused navigation events in QTextControl
QFxTextEdit, as well as systems with keypad navigation, needs the text
control to ignore navigation events that have no effect (like hitting
the right navigation key at the end of the text.) Previously, we would
only support this for keypad navigation. This patch introduces a flag
that you can set to tell the QTextControl to ignore these events. If
the flag is not explicitly set, behavior should remain as before.
The if-test has been refactored to make it more readable.
Done-with: Alan Alpert
Reviewed-by: Samuel
Diffstat (limited to 'src/gui/text/qtextcontrol.cpp')
-rw-r--r-- | src/gui/text/qtextcontrol.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index 62039f3..e96d445 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -127,6 +127,7 @@ QTextControlPrivate::QTextControlPrivate() #endif isEnabled(true), hadSelectionOnMousePress(false), + ignoreUnusedNavigationEvents(false), openExternalLinks(false) {} @@ -265,19 +266,25 @@ bool QTextControlPrivate::cursorMoveKeyEvent(QKeyEvent *e) cursor.setVisualNavigation(visualNavigation); q->ensureCursorVisible(); + bool ignoreNavigationEvents = ignoreUnusedNavigationEvents; + bool isNavigationEvent = e->key() == Qt::Key_Up || e->key() == Qt::Key_Down; + +#ifdef QT_KEYPAD_NAVIGATION + ignoreNavigationEvents = ignoreNavigationEvents || QApplication::keypadNavigationEnabled(); + isNavigationEvent = isNavigationEvent || + (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional + && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right)); +#else + isNavigationEvent = isNavigationEvent || e->key() == Qt::Key_Left || e->key() == Qt::Key_Right; +#endif + if (moved) { if (cursor.position() != oldCursorPos) emit q->cursorPositionChanged(); emit q->microFocusChanged(); - } -#ifdef QT_KEYPAD_NAVIGATION - else if (QApplication::keypadNavigationEnabled() - && ((e->key() == Qt::Key_Up || e->key() == Qt::Key_Down) - || QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional - && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))) { + } else if (ignoreNavigationEvents && isNavigationEvent) { return false; } -#endif selectionChanged(/*forceEmitSelectionChanged =*/(mode == QTextCursor::KeepAnchor)); @@ -2258,6 +2265,18 @@ bool QTextControl::openExternalLinks() const return d->openExternalLinks; } +bool QTextControl::ignoreUnusedNavigationEvents() const +{ + Q_D(const QTextControl); + return d->ignoreUnusedNavigationEvents; +} + +void QTextControl::setIgnoreUnusedNavigationEvents(bool ignore) +{ + Q_D(QTextControl); + d->ignoreUnusedNavigationEvents = ignore; +} + void QTextControl::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode) { Q_D(QTextControl); |