if (ECM_FOUND)
list(APPEND CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
if (WITH_KDE)
- find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig TextWidgets WidgetsAddons XmlGui QUIET)
+ find_package(KF5 COMPONENTS ConfigWidgets CoreAddons Notifications NotifyConfig Sonnet TextWidgets WidgetsAddons XmlGui QUIET REQUIRED)
set_package_properties(KF5 PROPERTIES TYPE REQUIRED
URL "http://www.kde.org"
DESCRIPTION "KDE Frameworks"
UiSettings s("InputWidget");
-#ifdef HAVE_KDE4
- s.notify("EnableSpellCheck", this, SLOT(setEnableSpellCheck(QVariant)));
- setEnableSpellCheck(s.value("EnableSpellCheck", false));
-#endif
-
s.notify("EnableEmacsMode", this, SLOT(setEnableEmacsMode(QVariant)));
setEnableEmacsMode(s.value("EnableEmacsMode", false));
}
-void InputWidget::setEnableSpellCheck(const QVariant &v)
-{
- ui.inputEdit->setSpellCheckEnabled(v.toBool());
-}
-
-
void InputWidget::setEnableEmacsMode(const QVariant &v)
{
ui.inputEdit->setEmacsMode(v.toBool());
private slots:
void setCustomFont(const QVariant &font);
void setUseCustomFont(const QVariant &);
- void setEnableSpellCheck(const QVariant &);
void setEnableEmacsMode(const QVariant &);
void setShowNickSelector(const QVariant &);
void setShowStyleButtons(const QVariant &);
: SettingsPage(tr("Interface"), tr("Input Widget"), parent)
{
ui.setupUi(this);
-
-#ifndef HAVE_KDE4
- ui.enableSpellCheck->hide();
-#endif
-
initAutoWidgets();
}
<rect>
<x>0</x>
<y>0</y>
- <width>507</width>
+ <width>512</width>
<height>514</height>
</rect>
</property>
</item>
</layout>
</item>
- <item>
- <widget class="QCheckBox" name="enableSpellCheck">
- <property name="text">
- <string>Enable spell check</string>
- </property>
- <property name="settingsKey" stdset="0">
- <string notr="true">EnableSpellCheck</string>
- </property>
- <property name="defaultValue" stdset="0">
- <bool>false</bool>
- </property>
- </widget>
- </item>
<item>
<widget class="QCheckBox" name="enablePerBufferHistory">
<property name="text">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
- <string>Multi-Line Editing</string>
+ <string>&Multi-Line Editing</string>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="settingsKey" stdset="0">
- <string notr="true">/TabCompletion/AddSpaceMidSentence</string>
+ <string notr="true">/TabCompletion/AddSpaceMidSentence</string>
</property>
<property name="defaultValue" stdset="0">
- <bool>false</bool>
+ <bool>false</bool>
</property>
</widget>
</item>
</customwidgets>
<tabstops>
<tabstop>customFont</tabstop>
- <tabstop>enableSpellCheck</tabstop>
<tabstop>showNickSelector</tabstop>
<tabstop>groupBox</tabstop>
<tabstop>maxNumLines</tabstop>
if (WITH_KF5)
target_link_libraries(mod_uisupport KF5::CoreAddons KF5::TextWidgets KF5::XmlGui)
-elseif (KF5Sonnet_FOUND)
+endif()
+
+if (KF5Sonnet_FOUND)
add_definitions(-DHAVE_SONNET)
target_link_libraries(mod_uisupport KF5::SonnetUi)
endif()
#include <QMessageBox>
#include <QScrollBar>
-#ifdef HAVE_SONNET
-# include <Sonnet/SpellCheckDecorator>
-#endif
-
#include "actioncollection.h"
#include "bufferview.h"
#include "graphicalui.h"
enableFindReplace(false);
#endif
-#ifdef HAVE_SONNET
- new Sonnet::SpellCheckDecorator(this);
+#if defined HAVE_SONNET && !defined HAVE_KDE
+ _spellCheckDecorator = new Sonnet::SpellCheckDecorator(this);
+ highlighter()->setActive(highlighter()->checkerEnabledByDefault());
#endif
setMode(SingleLine);
{
}
-#if defined HAVE_KF5 || defined HAVE_KDE4
-void MultiLineEdit::createHighlighter()
+
+#if defined HAVE_SONNET && !defined HAVE_KDE
+Sonnet::Highlighter *MultiLineEdit::highlighter() const
+{
+ return _spellCheckDecorator->highlighter();
+}
+
+
+void MultiLineEdit::setSpellCheckEnabled(bool enabled)
+{
+ highlighter()->setActive(enabled);
+ if (enabled) {
+ highlighter()->slotRehighlight();
+ }
+}
+
+void MultiLineEdit::contextMenuEvent(QContextMenuEvent *event)
{
- KTextEdit::createHighlighter();
- if (highlighter())
- highlighter()->setAutomatic(false);
+ QMenu *menu = createStandardContextMenu();
+ menu->addSeparator();
+
+ auto action = menu->addAction(tr("Auto Spell Check"));
+ action->setCheckable(true);
+ action->setChecked(highlighter()->isActive());
+ connect(action, SIGNAL(toggled(bool)), this, SLOT(setSpellCheckEnabled(bool)));
+
+ menu->exec(event->globalPos());
+ delete menu;
}
+
#endif
+
void MultiLineEdit::setCustomFont(const QFont &font)
{
setFont(font);
}
-void MultiLineEdit::setSpellCheckEnabled(bool enable)
-{
-#ifdef HAVE_KDE
- setCheckSpellingEnabled(enable);
-#else
- Q_UNUSED(enable)
-#endif
-}
-
-
void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *)
{
_pasteProtectionEnabled = enable;
# define MultiLineEditParent QTextEdit
#endif
+#if defined HAVE_SONNET && !defined HAVE_KDE
+# include <QContextMenuEvent>
+# include <Sonnet/Highlighter>
+# include <Sonnet/SpellCheckDecorator>
+#endif
+
class MultiLineEdit : public MultiLineEditParent
{
Q_OBJECT
inline bool emacsMode() const { return _emacsMode; }
void addCompletionSpace();
-#if defined HAVE_KF5 || defined HAVE_KDE4
- void createHighlighter() override;
-#endif
public slots:
void setMode(Mode mode);
void setMaxHeight(int numLines);
void setEmacsMode(bool enable = true);
void setScrollBarsEnabled(bool enable = true);
- void setSpellCheckEnabled(bool enable = true);
void setPasteProtectionEnabled(bool enable = true, QWidget *msgBoxParent = 0);
void setLineWrapEnabled(bool enable = false);
void keyPressEvent(QKeyEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
+#if defined HAVE_SONNET && !defined HAVE_KDE
+ void contextMenuEvent(QContextMenuEvent *event) override;
+#endif
+
private slots:
void on_returnPressed();
void on_returnPressed(QString text);
QString convertMircCodesToHtml(const QString &text);
bool mircCodesChanged(QTextCursor &cursor, QTextCursor &peekcursor);
+private:
+ void reset();
+ void showHistoryEntry();
+ void updateScrollBars();
+ void updateSizeHint();
+
private:
QStringList _history;
QHash<int, QString> _tempHistory;
QMap<QString, QString> _mircColorMap;
- void reset();
- void showHistoryEntry();
- void updateScrollBars();
- void updateSizeHint();
+#if defined HAVE_SONNET && !defined HAVE_KDE
+ // This member function is provided by KTextEdit
+ Sonnet::Highlighter *highlighter() const;
+
+private slots:
+ void setSpellCheckEnabled(bool enabled);
+
+private:
+ Sonnet::SpellCheckDecorator *_spellCheckDecorator{nullptr};
+#endif
};