Properly re-layout on resizing
[quassel.git] / src / qtui / chatitem.h
index 5f13a9a..d32b3cc 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-07 by the Quassel IRC Team                         *
+ *   Copyright (C) 2005-08 by the Quassel Project                          *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
 
-#ifndef _CHATITEM_H_
-#define _CHATITEM_H_
+#ifndef CHATITEM_H_
+#define CHATITEM_H_
 
 #include <QGraphicsItem>
-#include <QTextLayout>
-#include <QTextOption>
 
+#include "chatline.h"
+#include "chatlinemodel.h"
 #include "uistyle.h"
 
-class QGraphicsSceneMouseEvent;
+class QTextLayout;
 
 class ChatItem : public QGraphicsItem {
 
   public:
-    ChatItem(QGraphicsItem *parent = 0);
+    ChatItem(const QPersistentModelIndex &index, QGraphicsItem *parent);
     virtual ~ChatItem();
 
-    virtual QRectF boundingRect() const;
+    inline QPersistentModelIndex index() const { return _index; }
+    inline const MessageModel *model() const { return _index.isValid() ? qobject_cast<const MessageModel *>(_index.model()) : 0; }
+    inline int row() const { return _index.isValid() ? _index.row() : 0; }
+
+    inline virtual QRectF boundingRect() const { return _boundingRect; }
+    inline qreal width() const { return _boundingRect.width(); }
+    inline qreal height() const { return _boundingRect.height(); }
+
+    inline bool haveLayout() const { return _layout != 0; }
+    void clearLayout();
+    void updateLayout();
     virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
 
-    QString text() const;
-    void setText(const UiStyle::StyledText &text);
+    virtual QVariant data(int role) const;
+    //QString text() const;
+    //void setText(const UiStyle::StyledText &text);
 
-    QTextOption textOption() const;
-    void setTextOption(const QTextOption &option);
+    //QTextOption textOption() const;
+    //void setTextOption(const QTextOption &option);
 
-    void setWidth(int width);
-    virtual void layout();
+    // returns height
+    int setWidth(int width);
+    //virtual void layout();
 
   protected:
     //void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
 
   private:
-    int _width;
-    QTextLayout _layout;
-    QTextOption _textOption;
+    int heightForWidth(int width);
+    void layout();
+
+    int _lineHeight;
+    qreal _lineLeading;
+    QRectF _boundingRect;
+    //QTextLayout _layout;
+    //QTextOption _textOption;
+    QPersistentModelIndex _index;
+
+    QTextLayout *_layout;
 };
 
 #endif