1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

Add Spell Check config to Preferences

Spell checking now works with QtWebEngine >= 5.8
This commit is contained in:
David Rosca 2016-10-25 23:36:39 +02:00
parent 00c806d5d0
commit 4d9137a1d9
5 changed files with 116 additions and 1 deletions

View File

@ -894,6 +894,13 @@ void MainApplication::loadSettings()
const bool allowCache = settings.value(QSL("Web-Browser-Settings/AllowLocalCache"), true).toBool();
profile->setHttpCacheType(allowCache ? QWebEngineProfile::DiskHttpCache : QWebEngineProfile::MemoryHttpCache);
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
settings.beginGroup(QSL("SpellCheck"));
profile->setSpellCheckEnabled(settings.value(QSL("Enabled"), false).toBool());
profile->setSpellCheckLanguage(settings.value(QSL("Language"), QString()).toString());
settings.endGroup();
#endif
if (isPrivate()) {
webSettings->setAttribute(QWebEngineSettings::LocalStorageEnabled, false);
history()->setSaving(false);

View File

@ -66,5 +66,6 @@
<file>icons/other/startpage.png</file>
<file>icons/other/audioplaying.png</file>
<file>icons/other/audiomuted.png</file>
<file>icons/preferences/tools-check-spelling.png</file>
</qresource>
</RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -58,11 +58,16 @@
#include <QDesktopWidget>
#include <QWebEngineProfile>
#include <QWebEngineSettings>
#include <QLibraryInfo>
static QString createLanguageItem(const QString &lang)
{
QLocale locale(lang);
if (locale.language() == QLocale::C) {
return lang;
}
QString country = QLocale::countryToString(locale.country());
QString language = QLocale::languageToString(locale.language());
@ -119,7 +124,8 @@ Preferences::Preferences(BrowserWindow* window)
ui->listWidget->item(8)->setIcon(QIcon::fromTheme("preferences-system-firewall", QIcon(":/icons/preferences/preferences-system-firewall.png")));
ui->listWidget->item(9)->setIcon(QIcon::fromTheme("dialog-question", QIcon(":/icons/preferences/dialog-question.png")));
ui->listWidget->item(10)->setIcon(QIcon::fromTheme("extension", QIcon(":/icons/preferences/extension.png")));
ui->listWidget->item(11)->setIcon(QIcon::fromTheme("applications-system", QIcon(":/icons/preferences/applications-system.png")));
ui->listWidget->item(11)->setIcon(QIcon::fromTheme("tools-check-spelling", QIcon(":/icons/preferences/tools-check-spelling.png")));
ui->listWidget->item(12)->setIcon(QIcon::fromTheme("applications-system", QIcon(":/icons/preferences/applications-system.png")));
Settings settings;
//GENERAL URLs
@ -395,6 +401,34 @@ Preferences::Preferences(BrowserWindow* window)
m_notifPosition = settings.value("Position", QPoint(10, 10)).toPoint();
settings.endGroup();
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
//SPELLCHECK
settings.beginGroup(QSL("SpellCheck"));
ui->spellcheckEnabled->setChecked(settings.value(QSL("Enabled"), false).toBool());
const QString spellcheckLanguage = settings.value(QSL("Language")).toString();
settings.endGroup();
const QStringList dictionariesDirs = {
QCoreApplication::applicationDirPath() + QL1S("/qtwebengine_dictionaries"),
QLibraryInfo::location(QLibraryInfo::DataPath) + QL1S("/qtwebengine_dictionaries")
};
for (const QString &path : dictionariesDirs) {
QDir dir(path);
const QStringList files = dir.entryList({QSL("*.bdic")});
for (const QString &file : files) {
const QString lang = file.left(file.size() - 5);
ui->spellcheckLanguage->addItem(createLanguageItem(lang), lang);
if (lang == spellcheckLanguage) {
ui->spellcheckLanguage->setCurrentIndex(ui->spellcheckLanguage->count() - 1);
}
}
}
#else
delete ui->listWidget->item(11);
delete ui->stackedWidget->widget(11);
#endif
//OTHER
//Languages
QString activeLanguage = mApp->currentLanguage();
@ -948,6 +982,14 @@ void Preferences::saveSettings()
settings.setValue("Position", m_notification.data() ? m_notification.data()->pos() : m_notifPosition);
settings.endGroup();
#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
//SPELLCHECK
settings.beginGroup(QSL("SpellCheck"));
settings.setValue("Enabled", ui->spellcheckEnabled->isChecked());
settings.setValue("Language", ui->spellcheckLanguage->currentData().toString());
settings.endGroup();
#endif
//OTHER
//AddressBar
settings.beginGroup("AddressBar");

View File

@ -110,6 +110,11 @@
<string>Extensions</string>
</property>
</item>
<item>
<property name="text">
<string>Spell Check</string>
</property>
</item>
<item>
<property name="text">
<string>Other</string>
@ -2275,6 +2280,66 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="spellcheckPage">
<layout class="QGridLayout" name="gridLayout_20">
<item row="2" column="3">
<spacer name="horizontalSpacer_16">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_7">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Language:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="spellcheckLanguage"/>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_17">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="4">
<widget class="QLabel" name="label_10">
<property name="text">
<string>&lt;b&gt;Spell Check&lt;/b&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="spellcheckEnabled">
<property name="text">
<string>Enable Spell Check</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="otherPage">
<layout class="QGridLayout" name="gridLayout_13">
<item row="9" column="0" colspan="4">