Introduce a timer for resizing the ChatView
[quassel.git] / src / qtui / chatview.cpp
index 2a999ea..866ad4e 100644 (file)
@@ -28,7 +28,8 @@
 #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,6 +66,10 @@ 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)));
@@ -72,6 +77,7 @@ void ChatView::init(MessageFilter *filter) {
   setScene(_scene);
 
   connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(verticalScrollbarChanged(int)));
+  connect(QtUi::style(), SIGNAL(changed()), this, SLOT(styleChanged()));
 }
 
 bool ChatView::event(QEvent *event) {
@@ -103,6 +109,10 @@ bool ChatView::event(QEvent *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());
@@ -164,6 +174,16 @@ 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() {
+  invalidateScene();
+  if(scene())
+    scene()->update();
 }
 
 MsgId ChatView::lastMsgId() const {