summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authoraxis <qt-info@nokia.com>2009-11-20 07:56:40 (GMT)
committeraxis <qt-info@nokia.com>2009-11-20 07:56:40 (GMT)
commitd9fa92933ff6ff1afad342f7f94e37f810cf8176 (patch)
tree77e2c90877ea528d71755e7322c025c8284636a7 /src/gui/widgets
parenta8c8c2274d2d0a708786adbb357013955f99c0af (diff)
parentc7d7fae74f3b8df9e5b07493a36db31f2c499699 (diff)
downloadQt-d9fa92933ff6ff1afad342f7f94e37f810cf8176.zip
Qt-d9fa92933ff6ff1afad342f7f94e37f810cf8176.tar.gz
Qt-d9fa92933ff6ff1afad342f7f94e37f810cf8176.tar.bz2
Merge branch '4.6' of git@scm.dev.nokia.troll.no:qt/qt-s60-public into 4.6-staging2
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qabstractslider.cpp45
-rw-r--r--src/gui/widgets/qabstractslider_p.h33
2 files changed, 74 insertions, 4 deletions
diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp
index e0db9c2..988a7e7 100644
--- a/src/gui/widgets/qabstractslider.cpp
+++ b/src/gui/widgets/qabstractslider.cpp
@@ -219,6 +219,10 @@ QAbstractSliderPrivate::QAbstractSliderPrivate()
blocktracking(false), pressed(false),
invertedAppearance(false), invertedControls(false),
orientation(Qt::Horizontal), repeatAction(QAbstractSlider::SliderNoAction)
+#ifdef QT_KEYPAD_NAVIGATION
+ , isAutoRepeating(false)
+ , repeatMultiplier(1)
+#endif
{
}
@@ -371,6 +375,9 @@ int QAbstractSlider::maximum() const
abstract sliders provides and typically corresponds to the user
pressing an arrow key.
+ If the property is modified during an auto repeating key event, behavior
+ is undefined.
+
\sa pageStep
*/
@@ -598,10 +605,10 @@ void QAbstractSlider::triggerAction(SliderAction action)
d->blocktracking = true;
switch (action) {
case SliderSingleStepAdd:
- setSliderPosition(d->overflowSafeAdd(d->singleStep));
+ setSliderPosition(d->overflowSafeAdd(d->effectiveSingleStep()));
break;
case SliderSingleStepSub:
- setSliderPosition(d->overflowSafeAdd(-d->singleStep));
+ setSliderPosition(d->overflowSafeAdd(-d->effectiveSingleStep()));
break;
case SliderPageStepAdd:
setSliderPosition(d->overflowSafeAdd(d->pageStep));
@@ -702,7 +709,7 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e)
// 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->singleStep;
+ 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;
@@ -773,6 +780,38 @@ void QAbstractSlider::keyPressEvent(QKeyEvent *ev)
{
Q_D(QAbstractSlider);
SliderAction action = SliderNoAction;
+#ifdef QT_KEYPAD_NAVIGATION
+ if (ev->isAutoRepeat()) {
+ if (d->firstRepeat.isNull())
+ d->firstRepeat = QTime::currentTime();
+ else if (1 == d->repeatMultiplier) {
+ // This is the interval in milli seconds which one key repetition
+ // takes.
+ const int repeatMSecs = d->firstRepeat.msecsTo(QTime::currentTime());
+
+ /**
+ * The time it takes to currently navigate the whole slider.
+ */
+ const qreal currentTimeElapse = (qreal(maximum()) / singleStep()) * repeatMSecs;
+
+ /**
+ * This is an arbitrarily determined constant in msecs that
+ * specifies how long time it should take to navigate from the
+ * start to the end(excluding starting key auto repeat).
+ */
+ const int SliderRepeatElapse = 2500;
+
+ d->repeatMultiplier = currentTimeElapse / SliderRepeatElapse;
+ }
+
+ }
+ else if (!d->firstRepeat.isNull()) {
+ d->firstRepeat = QTime();
+ d->repeatMultiplier = 1;
+ }
+
+#endif
+
switch (ev->key()) {
#ifdef QT_KEYPAD_NAVIGATION
case Qt::Key_Select:
diff --git a/src/gui/widgets/qabstractslider_p.h b/src/gui/widgets/qabstractslider_p.h
index 9324d44..6591981 100644
--- a/src/gui/widgets/qabstractslider_p.h
+++ b/src/gui/widgets/qabstractslider_p.h
@@ -68,7 +68,13 @@ public:
void setSteps(int single, int page);
- int minimum, maximum, singleStep, pageStep, value, position, pressValue;
+ int minimum, maximum, pageStep, value, position, pressValue;
+
+ /**
+ * Call effectiveSingleStep() when changing the slider value.
+ */
+ int singleStep;
+
float offset_accumulated;
uint tracking : 1;
uint blocktracking :1;
@@ -83,8 +89,33 @@ public:
#ifdef QT_KEYPAD_NAVIGATION
int origValue;
+
+ /**
+ */
+ bool isAutoRepeating;
+
+ /**
+ * When we're auto repeating, we multiply singleStep with this value to
+ * get our effective step.
+ */
+ qreal repeatMultiplier;
+
+ /**
+ * The time of when the first auto repeating key press event occurs.
+ */
+ QTime firstRepeat;
+
#endif
+ inline int effectiveSingleStep() const
+ {
+ return singleStep
+#ifdef QT_KEYPAD_NAVIGATION
+ * repeatMultiplier
+#endif
+ ;
+ }
+
inline int bound(int val) const { return qMax(minimum, qMin(maximum, val)); }
inline int overflowSafeAdd(int add) const
{