*headdesk* Apparently QTextLayout::FormatRange() does not have an initializing ctor...
authorManuel Nickschas <sputnick@quassel-irc.org>
Thu, 3 Apr 2008 16:18:00 +0000 (16:18 +0000)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 3 Apr 2008 16:18:00 +0000 (16:18 +0000)
uninitialized stuff can lead to _very_ strange results, including being magically resolved
by touching a variable elsewhere in the program.
This should now _finally_ and once-and-for-all fix font formatting issues (if it doesn't, let me know,
then it's caused by something else).
/me goes and sits in a corner now.

src/client/client.cpp
src/qtui/chatline-old.cpp
src/qtui/chatline-old.h
src/qtui/mainwin.cpp
src/uisupport/uistyle.cpp
version.inc

index 865855e..69ffbfc 100644 (file)
@@ -429,6 +429,8 @@ void Client::recvMessage(const Message &message) {
 
   checkForHighlight(msg);
 
+  // FIXME clean up code! (dup)
+
   if(msg.flags() & Message::Redirected) {
     BufferSettings bufferSettings;
     bool inStatus = bufferSettings.value("UserMessagesInStatusBuffer", QVariant(true)).toBool();
@@ -438,22 +440,21 @@ void Client::recvMessage(const Message &message) {
     if(inStatus) {
       b = statusBuffer(msg.bufferInfo().networkId());
       if(b) {
-       b->appendMsg(msg);
+        b->appendMsg(msg);
       } else if(!inQuery && !inCurrent) {      // make sure the message get's shown somewhere
-       b = buffer(msg.bufferInfo());
-       b->appendMsg(msg);
+        b = buffer(msg.bufferInfo());
+        b->appendMsg(msg);
       }
     }
 
     if(inQuery) {
       b = buffer(msg.bufferInfo().bufferId());
       if(b) {
-       b->appendMsg(msg);
-      } else if(!inStatus && !inCurrent) {     // make sure the message get's shown somewhere
-       b = statusBuffer(msg.bufferInfo().networkId());
-       if(!b)
-         b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways... 
-       b->appendMsg(msg);
+        b->appendMsg(msg);
+      } else if(!inStatus && !inCurrent) { // make sure the message get's shown somewhere
+        b = statusBuffer(msg.bufferInfo().networkId());
+      if(!b) b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways...
+      b->appendMsg(msg);
       }
     }
 
@@ -461,12 +462,11 @@ void Client::recvMessage(const Message &message) {
       BufferId currentId = bufferModel()->currentIndex().data(NetworkModel::BufferIdRole).value<BufferId>();
       b = buffer(currentId);
       if(b && currentId != msg.bufferInfo().bufferId() && !inQuery) {
-       b->appendMsg(msg);
+        b->appendMsg(msg);
       } else if(!inStatus && !inQuery) {       // make sure the message get's shown somewhere
-       b = statusBuffer(msg.bufferInfo().networkId());
-       if(!b)
-         b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways... 
-       b->appendMsg(msg);
+        b = statusBuffer(msg.bufferInfo().networkId());
+        if(!b) b = buffer(msg.bufferInfo()); // seems like we have to create the buffer anyways...
+        b->appendMsg(msg);
       }
     }
   } else {
index 2c9cb0d..0a3cc20 100644 (file)
@@ -29,8 +29,7 @@
  */
 ChatLineOld::ChatLineOld(Message m) {
   hght = 0;
-  //networkName = m.buffer.network();
-  //bufferName = m.buffer.buffer();
+
   msg = m;
   selectionMode = None;
   isHighlight = false;
@@ -50,9 +49,17 @@ void ChatLineOld::formatMsg(Message msg) {
   precomputeLine();
 }
 
+QList<ChatLineOld::FormatRange> ChatLineOld::calcFormatRanges(const UiStyle::StyledText &fs) {
+  QTextLayout::FormatRange additional;
+  additional.start = additional.length = 0;
+  return calcFormatRanges(fs, additional);
+}
+
 // 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 ChatLineOld, so I won't bother making this actually nice.
-QList<ChatLineOld::FormatRange> ChatLineOld::calcFormatRanges(UiStyle::StyledText fs, QTextLayout::FormatRange additional) {
+QList<ChatLineOld::FormatRange> ChatLineOld::calcFormatRanges(const UiStyle::StyledText &_fs,
+     const QTextLayout::FormatRange &additional) {
+  UiStyle::StyledText fs = _fs;
   QList<FormatRange> ranges;
 
   if(additional.length > 0) {
@@ -76,6 +83,7 @@ QList<ChatLineOld::FormatRange> ChatLineOld::calcFormatRanges(UiStyle::StyledTex
       }
     }
   }
+
   foreach(QTextLayout::FormatRange f, fs.formats) {
     if(f.length <= 0) continue;
     FormatRange range;
index ac95494..8d286b0 100644 (file)
@@ -104,7 +104,8 @@ class ChatLineOld : public QObject, public AbstractUiMsg {
     int selectionStart, selectionEnd;
     void formatMsg(Message);
     void precomputeLine();
-    QList<FormatRange> calcFormatRanges(UiStyle::StyledText, QTextLayout::FormatRange additional = QTextLayout::FormatRange());
+    QList<FormatRange> calcFormatRanges(const UiStyle::StyledText &);
+    QList<FormatRange> calcFormatRanges(const UiStyle::StyledText &, const QTextLayout::FormatRange &additional);
 };
 
 #endif
index 959cd9b..9b49da1 100644 (file)
@@ -57,6 +57,7 @@
 
 #include "debugconsole.h"
 #include "global.h"
+#include "qtuistyle.h"
 
 MainWin::MainWin(QtUi *_gui, QWidget *parent)
   : QMainWindow(parent),
@@ -441,11 +442,12 @@ void MainWin::receiveMessage(const Message &msg) {
         sender = sender.left(i);
       title += QString(" - %1").arg(sender);
     }
-    QString text = QtUi::style()->styleString(Message::mircToInternal(msg.text())).text;
 
     UiSettings uiSettings;
 
     if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) {
+      // FIXME don't invoke style engine for this!
+      QString text = QtUi::style()->styleString(Message::mircToInternal(msg.text())).text;
       displayTrayIconMessage(title, text);
     }
 
index 79f23c6..5f0f717 100644 (file)
@@ -26,6 +26,7 @@ UiStyle::UiStyle(const QString &settingsKey) : _settingsKey(settingsKey) {
   QTextCharFormat def;
   def.setForeground(QBrush("#000000"));
   //def.setFont(QFont("Courier", 10));
+  def.font().setFixedPitch(true);
   def.font().setStyleHint(QFont::TypeWriter);
   _defaultFormats = QVector<QTextCharFormat>(NumFormatTypes, def);
   _customFormats = QVector<QTextCharFormat>(NumFormatTypes, QTextFormat().toCharFormat());
@@ -130,9 +131,7 @@ QString UiStyle::formatCode(FormatType ftype) const {
 }
 
 UiStyle::StyledText UiStyle::styleString(const QString &_s) {
-  QString s = _s;  // we can't use call-by-value since this seems to maybe screw up Qt's implicit sharing somehow
-                   // at least invalid formats are created if we do that
-  if(s.startsWith(" ")) {};  // and yet some other stupid no-op that seems to fix the font issue on some machines... -_- 
+  QString s = _s;
   StyledText result;
   QList<FormatType> fmtList;
   fmtList.append(None);
@@ -240,5 +239,3 @@ QTextCharFormat UiStyle::mergedFormat(QList<FormatType> formatList) {
   }
   return fmt;
 }
-
-
index 78c964a..b005cf8 100644 (file)
@@ -5,7 +5,7 @@
 
   quasselVersion = "0.2.0-alpha5-pre";
   quasselDate = "2008-04-03";
-  quasselBuild = 695;
+  quasselBuild = 696;
 
   //! Minimum client build number the core needs
   clientBuildNeeded = 642;