Commit e855b199319c932f2e9500235775f961bc32e41a

Fixes scrolling horizontally with a mouse wheel over sliders.

When scrolling horizontally over sliders the slider should go to the right,
which means the value of the slider should increase. However in Qt scrolling
with a mouse wheel horizontally means the delta value is negative, which is
wrong. So changed the delta to be inversed.

Reviewed-by: Richard Moe Gustavsen
  
688688 update();
689689}
690690
691
692/*!
693 \reimp
694*/
695#ifndef QT_NO_WHEELEVENT
696void QAbstractSlider::wheelEvent(QWheelEvent * e)
691bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta)
697692{
698 Q_D(QAbstractSlider);
699 e->ignore();
700
693 Q_Q(QAbstractSlider);
701694 int stepsToScroll = 0;
702 qreal offset = qreal(e->delta()) / 120;
695 // in Qt scrolling to the right gives negative values.
696 if (orientation == Qt::Horizontal)
697 delta = -delta;
698 qreal offset = qreal(delta) / 120;
703699
704 if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) {
700 if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
705701 // Scroll one page regardless of delta:
706 stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep);
707 d->offset_accumulated = 0;
702 stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep);
703 offset_accumulated = 0;
708704 } else {
709705 // Calculate how many lines to scroll. Depending on what delta is (and
710706 // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can
711707 // only scroll whole lines, so we keep the reminder until next event.
712 qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep();
708 qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * effectiveSingleStep();
713709 // Check if wheel changed direction since last event:
714 if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0)
715 d->offset_accumulated = 0;
710 if (offset_accumulated != 0 && (offset / offset_accumulated) < 0)
711 offset_accumulated = 0;
716712
717 d->offset_accumulated += stepsToScrollF;
718 stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep);
719 d->offset_accumulated -= int(d->offset_accumulated);
713 offset_accumulated += stepsToScrollF;
714 stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep);
715 offset_accumulated -= int(offset_accumulated);
720716 if (stepsToScroll == 0)
721 return;
717 return false;
722718 }
723719
724 if (d->invertedControls)
720 if (invertedControls)
725721 stepsToScroll = -stepsToScroll;
726722
727 int prevValue = d->value;
728 d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
729 triggerAction(SliderMove);
723 int prevValue = value;
724 position = overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
725 q->triggerAction(QAbstractSlider::SliderMove);
730726
731 if (prevValue == d->value)
732 d->offset_accumulated = 0;
733 else
727 if (prevValue == value) {
728 offset_accumulated = 0;
729 return false;
730 }
731 return true;
732}
733
734/*!
735 \reimp
736*/
737#ifndef QT_NO_WHEELEVENT
738void QAbstractSlider::wheelEvent(QWheelEvent * e)
739{
740 Q_D(QAbstractSlider);
741 e->ignore();
742 if (e->orientation() != d->orientation && !rect().contains(e->pos()))
743 return;
744 int delta = e->delta();
745 if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
734746 e->accept();
735747}
748
736749#endif
737750#ifdef QT_KEYPAD_NAVIGATION
738751/*!
  
138138 }
139139 q->triggerAction(repeatAction);
140140 }
141 bool scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta);
141142};
142143
143144QT_END_NAMESPACE
  
521521 if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
522522 d_func()->updateHoverControl(he->pos());
523523 break;
524 case QEvent::Wheel: {
525 // override wheel event without adding virtual function override
526 QWheelEvent *ev = static_cast<QWheelEvent *>(event);
527 int delta = ev->delta();
528 // scrollbar is a special case - in vertical mode it reaches minimum
529 // value in the upper position, however QSlider's minimum value is on
530 // the bottom. So we need to invert a value, but since the scrollbar is
531 // inverted by default, we need to inverse the delta value for the
532 // horizontal orientation.
533 if (ev->orientation() == Qt::Horizontal)
534 delta = -delta;
535 Q_D(QScrollBar);
536 if (d->scrollByDelta(ev->orientation(), ev->modifiers(), delta))
537 event->accept();
538 return true;
539 }
524540 default:
525541 break;
526542 }