From b1cdd3a160ea995f9c48eab9aeb02bd28d98f8c9 Mon Sep 17 00:00:00 2001 From: Stian Sandvik Thomassen Date: Wed, 2 Sep 2009 08:51:20 +1000 Subject: Made mouse wheel navigation skip disabled tabs Mouse wheel navigation should skip disabled tabs like keyboard navigation does. Task-number: 260568 Reviewed-by: Jens Bache-Wiig --- src/gui/widgets/qtabbar.cpp | 27 +++++++++++++++------------ src/gui/widgets/qtabbar_p.h | 1 + 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/gui/widgets/qtabbar.cpp b/src/gui/widgets/qtabbar.cpp index bf2c0bb..e749ce7 100644 --- a/src/gui/widgets/qtabbar.cpp +++ b/src/gui/widgets/qtabbar.cpp @@ -1913,13 +1913,8 @@ void QTabBar::keyPressEvent(QKeyEvent *event) event->ignore(); return; } - int dx = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1; - for (int index = d->currentIndex + dx; d->validIndex(index); index += dx) { - if (d->tabList.at(index).enabled) { - setCurrentIndex(index); - break; - } - } + int offset = event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1; + d->setCurrentNextEnabledIndex(offset); } /*!\reimp @@ -1928,15 +1923,23 @@ void QTabBar::keyPressEvent(QKeyEvent *event) void QTabBar::wheelEvent(QWheelEvent *event) { Q_D(QTabBar); - int overIndex = d->indexAtPos(event->pos()); - if (overIndex != -1) { - int offset = event->delta() > 0 ? -1 : 1; - setCurrentIndex(currentIndex() + offset); - } + int offset = event->delta() > 0 ? -1 : 1; + d->setCurrentNextEnabledIndex(offset); QWidget::wheelEvent(event); } #endif //QT_NO_WHEELEVENT +void QTabBarPrivate::setCurrentNextEnabledIndex(int offset) +{ + Q_Q(QTabBar); + for (int index = currentIndex + offset; validIndex(index); index += offset) { + if (tabList.at(index).enabled) { + q->setCurrentIndex(index); + break; + } + } +} + /*!\reimp */ void QTabBar::changeEvent(QEvent *event) diff --git a/src/gui/widgets/qtabbar_p.h b/src/gui/widgets/qtabbar_p.h index d632753..2c4d625 100644 --- a/src/gui/widgets/qtabbar_p.h +++ b/src/gui/widgets/qtabbar_p.h @@ -144,6 +144,7 @@ public: int indexAtPos(const QPoint &p) const; inline bool validIndex(int index) const { return index >= 0 && index < tabList.count(); } + void setCurrentNextEnabledIndex(int offset); QSize minimumTabSizeHint(int index); -- cgit v0.12