700 if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { |
697 if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { |
701 // Scroll one page regardless of delta: |
698 // Scroll one page regardless of delta: |
702 stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep); |
699 stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep); |
703 offset_accumulated = 0; |
700 offset_accumulated = 0; |
704 } else { |
701 } else { |
705 // Calculate how many lines to scroll. Depending on what delta is (and |
702 // Calculate how many lines to scroll. Depending on what delta is (and |
706 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can |
703 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can |
707 // only scroll whole lines, so we keep the reminder until next event. |
704 // only scroll whole lines, so we keep the reminder until next event. |
708 qreal stepsToScrollF = |
705 qreal stepsToScrollF = |
709 #ifndef QT_NO_WHEELEVENT |
706 #ifndef QT_NO_WHEELEVENT |
710 QApplication::wheelScrollLines() * |
707 QApplication::wheelScrollLines() * |
747 if (d->scrollByDelta(e->orientation(), e->modifiers(), delta)) |
744 if (d->scrollByDelta(e->orientation(), e->modifiers(), delta)) |
748 e->accept(); |
745 e->accept(); |
749 } |
746 } |
750 |
747 |
751 #endif |
748 #endif |
752 #ifdef QT_KEYPAD_NAVIGATION |
749 |
753 /*! |
|
754 \internal |
|
755 |
|
756 Tells us if it there is currently a reachable widget by keypad navigation in |
|
757 a certain \a orientation. |
|
758 If no navigation is possible, occuring key events in that \a orientation may |
|
759 be used to interact with the value in the focussed widget, even though it |
|
760 currently has not the editFocus. |
|
761 |
|
762 \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus() |
|
763 */ |
|
764 inline static bool canKeypadNavigate(Qt::Orientation orientation) |
|
765 { |
|
766 return orientation == Qt::Horizontal? |
|
767 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast) |
|
768 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest)) |
|
769 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth) |
|
770 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth)); |
|
771 } |
|
772 /*! |
|
773 \internal |
|
774 |
|
775 Checks, if the \a widget is inside a QTabWidget. If is is inside |
|
776 one, left/right key events will be used to switch between tabs in keypad |
|
777 navigation. If there is no QTabWidget, the horizontal key events can be used to |
|
778 interact with the value in the focussed widget, even though it currently has |
|
779 not the editFocus. |
|
780 |
|
781 \sa QWidget::hasEditFocus() |
|
782 */ |
|
783 inline static bool inTabWidget(QWidget *widget) |
|
784 { |
|
785 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget()) |
|
786 if (qobject_cast<const QTabWidget*>(tabWidget)) |
|
787 return true; |
|
788 return false; |
|
789 } |
|
790 #endif // QT_KEYPAD_NAVIGATION |
|
791 /*! |
750 /*! |
792 \reimp |
751 \reimp |
793 */ |
752 */ |
794 void QAbstractSlider::keyPressEvent(QKeyEvent *ev) |
753 void QAbstractSlider::keyPressEvent(QKeyEvent *ev) |
795 { |
754 { |
851 // value if there is no left/right navigation possible and if this slider is not |
810 // value if there is no left/right navigation possible and if this slider is not |
852 // inside a tab widget. |
811 // inside a tab widget. |
853 if (QApplication::keypadNavigationEnabled() |
812 if (QApplication::keypadNavigationEnabled() |
854 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
813 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
855 || d->orientation == Qt::Vertical |
814 || d->orientation == Qt::Vertical |
856 || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { |
815 || !hasEditFocus() |
|
816 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) { |
857 ev->ignore(); |
817 ev->ignore(); |
858 return; |
818 return; |
859 } |
819 } |
860 if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) |
820 if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) |
861 action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; |
821 action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; |
870 #ifdef QT_KEYPAD_NAVIGATION |
830 #ifdef QT_KEYPAD_NAVIGATION |
871 // Same logic as in Qt::Key_Left |
831 // Same logic as in Qt::Key_Left |
872 if (QApplication::keypadNavigationEnabled() |
832 if (QApplication::keypadNavigationEnabled() |
873 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
833 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
874 || d->orientation == Qt::Vertical |
834 || d->orientation == Qt::Vertical |
875 || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { |
835 || !hasEditFocus() |
|
836 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) { |
876 ev->ignore(); |
837 ev->ignore(); |
877 return; |
838 return; |
878 } |
839 } |
879 if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) |
840 if (QApplication::keypadNavigationEnabled() && d->orientation == Qt::Vertical) |
880 action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; |
841 action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; |
890 // In QApplication::KeypadNavigationDirectional, we want to change the slider |
851 // In QApplication::KeypadNavigationDirectional, we want to change the slider |
891 // value if there is no up/down navigation possible. |
852 // value if there is no up/down navigation possible. |
892 if (QApplication::keypadNavigationEnabled() |
853 if (QApplication::keypadNavigationEnabled() |
893 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
854 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
894 || d->orientation == Qt::Horizontal |
855 || d->orientation == Qt::Horizontal |
895 || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { |
856 || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { |
896 ev->ignore(); |
857 ev->ignore(); |
897 break; |
858 break; |
898 } |
859 } |
899 #endif |
860 #endif |
900 action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; |
861 action = d->invertedControls ? SliderSingleStepSub : SliderSingleStepAdd; |
903 #ifdef QT_KEYPAD_NAVIGATION |
864 #ifdef QT_KEYPAD_NAVIGATION |
904 // Same logic as in Qt::Key_Up |
865 // Same logic as in Qt::Key_Up |
905 if (QApplication::keypadNavigationEnabled() |
866 if (QApplication::keypadNavigationEnabled() |
906 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
867 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder |
907 || d->orientation == Qt::Horizontal |
868 || d->orientation == Qt::Horizontal |
908 || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) { |
869 || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { |
909 ev->ignore(); |
870 ev->ignore(); |
910 break; |
871 break; |
911 } |
872 } |
912 #endif |
873 #endif |
913 action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; |
874 action = d->invertedControls ? SliderSingleStepAdd : SliderSingleStepSub; |