X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatview.cpp;h=6e40c0995a52d9093cc0b146de65bf14f5b3ca43;hp=be2cbc62debcd9564a20c3c1d4a3c65469b98878;hb=533eaaeda64759c01daa624365b8fc63eeba5ccf;hpb=e1b6d538b7c4cc279f9218614e23adb5d8a81fe5 diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index be2cbc62..6e40c099 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -29,7 +29,10 @@ #include "messagefilter.h" #include "quasselui.h" -ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), AbstractChatView() { +ChatView::ChatView(Buffer *buf, QWidget *parent) + : QGraphicsView(parent), + AbstractChatView() +{ QList filterList; filterList.append(buf->bufferInfo().bufferId()); MessageFilter *filter = new MessageFilter(Client::messageModel(), filterList, this); @@ -37,7 +40,10 @@ ChatView::ChatView(Buffer *buf, QWidget *parent) : QGraphicsView(parent), Abstra } -ChatView::ChatView(MessageFilter *filter, QWidget *parent) : QGraphicsView(parent), AbstractChatView() { +ChatView::ChatView(MessageFilter *filter, QWidget *parent) + : QGraphicsView(parent), + AbstractChatView() +{ init(filter); } @@ -49,15 +55,10 @@ void ChatView::init(MessageFilter *filter) { _scene = new ChatScene(filter, filter->idString(), this); connect(_scene, SIGNAL(heightChanged(qreal)), this, SLOT(sceneHeightChanged(qreal))); setScene(_scene); -} - -ChatView::~ChatView() { - -} - -ChatScene *ChatView::scene() const { - return _scene; + connect(verticalScrollBar(), SIGNAL(sliderPressed()), this, SLOT(sliderPressed())); + connect(verticalScrollBar(), SIGNAL(sliderReleased()), this, SLOT(sliderReleased())); + connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int))); } void ChatView::resizeEvent(QResizeEvent *event) { @@ -72,6 +73,44 @@ void ChatView::sceneHeightChanged(qreal h) { if(scrollable) verticalScrollBar()->setValue(verticalScrollBar()->maximum()); } -void ChatView::clear() -{ +void ChatView::setBufferForBacklogFetching(BufferId id) { + scene()->setBufferForBacklogFetching(id); +} + +void ChatView::sliderPressed() { + verticalScrollbarChanged(verticalScrollBar()->value()); +} + +void ChatView::sliderReleased() { + if(scene()->isFetchingBacklog()) scene()->setIsFetchingBacklog(false); +} + +void ChatView::verticalScrollbarChanged(int newPos) { + Q_UNUSED(newPos); + if(!scene()->isBacklogFetchingEnabled()) return; + + QAbstractSlider *vbar = verticalScrollBar(); + if(!vbar) + return; + if(vbar->isSliderDown()) { + /* + int relativePos = 100; + if(vbar->maximum() - vbar->minimum() != 0) + relativePos = (newPos - vbar->minimum()) * 100 / (vbar->maximum() - vbar->minimum()); + scene()->setIsFetchingBacklog(relativePos < 20); + */ + scene()->setIsFetchingBacklog(vbar->value() == vbar->minimum()); + } +} + +MsgId ChatView::lastMsgId() const { + if(!scene()) + return MsgId(); + + QAbstractItemModel *model = scene()->model(); + if(!model || model->rowCount() == 0) + return MsgId(); + + + return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value(); }