src/gui/widgets/qabstractslider.cpp
changeset 18 2f34d5167611
parent 3 41300fa6a67c
child 19 fcece45ef507
equal deleted inserted replaced
3:41300fa6a67c 18:2f34d5167611
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     7 ** This file is part of the QtGui module of the Qt Toolkit.
     8 **
     8 **
   212     \value SliderStepsChange
   212     \value SliderStepsChange
   213     \value SliderValueChange
   213     \value SliderValueChange
   214 */
   214 */
   215 
   215 
   216 QAbstractSliderPrivate::QAbstractSliderPrivate()
   216 QAbstractSliderPrivate::QAbstractSliderPrivate()
   217     : minimum(0), maximum(99), singleStep(1), pageStep(10),
   217     : minimum(0), maximum(99), pageStep(10), value(0), position(0), pressValue(-1),
   218       value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true),
   218       singleStep(1), offset_accumulated(0), tracking(true),
   219       blocktracking(false), pressed(false),
   219       blocktracking(false), pressed(false),
   220       invertedAppearance(false), invertedControls(false),
   220       invertedAppearance(false), invertedControls(false),
   221       orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction)
   221       orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction)
   222 #ifdef QT_KEYPAD_NAVIGATION
   222 #ifdef QT_KEYPAD_NAVIGATION
   223       , isAutoRepeating(false)
   223       , isAutoRepeating(false)
   686 void QAbstractSlider::sliderChange(SliderChange)
   686 void QAbstractSlider::sliderChange(SliderChange)
   687 {
   687 {
   688     update();
   688     update();
   689 }
   689 }
   690 
   690 
   691 
   691 bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta)
   692 /*!
   692 {
   693     \reimp
   693     Q_Q(QAbstractSlider);
   694 */
       
   695 #ifndef QT_NO_WHEELEVENT
       
   696 void QAbstractSlider::wheelEvent(QWheelEvent * e)
       
   697 {
       
   698     Q_D(QAbstractSlider);
       
   699     e->ignore();
       
   700 
       
   701     int stepsToScroll = 0;
   694     int stepsToScroll = 0;
   702     qreal offset = qreal(e->delta()) / 120;
   695     // in Qt scrolling to the right gives negative values.
   703 
   696     if (orientation == Qt::Horizontal)
   704     if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) {
   697         delta = -delta;
       
   698     qreal offset = qreal(delta) / 120;
       
   699 
       
   700     if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
   705         // Scroll one page regardless of delta:
   701         // Scroll one page regardless of delta:
   706         stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep);
   702         stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep);
   707         d->offset_accumulated = 0;
   703         offset_accumulated = 0;
   708     } else {
   704     } else {
   709         // Calculate how many lines to scroll. Depending on what delta is (and 
   705         // Calculate how many lines to scroll. Depending on what delta is (and 
   710         // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can
   706         // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can
   711         // only scroll whole lines, so we keep the reminder until next event.
   707         // only scroll whole lines, so we keep the reminder until next event.
   712         qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep();
   708         qreal stepsToScrollF =
       
   709 #ifndef QT_NO_WHEELEVENT
       
   710                 QApplication::wheelScrollLines() *
       
   711 #endif
       
   712                 offset * effectiveSingleStep();
   713         // Check if wheel changed direction since last event:
   713         // Check if wheel changed direction since last event:
   714         if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0)
   714         if (offset_accumulated != 0 && (offset / offset_accumulated) < 0)
   715             d->offset_accumulated = 0;
   715             offset_accumulated = 0;
   716 
   716 
   717         d->offset_accumulated += stepsToScrollF;
   717         offset_accumulated += stepsToScrollF;
   718         stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep);
   718         stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep);
   719         d->offset_accumulated -= int(d->offset_accumulated);
   719         offset_accumulated -= int(offset_accumulated);
   720         if (stepsToScroll == 0)
   720         if (stepsToScroll == 0)
   721             return;
   721             return false;
   722     }
   722     }
   723 
   723 
   724     if (d->invertedControls)
   724     if (invertedControls)
   725         stepsToScroll = -stepsToScroll;
   725         stepsToScroll = -stepsToScroll;
   726 
   726 
   727     int prevValue = d->value;
   727     int prevValue = value;
   728     d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
   728     position = overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
   729     triggerAction(SliderMove);
   729     q->triggerAction(QAbstractSlider::SliderMove);
   730 
   730 
   731     if (prevValue == d->value)
   731     if (prevValue == value) {
   732         d->offset_accumulated = 0;
   732         offset_accumulated = 0;
   733     else
   733         return false;
       
   734     }
       
   735     return true;
       
   736 }
       
   737 
       
   738 /*!
       
   739     \reimp
       
   740 */
       
   741 #ifndef QT_NO_WHEELEVENT
       
   742 void QAbstractSlider::wheelEvent(QWheelEvent * e)
       
   743 {
       
   744     Q_D(QAbstractSlider);
       
   745     e->ignore();
       
   746     int delta = e->delta();
       
   747     if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
   734         e->accept();
   748         e->accept();
   735 }
   749 }
       
   750 
   736 #endif
   751 #endif
   737 #ifdef QT_KEYPAD_NAVIGATION
   752 #ifdef QT_KEYPAD_NAVIGATION
   738 /*!
   753 /*!
   739     \internal
   754     \internal
   740 
   755