diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-10-08 23:49:26 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2016-02-01 15:57:30 +0000 |
commit | 4713387c052d54e0f5ea02efaeaa25931d1cd7ee (patch) | |
tree | 1ada7f8b38cf4c31ab90468a32b1a6df3c4a362b /src/webenginewidgets/api/qwebenginepage.cpp | |
parent | 1910ddb3e2869e50514da343aa6947e88f734c38 (diff) |
Add spell checker support
Integrate chromium spell checker:
* add spellchecker and dependencies to build
* underline misspelled words in html text areas
* right-click context menu shows up to 4 options to
correct the misspelled word
* toggle spell check from context menu
* add new qml and widget api calls to qwebengineprofile
to enable/disable spell check, select spell check language,
get list of supported languages/dictionaries
* register new qml spell check properties for QtWebEngine 1.3
* CONFIG+="no_spellcheck" to remove spellcheck support
Change-Id: Ie61434ab9493597d7759a6f33794f6859c4e3a4c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/webenginewidgets/api/qwebenginepage.cpp')
-rw-r--r-- | src/webenginewidgets/api/qwebenginepage.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/webenginewidgets/api/qwebenginepage.cpp b/src/webenginewidgets/api/qwebenginepage.cpp index d68f364e4..62c1adee6 100644 --- a/src/webenginewidgets/api/qwebenginepage.cpp +++ b/src/webenginewidgets/api/qwebenginepage.cpp @@ -835,6 +835,11 @@ QAction *QWebEnginePage::action(WebAction action) const case SavePage: text = tr("Save &Page"); break; +#if !defined(QT_NO_SPELLCHECK) + case ToggleSpellcheck: + text = tr("Check Spelling"); + break; +#endif default: break; } @@ -1015,6 +1020,17 @@ void QWebEnginePage::triggerAction(WebAction action, bool) case SavePage: d->adapter->save(); break; +#if !defined(QT_NO_SPELLCHECK) + case ToggleSpellcheck: + d->adapter->toogleSpellCheckEnabled(); + break; + case ReplaceMisspelledWord_1: + case ReplaceMisspelledWord_2: + case ReplaceMisspelledWord_3: + case ReplaceMisspelledWord_4: + d->adapter->replaceMisspelling(d->actions[action]->text()); + break; +#endif default: Q_UNREACHABLE(); } @@ -1194,6 +1210,19 @@ QMenu *QWebEnginePage::createStandardContextMenu() QMenu *menu = new QMenu(d->view); QAction *action = 0; WebEngineContextMenuData contextMenuData(d->m_menuData); + +#if !defined(QT_NO_SPELLCHECK) + if (contextMenuData.isEditable && !contextMenuData.spellCheckerSuggestions.isEmpty()) { + for (int i=0; i < contextMenuData.spellCheckerSuggestions.count() && i < 4; i++) { + int index = ReplaceMisspelledWord_1 + i; + QAction *action(QWebEnginePage::action(static_cast<QWebEnginePage::WebAction>(index))); + action->setText(contextMenuData.spellCheckerSuggestions.at(i)); + menu->addAction(action); + } + menu->addSeparator(); + } +#endif + if (!contextMenuData.linkText.isEmpty() && contextMenuData.linkUrl.isValid()) { action = QWebEnginePage::action(OpenLinkInThisWindow); action->setText(tr("Follow Link")); @@ -1259,6 +1288,15 @@ QMenu *QWebEnginePage::createStandardContextMenu() if (d->isFullScreenMode()) menu->addAction(QWebEnginePage::action(ExitFullScreen)); +#if !defined(QT_NO_SPELLCHECK) + if (contextMenuData.isEditable) { + QAction* spellcheckAction(QWebEnginePage::action(ToggleSpellcheck)); + menu->addAction(spellcheckAction); + spellcheckAction->setCheckable(true); + spellcheckAction->setChecked(contextMenuData.isSpellCheckerEnabled); + } +#endif + return menu; } |