aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar keshavbhatt <keshavnrj@gmail.com>2021-04-09 10:23:26 +0530
committerLibravatar keshavbhatt <keshavnrj@gmail.com>2021-04-09 10:23:26 +0530
commit2b3f192127466b044e87a39020ef57d734793f38 (patch)
tree02ab3529d0a2c481856e73dcd8fc29472cd559e8 /src
parentbe673a4a1e539307517439d0a8696afa681d8cb6 (diff)
downloadwhatsie-2b3f192127466b044e87a39020ef57d734793f38.tar.gz
whatsie-2b3f192127466b044e87a39020ef57d734793f38.zip
added webview class
new dictionaries deployment strategy
Diffstat (limited to 'src')
-rw-r--r--src/WhatsApp.pro59
-rw-r--r--src/webview.cpp51
-rw-r--r--src/webview.h22
3 files changed, 123 insertions, 9 deletions
diff --git a/src/WhatsApp.pro b/src/WhatsApp.pro
index aa51a4b..c07761d 100644
--- a/src/WhatsApp.pro
+++ b/src/WhatsApp.pro
@@ -10,6 +10,13 @@ CONFIG += c++11
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+!qtConfig(webengine-spellchecker) {
+ error("Qt WebEngine compiled without spellchecker support, this example will not work.")
+}
+
+qtConfig(webengine-native-spellchecker) {
+ error("Spellcheck example can not be built when using native OS dictionaries.")
+}
TARGET = whatsie
TEMPLATE = app
@@ -52,6 +59,7 @@ SOURCES += \
settingswidget.cpp \
utils.cpp \
webenginepage.cpp \
+ webview.cpp \
widgets/scrolltext/scrolltext.cpp
RESOURCES += \
@@ -72,9 +80,51 @@ HEADERS += \
settingswidget.h \
utils.h \
webenginepage.h \
+ webview.h \
widgets/scrolltext/scrolltext.h
+FORMS += \
+ about.ui \
+ certificateerrordialog.ui \
+ downloadmanagerwidget.ui \
+ downloadwidget.ui \
+ lock.ui \
+ passworddialog.ui \
+ settingswidget.ui
+
+DISTFILES += \
+ dict/de/de-DE.aff \
+ dict/de/de-DE.dic \
+ dict/en/en-US.aff \
+ dict/en/en-US.dic \
+ dict/es/es.aff \
+ dict/es/es.dic \
+ dict/fr/fr.aff \
+ dict/fr/fr.dic \
+ dict/gb/en-GB.aff \
+ dict/gb/en-GB.dic
+
+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 = $$files($$PWD/dictionaries/*.dic, true)
+
+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
+
+
# Default rules for deployment.
isEmpty(PREFIX){
PREFIX = /usr
@@ -93,12 +143,3 @@ desktop.path = $$DATADIR/applications/
INSTALLS += target icon desktop
-FORMS += \
- about.ui \
- certificateerrordialog.ui \
- downloadmanagerwidget.ui \
- downloadwidget.ui \
- lock.ui \
- passworddialog.ui \
- settingswidget.ui
-
diff --git a/src/webview.cpp b/src/webview.cpp
new file mode 100644
index 0000000..8e61f2e
--- /dev/null
+++ b/src/webview.cpp
@@ -0,0 +1,51 @@
+#include "webview.h"
+
+#include <QContextMenuEvent>
+#include <QMenu>
+#include <QWebEngineProfile>
+#include <QWebEngineContextMenuData>
+
+WebView::WebView(QWidget *parent, QStringList dictionaries)
+ : QWebEngineView(parent)
+{
+ m_dictionaries = dictionaries;
+}
+
+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 QStringList &languages = profile->spellCheckLanguages();
+ QMenu *menu = page()->createStandardContextMenu();
+ menu->addSeparator();
+
+ QAction *spellcheckAction = new QAction(tr("Check Spelling"), nullptr);
+ 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"));
+ for (const QString &dict : m_dictionaries) {
+ QAction *action = subMenu->addAction(dict);
+ action->setCheckable(true);
+ action->setChecked(languages.contains(dict));
+ connect(action, &QAction::triggered, this, [profile, dict,this](){
+ profile->setSpellCheckLanguages(QStringList()<<dict);
+ settings.setValue("sc_dict",dict);
+ });
+ }
+ }
+ connect(menu, &QMenu::aboutToHide, menu, &QObject::deleteLater);
+ menu->popup(event->globalPos());
+}
diff --git a/src/webview.h b/src/webview.h
new file mode 100644
index 0000000..b896ad6
--- /dev/null
+++ b/src/webview.h
@@ -0,0 +1,22 @@
+#ifndef WEBVIEW_H
+#define WEBVIEW_H
+
+#include <QWebEngineView>
+#include <QSettings>
+
+class WebView: public QWebEngineView
+{
+ Q_OBJECT
+
+public:
+ WebView(QWidget *parent = nullptr, QStringList dictionaries = {});
+
+protected:
+ void contextMenuEvent(QContextMenuEvent *event) override;
+
+private:
+ QStringList m_dictionaries;
+ QSettings settings;
+};
+
+#endif // WEBVIEW_H