X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fqtui%2Fchatview.cpp;h=e8a06f13fab59856b1f9fae4bf5bdbad7a174392;hb=86a1220cc45c658954860e6dedbc18e38986ca94;hp=024e49d602b4f7e3d04e1ceb017dac6bce809235;hpb=16e4a21c1292448c1a524010d70f6e59b84802f4;p=quassel.git diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 024e49d6..e8a06f13 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -19,16 +19,17 @@ ***************************************************************************/ #include +#include #include #include #include "bufferwidget.h" -#include "chatlinemodelitem.h" #include "chatscene.h" #include "chatview.h" #include "client.h" #include "messagefilter.h" -#include "quasselui.h" +#include "qtui.h" +#include "qtuistyle.h" ChatView::ChatView(BufferId bufferId, QWidget *parent) : QGraphicsView(parent), @@ -53,7 +54,7 @@ ChatView::ChatView(MessageFilter *filter, QWidget *parent) void ChatView::init(MessageFilter *filter) { setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setAlignment(Qt::AlignBottom); + setAlignment(Qt::AlignBottom|Qt::AlignLeft); setInteractive(true); //setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontAdjustForAntialiasing); // setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing); @@ -65,18 +66,53 @@ void ChatView::init(MessageFilter *filter) { _scrollTimer.setSingleShot(true); connect(&_scrollTimer, SIGNAL(timeout()), SLOT(scrollTimerTimeout())); + _resizeTimer.setInterval(100); + _resizeTimer.setSingleShot(true); + connect(&_resizeTimer, SIGNAL(timeout()), SLOT(resizeTimerTimeout())); + _scene = new ChatScene(filter, filter->idString(), viewport()->width() - 4, this); // see below: resizeEvent() connect(_scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &))); connect(_scene, SIGNAL(lastLineChanged(QGraphicsItem *, qreal)), this, SLOT(lastLineChanged(QGraphicsItem *, qreal))); connect(_scene, SIGNAL(mouseMoveWhileSelecting(const QPointF &)), this, SLOT(mouseMoveWhileSelecting(const QPointF &))); setScene(_scene); - // installEventFilter(_scene); connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int))); + connect(QtUi::style(), SIGNAL(changed()), this, SLOT(styleChanged())); +} + +bool ChatView::event(QEvent *event) { + if(event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + switch(keyEvent->key()) { + case Qt::Key_Up: + case Qt::Key_Down: + case Qt::Key_PageUp: + case Qt::Key_PageDown: + if(!verticalScrollBar()->isVisible()) { + scene()->requestBacklog(); + return true; + } + default: + break; + } + } + + if(event->type() == QEvent::Wheel) { + if(!verticalScrollBar()->isVisible()) { + scene()->requestBacklog(); + return true; + } + } + + return QGraphicsView::event(event); } void ChatView::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); + _resizeTimer.start(); +} + +void ChatView::resizeTimerTimeout() { // we can reduce viewport updates if we scroll to the bottom allready at the beginning verticalScrollBar()->setValue(verticalScrollBar()->maximum()); @@ -138,6 +174,14 @@ void ChatView::verticalScrollbarChanged(int newPos) { } } _lastScrollbarPos = newPos; + + // FIXME: Fugly workaround for the ChatView scrolling up 1px on buffer switch + if(vbar->maximum() - newPos <= 2) + vbar->setValue(vbar->maximum()); +} + +void ChatView::styleChanged() { + scene()->layout(); } MsgId ChatView::lastMsgId() const {