X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatview.cpp;h=ff0460aa15abfa3626ffe22af3651e7d431e80cb;hp=a4582546a8bad425e28bfa7005395266b1154025;hb=70ededc490cb201e52b6d8ca4c2364d4a001b6c4;hpb=99bb37d9938f3d88ce7551ded454146359fadc03 diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index a4582546..ff0460aa 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -19,83 +19,82 @@ ***************************************************************************/ #include +#include -#include "buffer.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() { - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setOptimizationFlags(QGraphicsView::DontClipPainter - |QGraphicsView::DontSavePainterState - |QGraphicsView::DontAdjustForAntialiasing); - _scene = new ChatScene(Client::messageModel(), this); - connect(_scene, SIGNAL(heightChanged(int)), this, SLOT(sceneHeightChanged(int))); - //_scene->setWidth(width()); - setScene(_scene); - setSceneRect(0, 0, width(), 0); - -} - - -ChatView::~ChatView() { - +ChatView::ChatView(BufferId bufferId, QWidget *parent) + : QGraphicsView(parent), + AbstractChatView() +{ + QList filterList; + filterList.append(bufferId); + MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this); + init(filter); } - -ChatScene *ChatView::scene() const { - return _scene; +ChatView::ChatView(MessageFilter *filter, QWidget *parent) + : QGraphicsView(parent), + AbstractChatView() +{ + init(filter); } -void ChatView::resizeEvent(QResizeEvent *event) { - scene()->setWidth(event->size().width()); - qDebug() << "resize"; -} +void ChatView::init(MessageFilter *filter) { + setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + setAlignment(Qt::AlignBottom); + setInteractive(true); -void ChatView::sceneHeightChanged(int h) { - setSceneRect(0, 0, width(), h); -} + _scene = new ChatScene(filter, filter->idString(), viewport()->width(), this); + connect(_scene, SIGNAL(sceneHeightChanged(qreal)), this, SLOT(sceneHeightChanged(qreal))); + setScene(_scene); -void ChatView::clear() -{ + _lastScrollbarPos = verticalScrollBar()->maximum(); + connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int))); } -void ChatView::prependMsg(AbstractUiMsg *msg) { - //ChatLine *line = dynamic_cast(msg); - //Q_ASSERT(line); - //prependChatLine(line); +void ChatView::resizeEvent(QResizeEvent *event) { +// scene()->setWidth(event->size().width() - 2); // FIXME figure out why we have to hardcode the -2 here + QGraphicsView::resizeEvent(event); + scene()->setWidth(viewport()->width()); + verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } -void ChatView::prependChatLine(ChatLine *line) { - //qDebug() << "prepending"; +void ChatView::sceneHeightChanged(qreal dh) { + QAbstractSlider *vbar = verticalScrollBar(); + Q_ASSERT(vbar); + if(vbar->maximum() - vbar->value() <= dh + 5) // in case we had scrolled only about half a line to the bottom we allow a grace of 5 + vbar->setValue(vbar->maximum()); } -void ChatView::prependChatLines(QList clist) { +void ChatView::verticalScrollbarChanged(int newPos) { + QAbstractSlider *vbar = verticalScrollBar(); + Q_ASSERT(vbar); -} + if(newPos < _lastScrollbarPos) { + int relativePos = 100; + if(vbar->maximum() - vbar->minimum() != 0) + relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum()); -void ChatView::appendMsg(AbstractUiMsg *msg) { - //ChatLine *line = dynamic_cast(msg); - //Q_ASSERT(line); - //appendChatLine(line); + if(relativePos < 20) { + scene()->requestBacklog(); + } + } + _lastScrollbarPos = newPos; } -void ChatView::appendChatLine(ChatLine *line) { - //qDebug() << "appending"; -} +MsgId ChatView::lastMsgId() const { + if(!scene()) + return MsgId(); + QAbstractItemModel *model = scene()->model(); + if(!model || model->rowCount() == 0) + return MsgId(); -void ChatView::appendChatLines(QList list) { - //foreach(ChatLine *line, list) { - - //} + return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value(); } - -void ChatView::setContents(const QList &list) { - //qDebug() << "setting" << list.count(); - //appendChatLines(list); -} -