X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatitem.h;h=73e180670d1fcf231dfa7be393d2297c7dd30d47;hp=4ffb94426344eccde0abb772613dbc1216255b2a;hb=275c435910183d8a0755fd360a8a4e2a045cbca2;hpb=70706ff642683d03ff091cab25d984ec7d9612de diff --git a/src/qtui/chatitem.h b/src/qtui/chatitem.h index 4ffb9442..73e18067 100644 --- a/src/qtui/chatitem.h +++ b/src/qtui/chatitem.h @@ -1,11 +1,11 @@ /*************************************************************************** - * 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 * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -18,42 +18,76 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef _CHATITEM_H_ -#define _CHATITEM_H_ +#ifndef CHATITEM_H_ +#define CHATITEM_H_ #include -#include -#include +#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; - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + inline QPersistentModelIndex index() const { return _index; } + inline const MessageModel *model() const { return _index.isValid() ? qobject_cast(_index.model()) : 0; } + inline int row() const { return _index.isValid() ? _index.row() : 0; } + + inline QFontMetricsF *fontMetrics() const { return _fontMetrics; } + inline virtual QRectF boundingRect() const { return _boundingRect; } + inline qreal width() const { return _boundingRect.width(); } + inline qreal height() const { return _boundingRect.height(); } - QString text() const; - void setText(const UiStyle::StyledText &text); + inline bool haveLayout() const { return _layout != 0; } + void clearLayout(); + void updateLayout(); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - QTextOption textOption() const; - void setTextOption(const QTextOption &option); + virtual QVariant data(int role) const; - void setWidth(int width); - virtual void layout(); + // returns height + int setWidth(int width); protected: //void mouseMoveEvent ( QGraphicsSceneMouseEvent * event ); private: - int _width; - QTextLayout _layout; - QTextOption _textOption; + int heightForWidth(int width); + QTextLayout *createLayout(QTextOption::WrapMode, Qt::Alignment = Qt::AlignLeft); + + QRectF _boundingRect; + QFontMetricsF *_fontMetrics; + quint8 _lines; + QPersistentModelIndex _index; + + QTextLayout *_layout; + QList _wrapPositions; + + class WrapColumnFinder; +}; + +class ChatItem::WrapColumnFinder { + public: + WrapColumnFinder(ChatItem *parent); + ~WrapColumnFinder(); + + int nextWrapColumn(); + + private: + ChatItem *item; + QTextLayout *layout; + QTextLine line; + ChatLineModel::WrapList wrapList; + int wordidx; + int lastwrapcol; + qreal lastwrappos; + qreal w; }; #endif