diff options
Diffstat (limited to 'src/gui/widgets/qabstractslider.cpp')
-rw-r--r-- | src/gui/widgets/qabstractslider.cpp | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index 34fe340..a50c105 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -47,6 +47,9 @@ #ifndef QT_NO_ACCESSIBILITY #include "qaccessible.h" #endif +#ifdef QT_KEYPAD_NAVIGATION +#include "qtabwidget.h" // Needed in inTabWidget() +#endif // QT_KEYPAD_NAVIGATION #include <limits.h> QT_BEGIN_NAMESPACE @@ -724,6 +727,45 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) } } #endif +#ifdef QT_KEYPAD_NAVIGATION +/*! + \internal + + Tells us if it there is currently a reachable widget by keypad navigation in + a certain \a orientation. + If no navigation is possible, occuring key events in that \a orientation may + be used to interact with the value in the focussed widget, even though it + currently has not the editFocus. + + \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus() +*/ +inline static bool canKeypadNavigate(Qt::Orientation orientation) +{ + return orientation == Qt::Horizontal? + (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast) + || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest)) + :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth) + || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth)); +} +/*! + \internal + + Checks, if the \a widget is inside a QTabWidget. If is is inside + one, left/right key events will be used to switch between tabs in keypad + navigation. If there is no QTabWidget, the horizontal key events can be used to + interact with the value in the focussed widget, even though it currently has + not the editFocus. + + \sa QWidget::hasEditFocus() +*/ +inline static bool inTabWidget(QWidget *widget) +{ + for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget()) + if (qobject_cast<const QTabWidget*>(tabWidget)) + return true; + return false; +} +#endif // QT_KEYPAD_NAVIGATION /*! \reimp */ @@ -751,7 +793,13 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) // It seems we need to use invertedAppearance for Left and right, otherwise, things look weird. case Qt::Key_Left: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + // In QApplication::KeypadNavigationDirectional, we want to change the slider + // value if there is no left/right navigation possible and if this slider is not + // inside a tab widget. + if (QApplication::keypadNavigationEnabled() + && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder + || d->orientation == Qt::Vertical + || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { ev->ignore(); return; } @@ -766,7 +814,11 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) break; case Qt::Key_Right: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) { + // Same logic as in Qt::Key_Left + if (QApplication::keypadNavigationEnabled() + && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder + || d->orientation == Qt::Vertical + || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { ev->ignore(); return; } @@ -781,7 +833,12 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) break; case Qt::Key_Up: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { + // In QApplication::KeypadNavigationDirectional, we want to change the slider + // value if there is no up/down navigation possible. + if (QApplication::keypadNavigationEnabled() + && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder + || d->orientation == Qt::Horizontal + || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { ev->ignore(); break; } @@ -790,7 +847,11 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev) break; case Qt::Key_Down: #ifdef QT_KEYPAD_NAVIGATION - if (QApplication::keypadNavigationEnabled()) { + // Same logic as in Qt::Key_Up + if (QApplication::keypadNavigationEnabled() + && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder + || d->orientation == Qt::Horizontal + || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { ev->ignore(); break; } |