From 56e1d275c2f8a59eaf9d19ba76aca5f1d3163683 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 26 Oct 2014 19:07:19 +0100 Subject: [PATCH] Add spell-checking support via the Sonnet framework Sonnet is a Tier 1 KDE Framework providing support for spell-checking. We now include this framework as an optional dependency for the Qt5 version of Quassel. Since Tier 1 frameworks have no dependencies other than Qt itself, it should be easy to integrate on all platforms. This commit adds spell-checking support for both the input and the topic widget, and a settings page for configuring the spell-checking engine, if Quassel is built against Qt5 and the Sonnet framework was found. Note in the current version, the feature is broken, pending investigation! --- CMakeLists.txt | 27 +++++--- src/qtui/CMakeLists.txt | 6 ++ src/qtui/mainwin.cpp | 8 +++ src/qtui/settingspages/sonnetsettingspage.cpp | 67 +++++++++++++++++++ src/qtui/settingspages/sonnetsettingspage.h | 47 +++++++++++++ src/uisupport/CMakeLists.txt | 3 + src/uisupport/multilineedit.cpp | 9 ++- 7 files changed, 155 insertions(+), 12 deletions(-) create mode 100644 src/qtui/settingspages/sonnetsettingspage.cpp create mode 100644 src/qtui/settingspages/sonnetsettingspage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d8739738..b1d08e83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -262,17 +262,22 @@ if (USE_QT5) if (ECM_FOUND) list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) - endif() - - if (WITH_KDE) - find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig TextWidgets WidgetsAddons XmlGui QUIET) - set_package_properties(KF5 PROPERTIES TYPE REQUIRED - URL "http://www.kde.org" - DESCRIPTION "KDE Frameworks" - PURPOSE "Required for integration into the Plasma desktop" - ) - - endif() + if (WITH_KDE) + find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig TextWidgets WidgetsAddons XmlGui QUIET) + set_package_properties(KF5 PROPERTIES TYPE REQUIRED + URL "http://www.kde.org" + DESCRIPTION "KDE Frameworks" + PURPOSE "Required for integration into the Plasma desktop" + ) + else(WITH_KDE) + find_package(KF5Sonnet QUIET) + set_package_properties(KF5Sonnet PROPERTIES TYPE RECOMMENDED + URL "http://api.kde.org/frameworks-api/frameworks5-apidocs/sonnet/html" + DESCRIPTION "framework for providing spell-checking capabilities" + PURPOSE "Enables spell-checking support in input widgets" + ) + endif(WITH_KDE) + endif(ECM_FOUND) endif(BUILD_GUI) diff --git a/src/qtui/CMakeLists.txt b/src/qtui/CMakeLists.txt index be9a14b5..c9947671 100644 --- a/src/qtui/CMakeLists.txt +++ b/src/qtui/CMakeLists.txt @@ -157,6 +157,12 @@ if (WITH_NOTIFICATION_CENTER) list(APPEND LIBS "/System/Library/Frameworks/Foundation.framework") endif() +if (KF5Sonnet_FOUND) + add_definitions(-DHAVE_SONNET) + list(APPEND SOURCES settingspages/sonnetsettingspage.cpp) + list(APPEND LIBS KF5::SonnetUi) +endif() + foreach(FORM ${FORMS}) set(FORMPATH ${FORMPATH} ui/${FORM}) endforeach(FORM ${FORMS}) diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 8f022cac..cacef8b9 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -151,6 +151,11 @@ # include "settingspages/shortcutssettingspage.h" #endif +#ifdef HAVE_SONNET +# include "settingspages/sonnetsettingspage.h" +#endif + + MainWin::MainWin(QWidget *parent) #ifdef HAVE_KDE : KMainWindow(parent), _kHelpMenu(new KHelpMenu(this)), @@ -1362,6 +1367,9 @@ void MainWin::showSettingsDlg() dlg->registerSettingsPage(new BufferViewSettingsPage(dlg)); dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg)); dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg)); +#ifdef HAVE_SONNET + dlg->registerSettingsPage(new SonnetSettingsPage(dlg)); +#endif dlg->registerSettingsPage(new HighlightSettingsPage(dlg)); dlg->registerSettingsPage(new NotificationsSettingsPage(dlg)); dlg->registerSettingsPage(new BacklogSettingsPage(dlg)); diff --git a/src/qtui/settingspages/sonnetsettingspage.cpp b/src/qtui/settingspages/sonnetsettingspage.cpp new file mode 100644 index 00000000..73b739d6 --- /dev/null +++ b/src/qtui/settingspages/sonnetsettingspage.cpp @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2005-2014 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "sonnetsettingspage.h" + +#include + +#include "qtui.h" + +SonnetSettingsPage::SonnetSettingsPage(QWidget *parent) + : SettingsPage(tr("Interface"), tr("Spell Checking"), parent) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + _configWidget = new Sonnet::ConfigWidget(this); + layout->addWidget(_configWidget); + connect(_configWidget, SIGNAL(configChanged()), SLOT(widgetHasChanged())); +} + + +bool SonnetSettingsPage::hasDefaults() const +{ + return true; +} + + +void SonnetSettingsPage::defaults() +{ + _configWidget->slotDefault(); + widgetHasChanged(); +} + + +void SonnetSettingsPage::load() +{ + +} + + +void SonnetSettingsPage::save() +{ + _configWidget->save(); + setChangedState(false); +} + + +void SonnetSettingsPage::widgetHasChanged() +{ + if (!hasChanged()) + setChangedState(true); +} diff --git a/src/qtui/settingspages/sonnetsettingspage.h b/src/qtui/settingspages/sonnetsettingspage.h new file mode 100644 index 00000000..c9ad34a7 --- /dev/null +++ b/src/qtui/settingspages/sonnetsettingspage.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2005-2014 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#pragma once + +#include + +#include "settingspage.h" + +//! A settings page for configuring the Sonnet spell-checking engine +class SonnetSettingsPage : public SettingsPage +{ + Q_OBJECT + +public: + SonnetSettingsPage(QWidget *parent = 0); + + bool hasDefaults() const; + +public slots: + void save(); + void load(); + void defaults(); + +private slots: + void widgetHasChanged(); + +private: + Sonnet::ConfigWidget *_configWidget; +}; diff --git a/src/uisupport/CMakeLists.txt b/src/uisupport/CMakeLists.txt index 37ea3114..a72a9c73 100644 --- a/src/uisupport/CMakeLists.txt +++ b/src/uisupport/CMakeLists.txt @@ -60,4 +60,7 @@ endif() if (WITH_KF5) target_link_libraries(mod_uisupport KF5::CoreAddons KF5::TextWidgets KF5::XmlGui) +elseif (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 ed0dbb60..89564840 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -19,10 +19,13 @@ ***************************************************************************/ #include -#include #include #include +#ifdef HAVE_SONNET +# include +#endif + #include "actioncollection.h" #include "bufferview.h" #include "graphicalui.h" @@ -50,6 +53,10 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) enableFindReplace(false); #endif +#ifdef HAVE_SONNET + new Sonnet::SpellCheckDecorator(this); +#endif + setMode(SingleLine); setLineWrapEnabled(false); reset(); -- 2.20.1