From e8d1b9915a60732b764d6c18efd184b5ae73c06b Mon Sep 17 00:00:00 2001 From: Michal Klocek Date: Wed, 13 Apr 2016 16:06:23 +0200 Subject: Add widget based spellchecker example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This example demonstrates how to convert 'dic' dictionary files into 'bdict' binary format using qwebengine_convert_dict tool. It shows how to implement language selection. It adds two dummy dictionaries. Change-Id: Iffc23a0ed4e51cbc749f666c8f565fafb3739a9b Reviewed-by: Michael BrĂ¼ning --- examples/examples.pro | 7 +- .../webenginewidgets/spellchecker/data/icon.svg | 24 ++++ .../webenginewidgets/spellchecker/data/index.html | 33 +++++ .../spellchecker/data/spellchecker.qrc | 7 ++ .../webenginewidgets/spellchecker/data/style.css | 90 ++++++++++++++ .../spellchecker/dict/de/README.txt | 20 +++ .../spellchecker/dict/de/de-DE.aff | 5 + .../spellchecker/dict/de/de-DE.dic | 14 +++ .../spellchecker/dict/en/README.txt | 16 +++ .../spellchecker/dict/en/en-US.aff | 5 + .../spellchecker/dict/en/en-US.dic | 11 ++ .../doc/images/spellchecker-example.png | Bin 0 -> 15978 bytes .../spellchecker/doc/src/spellchecker.qdoc | 134 +++++++++++++++++++++ examples/webenginewidgets/spellchecker/main.cpp | 54 +++++++++ .../webenginewidgets/spellchecker/spellchecker.pro | 43 +++++++ examples/webenginewidgets/spellchecker/webview.cpp | 96 +++++++++++++++ examples/webenginewidgets/spellchecker/webview.h | 60 +++++++++ 17 files changed, 618 insertions(+), 1 deletion(-) create mode 100644 examples/webenginewidgets/spellchecker/data/icon.svg create mode 100644 examples/webenginewidgets/spellchecker/data/index.html create mode 100644 examples/webenginewidgets/spellchecker/data/spellchecker.qrc create mode 100644 examples/webenginewidgets/spellchecker/data/style.css create mode 100644 examples/webenginewidgets/spellchecker/dict/de/README.txt create mode 100644 examples/webenginewidgets/spellchecker/dict/de/de-DE.aff create mode 100644 examples/webenginewidgets/spellchecker/dict/de/de-DE.dic create mode 100644 examples/webenginewidgets/spellchecker/dict/en/README.txt create mode 100644 examples/webenginewidgets/spellchecker/dict/en/en-US.aff create mode 100644 examples/webenginewidgets/spellchecker/dict/en/en-US.dic create mode 100644 examples/webenginewidgets/spellchecker/doc/images/spellchecker-example.png create mode 100644 examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc create mode 100644 examples/webenginewidgets/spellchecker/main.cpp create mode 100644 examples/webenginewidgets/spellchecker/spellchecker.pro create mode 100644 examples/webenginewidgets/spellchecker/webview.cpp create mode 100644 examples/webenginewidgets/spellchecker/webview.h (limited to 'examples') diff --git a/examples/examples.pro b/examples/examples.pro index 0de2ec505..f15007e83 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -13,5 +13,10 @@ qtHaveModule(webenginewidgets) { webenginewidgets/cookiebrowser \ webenginewidgets/demobrowser \ webenginewidgets/markdowneditor \ - webenginewidgets/simplebrowser \ + webenginewidgets/simplebrowser + + !contains(WEBENGINE_CONFIG, no_spellcheck):!osx:!cross_compile { + SUBDIRS += webenginewidgets/spellchecker + } + } diff --git a/examples/webenginewidgets/spellchecker/data/icon.svg b/examples/webenginewidgets/spellchecker/data/icon.svg new file mode 100644 index 000000000..b90ff26dd --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/icon.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/examples/webenginewidgets/spellchecker/data/index.html b/examples/webenginewidgets/spellchecker/data/index.html new file mode 100644 index 000000000..b6cec5fe0 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/index.html @@ -0,0 +1,33 @@ + + + + + Contact us + + + +
+ +
+

Contact us

+

We are here to help

