added zoom feature: "ctrl +" magnifies, "ctrl -" demagnifies and "ctrl 0" normalizes
authorAlexander von Renteln <phon@quassel-irc.org>
Sat, 25 Oct 2008 21:57:58 +0000 (23:57 +0200)
committerAlexander von Renteln <phon@quassel-irc.org>
Sat, 25 Oct 2008 22:01:45 +0000 (00:01 +0200)
page-up and page-down key in the inputline now scrolls the bufferwidget

src/qtui/bufferwidget.cpp
src/qtui/bufferwidget.h
src/qtui/chatview.cpp
src/qtui/chatview.h
src/qtui/inputwidget.cpp
src/qtui/inputwidget.h
src/qtui/jumpkeyhandler.cpp
src/qtui/mainwin.cpp

index f9b6986..6bc3046 100644 (file)
 #include "settings.h"
 #include "client.h"
 
+#include "action.h"
+#include "actioncollection.h"
+#include "qtui.h"
+
 #include <QLayout>
+#include <QKeyEvent>
 
 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<Action>("ZoomChatView");
+  connect(zoomChatview, SIGNAL(triggered()), SLOT(zoomIn()));
+  zoomChatview->setText(tr("Enlarge Chat View"));
+  zoomChatview->setShortcut(tr("Ctrl++"));
+
+  Action *zoomOutChatview = coll->add<Action>("ZoomOutChatView");
+  connect(zoomOutChatview, SIGNAL(triggered()), SLOT(zoomOut()));
+  zoomOutChatview->setText(tr("Demagnify Chat View"));
+  zoomOutChatview->setShortcut(tr("Ctrl+-"));
+
+  Action *zoomNormalChatview = coll->add<Action>("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<ChatView *>(ui.stackedWidget->currentWidget());
+  if(!view) return;
+  view->zoomIn();
+}
+
+void BufferWidget::zoomOut() {
+  ChatView *view = qobject_cast<ChatView *>(ui.stackedWidget->currentWidget());
+  if(!view) return;
+  view->zoomOut();
+}
+
+void BufferWidget::zoomNormal() {
+  ChatView *view = qobject_cast<ChatView *>(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<QKeyEvent*>(event);
+  switch(keyEvent->key()) {
+    case Qt::Key_PageUp:
+    case Qt::Key_PageDown:
+      // static cast to access public qobject::event
+      return static_cast<QObject*>(ui.stackedWidget->currentWidget())->event(event);
+    default:
+      return false;
+  }
+}
index 75027cb..1d70c27 100644 (file)
@@ -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;
index 94f3fb7..6e55bba 100644 (file)
@@ -30,7 +30,8 @@
 
 ChatView::ChatView(BufferId bufferId, QWidget *parent)
   : QGraphicsView(parent),
-    AbstractChatView()
+    AbstractChatView(),
+    _currentScaleFactor(1)
 {
   QList<BufferId> 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<MsgId>();
 }
+
+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);
+}
index 293e97c..11bd417 100644 (file)
@@ -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;
 };
 
 
index c1fbe7e..f885819 100644 (file)
@@ -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() {
index 5bffbc7..fc358f2 100644 (file)
@@ -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 &current, const QModelIndex &previous);
   virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
index 941c5d2..d4fb780 100644 (file)
@@ -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) {
index df005d5..5f302a9 100644 (file)
@@ -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() {