/***************************************************************************
- * Copyright (C) 2005-2015 by the Quassel Project *
+ * Copyright (C) 2005-2016 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>
+#ifdef HAVE_SONNET
+# include <Sonnet/SpellCheckDecorator>
+#endif
+
#include "actioncollection.h"
#include "bufferview.h"
#include "graphicalui.h"
_scrollBarsEnabled(true),
_pasteProtectionEnabled(true),
_emacsMode(false),
+ _completionSpace(0),
_lastDocumentHeight(-1)
{
document()->setDocumentMargin(0);
enableFindReplace(false);
#endif
+#ifdef HAVE_SONNET
+ new Sonnet::SpellCheckDecorator(this);
+#endif
+
setMode(SingleLine);
setLineWrapEnabled(false);
reset();
{
}
+#if defined HAVE_KF5 || defined HAVE_KDE4
+void MultiLineEdit::createHighlighter()
+{
+ KTextEdit::createHighlighter();
+ if (highlighter())
+ highlighter()->setAutomatic(false);
+}
+#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();
+#if QT_VERSION < 0x050000
QStyleOptionFrameV2 opt;
+#else
+ QStyleOptionFrame opt;
+#endif
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();
}
-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');
setTextCursor(cursor);
updateScrollBars();
}
+
+
+void MultiLineEdit::addCompletionSpace()
+{
+ // Inserting the space emits textChanged, which should not disable removal
+ _completionSpace = 2;
+ insertPlainText(" ");
+}
+