X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatview.cpp;h=98346ca4638da2905dcc908887722f4f474457e9;hb=f8557ba65eb38ac4988bfbbb2c4ef579d4534cf0;hp=db93f0748cf7bc5d277f757187f4206ca569df6f;hpb=22f141be889377b07472bb967d92186dad23be3e;p=quassel.git diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index db93f074..98346ca4 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -19,21 +19,37 @@ ***************************************************************************/ #include +#include #include "buffer.h" -#include "chatline.h" +#include "chatlinemodelitem.h" #include "chatscene.h" #include "chatview.h" +#include "client.h" +#include "messagefilter.h" #include "quasselui.h" ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() { - _scene = new ChatScene(buf, this); - setScene(_scene); + QList filterList; + filterList.append(buf->bufferInfo().bufferId()); + MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this); + init(filter); - QGraphicsTextItem *item = scene()->addText(buf->bufferInfo().bufferName()); +} +ChatView::ChatView(MessageFilter *filter, QWidget *parent) : QGraphicsView(parent), AbstractChatView() { + init(filter); } +void ChatView::init(MessageFilter *filter) { + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setAlignment(Qt::AlignBottom); + setInteractive(true); + + _scene = new ChatScene(filter, filter->idString(), this); + connect(_scene, SIGNAL(heightChanged(qreal)), this, SLOT(sceneHeightChanged(qreal))); + setScene(_scene); +} ChatView::~ChatView() { @@ -44,6 +60,17 @@ ChatScene *ChatView::scene() const { return _scene; } +void ChatView::resizeEvent(QResizeEvent *event) { + scene()->setWidth(event->size().width() - 2); // FIXME figure out why we have to hardcode the -2 here + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); +} + +void ChatView::sceneHeightChanged(qreal h) { + Q_UNUSED(h) + bool scrollable = qAbs(verticalScrollBar()->value() - verticalScrollBar()->maximum()) <= 2; // be a bit tolerant here, also FIXME (why we need this?) + setSceneRect(scene()->sceneRect()); + if(scrollable) verticalScrollBar()->setValue(verticalScrollBar()->maximum()); +} void ChatView::clear() { @@ -76,12 +103,12 @@ void ChatView::appendChatLine(ChatLine *line) { void ChatView::appendChatLines(QList list) { //foreach(ChatLine *line, list) { - + //} } void ChatView::setContents(const QList &list) { - qDebug() << "setting" << list.count(); + //qDebug() << "setting" << list.count(); //appendChatLines(list); }