From 74e64f292417228c99d0c775defba999281e2afd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Kundr=C3=A1t?= Date: Mon, 6 Nov 2017 22:03:34 +0100 Subject: [PATCH] Add optional support for spell checking This is based on some old code that I wrote in May 2014 (!) and which was subsequently fixed and cleaned up by Martin. I should have picked these pieces much, much sooner... Relevant git commits: 00ab5e33, c051a4d9 Co-Authored-By: Martin T. H. Sandsmark Change-Id: I94ecdbcea15268418e332496fd2febb752d39bf6 --- CMakeLists.txt | 11 +++++++++++ src/Gui/ComposerTextEdit.cpp | 10 ++++++++++ src/configure.cmake.in | 1 + 3 files changed, 22 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc306415..3ec6e409 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ trojita_option(BUILD_TESTING "Build tests" ON) trojita_option(WITH_MIMETIC "Build with client-side MIME parsing" AUTO) trojita_option(WITH_GPGMEPP "Use GpgME's native C++ bindings" AUTO) trojita_option(WITH_KF5_GPGMEPP "Use legacy discontinued GpgME++ library from KDE frameworks" AUTO) +trojita_option(WITH_SPELLCHECKER_SONNET "Build with spellchecker through KDE's Sonnet" AUTO "WITH_DESKTOP") if(WIN32) trojita_option(WITH_NSIS "Build Windows NSIS installer" AUTO "WITH_DESKTOP") @@ -226,6 +227,13 @@ else() message(STATUS "Disabling COMPRESS=DEFLATE, zlib is not available") endif() +trojita_find_package(KF5Sonnet "" "https://projects.kde.org/projects/frameworks/sonnet" "Qt5 Spell Checking Library from KDE" "Spell checking support" WITH_SPELLCHECKER_SONNET) +if(WITH_SPELLCHECKER_SONNET) + set(TROJITA_HAVE_SONNET True) +else() + set(TROJITA_HAVE_SONNET False) +endif() + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/configure.cmake.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/configure-plugins.cmake.in @@ -731,6 +739,9 @@ if(WITH_DESKTOP) # The ${path_DesktopGui} is needed so that the generated ui_*.h file can find the headers of the custom widgets set_property(TARGET DesktopGui APPEND PROPERTY INCLUDE_DIRECTORIES ${path_DesktopGui}) target_link_libraries(DesktopGui Common UiUtils Composer Cryptography Imap IPC MSA Plugins Streams qwwsmtpclient Qt5::WebKitWidgets) + if(WITH_SPELLCHECKER_SONNET) + target_link_libraries(DesktopGui KF5::SonnetUi) + endif() # On Windows build a real Win32 GUI application without console window # On other platforms WIN32 flag is ignored diff --git a/src/Gui/ComposerTextEdit.cpp b/src/Gui/ComposerTextEdit.cpp index ada0524d..2d417575 100644 --- a/src/Gui/ComposerTextEdit.cpp +++ b/src/Gui/ComposerTextEdit.cpp @@ -31,6 +31,11 @@ #include #include #include +#include "configure.cmake.h" +#ifdef TROJITA_HAVE_SONNET +#include +#include +#endif #include "Gui/Util.h" #include "UiUtils/Color.h" @@ -54,6 +59,11 @@ ComposerTextEdit::ComposerTextEdit(QWidget *parent) : QTextEdit(parent) m_pasteQuoted = new QAction(tr("Paste as Quoted Text"), this); connect(m_pasteQuoted, &QAction::triggered, this, &ComposerTextEdit::slotPasteAsQuotation); + +#ifdef TROJITA_HAVE_SONNET + Sonnet::SpellCheckDecorator *decorator = new Sonnet::SpellCheckDecorator(this); + decorator->highlighter()->setAutomatic(false); +#endif } void ComposerTextEdit::notify(const QString &n, uint timeout) diff --git a/src/configure.cmake.in b/src/configure.cmake.in index 702126d5..b7167ab7 100644 --- a/src/configure.cmake.in +++ b/src/configure.cmake.in @@ -4,3 +4,4 @@ #cmakedefine TROJITA_HAVE_MIMETIC #cmakedefine TROJITA_HAVE_GPGMEPP #cmakedefine TROJITA_HAVE_CRYPTO_MESSAGES +#cmakedefine TROJITA_HAVE_SONNET -- 2.11.4.GIT