From c80e9d81bfecf4126ed5a0a8b34802aa320ade0c Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Thu, 5 Aug 2010 21:44:25 +0200 Subject: [PATCH] Add rudimentary keyboard navigation for previous/next buffer Default keys are Alt+Up/Down to navigate through the channels in the bufferview marked as active (indicated by a dot in the view name). The active view can be changed with Alt+Left/Right and/or the Forward/Back keys depending on the platform. --- src/qtui/mainwin.cpp | 18 +++++++++++++- src/qtui/mainwin.h | 2 ++ src/uisupport/bufferview.cpp | 48 ++++++++++++++++++++++-------------- src/uisupport/bufferview.h | 9 +++++++ 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 334c5c1b..e264c6ce 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -425,7 +425,11 @@ void MainWin::setupActions() { coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll, this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward))); coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll, - this, SLOT(previousBufferView()), QKeySequence(QKeySequence::Back))); + this, SLOT(previousBufferView()), QKeySequence::Back)); + coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll, + this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down))); + coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll, + this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up))); } void MainWin::setupMenus() { @@ -671,6 +675,18 @@ void MainWin::previousBufferView() { changeActiveBufferView(true); } +void MainWin::nextBuffer() { + BufferView *view = activeBufferView(); + if(view) + view->nextBuffer(); +} + +void MainWin::previousBuffer() { + BufferView *view = activeBufferView(); + if(view) + view->previousBuffer(); +} + void MainWin::showNotificationsDlg() { SettingsPageDlg dlg(new NotificationsSettingsPage(this), this); dlg.exec(); diff --git a/src/qtui/mainwin.h b/src/qtui/mainwin.h index e882e0e6..17377097 100644 --- a/src/qtui/mainwin.h +++ b/src/qtui/mainwin.h @@ -87,6 +87,8 @@ class MainWin void showStatusBarMessage(const QString &message); void nextBufferView(); //!< Activate the next bufferview void previousBufferView(); //!< Activate the previous bufferview + void nextBuffer(); + void previousBuffer(); //! Quit application void quit(); diff --git a/src/uisupport/bufferview.cpp b/src/uisupport/bufferview.cpp index 076c9a87..b2fbc0fb 100644 --- a/src/uisupport/bufferview.cpp +++ b/src/uisupport/bufferview.cpp @@ -428,31 +428,41 @@ void BufferView::menuActionTriggered(QAction *result) { } } -void BufferView::wheelEvent(QWheelEvent* event) { - if(ItemViewSettings().mouseWheelChangesBuffer() == (bool)(event->modifiers() & Qt::AltModifier)) - return QTreeView::wheelEvent(event); +void BufferView::nextBuffer() { + changeBuffer(Forward); +} - int rowDelta = ( event->delta() > 0 ) ? -1 : 1; +void BufferView::previousBuffer() { + changeBuffer(Backward); +} + +void BufferView::changeBuffer(Direction direction) { QModelIndex currentIndex = selectionModel()->currentIndex(); QModelIndex resultingIndex; - if( model()->hasIndex( currentIndex.row() + rowDelta, currentIndex.column(), currentIndex.parent() ) ) - { - resultingIndex = currentIndex.sibling( currentIndex.row() + rowDelta, currentIndex.column() ); - } - else //if we scroll into a the parent node... - { - QModelIndex parent = currentIndex.parent(); - QModelIndex aunt = parent.sibling( parent.row() + rowDelta, parent.column() ); - if( rowDelta == -1 ) - resultingIndex = aunt.child( model()->rowCount( aunt ) - 1, 0 ); - else - resultingIndex = aunt.child( 0, 0 ); - if( !resultingIndex.isValid() ) - return; - } + if(model()->hasIndex( currentIndex.row() + direction, currentIndex.column(), currentIndex.parent())) + resultingIndex = currentIndex.sibling(currentIndex.row() + direction, currentIndex.column()); + + else { + //if we scroll into a the parent node... + QModelIndex parent = currentIndex.parent(); + QModelIndex aunt = parent.sibling(parent.row() + direction, parent.column()); + if(direction == Backward) + resultingIndex = aunt.child(model()->rowCount(aunt) - 1, 0); + else + resultingIndex = aunt.child(0, 0); + if(!resultingIndex.isValid()) + return; + } selectionModel()->setCurrentIndex( resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows ); selectionModel()->select( resultingIndex, QItemSelectionModel::ClearAndSelect ); +} +void BufferView::wheelEvent(QWheelEvent* event) { + if(ItemViewSettings().mouseWheelChangesBuffer() == (bool)(event->modifiers() & Qt::AltModifier)) + return QTreeView::wheelEvent(event); + + int rowDelta = ( event->delta() > 0 ) ? -1 : 1; + changeBuffer((Direction)rowDelta); } QSize BufferView::sizeHint() const { diff --git a/src/uisupport/bufferview.h b/src/uisupport/bufferview.h index b4fcbee0..8eca6756 100644 --- a/src/uisupport/bufferview.h +++ b/src/uisupport/bufferview.h @@ -41,6 +41,11 @@ class BufferView : public QTreeView { Q_OBJECT public: + enum Direction { + Forward = 1, + Backward = -1 + }; + BufferView(QWidget *parent = 0); void init(); @@ -58,6 +63,8 @@ public slots: void setRootIndexForNetworkId(const NetworkId &networkId); void removeSelectedBuffers(bool permanently = false); void menuActionTriggered(QAction *); + void nextBuffer(); + void previousBuffer(); signals: void removeBuffer(const QModelIndex &); @@ -83,6 +90,8 @@ private slots: void on_configChanged(); void on_layoutChanged(); + void changeBuffer(Direction direction); + private: QPointer _config; -- 2.20.1