From: Alexander von Renteln Date: Sat, 25 Oct 2008 21:57:58 +0000 (+0200) Subject: added zoom feature: "ctrl +" magnifies, "ctrl -" demagnifies and "ctrl 0" normalizes X-Git-Tag: 0.3.1~128 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=dcdc88676f6bf6c961c554e1ff0d160082ba0973 added zoom feature: "ctrl +" magnifies, "ctrl -" demagnifies and "ctrl 0" normalizes page-up and page-down key in the inputline now scrolls the bufferwidget --- diff --git a/src/qtui/bufferwidget.cpp b/src/qtui/bufferwidget.cpp index f9b69867..6bc30468 100644 --- a/src/qtui/bufferwidget.cpp +++ b/src/qtui/bufferwidget.cpp @@ -25,7 +25,12 @@ #include "settings.h" #include "client.h" +#include "action.h" +#include "actioncollection.h" +#include "qtui.h" + #include +#include BufferWidget::BufferWidget(QWidget *parent) : AbstractBufferContainer(parent), @@ -58,6 +63,23 @@ BufferWidget::BufferWidget(QWidget *parent) connect(_chatViewSearchController, SIGNAL(newCurrentHighlight(QGraphicsItem *)), this, SLOT(scrollToHighlight(QGraphicsItem *))); + + ActionCollection *coll = QtUi::actionCollection(); + + Action *zoomChatview = coll->add("ZoomChatView"); + connect(zoomChatview, SIGNAL(triggered()), SLOT(zoomIn())); + zoomChatview->setText(tr("Enlarge Chat View")); + zoomChatview->setShortcut(tr("Ctrl++")); + + Action *zoomOutChatview = coll->add("ZoomOutChatView"); + connect(zoomOutChatview, SIGNAL(triggered()), SLOT(zoomOut())); + zoomOutChatview->setText(tr("Demagnify Chat View")); + zoomOutChatview->setShortcut(tr("Ctrl+-")); + + Action *zoomNormalChatview = coll->add("ZoomNormalChatView"); + connect(zoomNormalChatview, SIGNAL(triggered()), SLOT(zoomNormal())); + zoomNormalChatview->setText(tr("Normalize zoom of Chat View")); + zoomNormalChatview->setShortcut(tr("Ctrl+0")); } BufferWidget::~BufferWidget() { @@ -99,3 +121,38 @@ void BufferWidget::scrollToHighlight(QGraphicsItem *highlightItem) { view->centerOn(highlightItem); } } + + +void BufferWidget::zoomIn() { + ChatView *view = qobject_cast(ui.stackedWidget->currentWidget()); + if(!view) return; + view->zoomIn(); +} + +void BufferWidget::zoomOut() { + ChatView *view = qobject_cast(ui.stackedWidget->currentWidget()); + if(!view) return; + view->zoomOut(); +} + +void BufferWidget::zoomNormal() { + ChatView *view = qobject_cast(ui.stackedWidget->currentWidget()); + if(!view) return; + view->zoomNormal(); +} + +bool BufferWidget::eventFilter(QObject *watched, QEvent *event) { + Q_UNUSED(watched); + if(event->type() != QEvent::KeyPress) + return false; + + QKeyEvent *keyEvent = static_cast(event); + switch(keyEvent->key()) { + case Qt::Key_PageUp: + case Qt::Key_PageDown: + // static cast to access public qobject::event + return static_cast(ui.stackedWidget->currentWidget())->event(event); + default: + return false; + } +} diff --git a/src/qtui/bufferwidget.h b/src/qtui/bufferwidget.h index 75027cbf..1d70c272 100644 --- a/src/qtui/bufferwidget.h +++ b/src/qtui/bufferwidget.h @@ -36,6 +36,8 @@ public: BufferWidget(QWidget *parent); ~BufferWidget(); + virtual bool eventFilter(QObject *watched, QEvent *event); + inline ChatViewSearchBar *searchBar() const { return ui.searchBar; } protected: @@ -47,6 +49,9 @@ protected slots: private slots: void scrollToHighlight(QGraphicsItem *highlightItem); + void zoomIn(); + void zoomOut(); + void zoomNormal(); private: Ui::BufferWidget ui; diff --git a/src/qtui/chatview.cpp b/src/qtui/chatview.cpp index 94f3fb74..6e55bba6 100644 --- a/src/qtui/chatview.cpp +++ b/src/qtui/chatview.cpp @@ -30,7 +30,8 @@ ChatView::ChatView(BufferId bufferId, QWidget *parent) : QGraphicsView(parent), - AbstractChatView() + AbstractChatView(), + _currentScaleFactor(1) { QList filterList; filterList.append(bufferId); @@ -40,7 +41,8 @@ ChatView::ChatView(BufferId bufferId, QWidget *parent) ChatView::ChatView(MessageFilter *filter, QWidget *parent) : QGraphicsView(parent), - AbstractChatView() + AbstractChatView(), + _currentScaleFactor(1) { init(filter); } @@ -52,7 +54,8 @@ void ChatView::init(MessageFilter *filter) { //setOptimizationFlags(QGraphicsView::DontClipPainter | QGraphicsView::DontAdjustForAntialiasing); // setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing); setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate); - setTransformationAnchor(QGraphicsView::NoAnchor); + // setTransformationAnchor(QGraphicsView::NoAnchor); + setTransformationAnchor(QGraphicsView::AnchorViewCenter); _scene = new ChatScene(filter, filter->idString(), viewport()->width() - 2, this); // see below: resizeEvent() connect(_scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(sceneRectChanged(const QRectF &))); @@ -113,3 +116,21 @@ MsgId ChatView::lastMsgId() const { return model->data(model->index(model->rowCount() - 1, 0), MessageModel::MsgIdRole).value(); } + +void ChatView::zoomIn() { + _currentScaleFactor *= 1.2; + scale(1.2, 1.2); + scene()->setWidth(viewport()->width() / _currentScaleFactor - 2); +} + +void ChatView::zoomOut() { + _currentScaleFactor /= 1.2; + scale(1 / 1.2, 1 / 1.2); + scene()->setWidth(viewport()->width() / _currentScaleFactor - 2); +} + +void ChatView::zoomNormal() { + scale(1/_currentScaleFactor, 1/_currentScaleFactor); + _currentScaleFactor = 1; + scene()->setWidth(viewport()->width() - 2); +} diff --git a/src/qtui/chatview.h b/src/qtui/chatview.h index 293e97c6..11bd4174 100644 --- a/src/qtui/chatview.h +++ b/src/qtui/chatview.h @@ -43,6 +43,9 @@ public: public slots: inline virtual void clear() {} + void zoomIn(); + void zoomOut(); + void zoomNormal(); protected: virtual void resizeEvent(QResizeEvent *event); @@ -57,6 +60,7 @@ private: ChatScene *_scene; int _lastScrollbarPos; + qreal _currentScaleFactor; }; diff --git a/src/qtui/inputwidget.cpp b/src/qtui/inputwidget.cpp index c1fbe7eb..f885819d 100644 --- a/src/qtui/inputwidget.cpp +++ b/src/qtui/inputwidget.cpp @@ -56,7 +56,6 @@ InputWidget::InputWidget(QWidget *parent) connect(activateInputline, SIGNAL(triggered()), SLOT(setFocus())); activateInputline->setText(tr("Focus Input Line")); activateInputline->setShortcut(tr("Ctrl+L")); - } InputWidget::~InputWidget() { diff --git a/src/qtui/inputwidget.h b/src/qtui/inputwidget.h index 5bffbc7f..fc358f24 100644 --- a/src/qtui/inputwidget.h +++ b/src/qtui/inputwidget.h @@ -29,6 +29,8 @@ #include "identity.h" #include "network.h" +class InputLine; + class InputWidget : public AbstractItemView { Q_OBJECT @@ -38,6 +40,8 @@ public: const Network *currentNetwork() const; + inline InputLine* inputLine() const { return ui.inputEdit; } + protected slots: virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); diff --git a/src/qtui/jumpkeyhandler.cpp b/src/qtui/jumpkeyhandler.cpp index 941c5d2e..d4fb780e 100644 --- a/src/qtui/jumpkeyhandler.cpp +++ b/src/qtui/jumpkeyhandler.cpp @@ -46,7 +46,7 @@ bool JumpKeyHandler::eventFilter(QObject *obj, QEvent *event) { const int key = keyEvent->key(); - if(key < Qt::Key_0 || Qt::Key_9 < key) + if(key < Qt::Key_1 || Qt::Key_9 < key) return QObject::eventFilter(obj, event); if(keyEvent->modifiers() == bindModifier) { diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index df005d57..5f302a90 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -36,6 +36,7 @@ #include "coreconnectdlg.h" #include "iconloader.h" #include "inputwidget.h" +#include "inputline.h" #include "irclistmodel.h" #include "jumpkeyhandler.h" #include "msgprocessorstatuswidget.h" @@ -358,6 +359,8 @@ void MainWin::setupInputWidget() { inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); _bufferWidget->setFocusProxy(inputWidget); + + inputWidget->inputLine()->installEventFilter(_bufferWidget); } void MainWin::setupTopicWidget() {