Changeset 769 for trunk/src/gui/widgets/qabstractslider.cpp
- Timestamp:
- Aug 2, 2010, 9:27:30 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.6.3 (added) merged: 768 /branches/vendor/nokia/qt/current merged: 767 /branches/vendor/nokia/qt/4.6.2 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/widgets/qabstractslider.cpp
r651 r769 48 48 #include "qaccessible.h" 49 49 #endif 50 #ifdef QT_KEYPAD_NAVIGATION51 #include "qtabwidget.h" // Needed in inTabWidget()52 #endif // QT_KEYPAD_NAVIGATION53 50 #include <limits.h> 54 51 … … 215 212 216 213 QAbstractSliderPrivate::QAbstractSliderPrivate() 217 : minimum(0), maximum(99), singleStep(1), pageStep(10),218 value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true),214 : minimum(0), maximum(99), pageStep(10), value(0), position(0), pressValue(-1), 215 singleStep(1), offset_accumulated(0), tracking(true), 219 216 blocktracking(false), pressed(false), 220 217 invertedAppearance(false), invertedControls(false), … … 689 686 } 690 687 688 bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta) 689 { 690 Q_Q(QAbstractSlider); 691 int stepsToScroll = 0; 692 // in Qt scrolling to the right gives negative values. 693 if (orientation == Qt::Horizontal) 694 delta = -delta; 695 qreal offset = qreal(delta) / 120; 696 697 if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { 698 // Scroll one page regardless of delta: 699 stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep); 700 offset_accumulated = 0; 701 } else { 702 // Calculate how many lines to scroll. Depending on what delta is (and 703 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can 704 // only scroll whole lines, so we keep the reminder until next event. 705 qreal stepsToScrollF = 706 #ifndef QT_NO_WHEELEVENT 707 QApplication::wheelScrollLines() * 708 #endif 709 offset * effectiveSingleStep(); 710 // Check if wheel changed direction since last event: 711 if (offset_accumulated != 0 && (offset / offset_accumulated) < 0) 712 offset_accumulated = 0; 713 714 offset_accumulated += stepsToScrollF; 715 stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep); 716 offset_accumulated -= int(offset_accumulated); 717 if (stepsToScroll == 0) 718 return false; 719 } 720 721 if (invertedControls) 722 stepsToScroll = -stepsToScroll; 723 724 int prevValue = value; 725 position = overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction() 726 q->triggerAction(QAbstractSlider::SliderMove); 727 728 if (prevValue == value) { 729 offset_accumulated = 0; 730 return false; 731 } 732 return true; 733 } 691 734 692 735 /*! … … 698 741 Q_D(QAbstractSlider); 699 742 e->ignore(); 700 if (e->orientation() != d->orientation && !rect().contains(e->pos())) 701 return; 702 703 int stepsToScroll = 0; 704 qreal offset = qreal(e->delta()) / 120; 705 706 if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) { 707 // Scroll one page regardless of delta: 708 stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep); 709 d->offset_accumulated = 0; 710 } else { 711 // Calculate how many lines to scroll. Depending on what delta is (and 712 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can 713 // only scroll whole lines, so we keep the reminder until next event. 714 qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep(); 715 // Check if wheel changed direction since last event: 716 if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0) 717 d->offset_accumulated = 0; 718 719 d->offset_accumulated += stepsToScrollF; 720 stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep); 721 d->offset_accumulated -= int(d->offset_accumulated); 722 if (stepsToScroll == 0) 723 return; 724 } 725 726 if (d->invertedControls) 727 stepsToScroll = -stepsToScroll; 728 729 int prevValue = d->value; 730 d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction() 731 triggerAction(SliderMove); 732 733 if (prevValue == d->value) 734 d->offset_accumulated = 0; 735 else 743 int delta = e->delta(); 744 if (d->scrollByDelta(e->orientation(), e->modifiers(), delta)) 736 745 e->accept(); 737 746 } 738 #endif 739 #ifdef QT_KEYPAD_NAVIGATION 740 /*! 741 \internal 742 743 Tells us if it there is currently a reachable widget by keypad navigation in 744 a certain \a orientation. 745 If no navigation is possible, occuring key events in that \a orientation may 746 be used to interact with the value in the focussed widget, even though it 747 currently has not the editFocus. 748 749 \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus() 750 */ 751 inline static bool canKeypadNavigate(Qt::Orientation orientation) 752 { 753 return orientation == Qt::Horizontal? 754 (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast) 755 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest)) 756 :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth) 757 || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth)); 758 } 759 /*! 760 \internal 761 762 Checks, if the \a widget is inside a QTabWidget. If is is inside 763 one, left/right key events will be used to switch between tabs in keypad 764 navigation. If there is no QTabWidget, the horizontal key events can be used to 765 interact with the value in the focussed widget, even though it currently has 766 not the editFocus. 767 768 \sa QWidget::hasEditFocus() 769 */ 770 inline static bool inTabWidget(QWidget *widget) 771 { 772 for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget()) 773 if (qobject_cast<const QTabWidget*>(tabWidget)) 774 return true; 775 return false; 776 } 777 #endif // QT_KEYPAD_NAVIGATION 747 748 #endif 749 778 750 /*! 779 751 \reimp … … 841 813 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 842 814 || d->orientation == Qt::Vertical 843 || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { 815 || !hasEditFocus() 816 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) { 844 817 ev->ignore(); 845 818 return; … … 860 833 && (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 861 834 || d->orientation == Qt::Vertical 862 || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) { 835 || !hasEditFocus() 836 && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) { 863 837 ev->ignore(); 864 838 return; … … 880 854 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 881 855 || d->orientation == Qt::Horizontal 882 || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) {856 || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { 883 857 ev->ignore(); 884 858 break; … … 893 867 && (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder 894 868 || d->orientation == Qt::Horizontal 895 || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) {869 || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) { 896 870 ev->ignore(); 897 871 break;
Note:
See TracChangeset
for help on using the changeset viewer.