diff options
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp index 7e7683c..60f0939 100644 --- a/Swift/QtUI/QtTextEdit.cpp +++ b/Swift/QtUI/QtTextEdit.cpp @@ -12,6 +12,7 @@ #include <Swift/QtUI/QtTextEdit.h> #include <Swift/QtUI/QtSwiftUtil.h> +#include <QApplication> #include <QFontMetrics> #include <QKeyEvent> #include <QDebug> @@ -122,9 +123,14 @@ QSize QtTextEdit::sizeHint() const { } void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { + QMenu *menu = createStandardContextMenu(); QTextCursor cursor = cursorForPosition(event->pos()); boost::tuple<int, int> wordPosition = getWordFromCursor(cursor.position()); if (boost::get<0>(wordPosition) < 0) { + // The click was executed outside a spellable word so no + // suggestion menu is necessary + menu->exec(event->globalPos()); + delete menu; return; } cursor.setPosition(boost::get<0>(wordPosition), QTextCursor::MoveAnchor); @@ -132,11 +138,19 @@ void QtTextEdit::contextMenuEvent(QContextMenuEvent* event) { std::vector<std::string> wordList; checker_->getSuggestions(Q2PSTRING(cursor.selectedText()), wordList); std::vector<QAction*> replaceWordActions; - QMenu *menu = createStandardContextMenu(); - for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { - replaceWordActions.push_back(menu->addAction(tr(it->c_str()))); + QAction *insertPoint = menu->actions().first(); + if (wordList.size() == 0) { + QAction *noSuggestions = new QAction(QApplication::translate("QtTextEdit", "No Suggestions", 0, QApplication::UnicodeUTF8), menu); + noSuggestions->setDisabled(true); + menu->insertAction(insertPoint, noSuggestions); + } else { + for (std::vector<std::string>::iterator it = wordList.begin(); it != wordList.end(); ++it) { + QAction *wordAction = new QAction(it->c_str(), menu); + menu->insertAction(insertPoint, wordAction); + replaceWordActions.push_back(wordAction); + } } - + menu->insertAction(insertPoint, menu->addSeparator()); QAction* result = menu->exec(event->globalPos()); for (std::vector<QAction*>::iterator it = replaceWordActions.begin(); it != replaceWordActions.end(); ++it) { if (*it == result) { |