Commit e855b199319c932f2e9500235775f961bc32e41a
- Diff rendering mode:
- inline
- side by side
src/gui/widgets/qabstractslider.cpp
(40 / 27)
|   | |||
| 688 | 688 | update(); | |
| 689 | 689 | } | |
| 690 | 690 | ||
| 691 | |||
| 692 | /*! | ||
| 693 | \reimp | ||
| 694 | */ | ||
| 695 | #ifndef QT_NO_WHEELEVENT | ||
| 696 | void QAbstractSlider::wheelEvent(QWheelEvent * e) | ||
| 691 | bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta) | ||
| 697 | 692 | { | |
| 698 | Q_D(QAbstractSlider); | ||
| 699 | e->ignore(); | ||
| 700 | |||
| 693 | Q_Q(QAbstractSlider); | ||
| 701 | 694 | 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; | ||
| 703 | 699 | ||
| 704 | if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) { | ||
| 700 | if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { | ||
| 705 | 701 | // 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; | ||
| 708 | 704 | } else { | |
| 709 | 705 | // Calculate how many lines to scroll. Depending on what delta is (and | |
| 710 | 706 | // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can | |
| 711 | 707 | // 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(); | ||
| 713 | 709 | // 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; | ||
| 716 | 712 | ||
| 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); | ||
| 720 | 716 | if (stepsToScroll == 0) | |
| 721 | return; | ||
| 717 | return false; | ||
| 722 | 718 | } | |
| 723 | 719 | ||
| 724 | if (d->invertedControls) | ||
| 720 | if (invertedControls) | ||
| 725 | 721 | stepsToScroll = -stepsToScroll; | |
| 726 | 722 | ||
| 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); | ||
| 730 | 726 | ||
| 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 | ||
| 738 | void 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)) | ||
| 734 | 746 | e->accept(); | |
| 735 | 747 | } | |
| 748 | |||
| 736 | 749 | #endif | |
| 737 | 750 | #ifdef QT_KEYPAD_NAVIGATION | |
| 738 | 751 | /*! |
|   | |||
| 138 | 138 | } | |
| 139 | 139 | q->triggerAction(repeatAction); | |
| 140 | 140 | } | |
| 141 | bool scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta); | ||
| 141 | 142 | }; | |
| 142 | 143 | ||
| 143 | 144 | QT_END_NAMESPACE |
src/gui/widgets/qscrollbar.cpp
(16 / 0)
|   | |||
| 521 | 521 | if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event)) | |
| 522 | 522 | d_func()->updateHoverControl(he->pos()); | |
| 523 | 523 | 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 | } | ||
| 524 | 540 | default: | |
| 525 | 541 | break; | |
| 526 | 542 | } |

