X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fuisupport%2Fbufferview.cpp;h=b2fbc0fb3b8de96d09d2490574c2646317bfde54;hp=076c9a87adfb6ec8fede93f7d7d5ecc39c81a4d8;hb=c80e9d81bfecf4126ed5a0a8b34802aa320ade0c;hpb=1b9dc90e54c1c7c2012decfb87cce80dbae60be9 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 {