[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ktextwidgets] src/widgets: Add a new submenu to KTextEdit to switch between spell-checking language
From: Dan_Vrátil <dvratil () redhat ! com>
Date: 2015-10-12 12:32:39
Message-ID: E1ZlcHP-0006s1-TG () scm ! kde ! org
[Download RAW message or body]
Git commit fdfd1b70ed3bc593db04d130f0a9adec0b4005a6 by Dan Vrátil.
Committed on 12/10/2015 at 12:32.
Pushed by dvratil into branch 'master'.
Add a new submenu to KTextEdit to switch between spell-checking languages
REVIEW: 125532
M +33 -1 src/widgets/ktextedit.cpp
http://commits.kde.org/ktextwidgets/fdfd1b70ed3bc593db04d130f0a9adec0b4005a6
diff --git a/src/widgets/ktextedit.cpp b/src/widgets/ktextedit.cpp
index ee83f05..4cc27cd 100644
--- a/src/widgets/ktextedit.cpp
+++ b/src/widgets/ktextedit.cpp
@@ -66,12 +66,13 @@ class KTextEdit::Private
public:
Private(KTextEdit *_parent)
: parent(_parent),
+ languagesMenu(Q_NULLPTR),
customPalette(false),
spellCheckingEnabled(false),
findReplaceEnabled(true),
showTabAction(true),
showAutoCorrectionButton(false),
- decorator(0), findDlg(0), find(0), repDlg(0), replace(0),
+ decorator(0), speller(0), findDlg(0), find(0), repDlg(0), replace(0),
#ifdef HAVE_SPEECH
textToSpeech(Q_NULLPTR),
#endif
@@ -93,6 +94,7 @@ public:
delete find;
delete replace;
delete repDlg;
+ delete speller;
#ifdef HAVE_SPEECH
delete textToSpeech;
#endif
@@ -135,6 +137,7 @@ public:
QAction *autoSpellCheckAction;
QAction *allowTab;
QAction *spellCheckAction;
+ QMenu *languagesMenu;
bool customPalette : 1;
bool spellCheckingEnabled : 1;
@@ -144,6 +147,7 @@ public:
QTextDocumentFragment originalDoc;
QString spellCheckingLanguage;
Sonnet::SpellCheckDecorator *decorator;
+ Sonnet::Speller *speller;
KFindDialog *findDlg;
KFind *find;
KReplaceDialog *repDlg;
@@ -558,6 +562,34 @@ QMenu *KTextEdit::mousePopupMenu()
if (emptyDocument) {
d->spellCheckAction->setEnabled(false);
}
+
+ if (checkSpellingEnabled()) {
+ d->languagesMenu = new QMenu(i18n("Spell Checking Language"), popup);
+ QActionGroup *languagesGroup = new QActionGroup(d->languagesMenu);
+ languagesGroup->setExclusive(true);
+ if (!d->speller) {
+ d->speller = new Sonnet::Speller();
+ }
+
+ QMapIterator<QString, QString> i(d->speller->availableDictionaries());
+ const QString language = spellCheckingLanguage();
+ while (i.hasNext()) {
+ i.next();
+
+ QAction *languageAction = d->languagesMenu->addAction(i.key());
+ languageAction->setCheckable(true);
+ languageAction->setChecked(language == i.value() || (language.isEmpty()
+ && d->speller->defaultLanguage() == i.value()));
+ languageAction->setData(i.value());
+ languageAction->setActionGroup(languagesGroup);
+ connect(languageAction, &QAction::triggered,
+ [this, languageAction]() {
+ setSpellCheckingLanguage(languageAction->data().toString());
+ });
+ }
+ popup->addMenu(d->languagesMenu);
+ }
+
d->autoSpellCheckAction = popup->addAction(i18n("Auto Spell Check"));
d->autoSpellCheckAction->setCheckable(true);
d->autoSpellCheckAction->setChecked(checkSpellingEnabled());
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic