Merge pull request #136 from sandsmark/sonnet
authorManuel Nickschas <sputnick@quassel-irc.org>
Sun, 28 Feb 2016 17:58:03 +0000 (18:58 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 28 Feb 2016 17:58:03 +0000 (18:58 +0100)
Add spell-checking support via the Sonnet framework

CMakeLists.txt
src/qtui/CMakeLists.txt
src/qtui/mainwin.cpp
src/qtui/settingspages/sonnetsettingspage.cpp [new file with mode: 0644]
src/qtui/settingspages/sonnetsettingspage.h [new file with mode: 0644]
src/uisupport/CMakeLists.txt
src/uisupport/multilineedit.cpp

index 046b66d..7268dac 100644 (file)
@@ -275,17 +275,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)
 
index 8510a71..eedb69c 100644 (file)
@@ -156,6 +156,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})
index 95d2e6f..e27c2fe 100644 (file)
 #  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)),
@@ -1367,6 +1372,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 (file)
index 0000000..73b739d
--- /dev/null
@@ -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 <QVBoxLayout>
+
+#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 (file)
index 0000000..c9ad34a
--- /dev/null
@@ -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 <Sonnet/ConfigWidget>
+
+#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;
+};
index 37ea311..a72a9c7 100644 (file)
@@ -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()
index 37f1f62..68de357 100644 (file)
  ***************************************************************************/
 
 #include <QApplication>
-#include <QMenu>
 #include <QMessageBox>
 #include <QScrollBar>
 
+#ifdef HAVE_SONNET
+#  include <Sonnet/SpellCheckDecorator>
+#endif
+
 #include "actioncollection.h"
 #include "bufferview.h"
 #include "graphicalui.h"
@@ -51,6 +54,10 @@ MultiLineEdit::MultiLineEdit(QWidget *parent)
     enableFindReplace(false);
 #endif
 
+#ifdef HAVE_SONNET
+    new Sonnet::SpellCheckDecorator(this);
+#endif
+
     setMode(SingleLine);
     setLineWrapEnabled(false);
     reset();