projects
/
quassel.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #168 from esainane/irssi-msg-escape
[quassel.git]
/
src
/
uisupport
/
multilineedit.cpp
diff --git
a/src/uisupport/multilineedit.cpp
b/src/uisupport/multilineedit.cpp
index
05f630d
..
68de357
100644
(file)
--- a/
src/uisupport/multilineedit.cpp
+++ b/
src/uisupport/multilineedit.cpp
@@
-1,5
+1,5
@@
/***************************************************************************
/***************************************************************************
- * Copyright (C) 2005-201
2
by the Quassel Project *
+ * Copyright (C) 2005-201
5
by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
@@
-19,10
+19,13
@@
***************************************************************************/
#include <QApplication>
***************************************************************************/
#include <QApplication>
-#include <QMenu>
#include <QMessageBox>
#include <QScrollBar>
#include <QMessageBox>
#include <QScrollBar>
+#ifdef HAVE_SONNET
+# include <Sonnet/SpellCheckDecorator>
+#endif
+
#include "actioncollection.h"
#include "bufferview.h"
#include "graphicalui.h"
#include "actioncollection.h"
#include "bufferview.h"
#include "graphicalui.h"
@@
-41,21
+44,27
@@
MultiLineEdit::MultiLineEdit(QWidget *parent)
_scrollBarsEnabled(true),
_pasteProtectionEnabled(true),
_emacsMode(false),
_scrollBarsEnabled(true),
_pasteProtectionEnabled(true),
_emacsMode(false),
+ _completionSpace(0),
_lastDocumentHeight(-1)
{
_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_KDE
enableFindReplace(false);
#endif
setAcceptRichText(false);
#ifdef HAVE_KDE
enableFindReplace(false);
#endif
+#ifdef HAVE_SONNET
+ new Sonnet::SpellCheckDecorator(this);
+#endif
+
setMode(SingleLine);
setMode(SingleLine);
- set
Word
WrapEnabled(false);
+ set
Line
WrapEnabled(false);
reset();
reset();
+ // Prevent QTextHtmlImporter::appendNodeText from eating whitespace
+ document()->setDefaultStyleSheet("span { white-space: pre-wrap; }");
+
connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
_mircColorMap["00"] = "#ffffff";
connect(this, SIGNAL(textChanged()), this, SLOT(on_textChanged()));
_mircColorMap["00"] = "#ffffff";
@@
-98,6
+107,13
@@
void MultiLineEdit::setMode(Mode mode)
}
}
+void MultiLineEdit::setLineWrapEnabled(bool enable)
+{
+ setLineWrapMode(enable ? WidgetWidth : NoWrap);
+ updateSizeHint();
+}
+
+
void MultiLineEdit::setMinHeight(int lines)
{
if (lines == _minHeight)
void MultiLineEdit::setMinHeight(int lines)
{
if (lines == _minHeight)
@@
-207,13
+223,6
@@
void MultiLineEdit::setSpellCheckEnabled(bool enable)
}
}
-void MultiLineEdit::setWordWrapEnabled(bool enable)
-{
- setLineWrapMode(enable ? WidgetWidth : NoWrap);
- updateSizeHint();
-}
-
-
void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *)
{
_pasteProtectionEnabled = enable;
void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *)
{
_pasteProtectionEnabled = enable;
@@
-296,18
+305,7
@@
bool MultiLineEdit::event(QEvent *e)
void MultiLineEdit::keyPressEvent(QKeyEvent *event)
{
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) {
if (event == QKeySequence::InsertLineSeparator) {
-#else
-
-# ifdef Q_WS_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();
if (_mode == SingleLine) {
event->accept();
on_returnPressed();
@@
-564,22
+562,18
@@
QString MultiLineEdit::convertRichtextToMircCodes()
cursor.clearSelection();
}
cursor.clearSelection();
}
- if (color) {
- color = false;
+
+ if (color)
mircText.append('\x03');
mircText.append('\x03');
- }
- if (underline) {
- underline = false;
+
+ if (underline)
mircText.append('\x1f');
mircText.append('\x1f');
- }
- if (italic) {
- italic = false;
+
+ if (italic)
mircText.append('\x1d');
mircText.append('\x1d');
- }
- if (bold) {
- bold = false;
+
+ if (bold)
mircText.append('\x02');
mircText.append('\x02');
- }
return mircText;
}
return mircText;
}
@@
-684,8
+678,12
@@
void MultiLineEdit::on_returnPressed()
}
}
-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())
if (!text.isEmpty()) {
foreach(const QString &line, text.split('\n', QString::SkipEmptyParts)) {
if (line.isEmpty())
@@
-704,6
+702,8
@@
void MultiLineEdit::on_returnPressed(const QString &text)
void MultiLineEdit::on_textChanged()
{
void MultiLineEdit::on_textChanged()
{
+ _completionSpace = qMax(_completionSpace - 1, 0);
+
QString newText = text();
newText.replace("\r\n", "\n");
newText.replace('\r', '\n');
QString newText = text();
newText.replace("\r\n", "\n");
newText.replace('\r', '\n');
@@
-718,7
+718,11
@@
void MultiLineEdit::on_textChanged()
QString msg = tr("Do you really want to paste %n line(s)?", "", lines.count());
msg += "<p>";
for (int i = 0; i < 4; i++) {
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));
msg += Qt::escape(lines[i].left(40));
+#else
+ msg += lines[i].left(40).toHtmlEscaped();
+#endif
if (lines[i].count() > 40)
msg += "...";
msg += "<br />";
if (lines[i].count() > 40)
msg += "...";
msg += "<br />";
@@
-726,7
+730,7
@@
void MultiLineEdit::on_textChanged()
msg += "...</p>";
QMessageBox question(QMessageBox::NoIcon, tr("Paste Protection"), msg, QMessageBox::Yes|QMessageBox::No);
question.setDefaultButton(QMessageBox::No);
msg += "...</p>";
QMessageBox question(QMessageBox::NoIcon, tr("Paste Protection"), msg, QMessageBox::Yes|QMessageBox::No);
question.setDefaultButton(QMessageBox::No);
-#ifdef Q_
W
S_MAC
+#ifdef Q_
O
S_MAC
question.setWindowFlags(question.windowFlags() | Qt::Sheet);
#endif
if (question.exec() != QMessageBox::Yes)
question.setWindowFlags(question.windowFlags() | Qt::Sheet);
#endif
if (question.exec() != QMessageBox::Yes)
@@
-782,3
+786,12
@@
void MultiLineEdit::showHistoryEntry()
setTextCursor(cursor);
updateScrollBars();
}
setTextCursor(cursor);
updateScrollBars();
}
+
+
+void MultiLineEdit::addCompletionSpace()
+{
+ // Inserting the space emits textChanged, which should not disable removal
+ _completionSpace = 2;
+ insertPlainText(" ");
+}
+