The items now fill out the available space and automatically re-adjust to size changes.
#include "chatitem.h"
ChatItem::ChatItem(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) {
#include "chatitem.h"
ChatItem::ChatItem(const QPersistentModelIndex &index_, QGraphicsItem *parent) : QGraphicsItem(parent), _index(index_) {
- //if(_wrapMode == WordWrap) {
- // setFlags(QGraphicsItem::ItemClipsToShape, true);
- //}
-
}
ChatItem::~ChatItem() {
}
ChatItem::~ChatItem() {
}
QRectF ChatItem::boundingRect() const {
}
QRectF ChatItem::boundingRect() const {
- return QRectF(0, 0, 500,20);
+ return QRectF(0, 0, _width, _height);
}
void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(option); Q_UNUSED(widget);
}
void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
Q_UNUSED(option); Q_UNUSED(widget);
- painter->drawRect(boundingRect());
painter->drawText(boundingRect(), data(MessageModel::DisplayRole).toString());
painter->drawText(boundingRect(), data(MessageModel::DisplayRole).toString());
+ painter->setPen(Qt::DotLine);
+ painter->drawRect(boundingRect());
-/*
-void ChatItem::setWidth(int w) {
+
+int ChatItem::setWidth(int w) {
+ _height = 20; // FIXME
+ return _height;
void ChatItem::setTextOption(const QTextOption &option) {
_textOption = option;
layout();
void ChatItem::setTextOption(const QTextOption &option) {
_textOption = option;
layout();
//QTextOption textOption() const;
//void setTextOption(const QTextOption &option);
//QTextOption textOption() const;
//void setTextOption(const QTextOption &option);
- //void setWidth(int width);
+ // returns height
+ int setWidth(int width);
//virtual void layout();
protected:
//void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
private:
//virtual void layout();
protected:
//void mouseMoveEvent ( QGraphicsSceneMouseEvent * event );
private:
+ int _width;
+ int _height;
//QTextLayout _layout;
//QTextOption _textOption;
QPersistentModelIndex _index;
//QTextLayout _layout;
//QTextOption _textOption;
QPersistentModelIndex _index;
_senderItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::SenderColumn)), this);
_contentsItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::ContentsColumn)), this);
_senderItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::SenderColumn)), this);
_contentsItem = new ChatItem(QPersistentModelIndex(index.sibling(index.row(), ChatLineModel::ContentsColumn)), this);
- _senderItem->setPos(80, 0);
- _contentsItem->setPos(160, 0);
+ _timestampItem->setPos(0,0);
}
ChatLine::~ChatLine() {
}
ChatLine::~ChatLine() {
+ delete _timestampItem;
+ delete _senderItem;
+ delete _contentsItem;
+// FIXME make more efficient by caching width/height
QRectF ChatLine::boundingRect () const {
return childrenBoundingRect();
}
QRectF ChatLine::boundingRect () const {
return childrenBoundingRect();
}
+int ChatLine::setColumnWidths(int ts, int sender, int contents) {
+ _timestampItem->setWidth(ts);
+ _senderItem->setWidth(sender);
+ int h = _contentsItem->setWidth(contents);
+
+ _senderItem->setPos(ts, 0);
+ _contentsItem->setPos(ts + sender, 0);
+
+ return h;
+}
+
void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
}
void ChatLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) {
}
virtual void paint (QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
//void layout();
virtual void paint (QPainter * painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
//void layout();
- //void setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth);
+ // returns height
+ int setColumnWidths(int tsColWidth, int senderColWidth, int textColWidth);
//void myMousePressEvent ( QGraphicsSceneMouseEvent * event ) { qDebug() << "press"; mousePressEvent(event); }
//void myMousePressEvent ( QGraphicsSceneMouseEvent * event ) { qDebug() << "press"; mousePressEvent(event); }
connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
for(int i = 0; i < model->rowCount(); i++) {
ChatLine *line = new ChatLine(model->index(i, 0));
connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(rowsInserted(const QModelIndex &, int, int)));
for(int i = 0; i < model->rowCount(); i++) {
ChatLine *line = new ChatLine(model->index(i, 0));
- line->setPos(30, i*line->boundingRect().height());
}
ChatScene::~ChatScene() {
}
ChatScene::~ChatScene() {
+void ChatScene::setWidth(int w) {
+ _width = w;
+ int h = 0;
+ foreach(ChatLine *line, _lines) {
+ line->setPos(0, h);
+ h += line->setColumnWidths(60, 80, w - 60 - 80);
+ }
+ setSceneRect(QRectF(0, 0, w, h));
+}
void ChatScene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) {
/*
void ChatScene::mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent ) {
/*
inline MessageModel *model() const { return _model; }
public slots:
inline MessageModel *model() const { return _model; }
public slots:
protected slots:
void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent );
private:
protected slots:
void mousePressEvent ( QGraphicsSceneMouseEvent * mouseEvent );
private:
- //Buffer *_buffer;
- //QList<ChatLine*> _lines;
- QList<ChatItem *> _items;
+ QList<ChatLine *> _lines;
#include "quasselui.h"
ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
#include "quasselui.h"
ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() {
+ setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
_scene = new ChatScene(Client::messageModel(), this);
_scene = new ChatScene(Client::messageModel(), this);
+ _scene->setWidth(width());
- //QGraphicsTextItem *item = scene()->addText(buf->bufferInfo().bufferName());
+void ChatView::resizeEvent(QResizeEvent *event) {
+ scene()->setWidth(event->size().width());
+
+}
void setContents(const QList<AbstractUiMsg *> &);
void setContents(const QList<AbstractUiMsg *> &);
+ protected:
+ virtual void resizeEvent(QResizeEvent *event);
+
private:
ChatScene *_scene;
};
private:
ChatScene *_scene;
};