1 /***************************************************************************
2 * Copyright (C) 2005-08 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #include "jumpkeyhandler.h"
26 #include "networkmodel.h"
27 #include "buffermodel.h"
29 JumpKeyHandler::JumpKeyHandler(QObject *parent)
32 bindModifier(Qt::ControlModifier | Qt::AltModifier),
33 jumpModifier(Qt::ControlModifier)
35 bindModifier(Qt::ControlModifier),
36 jumpModifier(Qt::AltModifier)
41 bool JumpKeyHandler::eventFilter(QObject *obj, QEvent *event) {
42 if(event->type() != QEvent::KeyPress)
43 return QObject::eventFilter(obj, event);
45 QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
47 const int key = keyEvent->key();
49 if(key < Qt::Key_1 || Qt::Key_9 < key)
50 return QObject::eventFilter(obj, event);
52 if(keyEvent->modifiers() == bindModifier) {
57 if(keyEvent->modifiers() == jumpModifier) {
65 void JumpKeyHandler::bindKey(int key) {
66 QModelIndex bufferIdx = Client::bufferModel()->standardSelectionModel()->currentIndex();
67 NetworkId netId = bufferIdx.data(NetworkModel::NetworkIdRole).value<NetworkId>();
68 const Network *net = Client::network(netId);
72 QString bufferName = bufferIdx.sibling(bufferIdx.row(), 0).data().toString();
73 BufferId bufferId = bufferIdx.data(NetworkModel::BufferIdRole).value<BufferId>();
75 _keyboardJump[key] = bufferId;
76 CoreAccountSettings().setJumpKeyMap(_keyboardJump);
77 //emit statusMessage(tr("Bound Buffer %1::%2 to Key %3").arg(net->networkName()).arg(bufferName).arg(key - Qt::Key_0), 10000);
78 //statusBar()->showMessage(tr("Bound Buffer %1::%2 to Key %3").arg(net->networkName()).arg(bufferName).arg(key - Qt::Key_0), 10000);
81 void JumpKeyHandler::jumpKey(int key) {
82 if(key < Qt::Key_0 || Qt::Key_9 < key)
85 if(_keyboardJump.isEmpty())
86 _keyboardJump = CoreAccountSettings().jumpKeyMap();
88 if(!_keyboardJump.contains(key))
91 QModelIndex source_bufferIdx = Client::networkModel()->bufferIndex(_keyboardJump[key]);
92 QModelIndex bufferIdx = Client::bufferModel()->mapFromSource(source_bufferIdx);
94 if(bufferIdx.isValid())
95 Client::bufferModel()->standardSelectionModel()->setCurrentIndex(bufferIdx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);