/***************************************************************************
- * Copyright (C) 2005-2015 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 *
***************************************************************************/
#include <QApplication>
-#include <QMenu>
#include <QMessageBox>
#include <QScrollBar>
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),
- _lastDocumentHeight(-1)
+ : MultiLineEditParent(parent)
{
document()->setDocumentMargin(0);
enableFindReplace(false);
#endif
+#if defined HAVE_SONNET && !defined HAVE_KDE
+ _spellCheckDecorator = new Sonnet::SpellCheckDecorator(this);
+ highlighter()->setActive(highlighter()->checkerEnabledByDefault());
+#endif
+
setMode(SingleLine);
setLineWrapEnabled(false);
reset();
- connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
+ // Prevent QTextHtmlImporter::appendNodeText from eating whitespace
+ document()->setDefaultStyleSheet("span { white-space: pre-wrap; }");
+
+ connect(this, &QTextEdit::textChanged, this, &MultiLineEdit::on_textChanged);
_mircColorMap["00"] = "#ffffff";
_mircColorMap["01"] = "#000000";
}
-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();
+ }
+}
+
+void MultiLineEdit::contextMenuEvent(QContextMenuEvent *event)
{
+ 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)
{
// use the style to determine a decent size
int h = qMin(qMax((int)document()->size().height() + scrollBarHeight, minPixelHeight), maxPixelHeight) + 2 * frameWidth();
- QStyleOptionFrameV2 opt;
+
+ QStyleOptionFrame opt;
opt.initFrom(this);
opt.rect = QRect(0, 0, 100, h);
opt.lineWidth = lineWidth();
opt.midLineWidth = midLineWidth();
opt.state |= QStyle::State_Sunken;
- QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), this);
+ QWidget *widget = this;
+#ifdef Q_OS_MAC
+ widget = 0;
+#endif
+ QSize s = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(100, h).expandedTo(QApplication::globalStrut()), widget);
if (s != _sizeHint) {
_sizeHint = s;
updateGeometry();
QSize MultiLineEdit::sizeHint() const
{
if (!_sizeHint.isValid()) {
- MultiLineEdit *that = const_cast<MultiLineEdit *>(this);
+ auto *that = const_cast<MultiLineEdit *>(this);
that->updateSizeHint();
}
return _sizeHint;
}
-void MultiLineEdit::setSpellCheckEnabled(bool enable)
-{
-#ifdef HAVE_KDE
- setCheckSpellingEnabled(enable);
-#else
- Q_UNUSED(enable)
-#endif
-}
-
-
void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *)
{
_pasteProtectionEnabled = enable;
{
// We need to make sure that global shortcuts aren't eaten
if (e->type() == QEvent::ShortcutOverride) {
- QKeyEvent *event = static_cast<QKeyEvent *>(e);
+ auto *event = static_cast<QKeyEvent *>(e);
QKeySequence key = QKeySequence(event->key() | event->modifiers());
foreach(QAction *action, GraphicalUi::actionCollection()->actions()) {
if (action->shortcuts().contains(key)) {
}
-void MultiLineEdit::on_returnPressed(const QString &text)
+void MultiLineEdit::on_returnPressed(QString text)
{
+ if (_completionSpace && text.endsWith(" ")) {
+ text.chop(1);
+ }
+
if (!text.isEmpty()) {
foreach(const QString &line, text.split('\n', QString::SkipEmptyParts)) {
if (line.isEmpty())
void MultiLineEdit::on_textChanged()
{
+ _completionSpace = qMax(_completionSpace - 1, 0);
+
QString newText = text();
newText.replace("\r\n", "\n");
newText.replace('\r', '\n');
QString msg = tr("Do you really want to paste %n line(s)?", "", lines.count());
msg += "<p>";
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 += "<br />";
setTextCursor(cursor);
updateScrollBars();
}
+
+
+void MultiLineEdit::addCompletionSpace()
+{
+ // Inserting the space emits textChanged, which should not disable removal
+ _completionSpace = 2;
+ insertPlainText(" ");
+}
+