Use KTextEdit when building against KF5
authorManuel Nickschas <sputnick@quassel-irc.org>
Sat, 3 Jan 2015 00:21:01 +0000 (01:21 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sat, 3 Jan 2015 00:21:01 +0000 (01:21 +0100)
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
src/qtui/inputwidget.cpp
src/uisupport/CMakeLists.txt
src/uisupport/multilineedit.cpp
src/uisupport/multilineedit.h

index e30facf..f6e9f74 100644 (file)
@@ -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()
 
index 1ac3db0..7d3b3e0 100644 (file)
@@ -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);
index 52f386f..c0d6e4b 100644 (file)
@@ -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()
index e29ef20..48ffdba 100644 (file)
@@ -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);
index 2abb055..7591a51 100644 (file)
@@ -27,6 +27,9 @@
 #ifdef HAVE_KDE4
 #  include <KDE/KTextEdit>
 #  define MultiLineEditParent KTextEdit
+#elif defined HAVE_KF5
+#  include <KTextWidgets/KTextEdit>
+#  define MultiLineEditParent KTextEdit
 #else
 #  include <QTextEdit>
 #  define MultiLineEditParent QTextEdit