summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-12 13:34:01 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-12 13:40:24 (GMT)
commit037c1c3b3e1abc07f0570336bd7958121f32848a (patch)
treed36de93b4f95b03b462d4064c26587ac4ce5b871 /src/gui/widgets
parent65f38e884f40f02be6497819c876013750cce4ea (diff)
downloadQt-037c1c3b3e1abc07f0570336bd7958121f32848a.zip
Qt-037c1c3b3e1abc07f0570336bd7958121f32848a.tar.gz
Qt-037c1c3b3e1abc07f0570336bd7958121f32848a.tar.bz2
QLabel: Fixed text underlined when te label has a control and the text contains &
We need to search for '&' in the text each time the QTextControl's document is updated. Also make sure not to match && Task-number: QTBUG-4154 Reviewed-by: Thierry
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qlabel.cpp38
-rw-r--r--src/gui/widgets/qlabel_p.h2
2 files changed, 23 insertions, 17 deletions
diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp
index 3d908a1..ea711e8 100644
--- a/src/gui/widgets/qlabel.cpp
+++ b/src/gui/widgets/qlabel.cpp
@@ -1170,22 +1170,10 @@ void QLabelPrivate::updateShortcut()
// But then we do want to hide the ampersands, so we can't use shortcutId.
hasShortcut = false;
- if (control) {
- ensureTextPopulated();
- // Underline the first character that follows an ampersand
- shortcutCursor = control->document()->find(QLatin1String("&"));
- if (shortcutCursor.isNull())
- return;
- hasShortcut = true;
- shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
- shortcutCursor.deleteChar(); // remove the ampersand
- shortcutCursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
- } else {
- if (!text.contains(QLatin1Char('&')))
- return;
- hasShortcut = true;
- shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
- }
+ if (!text.contains(QLatin1Char('&')))
+ return;
+ hasShortcut = true;
+ shortcutId = q->grabShortcut(QKeySequence::mnemonic(text));
}
#endif // QT_NO_SHORTCUT
@@ -1456,6 +1444,24 @@ void QLabelPrivate::ensureTextPopulated() const
doc->setPlainText(text);
#endif
doc->setUndoRedoEnabled(false);
+
+#ifndef QT_NO_SHORTCUT
+ if (hasShortcut) {
+ // Underline the first character that follows an ampersand (and remove the others ampersands)
+ int from = 0;
+ bool found = false;
+ QTextCursor cursor;
+ while (!(cursor = control->document()->find((QLatin1String("&")), from)).isNull()) {
+ cursor.deleteChar(); // remove the ampersand
+ cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
+ from = cursor.position();
+ if (!found && cursor.selectedText() != QLatin1String("&")) { //not a second &
+ found = true;
+ shortcutCursor = cursor;
+ }
+ }
+ }
+#endif
}
}
textDirty = false;
diff --git a/src/gui/widgets/qlabel_p.h b/src/gui/widgets/qlabel_p.h
index c5a74e2..ca17a35 100644
--- a/src/gui/widgets/qlabel_p.h
+++ b/src/gui/widgets/qlabel_p.h
@@ -113,7 +113,7 @@ public:
mutable uint hasShortcut : 1;
Qt::TextFormat textformat;
mutable QTextControl *control;
- QTextCursor shortcutCursor;
+ mutable QTextCursor shortcutCursor;
Qt::TextInteractionFlags textInteractionFlags;
inline bool needTextControl() const {