X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fuisupport%2Fmultilineedit.cpp;h=19c222fecb9cec78a562d67992087f61c56244ba;hb=2c8434f74c68194d56f2084f637419123e61d18b;hp=31335d1fa651800e0a1d92281a91b7a42e0fb209;hpb=8eab2bd6ca5c9b8de11ed1db6d0900d9c9360a5d;p=quassel.git diff --git a/src/uisupport/multilineedit.cpp b/src/uisupport/multilineedit.cpp index 31335d1f..19c222fe 100644 --- a/src/uisupport/multilineedit.cpp +++ b/src/uisupport/multilineedit.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -22,10 +22,6 @@ #include #include -#ifdef HAVE_SONNET -# include -#endif - #include "actioncollection.h" #include "bufferview.h" #include "graphicalui.h" @@ -35,17 +31,7 @@ const int leftMargin = 3; MultiLineEdit::MultiLineEdit(QWidget *parent) - : MultiLineEditParent(parent), - _idx(0), - _mode(SingleLine), - _singleLine(true), - _minHeight(1), - _maxHeight(5), - _scrollBarsEnabled(true), - _pasteProtectionEnabled(true), - _emacsMode(false), - _completionSpace(0), - _lastDocumentHeight(-1) + : MultiLineEditParent(parent) { document()->setDocumentMargin(0); @@ -54,8 +40,9 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) 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); @@ -65,7 +52,7 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) // Prevent QTextHtmlImporter::appendNodeText from eating whitespace document()->setDefaultStyleSheet("span { white-space: pre-wrap; }"); - connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged())); + connect(this, &QTextEdit::textChanged, this, &MultiLineEdit::on_textChanged); _mircColorMap["00"] = "#ffffff"; _mircColorMap["01"] = "#000000"; @@ -86,19 +73,38 @@ MultiLineEdit::MultiLineEdit(QWidget *parent) } -MultiLineEdit::~MultiLineEdit() +#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(); + } } -#if defined HAVE_KF5 || defined HAVE_KDE4 -void MultiLineEdit::createHighlighter() +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, &QAction::toggled, this, &MultiLineEdit::setSpellCheckEnabled); + + menu->exec(event->globalPos()); + delete menu; } + #endif + void MultiLineEdit::setCustomFont(const QFont &font) { setFont(font); @@ -185,11 +191,8 @@ void MultiLineEdit::updateSizeHint() // use the style to determine a decent size int h = qMin(qMax((int)document()->size().height() + scrollBarHeight, minPixelHeight), maxPixelHeight) + 2 * frameWidth(); -#if QT_VERSION < 0x050000 - QStyleOptionFrameV2 opt; -#else + QStyleOptionFrame opt; -#endif opt.initFrom(this); opt.rect = QRect(0, 0, 100, h); opt.lineWidth = lineWidth(); @@ -210,7 +213,7 @@ void MultiLineEdit::updateSizeHint() QSize MultiLineEdit::sizeHint() const { if (!_sizeHint.isValid()) { - MultiLineEdit *that = const_cast(this); + auto *that = const_cast(this); that->updateSizeHint(); } return _sizeHint; @@ -229,16 +232,6 @@ void MultiLineEdit::setEmacsMode(bool enable) } -void MultiLineEdit::setSpellCheckEnabled(bool enable) -{ -#ifdef HAVE_KDE - setCheckSpellingEnabled(enable); -#else - Q_UNUSED(enable) -#endif -} - - void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *) { _pasteProtectionEnabled = enable; @@ -305,7 +298,7 @@ bool MultiLineEdit::event(QEvent *e) { // We need to make sure that global shortcuts aren't eaten if (e->type() == QEvent::ShortcutOverride) { - QKeyEvent *event = static_cast(e); + auto *event = static_cast(e); QKeySequence key = QKeySequence(event->key() | event->modifiers()); foreach(QAction *action, GraphicalUi::actionCollection()->actions()) { if (action->shortcuts().contains(key)) { @@ -734,11 +727,7 @@ void MultiLineEdit::on_textChanged() QString msg = tr("Do you really want to paste %n line(s)?", "", lines.count()); msg += "

"; for (int i = 0; i < 4; i++) { -#if QT_VERSION < 0x050000 - msg += Qt::escape(lines[i].left(40)); -#else msg += lines[i].left(40).toHtmlEscaped(); -#endif if (lines[i].count() > 40) msg += "..."; msg += "
";