We hate uninitialized values
[quassel.git] / src / uisupport / multilineedit.cpp
index 02e9df2..14eecf2 100644 (file)
@@ -37,12 +37,13 @@ MultiLineEdit::MultiLineEdit(QWidget *parent)
 #else
     QTextEdit(parent),
 #endif
-    idx(0),
+    _idx(0),
     _mode(SingleLine),
     _singleLine(true),
     _minHeight(1),
     _maxHeight(5),
     _scrollBarsEnabled(true),
+    _pasteProtectionEnabled(true),
     _lastDocumentHeight(-1)
 {
 #if QT_VERSION >= 0x040500
@@ -191,8 +192,8 @@ void MultiLineEdit::setPasteProtectionEnabled(bool enable, QWidget *) {
 void MultiLineEdit::historyMoveBack() {
   addToHistory(convertRichtextToMircCodes(), true);
 
-  if(idx > 0) {
-    idx--;
+  if(_idx > 0) {
+    _idx--;
     showHistoryEntry();
   }
 }
@@ -200,9 +201,9 @@ void MultiLineEdit::historyMoveBack() {
 void MultiLineEdit::historyMoveForward() {
   addToHistory(convertRichtextToMircCodes(), true);
 
-  if(idx < history.count()) {
-    idx++;
-    if(idx < history.count() || tempHistory.contains(idx)) // tempHistory might have an entry for idx == history.count() + 1
+  if(_idx < _history.count()) {
+    _idx++;
+    if(_idx < _history.count() || _tempHistory.contains(_idx)) // tempHistory might have an entry for idx == history.count() + 1
       showHistoryEntry();
     else
       reset();              // equals clear() in this case
@@ -216,20 +217,20 @@ bool MultiLineEdit::addToHistory(const QString &text, bool temporary) {
   if(text.isEmpty())
     return false;
 
-  Q_ASSERT(0 <= idx && idx <= history.count());
+  Q_ASSERT(0 <= _idx && _idx <= _history.count());
 
   if(temporary) {
     // if an entry of the history is changed, we remember it and show it again at this
     // position until a line was actually sent
     // sent lines get appended to the history
-    if(history.isEmpty() || text != history[idx - (int)(idx == history.count())]) {
-      tempHistory[idx] = text;
+    if(_history.isEmpty() || text != _history[_idx - (int)(_idx == _history.count())]) {
+      _tempHistory[_idx] = text;
       return true;
     }
   } else {
-    if(history.isEmpty() || text != history.last()) {
-      history << text;
-      tempHistory.clear();
+    if(_history.isEmpty() || text != _history.last()) {
+      _history << text;
+      _tempHistory.clear();
       return true;
     }
   }
@@ -328,7 +329,8 @@ QString MultiLineEdit::convertRichtextToMircCodes() {
 
   while (cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor)) {
 
-    if (cursor.selectedText() == QString(QChar(QChar::LineSeparator))) {
+    if (cursor.selectedText() == QString(QChar(QChar::LineSeparator))
+      || cursor.selectedText() == QString(QChar(QChar::ParagraphSeparator))) {
       if (color) {
         color = false;
         mircText.append('\x03');
@@ -524,7 +526,7 @@ void MultiLineEdit::on_returnPressed(const QString & text) {
       emit textEntered(line);
     }
     reset();
-    tempHistory.clear();
+    _tempHistory.clear();
   } else {
     emit noTextEntered();
   }
@@ -584,7 +586,7 @@ void MultiLineEdit::on_documentHeightChanged(qreal) {
 
 void MultiLineEdit::reset() {
   // every time the MultiLineEdit is cleared we also reset history index
-  idx = history.count();
+  _idx = _history.count();
   clear();
   QTextBlockFormat format = textCursor().blockFormat();
   format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents
@@ -594,7 +596,7 @@ void MultiLineEdit::reset() {
 
 void MultiLineEdit::showHistoryEntry() {
   // if the user changed the history, display the changed line
-  setHtml(convertMircCodesToHtml(tempHistory.contains(idx) ? tempHistory[idx] : history[idx]));
+  setHtml(convertMircCodesToHtml(_tempHistory.contains(_idx) ? _tempHistory[_idx] : _history[_idx]));
   QTextCursor cursor = textCursor();
   QTextBlockFormat format = cursor.blockFormat();
   format.setLeftMargin(leftMargin); // we want a little space between the frame and the contents