--- a/src/gui/widgets/qabstractslider.cpp Tue Feb 02 00:43:10 2010 +0200
+++ b/src/gui/widgets/qabstractslider.cpp Wed Mar 31 11:06:36 2010 +0300
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
@@ -47,9 +47,6 @@
#ifndef QT_NO_ACCESSIBILITY
#include "qaccessible.h"
#endif
-#ifdef QT_KEYPAD_NAVIGATION
-#include "qtabwidget.h" // Needed in inTabWidget()
-#endif // QT_KEYPAD_NAVIGATION
#include <limits.h>
QT_BEGIN_NAMESPACE
@@ -214,8 +211,8 @@
*/
QAbstractSliderPrivate::QAbstractSliderPrivate()
- : minimum(0), maximum(99), singleStep(1), pageStep(10),
- value(0), position(0), pressValue(-1), offset_accumulated(0), tracking(true),
+ : minimum(0), maximum(99), pageStep(10), value(0), position(0), pressValue(-1),
+ singleStep(1), offset_accumulated(0), tracking(true),
blocktracking(false), pressed(false),
invertedAppearance(false), invertedControls(false),
orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction)
@@ -688,6 +685,52 @@
update();
}
+bool QAbstractSliderPrivate::scrollByDelta(Qt::Orientation orientation, Qt::KeyboardModifiers modifiers, int delta)
+{
+ Q_Q(QAbstractSlider);
+ int stepsToScroll = 0;
+ // in Qt scrolling to the right gives negative values.
+ if (orientation == Qt::Horizontal)
+ delta = -delta;
+ qreal offset = qreal(delta) / 120;
+
+ if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) {
+ // Scroll one page regardless of delta:
+ stepsToScroll = qBound(-pageStep, int(offset * pageStep), pageStep);
+ offset_accumulated = 0;
+ } else {
+ // Calculate how many lines to scroll. Depending on what delta is (and
+ // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can
+ // only scroll whole lines, so we keep the reminder until next event.
+ qreal stepsToScrollF =
+#ifndef QT_NO_WHEELEVENT
+ QApplication::wheelScrollLines() *
+#endif
+ offset * effectiveSingleStep();
+ // Check if wheel changed direction since last event:
+ if (offset_accumulated != 0 && (offset / offset_accumulated) < 0)
+ offset_accumulated = 0;
+
+ offset_accumulated += stepsToScrollF;
+ stepsToScroll = qBound(-pageStep, int(offset_accumulated), pageStep);
+ offset_accumulated -= int(offset_accumulated);
+ if (stepsToScroll == 0)
+ return false;
+ }
+
+ if (invertedControls)
+ stepsToScroll = -stepsToScroll;
+
+ int prevValue = value;
+ position = overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
+ q->triggerAction(QAbstractSlider::SliderMove);
+
+ if (prevValue == value) {
+ offset_accumulated = 0;
+ return false;
+ }
+ return true;
+}
/*!
\reimp
@@ -697,82 +740,13 @@
{
Q_D(QAbstractSlider);
e->ignore();
-
- int stepsToScroll = 0;
- qreal offset = qreal(e->delta()) / 120;
-
- if ((e->modifiers() & Qt::ControlModifier) || (e->modifiers() & Qt::ShiftModifier)) {
- // Scroll one page regardless of delta:
- stepsToScroll = qBound(-d->pageStep, int(offset * d->pageStep), d->pageStep);
- d->offset_accumulated = 0;
- } else {
- // Calculate how many lines to scroll. Depending on what delta is (and
- // offset), we might end up with a fraction (e.g. scroll 1.3 lines). We can
- // only scroll whole lines, so we keep the reminder until next event.
- qreal stepsToScrollF = offset * QApplication::wheelScrollLines() * d->effectiveSingleStep();
- // Check if wheel changed direction since last event:
- if (d->offset_accumulated != 0 && (offset / d->offset_accumulated) < 0)
- d->offset_accumulated = 0;
-
- d->offset_accumulated += stepsToScrollF;
- stepsToScroll = qBound(-d->pageStep, int(d->offset_accumulated), d->pageStep);
- d->offset_accumulated -= int(d->offset_accumulated);
- if (stepsToScroll == 0)
- return;
- }
-
- if (d->invertedControls)
- stepsToScroll = -stepsToScroll;
-
- int prevValue = d->value;
- d->position = d->overflowSafeAdd(stepsToScroll); // value will be updated by triggerAction()
- triggerAction(SliderMove);
-
- if (prevValue == d->value)
- d->offset_accumulated = 0;
- else
+ int delta = e->delta();
+ if (d->scrollByDelta(e->orientation(), e->modifiers(), delta))
e->accept();
}
-#endif
-#ifdef QT_KEYPAD_NAVIGATION
-/*!
- \internal
-
- Tells us if it there is currently a reachable widget by keypad navigation in
- a certain \a orientation.
- If no navigation is possible, occuring key events in that \a orientation may
- be used to interact with the value in the focussed widget, even though it
- currently has not the editFocus.
- \sa QWidgetPrivate::widgetInNavigationDirection(), QWidget::hasEditFocus()
-*/
-inline static bool canKeypadNavigate(Qt::Orientation orientation)
-{
- return orientation == Qt::Horizontal?
- (QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionEast)
- || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionWest))
- :(QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionNorth)
- || QWidgetPrivate::widgetInNavigationDirection(QWidgetPrivate::DirectionSouth));
-}
-/*!
- \internal
+#endif
- Checks, if the \a widget is inside a QTabWidget. If is is inside
- one, left/right key events will be used to switch between tabs in keypad
- navigation. If there is no QTabWidget, the horizontal key events can be used to
- interact with the value in the focussed widget, even though it currently has
- not the editFocus.
-
- \sa QWidget::hasEditFocus()
-*/
-inline static bool inTabWidget(QWidget *widget)
-{
- for (QWidget *tabWidget = widget; tabWidget; tabWidget = tabWidget->parentWidget())
- if (qobject_cast<const QTabWidget*>(tabWidget))
- return true;
- return false;
-}
-#endif // QT_KEYPAD_NAVIGATION
/*!
\reimp
*/
@@ -838,7 +812,8 @@
if (QApplication::keypadNavigationEnabled()
&& (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Vertical
- || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) {
+ || !hasEditFocus()
+ && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) {
ev->ignore();
return;
}
@@ -857,7 +832,8 @@
if (QApplication::keypadNavigationEnabled()
&& (!hasEditFocus() && QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Vertical
- || !hasEditFocus() && (canKeypadNavigate(Qt::Horizontal) || inTabWidget(this)))) {
+ || !hasEditFocus()
+ && (QWidgetPrivate::canKeypadNavigate(Qt::Horizontal) || QWidgetPrivate::inTabWidget(this)))) {
ev->ignore();
return;
}
@@ -877,7 +853,7 @@
if (QApplication::keypadNavigationEnabled()
&& (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Horizontal
- || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) {
+ || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) {
ev->ignore();
break;
}
@@ -890,7 +866,7 @@
if (QApplication::keypadNavigationEnabled()
&& (QApplication::navigationMode() == Qt::NavigationModeKeypadTabOrder
|| d->orientation == Qt::Horizontal
- || !hasEditFocus() && canKeypadNavigate(Qt::Vertical))) {
+ || !hasEditFocus() && QWidgetPrivate::canKeypadNavigate(Qt::Vertical))) {
ev->ignore();
break;
}