+
+ + + + + + +
+ + diff --git a/examples/webenginewidgets/spellchecker/data/spellchecker.qrc b/examples/webenginewidgets/spellchecker/data/spellchecker.qrc new file mode 100644 index 000000000..a9c76cc7e --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/spellchecker.qrc @@ -0,0 +1,7 @@ + + + index.html + style.css + icon.svg + + diff --git a/examples/webenginewidgets/spellchecker/data/style.css b/examples/webenginewidgets/spellchecker/data/style.css new file mode 100644 index 000000000..7b6736f1f --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/style.css @@ -0,0 +1,90 @@ +.logo { + width: 50px; + height: 50px; + float: left; + margin: 20px 20px 0px 20px; + -webkit-animation:spin 8s linear infinite; +} +@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } } + +.header { + display: inline +} + +.form { + width: 450px; + height: 600px; + background: -webkit-linear-gradient(bottom, #ddd, #fff); + border: 1px solid #999; + border-radius: 12px; + color: #46a; + font-family: 'Lucida Sans Unicode', 'Lucida Grande', sans-serif; + font-size: 14px; + font-style: italic; + font-weight: bold; + margin: auto; + padding: 10px; + position: relative; + line-height: 26px; + text-decoration: none; + -webkit-box-shadow: 0px 0px 5px #444; +} + +h1 { + padding-left:40px; + color: #46a2da; +} + +h2 { + color: #80c342; + font-size: 13px; + margin-top: -20px; +} + +span { + margin-left: 20px; +} + +input { + width: 400px; + display: block; + border: 1px solid #999; + height: 25px; + margin-left: 20px; + margin-bottom: 10px; + padding-left: 10px; + -webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3); +} + +textarea { + width: 400px; + max-width: 400px; + height: 180px; + max-height: 400px; + display: block; + margin-left: 20px; + padding-left: 10px; + padding-right: 10px; + -webkit-box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3); +} + +input:focus, textarea:focus { + outline:none; + border: 1px solid #46a2da; +} + +input[type=submit] { + width: 100px; + left: 170px; + bottom: 10px; + background: #46a2da; + color: #fff; + height: 30px; + position: absolute; + border-radius: 14px; +} + +input[type=submit]:hover { + background: #80c342; +} + diff --git a/examples/webenginewidgets/spellchecker/dict/de/README.txt b/examples/webenginewidgets/spellchecker/dict/de/README.txt new file mode 100644 index 000000000..f9c94e06d --- /dev/null +++ b/examples/webenginewidgets/spellchecker/dict/de/README.txt @@ -0,0 +1,20 @@ +This is dummy german dictionary which knows only following words: + +* ich +* du +* er +* sie +* es +* wir +* ihr +* sie +* Sie +* liebe +* liebst +* liebt +* lieben +* liebt +* qt + +Also each of words above can start with 'q' for example +* qich diff --git a/examples/webenginewidgets/spellchecker/dict/de/de-DE.aff b/examples/webenginewidgets/spellchecker/dict/de/de-DE.aff new file mode 100644 index 000000000..ff8185771 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/dict/de/de-DE.aff @@ -0,0 +1,5 @@ +SET UTF-8 +TRY esianrtolcdugmphbyfvkwzqESIANRTOLCDUGMPHBYFVKWZQ + +PFX Q Y 1 +PFX Q 0 q . diff --git a/examples/webenginewidgets/spellchecker/dict/de/de-DE.dic b/examples/webenginewidgets/spellchecker/dict/de/de-DE.dic new file mode 100644 index 000000000..d10ae2600 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/dict/de/de-DE.dic @@ -0,0 +1,14 @@ +15 +du/Q +er/Q +es/Q +ich/Q +ihr/Q +liebe/Q +lieben/Q +liebst/Q +liebt/Q +qt/Q +sie/Q +Sie/Q +wir/Q diff --git a/examples/webenginewidgets/spellchecker/dict/en/README.txt b/examples/webenginewidgets/spellchecker/dict/en/README.txt new file mode 100644 index 000000000..41b529292 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/dict/en/README.txt @@ -0,0 +1,16 @@ +This is dummy english dictionary which knows only following words: + +* I +* you +* he +* she +* it +* we +* they +* love +* loves +* qt + +Also each of words above can start with 'q' for example: + +* qI diff --git a/examples/webenginewidgets/spellchecker/dict/en/en-US.aff b/examples/webenginewidgets/spellchecker/dict/en/en-US.aff new file mode 100644 index 000000000..ff8185771 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/dict/en/en-US.aff @@ -0,0 +1,5 @@ +SET UTF-8 +TRY esianrtolcdugmphbyfvkwzqESIANRTOLCDUGMPHBYFVKWZQ + +PFX Q Y 1 +PFX Q 0 q . diff --git a/examples/webenginewidgets/spellchecker/dict/en/en-US.dic b/examples/webenginewidgets/spellchecker/dict/en/en-US.dic new file mode 100644 index 000000000..3d4ecdfa4 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/dict/en/en-US.dic @@ -0,0 +1,11 @@ +10 +he/Q +I/Q +it/Q +love/Q +loves/Q +qt/Q +she/Q +they/Q +we/Q +you/Q diff --git a/examples/webenginewidgets/spellchecker/doc/images/spellchecker-example.png b/examples/webenginewidgets/spellchecker/doc/images/spellchecker-example.png new file mode 100644 index 000000000..cc4e74946 Binary files /dev/null and b/examples/webenginewidgets/spellchecker/doc/images/spellchecker-example.png differ diff --git a/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc b/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc new file mode 100644 index 000000000..d5b972b93 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/doc/src/spellchecker.qdoc @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: http://www.gnu.org/copyleft/fdl.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example webenginewidgets/spellchecker + \title WebEngine Widgets Spellchecker Example + \ingroup webengine-widgetexamples + \brief Integrates a spellchecker into a simple HTML form. + + \image spellchecker-example.png + + \e {Spellchecker} demonstrates how to integrate spellchecking support into + an HTML form that enables users to submit spellchecked messages. + + \include examples-run.qdocinc + + \section1 Dictionaries + + To be able to check the spelling, we need to provide the spellchecker with + dictionaries. In this example, we want to support the English and German + languages. + + The Qt WebEngine spellchecker supports dictionaries from the + \l{Hunspell project}, but they have to be compiled into a special binary + format. A Hunspell dictionary consists of two files: + + \list + + \li A \c .dic file that is a dictionary containing words for the + language + \li An \c .aff file that defines the meaning of special flags in the + dictionary + \endlist + + These two files can be converted into the \c bdic format by using the + \c qwebengine_convert_dict tool that is shipped together with Qt. + + In this example, we are going to compile en_US and de_DE dictionaries. + However, the real full dictionaries would take too much space for the + purposes of this example. Therefore, we have created two dummy dictionaries + that contain the following words and can be used to demonstrate the + conversion process: + + \list + \li English dictionary: I, you, he, she, it, we, they, love, loves, qt + \li German dictionary: ich, du, er, sie, es, wir, ihr, sie, Sie, liebe, + liebst, liebt, lieben, liebt, qt + \endlist + + Each word in a dictionary can be prefixed with \c q. For more information + about how to create \c dic and \c aff files, see the Hunspell dictionary + file format specification in the \l{Hunspell Project}. + + When a specific spellchecking language is requested, Qt WebEngine will try + to load the already compiled matching \c .bdic file first from + \e qtwebengine_dictionaries directories relative to the executable, + then it will look in \c QT_INSTALL_PREFIX/qtwebengines_dictionaries. + + We specify the QMAKE_EXTRA_COMPILERS parameter in the project file to add a + conversion step to the build process: + + \quotefromfile webenginewidgets/spellchecker/spellchecker.pro + \skipto CONVERT_TOOL + \printuntil QMAKE_EXTRA_COMPILERS + + To set up a dictionary, we run \c qwebengine_convert_dic passing the + file path of the dictionary \c dic and \c bdic files. The \c aff file and + optional \c delta file are also picked up by the \c convert process. + The output \c bdic file is placed into the \e qtwebengine_dictionaries local + directory, which the application binary will run from. + + \section1 Setting the Spellchecker + + The constructor of our class is trivial. + + \quotefromfile webenginewidgets/spellchecker/webview.cpp + \skipto WebView::WebView + \printuntil } + We define simple mapping between our dictionary filenames and + the actual language display name. We will use that mapping to display names + of dictionaries in the context menu. Spellchecking is disabled by default. + Therefore we also enable spellchecker and set the \e English dictionary. + When Qt WebEngine's spellcheck service initializes, it will try to load the + \c bdict dictionaries and to check them for consistency. + Any errors are logged by using the qWarning() function. + + \section1 Switching the Spellchecking Language + + The current language used for spellchecking is defined per profile, and can + get set using the QWebEngineProfile::setSpellCheckLanguage method. When the + user clicks on an underlined misspelled word, the default context menu + displays up to four suggestions. Selecting one will replace the misspelled + word. We could reimplement a number of suggestions, by overriding + QWebEngineView::contextMenuEvent and using + QWebEngineContextMenuData::spellCheckerSuggestions, but we will demonstrate + how to add langague options in the context menu instead: + + \quotefromfile webenginewidgets/spellchecker/webview.cpp + \skipto void WebView::contextMenuEvent + \printuntil menu->popup + \printline } + + Above, we get the QWebEngineContextMenuData instance using the + QWebEnginePage::contextMenuData method. We use it to be notified when the + user clicks on an editable field and show the \uicontrol {Check Spelling} + item in the context menu. Moreover, if spellchecking is enabled, we also + add the \uicontrol {Select Language} submenu with the supported languages. + When an action is triggered, we set the language with the + QWebEngineProfile::setSpellCheckLanguage call. +*/ diff --git a/examples/webenginewidgets/spellchecker/main.cpp b/examples/webenginewidgets/spellchecker/main.cpp new file mode 100644 index 000000000..0d411f665 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/main.cpp @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "webview.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + WebView view; + view.setUrl(QUrl(QStringLiteral("qrc:/index.html"))); + view.resize(500, 640); + view.show(); + + return app.exec(); +} diff --git a/examples/webenginewidgets/spellchecker/spellchecker.pro b/examples/webenginewidgets/spellchecker/spellchecker.pro new file mode 100644 index 000000000..c7bee6584 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/spellchecker.pro @@ -0,0 +1,43 @@ +TEMPLATE = app +TARGET = spellchecker +QT += webenginewidgets +CONFIG += c++11 + +HEADERS += \ + webview.h + +SOURCES += \ + main.cpp \ + webview.cpp + +RESOURCES += \ + data/spellchecker.qrc + +DISTFILES += \ + dict/en/README.txt \ + dict/en/en-US.dic \ + dict/en/en-US.aff \ + dict/de/README.txt \ + dict/de/de-DE.dic \ + dict/de/de-DE.aff + +target.path = $$[QT_INSTALL_EXAMPLES]/webenginewidgets/spellchecker +INSTALLS += target + +qtPrepareTool(CONVERT_TOOL, qwebengine_convert_dict) + +debug_and_release { + CONFIG(debug, debug|release): DICTIONARIES_DIR = debug/qtwebengine_dictionaries + else: DICTIONARIES_DIR = release/qtwebengine_dictionaries +} else { + DICTIONARIES_DIR = qtwebengine_dictionaries +} + +dict.files = $$PWD/dict/en/en-US.dic $$PWD/dict/de/de-DE.dic +dictoolbuild.input = dict.files +dictoolbuild.output = $${DICTIONARIES_DIR}/${QMAKE_FILE_BASE}.bdic +dictoolbuild.depends = ${QMAKE_FILE_PATH}/${QMAKE_FILE_BASE}.aff +dictoolbuild.commands = $${CONVERT_TOOL} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT} +dictoolbuild.name = Build ${QMAKE_FILE_IN_BASE} +dictoolbuild.CONFIG = no_link target_predeps +QMAKE_EXTRA_COMPILERS += dictoolbuild diff --git a/examples/webenginewidgets/spellchecker/webview.cpp b/examples/webenginewidgets/spellchecker/webview.cpp new file mode 100644 index 000000000..6c73d88fa --- /dev/null +++ b/examples/webenginewidgets/spellchecker/webview.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "webview.h" +#include +#include +#include +#include + +WebView::WebView(QWidget *parent) + : QWebEngineView(parent) +{ + m_spellCheckLanguages["English"] = "en-US"; + m_spellCheckLanguages["German"] = "de-DE"; + QWebEngineProfile *profile = page()->profile(); + profile->setSpellCheckEnabled(true); + profile->setSpellCheckLanguage("en-US"); +} + +void WebView::contextMenuEvent(QContextMenuEvent *event) +{ + const QWebEngineContextMenuData &data = page()->contextMenuData(); + Q_ASSERT(data.isValid()); + + if (!data.isContentEditable()) { + QWebEngineView::contextMenuEvent(event); + return; + } + + QWebEngineProfile *profile = page()->profile(); + const QString &language = profile->spellCheckLanguage(); + QMenu *menu = page()->createStandardContextMenu(); + menu->addSeparator(); + + QAction *spellcheckAction = new QAction(tr("Check Spelling")); + spellcheckAction->setCheckable(true); + spellcheckAction->setChecked(profile->isSpellCheckEnabled()); + connect(spellcheckAction, &QAction::toggled, this, [profile](bool toogled) { + profile->setSpellCheckEnabled(toogled); + }); + menu->addAction(spellcheckAction); + + if (profile->isSpellCheckEnabled()) { + QMenu *subMenu = menu->addMenu(tr("Select Language")); + foreach (const QString &str, m_spellCheckLanguages.keys()) { + QAction *action = subMenu->addAction(str); + action->setCheckable(true); + QString lang = m_spellCheckLanguages[str]; + action->setChecked(language == lang); + connect(action, &QAction::triggered, this, [profile, lang](){ + profile->setSpellCheckLanguage(lang); + }); + } + } + connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater); + menu->popup(event->globalPos()); +} + + diff --git a/examples/webenginewidgets/spellchecker/webview.h b/examples/webenginewidgets/spellchecker/webview.h new file mode 100644 index 000000000..787d06a1a --- /dev/null +++ b/examples/webenginewidgets/spellchecker/webview.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef WEBVIEW_H +#define WEBVIEW_H + +#include + +class WebView : public QWebEngineView +{ + Q_OBJECT + +public: + WebView(QWidget *parent = nullptr); + +protected: + void contextMenuEvent(QContextMenuEvent *event) override; + +private: + QMap m_spellCheckLanguages; +}; + +#endif -- cgit v1.2.3