summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-11-11 15:59:37 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-11-11 16:02:17 (GMT)
commitfab1ce65da8bacfce92b1df7656780e729d31b74 (patch)
tree5a18285c4a506ba778b018f52f8f8500ee0b4456
parent06baf7f173b0331a5192616b8ecf9611130f278b (diff)
downloadQt-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
-rw-r--r--src/gui/text/qtextcontrol.cpp33
-rw-r--r--src/gui/text/qtextcontrol_p.h4
-rw-r--r--src/gui/text/qtextcontrol_p_p.h1
3 files changed, 31 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);
diff --git a/src/gui/text/qtextcontrol_p.h b/src/gui/text/qtextcontrol_p.h
index 263af31..bc8e063 100644
--- a/src/gui/text/qtextcontrol_p.h
+++ b/src/gui/text/qtextcontrol_p.h
@@ -95,6 +95,7 @@ class Q_GUI_EXPORT QTextControl : public QObject
Q_PROPERTY(int cursorWidth READ cursorWidth WRITE setCursorWidth)
Q_PROPERTY(Qt::TextInteractionFlags textInteractionFlags READ textInteractionFlags WRITE setTextInteractionFlags)
Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks)
+ Q_PROPERTY(bool ignoreUnusedNavigationEvents READ ignoreUnusedNavigationEvents WRITE setIgnoreUnusedNavigationEvents)
public:
explicit QTextControl(QObject *parent = 0);
explicit QTextControl(const QString &text, QObject *parent = 0);
@@ -163,6 +164,9 @@ public:
void setOpenExternalLinks(bool open);
bool openExternalLinks() const;
+ void setIgnoreUnusedNavigationEvents(bool ignore);
+ bool ignoreUnusedNavigationEvents() const;
+
void moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor);
bool canPaste() const;
diff --git a/src/gui/text/qtextcontrol_p_p.h b/src/gui/text/qtextcontrol_p_p.h
index ca9db9f..af3b521 100644
--- a/src/gui/text/qtextcontrol_p_p.h
+++ b/src/gui/text/qtextcontrol_p_p.h
@@ -206,6 +206,7 @@ public:
QString anchorOnMousePress;
bool hadSelectionOnMousePress;
+ bool ignoreUnusedNavigationEvents;
bool openExternalLinks;
QString linkToCopy;