Made old ChatLine's code even more ugly by adding some more write-only code to it.
authorManuel Nickschas <sputnick@quassel-irc.org>
Mon, 11 Feb 2008 02:20:52 +0000 (02:20 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 11 Feb 2008 02:20:52 +0000 (02:20 +0000)
Small price to pay for having visible selections back, eh?

src/qtui/chatline-old.cpp
src/qtui/chatline-old.h
src/qtui/coreconnectdlg.cpp
version.inc

index b3b1683..86c4e28 100644 (file)
@@ -52,12 +52,32 @@ void ChatLine::formatMsg(Message msg) {
 
 // This function is almost obsolete, since with the new style engine, we already get a list of formats...
 // We don't know yet if we keep this implementation of ChatLine, so I won't bother making this actually nice.
 
 // This function is almost obsolete, since with the new style engine, we already get a list of formats...
 // We don't know yet if we keep this implementation of ChatLine, so I won't bother making this actually nice.
-// Also, the additional format is ignored for now, which means that you won't see a selection...
-// FIXME TODO
-QList<ChatLine::FormatRange> ChatLine::calcFormatRanges(const UiStyle::StyledText &fs, QTextLayout::FormatRange additional) {
+QList<ChatLine::FormatRange> ChatLine::calcFormatRanges(UiStyle::StyledText fs, QTextLayout::FormatRange additional) {
   QList<FormatRange> ranges;
 
   QList<FormatRange> ranges;
 
+  if(additional.length > 0) {
+    for(int i = 0; i < fs.formats.count(); i++) {
+      int oldend = fs.formats[i].start + fs.formats[i].length - 1;
+      int addend = additional.start + additional.length - 1;
+      if(oldend < additional.start) continue;
+      fs.formats[i].length = additional.start - fs.formats[i].start;
+      QTextLayout::FormatRange addfmtrng = fs.formats[i];
+      addfmtrng.format.merge(additional.format);
+      addfmtrng.start = additional.start;
+      addfmtrng.length = qMin(oldend, addend) - additional.start + 1;
+      fs.formats.insert(++i, addfmtrng);
+      if(addend == oldend) break;
+      if(addend < oldend) {
+        QTextLayout::FormatRange restfmtrng = fs.formats[i-1];
+        restfmtrng.start = addend + 1;
+        restfmtrng.length = oldend - addend;
+        fs.formats.insert(++i, restfmtrng);
+        break;
+      }
+    }
+  }
   foreach(QTextLayout::FormatRange f, fs.formats) {
   foreach(QTextLayout::FormatRange f, fs.formats) {
+    if(f.length <= 0) continue;
     FormatRange range;
     range.start = f.start;
     range.length = f.length;
     FormatRange range;
     range.start = f.start;
     range.length = f.length;
@@ -66,36 +86,6 @@ QList<ChatLine::FormatRange> ChatLine::calcFormatRanges(const UiStyle::StyledTex
     range.height = metrics.lineSpacing();
     ranges.append(range);
   }
     range.height = metrics.lineSpacing();
     ranges.append(range);
   }
-  /*
-  QList<QTextLayout::FormatRange> formats = fs.formats;
-  formats.append(additional);
-  int cur = -1;
-  FormatRange range, lastrange;
-  for(int i = 0; i < fs.text.length(); i++) {
-    QTextCharFormat format;
-    foreach(QTextLayout::FormatRange f, formats) {
-      if(i >= f.start && i < f.start + f.length) format.merge(f.format);
-    }
-    if(cur < 0) {
-      range.start = 0; range.length = 1; range.format= format;
-      cur = 0;
-    } else {
-      if(format == range.format) range.length++;
-      else {
-        QFontMetrics metrics(range.format.font());
-        range.height = metrics.lineSpacing();
-        ranges.append(range);
-        range.start = i; range.length = 1; range.format = format;
-        cur++;
-      }
-    }
-  }
-  if(cur >= 0) {
-    QFontMetrics metrics(range.format.font());
-    range.height = metrics.lineSpacing();
-    ranges.append(range);
-  }
-  */
   return ranges;
 }
 
   return ranges;
 }
 
@@ -116,9 +106,7 @@ void ChatLine::setSelection(SelectionMode mode, int start, int end) {
       textSel.format.setBackground(pal.brush(QPalette::Highlight));
       textSel.start = selectionStart;
       textSel.length = selectionEnd - selectionStart;
       textSel.format.setBackground(pal.brush(QPalette::Highlight));
       textSel.start = selectionStart;
       textSel.length = selectionEnd - selectionStart;
-      //textFormat.append(textSel);
       textFormat = calcFormatRanges(styledText, textSel);
       textFormat = calcFormatRanges(styledText, textSel);
-      foreach(FormatRange fr, textFormat);
       break;
     case Full:
       tsSel.format.setForeground(pal.brush(QPalette::HighlightedText));
       break;
     case Full:
       tsSel.format.setForeground(pal.brush(QPalette::HighlightedText));
index c243c95..b29aca2 100644 (file)
@@ -104,7 +104,7 @@ class ChatLine : public QObject, public AbstractUiMsg {
     int selectionStart, selectionEnd;
     void formatMsg(Message);
     void precomputeLine();
     int selectionStart, selectionEnd;
     void formatMsg(Message);
     void precomputeLine();
-    QList<FormatRange> calcFormatRanges(const UiStyle::StyledText &, QTextLayout::FormatRange additional = QTextLayout::FormatRange());
+    QList<FormatRange> calcFormatRanges(UiStyle::StyledText, QTextLayout::FormatRange additional = QTextLayout::FormatRange());
 };
 
 #endif
 };
 
 #endif
index 5d71aad..3f144a9 100644 (file)
@@ -109,8 +109,6 @@ void CoreConnectDlg::setAccountWidgetStates() {
     ui.autoConnect->setChecked(selectedItems[0]->data(Qt::UserRole).value<AccountId>() == autoConnectAccount);
   }
   ui.accountButtonBox->button(QDialogButtonBox::Ok)->setEnabled(ui.accountList->count());
     ui.autoConnect->setChecked(selectedItems[0]->data(Qt::UserRole).value<AccountId>() == autoConnectAccount);
   }
   ui.accountButtonBox->button(QDialogButtonBox::Ok)->setEnabled(ui.accountList->count());
-  //ui.accountButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
-  //ui.accountButtonBox->button(QDialogButtonBox::Ok)->setFocus();
 }
 
 void CoreConnectDlg::on_autoConnect_clicked(bool state) {
 }
 
 void CoreConnectDlg::on_autoConnect_clicked(bool state) {
@@ -229,7 +227,6 @@ void CoreConnectDlg::initPhaseError(const QString &error) {
   ui.connectLabel->setText(tr("<div style=color:red;>Connection to %1 failed!</div>").arg(accountData["Host"].toString()));
   ui.coreInfoLabel->setText(error);
   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Retry|QDialogButtonBox::Cancel);
   ui.connectLabel->setText(tr("<div style=color:red;>Connection to %1 failed!</div>").arg(accountData["Host"].toString()));
   ui.coreInfoLabel->setText(error);
   ui.loginButtonBox->setStandardButtons(QDialogButtonBox::Retry|QDialogButtonBox::Cancel);
-  //ui.loginButtonBox->button(QDialogButtonBox::Retry)->setDefault(true);
   ui.loginButtonBox->button(QDialogButtonBox::Retry)->setFocus();
   disconnect(ui.loginButtonBox, 0, this, 0);
   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(restartPhaseNull()));
   ui.loginButtonBox->button(QDialogButtonBox::Retry)->setFocus();
   disconnect(ui.loginButtonBox, 0, this, 0);
   connect(ui.loginButtonBox, SIGNAL(accepted()), this, SLOT(restartPhaseNull()));
index 5b49062..5e2776f 100644 (file)
@@ -4,8 +4,8 @@
 { using namespace Global;
 
   quasselVersion = "0.2.0-pre";
 { using namespace Global;
 
   quasselVersion = "0.2.0-pre";
-  quasselDate = "2008-02-10";
-  quasselBuild = 498;
+  quasselDate = "2008-02-11";
+  quasselBuild = 505;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 480;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 480;