diff --git a/examples/examples.pro b/examples/examples.pro index 0de2ec5051495826cfa56a334b64d53a436389f9..f15007e8375f9a9d93c17cdba7c9875993718dd0 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 0000000000000000000000000000000000000000..b90ff26ddec6086797b7be5f9993836c0dbc0ea1 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/icon.svg @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Generator: Adobe Illustrator 19.2.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) --> +<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + width="94px" height="94px" viewBox="0 0 94 94" enable-background="new 0 0 94 94" xml:space="preserve"> +<g> + <circle fill="none" cx="47" cy="47" r="47"/> + <g> + <path fill="#46A2DA" d="M47,92.979c-11.779,0-23.559-4.484-32.526-13.451C-3.461,61.591-3.461,32.409,14.472,14.474 + C32.41-3.463,61.592-3.461,79.526,14.473c17.935,17.936,17.935,47.119,0.002,65.054l-0.002,0.001 + C70.559,88.495,58.779,92.979,47,92.979z"/> + </g> + <path fill="#80C342" d="M93,47C93,21.595,72.405,1,47,1C34.297,1,22.797,6.149,14.473,14.473l65.054,65.054 + C87.851,71.203,93,59.703,93,47z"/> + <g> + <path fill="#46A2DA" d="M47,65c-4.808,0-9.328-1.873-12.728-5.272c-7.018-7.019-7.018-18.438,0-25.456 + C37.672,30.873,42.192,29,47,29s9.328,1.873,12.728,5.272c7.018,7.019,7.018,18.438,0,25.456C56.328,63.127,51.808,65,47,65z"/> + <path fill="#FFFFFF" d="M62.248,59.919c6.671-7.858,6.312-19.644-1.105-27.061C57.237,28.953,52.118,27,47,27 + c-5.118,0-10.237,1.953-14.142,5.858c-7.81,7.81-7.81,20.474,0,28.284C36.763,65.047,41.882,67,47,67 + c4.379,0,8.752-1.441,12.372-4.3L77.88,81.209c0.989-0.895,1.935-1.837,2.843-2.814L62.248,59.919z M35.686,58.314 + c-6.238-6.238-6.238-16.389,0-22.627C38.708,32.664,42.726,31,47,31c4.274,0,8.292,1.664,11.314,4.686 + c6.238,6.238,6.238,16.389,0,22.627C55.292,61.336,51.274,63,47,63C42.726,63,38.708,61.336,35.686,58.314z"/> + </g> +</g> +</svg> diff --git a/examples/webenginewidgets/spellchecker/data/index.html b/examples/webenginewidgets/spellchecker/data/index.html new file mode 100644 index 0000000000000000000000000000000000000000..b6cec5fe036bd091e50665be4883e1ea35e2e6ab --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/index.html @@ -0,0 +1,33 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Contact us</title> + <link rel="stylesheet" type="text/css" href="style.css"> + </head> + <body> + <form class="form"> + <img class="logo" src="icon.svg" alt="qtwebengine"> + <div class="header"> + <h1>Contact us</h1> + <h2>We are here to help</h2> + </div> + <label> + <span>First Name:</span><input id="firstname" type="text" name="name" /> + </label> + <label> + <span>Last Name:</span><input id="lastName" type="text" name="name" /> + </label> + <label> + <span>Email Address:</span><input id="email" type="text" name="email" /> + </label> + <label> + <span>Subject:</span><input id="subject" type="text" name="subject" /> + </label> + <label> + <span>Message:</span><textarea id="feedback" name="feedback"></textarea> + </label> + <input type="submit" value="Send" /> + </form> + </body> +</html> diff --git a/examples/webenginewidgets/spellchecker/data/spellchecker.qrc b/examples/webenginewidgets/spellchecker/data/spellchecker.qrc new file mode 100644 index 0000000000000000000000000000000000000000..a9c76cc7eed4a6f04b25eab672bccda70ddc3ee3 --- /dev/null +++ b/examples/webenginewidgets/spellchecker/data/spellchecker.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>index.html</file> + <file>style.css</file> + <file>icon.svg</file> + </qresource> +</RCC> diff --git a/examples/webenginewidgets/spellchecker/data/style.css b/examples/webenginewidgets/spellchecker/data/style.css new file mode 100644 index 0000000000000000000000000000000000000000..7b6736f1f7c4fd6b146530417bb51d904abf1a47 --- /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 0000000000000000000000000000000000000000..f9c94e06d00dde972ee35acc68b3d73d8813229d --- /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 0000000000000000000000000000000000000000..ff8185771663b203b4b2c3f6b22472c9036138b9 --- /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 0000000000000000000000000000000000000000..d10ae2600c76d025d2352dd45872a475e1da8fc2 --- /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 0000000000000000000000000000000000000000..41b5292920aab392ec4f4e08abdb675d1b595fa0 --- /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 0000000000000000000000000000000000000000..ff8185771663b203b4b2c3f6b22472c9036138b9 --- /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 0000000000000000000000000000000000000000..3d4ecdfa4b21c75670c452e0a763085ca5c95715 --- /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 0000000000000000000000000000000000000000..cc4e74946ae37aad9892c9c839bc8a5265227386 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 0000000000000000000000000000000000000000..d5b972b93f2532aade5259f116797c9b18c8d886 --- /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 0000000000000000000000000000000000000000..0d411f66551df859fd383e6178294baef7e56914 --- /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 <QApplication> + +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 0000000000000000000000000000000000000000..c7bee6584fa774aedfae2cb44458d96f46a8c7e3 --- /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 0000000000000000000000000000000000000000..6c73d88fa193d13db22c382e85eff9a43f07b239 --- /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 <QContextMenuEvent> +#include <QMenu> +#include <QWebEngineProfile> +#include <QWebEngineContextMenuData> + +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 0000000000000000000000000000000000000000..787d06a1a4485c04fe9975c516830dec4c924626 --- /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 <QWebEngineView> + +class WebView : public QWebEngineView +{ + Q_OBJECT + +public: + WebView(QWidget *parent = nullptr); + +protected: + void contextMenuEvent(QContextMenuEvent *event) override; + +private: + QMap<QString,QString> m_spellCheckLanguages; +}; + +#endif diff --git a/src/webengine/doc/qtwebengine.qdocconf b/src/webengine/doc/qtwebengine.qdocconf index 009902080cff9809d563de9336de9ef751ed008d..5e738f98d97a0638b23adac9281fbae980062ad8 100644 --- a/src/webengine/doc/qtwebengine.qdocconf +++ b/src/webengine/doc/qtwebengine.qdocconf @@ -66,6 +66,7 @@ exampledirs += . \ ../../core/doc/snippets \ ../../webenginewidgets/doc/snippets +examples.fileextensions += *.aff *.dic imagedirs += images diff --git a/src/webengine/doc/src/external-resources.qdoc b/src/webengine/doc/src/external-resources.qdoc index 8933513a4bb7351f3f72727c342af431a5c5363f..2ef88e8a49cf99ae4743910a1fe8fde049cbb17f 100644 --- a/src/webengine/doc/src/external-resources.qdoc +++ b/src/webengine/doc/src/external-resources.qdoc @@ -90,6 +90,11 @@ \title Shaka Player */ +/*! + \externalpage https://sourceforge.net/projects/hunspell/ + \title Hunspell Project +*/ + /* This prevents autolinking of each occurrence of 'WebEngine' To link to the WebEngine QML type, use explicit linking: