This allows for smooth resizing, as the layout is only calculated at most once every 100ms.
void ChatView::init(MessageFilter *filter) {
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
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);
setInteractive(true);
//setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontAdjustForAntialiasing);
// setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing);
_scrollTimer.setSingleShot(true);
connect(&_scrollTimer, SIGNAL(timeout()), SLOT(scrollTimerTimeout()));
_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)));
_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)));
void ChatView::resizeEvent(QResizeEvent *event) {
QGraphicsView::resizeEvent(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());
// we can reduce viewport updates if we scroll to the bottom allready at the beginning
verticalScrollBar()->setValue(verticalScrollBar()->maximum());
void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
void mouseMoveWhileSelecting(const QPointF &scenePos);
void scrollTimerTimeout();
void lastLineChanged(QGraphicsItem *chatLine, qreal offset);
void mouseMoveWhileSelecting(const QPointF &scenePos);
void scrollTimerTimeout();
+ void resizeTimerTimeout();
void styleChanged();
private:
void styleChanged();
private:
qreal _currentScaleFactor;
QTimer _scrollTimer;
int _scrollOffset;
qreal _currentScaleFactor;
QTimer _scrollTimer;
int _scrollOffset;