Introduce a timer for resizing the ChatView
authorManuel Nickschas <sputnick@quassel-irc.org>
Wed, 29 Jul 2009 15:49:54 +0000 (17:49 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Thu, 6 Aug 2009 18:25:06 +0000 (20:25 +0200)
This allows for smooth resizing, as the layout is only calculated at most once every 100ms.

src/qtui/chatview.cpp
src/qtui/chatview.h

index 3c7d8cf..866ad4e 100644 (file)
@@ -54,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);
@@ -66,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)));
@@ -105,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());
index 6f385bb..8ebe3a5 100644 (file)
@@ -68,6 +68,7 @@ private slots:
   void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
   void mouseMoveWhileSelecting(const QPointF &scenePos);
   void scrollTimerTimeout();
+  void resizeTimerTimeout();
   void styleChanged();
 
 private:
@@ -79,6 +80,7 @@ private:
   qreal _currentScaleFactor;
   QTimer _scrollTimer;
   int _scrollOffset;
+  QTimer _resizeTimer;
 };