You can now switch buffers via mousewhell, when the cursor is over a buffer view.
[quassel.git] / src / uisupport / bufferview.cpp
index aa82b58..380828d 100644 (file)
@@ -76,7 +76,7 @@ void BufferView::setModel(QAbstractItemModel *model) {
 
   QString sectionName;
   QAction *showSection;
-  for(int i = 0; i < model->columnCount(); i++) {
+  for(int i = 1; i < model->columnCount(); i++) {
     sectionName = (model->headerData(i, Qt::Horizontal, Qt::DisplayRole)).toString();
     showSection = new QAction(sectionName, header());
     showSection->setCheckable(true);
@@ -220,3 +220,27 @@ void BufferView::showContextMenu(const QPoint &pos) {
   }
 }
 
+void BufferView::wheelEvent(QWheelEvent* event)
+{
+    int rowDelta = ( event->delta() > 0 ) ? -1 : 1;
+    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;
+    }
+    selectionModel()->setCurrentIndex( resultingIndex, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
+    selectionModel()->select( resultingIndex, QItemSelectionModel::ClearAndSelect );
+}
+