From 399cac566c86141228358a7e7e14b2375fdc3259 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 3 Jan 2015 01:21:01 +0100 Subject: [PATCH] Use KTextEdit when building against KF5 When building against Qt5 and WITH_KDE enabled, the input widget now is a KTextEdit again, making use of features like spell check. Note that we'll add support for a stand-alone Sonnet framework to have spell checking without KDE integration later on. --- CMakeLists.txt | 6 ++++++ src/qtui/inputwidget.cpp | 4 ++-- src/uisupport/CMakeLists.txt | 3 +++ src/uisupport/multilineedit.cpp | 21 ++++----------------- src/uisupport/multilineedit.h | 3 +++ 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e30facfd..f6e9f748 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,12 @@ if (USE_QT5) endif() if (WITH_KDE) + find_package(KF5TextWidgets QUIET) + set_package_properties(KF5TextWidgets PROPERTIES TYPE REQUIRED + URL "http://inqlude.org/libraries/ktextwidgets.html" + DESCRIPTION "framework providing an assortment of widgets for displaying and editing text" + PURPOSE "Allows to use extra features provided by KDE Frameworks in input widgets" + ) endif() diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index 1ac3db05..7d3b3e0a 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -101,7 +101,7 @@ InputWidget::InputWidget(QWidget *parent) UiSettings s("InputWidget"); -#ifdef HAVE_KDE4 +#ifdef HAVE_KDE s.notify("EnableSpellCheck", this, SLOT(setEnableSpellCheck(QVariant))); setEnableSpellCheck(s.value("EnableSpellCheck", false)); #endif @@ -505,7 +505,7 @@ void InputWidget::onTextEntered(const QString &text) fmt.clearBackground(); inputLine()->setCurrentCharFormat(fmt); -#ifdef HAVE_KDE4 +#ifdef HAVE_KDE // Set highlighter back to active in case it was deactivated by too many errors. if (ui.inputEdit->highlighter()) ui.inputEdit->highlighter()->setActive(true); diff --git a/src/uisupport/CMakeLists.txt b/src/uisupport/CMakeLists.txt index 52f386f6..c0d6e4bd 100644 --- a/src/uisupport/CMakeLists.txt +++ b/src/uisupport/CMakeLists.txt @@ -57,3 +57,6 @@ if (WITH_KDE4) target_link_libraries(mod_uisupport ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBRARY}) endif() +if (WITH_KF5) + target_link_libraries(mod_uisupport KF5::TextWidgets) +endif() diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index e29ef205..48ffdbac 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -43,12 +43,10 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) _emacsMode(false), _lastDocumentHeight(-1) { -#if QT_VERSION >= 0x040500 - document()->setDocumentMargin(0); // new in Qt 4.5 and we really don't want it here -#endif + document()->setDocumentMargin(0); setAcceptRichText(false); -#ifdef HAVE_KDE4 +#ifdef HAVE_KDE enableFindReplace(false); #endif @@ -206,7 +204,7 @@ void MultiLineEdit::setEmacsMode(bool enable) void MultiLineEdit::setSpellCheckEnabled(bool enable) { -#ifdef HAVE_KDE4 +#ifdef HAVE_KDE setCheckSpellingEnabled(enable); #else Q_UNUSED(enable) @@ -296,18 +294,7 @@ bool MultiLineEdit::event(QEvent *e) void MultiLineEdit::keyPressEvent(QKeyEvent *event) { - // Workaround the fact that Qt < 4.5 doesn't know InsertLineSeparator yet -#if QT_VERSION >= 0x040500 if (event == QKeySequence::InsertLineSeparator) { -#else - -# ifdef Q_OS_MAC - if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && event->modifiers() & Qt::META) { -# else - if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) && event->modifiers() & Qt::SHIFT) { -# endif -#endif - if (_mode == SingleLine) { event->accept(); on_returnPressed(); @@ -470,7 +457,7 @@ void MultiLineEdit::keyPressEvent(QKeyEvent *event) } } -#ifdef HAVE_KDE4 +#ifdef HAVE_KDE KTextEdit::keyPressEvent(event); #else QTextEdit::keyPressEvent(event); diff --git a/src/uisupport/multilineedit.h b/src/uisupport/multilineedit.h index 2abb0554..7591a510 100644 --- a/src/uisupport/multilineedit.h +++ b/src/uisupport/multilineedit.h @@ -27,6 +27,9 @@ #ifdef HAVE_KDE4 # include # define MultiLineEditParent KTextEdit +#elif defined HAVE_KF5 +# include +# define MultiLineEditParent KTextEdit #else # include # define MultiLineEditParent QTextEdit -- 2.20.1