From fa6d3f8fad021a2a6f6d6228987c85997532e683 Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Mon, 4 Feb 2008 22:25:46 +0000 Subject: [PATCH] You can now jump to buffers with the keyboard. Select the buffer of choice with the mouse and hit ctrl + [0-9] to bind that buffer to a key. Jump to that buffer using alt + [0-9]. Not persistent yet :( --- src/qtui/mainwin.cpp | 35 +++++++++++++++++++++++++++++++++++ src/qtui/mainwin.h | 2 ++ src/uisupport/inputline.cpp | 13 +++++++++++++ src/uisupport/inputline.h | 3 +++ version.inc | 2 +- 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index e88dd355..3d4c12d9 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -399,3 +399,38 @@ void MainWin::connectOrDisconnectFromNet() { if(net->connectionState() == Network::Disconnected) net->requestConnect(); else net->requestDisconnect(); } + +void MainWin::keyPressEvent(QKeyEvent *event) { +#ifdef Q_WS_MAC + int bindModifier = Qt::ControlModifier | Qt::AltModifier; + int jumpModifier = Qt::ControlModifier; +#else + int bindModifier = Qt::ControlModifier; + int jumpModifier = Qt::AltModifier; +#endif + + if(Qt::Key_0 <= event->key() && event->key() <= Qt::Key_9) { + if(event->modifiers() == bindModifier) { + QModelIndex bufferIdx = Client::bufferModel()->standardSelectionModel()->currentIndex(); + NetworkId netId = bufferIdx.data(NetworkModel::NetworkIdRole).value(); + const Network *net = Client::network(netId); + if(!net) + return; + QString bufferName = bufferIdx.sibling(bufferIdx.row(), 0).data().toString(); + + _keyboardJump[event->key()] = bufferIdx; + statusBar()->showMessage(tr("Bound Buffer %1::%2 to Key %3").arg(net->networkName()).arg(bufferName).arg(event->key() - Qt::Key_0), 10000); + event->accept(); + } + + else if(event->modifiers() == jumpModifier && _keyboardJump.contains(event->key())) { + Client::bufferModel()->standardSelectionModel()->setCurrentIndex(_keyboardJump[event->key()], QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows); + event->accept(); + } + + else { + event->ignore(); + } + } + event->ignore(); +} diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index e2858961..277e4e8c 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -52,6 +52,7 @@ class MainWin : public QMainWindow { protected: void closeEvent(QCloseEvent *event); + virtual void keyPressEvent(QKeyEvent *event); protected slots: void connectedToCore(); @@ -93,6 +94,7 @@ class MainWin : public QMainWindow { void enableMenus(); + QHash _keyboardJump; QSystemTrayIcon *systray; CoreConnectDlg *coreConnectDlg; diff --git a/src/uisupport/inputline.cpp b/src/uisupport/inputline.cpp index 7511e07a..1d23faa0 100644 --- a/src/uisupport/inputline.cpp +++ b/src/uisupport/inputline.cpp @@ -28,12 +28,25 @@ InputLine::InputLine(QWidget *parent) { connect(this, SIGNAL(returnPressed()), this, SLOT(enter())); tabComplete = new TabCompleter(this); + +#ifdef Q_WS_MAC + bindModifier = Qt::ControlModifier | Qt::AltModifier; + jumpModifier = Qt::ControlModifier; +#else + bindModifier = Qt::ControlModifier; + jumpModifier = Qt::AltModifier; +#endif } InputLine::~InputLine() { } void InputLine::keyPressEvent(QKeyEvent * event) { + if(event->modifiers() == jumpModifier || event->modifiers() == bindModifier) { + event->ignore(); + return; + } + if(event->key() == Qt::Key_Tab) { // Tabcomplete tabComplete->complete(); event->accept(); diff --git a/src/uisupport/inputline.h b/src/uisupport/inputline.h index 802eae25..936e1bda 100644 --- a/src/uisupport/inputline.h +++ b/src/uisupport/inputline.h @@ -51,6 +51,9 @@ class InputLine : public QLineEdit { QStringList nickList; TabCompleter *tabComplete; + + int bindModifier; + int jumpModifier; }; #endif diff --git a/version.inc b/version.inc index c0abd2d1..3ee32ef0 100644 --- a/version.inc +++ b/version.inc @@ -5,7 +5,7 @@ quasselVersion = "0.2.0-pre"; quasselDate = "2008-02-04"; - quasselBuild = 456; + quasselBuild = 457; //! Minimum client build number the core needs clientBuildNeeded = 456; -- 2.20.1