X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fchatview.cpp;h=3c7d8cf9d59ea24d4bc8275a170b54e9a73c73d6;hp=d360d9de9f2a71b16202903d4ee83567bdab7568;hb=9fb25d34cfc4dee02159b112c72e018c6e26e63f;hpb=31745736b8b31647f6224c5a3fe9e82e0320f0f1 diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index d360d9de..3c7d8cf9 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,18 +19,22 @@ ***************************************************************************/ #include +#include +#include #include -#include "chatlinemodelitem.h" +#include "bufferwidget.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), AbstractChatView(), + _bufferContainer(0), _currentScaleFactor(1) { QList filterList; @@ -42,6 +46,7 @@ ChatView::ChatView(BufferId bufferId, QWidget *parent) ChatView::ChatView(MessageFilter *filter, QWidget *parent) : QGraphicsView(parent), AbstractChatView(), + _bufferContainer(0), _currentScaleFactor(1) { init(filter); @@ -61,14 +66,41 @@ void ChatView::init(MessageFilter *filter) { _scrollTimer.setSingleShot(true); connect(&_scrollTimer, SIGNAL(timeout()), SLOT(scrollTimerTimeout())); - _scene = new ChatScene(filter, filter->idString(), viewport()->width() - 2, this); // see below: resizeEvent() + _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) { @@ -108,6 +140,10 @@ void ChatView::scrollTimerTimeout() { void ChatView::lastLineChanged(QGraphicsItem *chatLine, qreal offset) { Q_UNUSED(chatLine) + // disabled until further testing/discussion + //if(!scene()->isScrollingAllowed()) + // return; + QAbstractSlider *vbar = verticalScrollBar(); Q_ASSERT(vbar); if(vbar->maximum() - vbar->value() <= (offset + 5) * _currentScaleFactor ) { // 5px grace area @@ -130,6 +166,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 { @@ -143,6 +189,15 @@ MsgId ChatView::lastMsgId() const { return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value(); } +void ChatView::addActionsToMenu(QMenu *menu, const QPointF &pos) { + // zoom actions + BufferWidget *bw = qobject_cast(bufferContainer()); + if(bw) { + bw->addActionsToMenu(menu, pos); + menu->addSeparator(); + } +} + void ChatView::zoomIn() { _currentScaleFactor *= 1.2; scale(1.2, 1.2); @@ -155,7 +210,7 @@ void ChatView::zoomOut() { scene()->setWidth(viewport()->width() / _currentScaleFactor - 2); } -void ChatView::zoomNormal() { +void ChatView::zoomOriginal() { scale(1/_currentScaleFactor, 1/_currentScaleFactor); _currentScaleFactor = 1; scene()->setWidth(viewport()->width() - 2);