From: Manuel Nickschas Date: Wed, 25 Jul 2018 20:26:59 +0000 (+0200) Subject: uisupport: Allow to disable spell checking X-Git-Tag: 0.13-rc2~83 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=488f17a85739983b6357a53bd9158d81b6ac2114 uisupport: Allow to disable spell checking Apparently, Sonnet, when used standalone (i.e. not in KTextEdit), does not honor its own setting to disable it by default. Explicitly read the setting when initializing the highlighter, and set its active state accordingly. Provide a context menu option to enable/disable spell check on-the-fly as well. Remove the bogus/unused checkbox in the InputWidget settings page; there is a dedicated settings page for configuring spell checking. Explicitly depend on Sonnet when building with KDE Frameworks (it was transitively depended upon anyway), so we can be sure to offer the Sonnet settings page even when using Frameworks. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index afdb3571..721e339c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -350,7 +350,7 @@ if (USE_QT5) if (ECM_FOUND) list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) if (WITH_KDE) - find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig TextWidgets WidgetsAddons XmlGui QUIET) + find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui QUIET REQUIRED) set_package_properties(KF5 PROPERTIES TYPE REQUIRED URL "http://www.kde.org" DESCRIPTION "KDE Frameworks" diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index 48d9bc6c..98ef2ba5 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -118,11 +118,6 @@ InputWidget::InputWidget(QWidget *parent) UiSettings s("InputWidget"); -#ifdef HAVE_KDE4 - s.notify("EnableSpellCheck", this, SLOT(setEnableSpellCheck(QVariant))); - setEnableSpellCheck(s.value("EnableSpellCheck", false)); -#endif - s.notify("EnableEmacsMode", this, SLOT(setEnableEmacsMode(QVariant))); setEnableEmacsMode(s.value("EnableEmacsMode", false)); @@ -189,12 +184,6 @@ void InputWidget::setCustomFont(const QVariant &v) } -void InputWidget::setEnableSpellCheck(const QVariant &v) -{ - ui.inputEdit->setSpellCheckEnabled(v.toBool()); -} - - void InputWidget::setEnableEmacsMode(const QVariant &v) { ui.inputEdit->setEmacsMode(v.toBool()); diff --git a/src/qtui/inputwidget.h b/src/qtui/inputwidget.h index b4aaf0f5..11512b27 100644 --- a/src/qtui/inputwidget.h +++ b/src/qtui/inputwidget.h @@ -102,7 +102,6 @@ protected slots: private slots: void setCustomFont(const QVariant &font); void setUseCustomFont(const QVariant &); - void setEnableSpellCheck(const QVariant &); void setEnableEmacsMode(const QVariant &); void setShowNickSelector(const QVariant &); void setShowStyleButtons(const QVariant &); diff --git a/src/qtui/settingspages/inputwidgetsettingspage.cpp b/src/qtui/settingspages/inputwidgetsettingspage.cpp index a8837b38..6ed56472 100644 --- a/src/qtui/settingspages/inputwidgetsettingspage.cpp +++ b/src/qtui/settingspages/inputwidgetsettingspage.cpp @@ -24,10 +24,5 @@ InputWidgetSettingsPage::InputWidgetSettingsPage(QWidget *parent) : SettingsPage(tr("Interface"), tr("Input Widget"), parent) { ui.setupUi(this); - -#ifndef HAVE_KDE4 - ui.enableSpellCheck->hide(); -#endif - initAutoWidgets(); } diff --git a/src/qtui/settingspages/inputwidgetsettingspage.ui b/src/qtui/settingspages/inputwidgetsettingspage.ui index 14f36669..a956567a 100644 --- a/src/qtui/settingspages/inputwidgetsettingspage.ui +++ b/src/qtui/settingspages/inputwidgetsettingspage.ui @@ -6,7 +6,7 @@ 0 0 - 507 + 512 514 @@ -44,19 +44,6 @@ - - - - Enable spell check - - - EnableSpellCheck - - - false - - - @@ -140,7 +127,7 @@ - Multi-Line Editing + &Multi-Line Editing true @@ -281,10 +268,10 @@ false - /TabCompletion/AddSpaceMidSentence + /TabCompletion/AddSpaceMidSentence - false + false @@ -331,7 +318,6 @@ customFont - enableSpellCheck showNickSelector groupBox maxNumLines diff --git a/src/uisupport/CMakeLists.txt b/src/uisupport/CMakeLists.txt index 1a9dcf3f..591b993c 100644 --- a/src/uisupport/CMakeLists.txt +++ b/src/uisupport/CMakeLists.txt @@ -62,7 +62,9 @@ endif() if (WITH_KF5) target_link_libraries(mod_uisupport KF5::CoreAddons KF5::TextWidgets KF5::XmlGui) -elseif (KF5Sonnet_FOUND) +endif() + +if (KF5Sonnet_FOUND) add_definitions(-DHAVE_SONNET) target_link_libraries(mod_uisupport KF5::SonnetUi) endif() diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 8a7f4bf6..133a2433 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -22,10 +22,6 @@ #include #include -#ifdef HAVE_SONNET -# include -#endif - #include "actioncollection.h" #include "bufferview.h" #include "graphicalui.h" @@ -54,8 +50,9 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) enableFindReplace(false); #endif -#ifdef HAVE_SONNET - new Sonnet::SpellCheckDecorator(this); +#if defined HAVE_SONNET && !defined HAVE_KDE + _spellCheckDecorator = new Sonnet::SpellCheckDecorator(this); + highlighter()->setActive(highlighter()->checkerEnabledByDefault()); #endif setMode(SingleLine); @@ -90,15 +87,39 @@ MultiLineEdit::~MultiLineEdit() { } -#if defined HAVE_KF5 || defined HAVE_KDE4 -void MultiLineEdit::createHighlighter() + +#if defined HAVE_SONNET && !defined HAVE_KDE +Sonnet::Highlighter *MultiLineEdit::highlighter() const +{ + return _spellCheckDecorator->highlighter(); +} + + +void MultiLineEdit::setSpellCheckEnabled(bool enabled) +{ + highlighter()->setActive(enabled); + if (enabled) { + highlighter()->slotRehighlight(); + } +} + +void MultiLineEdit::contextMenuEvent(QContextMenuEvent *event) { - KTextEdit::createHighlighter(); - if (highlighter()) - highlighter()->setAutomatic(false); + QMenu *menu = createStandardContextMenu(); + menu->addSeparator(); + + auto action = menu->addAction(tr("Auto Spell Check")); + action->setCheckable(true); + action->setChecked(highlighter()->isActive()); + connect(action, SIGNAL(toggled(bool)), this, SLOT(setSpellCheckEnabled(bool))); + + menu->exec(event->globalPos()); + delete menu; } + #endif + void MultiLineEdit::setCustomFont(const QFont &font) { setFont(font); @@ -229,16 +250,6 @@ void MultiLineEdit::setEmacsMode(bool enable) } -void MultiLineEdit::setSpellCheckEnabled(bool enable) -{ -#ifdef HAVE_KDE - setCheckSpellingEnabled(enable); -#else - Q_UNUSED(enable) -#endif -} - - void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *) { _pasteProtectionEnabled = enable; diff --git a/src/uisupport/multilineedit.h b/src/uisupport/multilineedit.h index 7cf41892..bd59bbc3 100644 --- a/src/uisupport/multilineedit.h +++ b/src/uisupport/multilineedit.h @@ -35,6 +35,12 @@ # define MultiLineEditParent QTextEdit #endif +#if defined HAVE_SONNET && !defined HAVE_KDE +# include +# include +# include +#endif + class MultiLineEdit : public MultiLineEditParent { Q_OBJECT @@ -74,9 +80,6 @@ public: inline bool emacsMode() const { return _emacsMode; } void addCompletionSpace(); -#if defined HAVE_KF5 || defined HAVE_KDE4 - void createHighlighter() override; -#endif public slots: void setMode(Mode mode); @@ -84,7 +87,6 @@ public slots: void setMaxHeight(int numLines); void setEmacsMode(bool enable = true); void setScrollBarsEnabled(bool enable = true); - void setSpellCheckEnabled(bool enable = true); void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0); void setLineWrapEnabled(bool enable = false); @@ -101,6 +103,10 @@ protected: void keyPressEvent(QKeyEvent *event) override; void resizeEvent(QResizeEvent *event) override; +#if defined HAVE_SONNET && !defined HAVE_KDE + void contextMenuEvent(QContextMenuEvent *event) override; +#endif + private slots: void on_returnPressed(); void on_returnPressed(QString text); @@ -115,6 +121,12 @@ private slots: QString convertMircCodesToHtml(const QString &text); bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor); +private: + void reset(); + void showHistoryEntry(); + void updateScrollBars(); + void updateSizeHint(); + private: QStringList _history; QHash _tempHistory; @@ -133,10 +145,16 @@ private: QMap _mircColorMap; - void reset(); - void showHistoryEntry(); - void updateScrollBars(); - void updateSizeHint(); +#if defined HAVE_SONNET && !defined HAVE_KDE + // This member function is provided by KTextEdit + Sonnet::Highlighter *highlighter() const; + +private slots: + void setSpellCheckEnabled(bool enabled); + +private: + Sonnet::SpellCheckDecorator *_spellCheckDecorator{nullptr}; +#endif };