Updated POT template, added LINGUAS file
[quassel.git] / src / qtui / chatitem.cpp
index e3ab1ab..6add446 100644 (file)
@@ -31,6 +31,7 @@
 #include "buffermodel.h"
 #include "bufferview.h"
 #include "chatitem.h"
+#include "chatline.h"
 #include "chatlinemodel.h"
 #include "contextmenuactionprovider.h"
 #include "iconloader.h"
@@ -49,6 +50,14 @@ ChatItem::ChatItem(const qreal &width, const qreal &height, const QPointF &pos,
   setPos(pos);
 }
 
+const QAbstractItemModel *ChatItem::model() const {
+  return static_cast<ChatLine *>(parentItem())->model();
+}
+
+int ChatItem::row() const {
+  return static_cast<ChatLine *>(parentItem())->row();
+}
+
 QVariant ChatItem::data(int role) const {
   QModelIndex index = model()->index(row(), column());
   if(!index.isValid()) {
@@ -426,7 +435,8 @@ qreal ContentsChatItem::setGeometryByWidth(qreal w) {
   WrapColumnFinder finder(this);
   while(finder.nextWrapColumn(w) > 0)
     lines++;
-  qreal h = lines * fontMetrics()->lineSpacing();
+  qreal spacing = qMax(fontMetrics()->lineSpacing(), fontMetrics()->height());  // cope with negative leading()
+  qreal h = lines * spacing;
   delete _data;
   _data = 0;
 
@@ -443,6 +453,7 @@ void ContentsChatItem::doLayout(QTextLayout *layout) const {
   if(!wrapList.count()) return; // empty chatitem
 
   qreal h = 0;
+  qreal spacing = qMax(fontMetrics()->lineSpacing(), fontMetrics()->height());  // cope with negative leading()
   WrapColumnFinder finder(this);
   layout->beginLayout();
   forever {
@@ -460,7 +471,7 @@ void ContentsChatItem::doLayout(QTextLayout *layout) const {
     // Sometimes, setNumColumns will create a line that's too long (cf. Qt bug 238249)
     // We verify this and try setting the width again, making it shorter each time until the lengths match.
     // Dead fugly, but seems to work…
-    for(int i = line.textLength()-1; line.textLength() > num; i--) {
+    for(int i = line.textLength()-1; i >= 0 && line.textLength() > num; i--) {
       line.setNumColumns(i);
     }
     if(num != line.textLength()) {
@@ -469,7 +480,7 @@ void ContentsChatItem::doLayout(QTextLayout *layout) const {
     }
 
     line.setPosition(QPointF(0, h));
-    h += fontMetrics()->lineSpacing();
+    h += spacing;
   }
   layout->endLayout();
 }