summaryrefslogtreecommitdiffstats
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-20 14:08:26 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-20 14:08:26 (GMT)
commit991a5ed5a8dc0c81d56c88823bd69d986618d4e5 (patch)
treed0391f75f14d3dfcf10773006869da3b574dd136 /src/gui/widgets
parentea990fc4c575a76c46464e8b8caa2a03c64f067b (diff)
parentd9fa92933ff6ff1afad342f7f94e37f810cf8176 (diff)
downloadQt-991a5ed5a8dc0c81d56c88823bd69d986618d4e5.zip
Qt-991a5ed5a8dc0c81d56c88823bd69d986618d4e5.tar.gz
Qt-991a5ed5a8dc0c81d56c88823bd69d986618d4e5.tar.bz2
Merge commit 'd9fa92' into origin-4.6
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/qabstractslider.cpp45
-rw-r--r--src/gui/widgets/qabstractslider_p.h33
-rw-r--r--src/gui/widgets/qcommandlinkbutton.cpp3
-rw-r--r--src/gui/widgets/qsizegrip.cpp29
4 files changed, 97 insertions, 13 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
{
diff --git a/src/gui/widgets/qcommandlinkbutton.cpp b/src/gui/widgets/qcommandlinkbutton.cpp
index 9adf280..8f47f25 100644
--- a/src/gui/widgets/qcommandlinkbutton.cpp
+++ b/src/gui/widgets/qcommandlinkbutton.cpp
@@ -326,7 +326,8 @@ int QCommandLinkButton::heightForWidth(int width) const
Q_D(const QCommandLinkButton);
int heightWithoutDescription = d->descriptionOffset() + d->bottomMargin();
// find the width available for the description area
- return heightWithoutDescription + d->descriptionHeight(width);
+ return qMax(heightWithoutDescription + d->descriptionHeight(width),
+ iconSize().height() + d->topMargin() + d->bottomMargin());
}
/*! \reimp */
diff --git a/src/gui/widgets/qsizegrip.cpp b/src/gui/widgets/qsizegrip.cpp
index cf193dc..6575dbb 100644
--- a/src/gui/widgets/qsizegrip.cpp
+++ b/src/gui/widgets/qsizegrip.cpp
@@ -99,6 +99,7 @@ public:
int dyMax;
Qt::Corner m_corner;
bool gotMousePress;
+ QWidget *tlw;
#ifdef Q_WS_MAC
void updateMacSizer(bool hide) const;
#endif
@@ -113,6 +114,19 @@ public:
return m_corner == Qt::BottomLeftCorner || m_corner == Qt::TopLeftCorner;
}
+ void updateTopLevelWidget()
+ {
+ Q_Q(QSizeGrip);
+ QWidget *w = qt_sizegrip_topLevelWidget(q);
+ if (tlw == w)
+ return;
+ if (tlw)
+ tlw->removeEventFilter(q);
+ tlw = w;
+ if (tlw)
+ tlw->installEventFilter(q);
+ }
+
// This slot is invoked by QLayout when the size grip is added to
// a layout or reparented after the tlw is shown. This re-implementation is basically
// the same as QWidgetPrivate::_q_showIfNotHidden except that it checks
@@ -121,7 +135,7 @@ public:
{
Q_Q(QSizeGrip);
bool showSizeGrip = !(q->isHidden() && q->testAttribute(Qt::WA_WState_ExplicitShowHide));
- QWidget *tlw = qt_sizegrip_topLevelWidget(q);
+ updateTopLevelWidget();
if (tlw && showSizeGrip) {
Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
#ifndef Q_WS_MAC
@@ -232,6 +246,7 @@ void QSizeGripPrivate::init()
Q_Q(QSizeGrip);
dxMax = 0;
dyMax = 0;
+ tlw = 0;
m_corner = q->isLeftToRight() ? Qt::BottomRightCorner : Qt::BottomLeftCorner;
gotMousePress = false;
@@ -240,8 +255,7 @@ void QSizeGripPrivate::init()
? Qt::SizeFDiagCursor : Qt::SizeBDiagCursor);
#endif
q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed));
- QWidget *tlw = qt_sizegrip_topLevelWidget(q);
- tlw->installEventFilter(q);
+ updateTopLevelWidget();
}
@@ -524,19 +538,18 @@ void QSizeGrip::setVisible(bool visible)
/*! \reimp */
bool QSizeGrip::eventFilter(QObject *o, QEvent *e)
{
+ Q_D(QSizeGrip);
if ((isHidden() && testAttribute(Qt::WA_WState_ExplicitShowHide))
- || e->type() != QEvent::WindowStateChange) {
+ || e->type() != QEvent::WindowStateChange
+ || o != d->tlw) {
return QWidget::eventFilter(o, e);
}
- QWidget *tlw = qt_sizegrip_topLevelWidget(this);
- if (o != tlw)
- return QWidget::eventFilter(o, e);
Qt::WindowStates sizeGripNotVisibleState = Qt::WindowFullScreen;
#ifndef Q_WS_MAC
sizeGripNotVisibleState |= Qt::WindowMaximized;
#endif
// Don't show the size grip if the tlw is maximized or in full screen mode.
- setVisible(!(tlw->windowState() & sizeGripNotVisibleState));
+ setVisible(!(d->tlw->windowState() & sizeGripNotVisibleState));
setAttribute(Qt::WA_WState_ExplicitShowHide, false);
return QWidget::eventFilter(o, e);
}