Ensure the timer is killed when appropriate before starting a new one

When the mouse moves while the sloppy menu timer is still running then it
would end up just creating a new one and the old one would continue to
run. If the action that it is relevant for is different then it should
restart the timer, otherwise it should just ignore the mouse move and let
the other timer continue.

Change-Id: Id03014fa05596bd6ede887fa917e21ca5a7690d8
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
This commit is contained in:
Andy Shaw 2013-08-26 12:05:54 +02:00 committed by The Qt Project
parent 0278310f9e
commit cdbf8dd276

View File

@ -2864,8 +2864,15 @@ void QMenu::mouseMoveEvent(QMouseEvent *e)
d->mouseDown = this;
}
if (d->sloppyRegion.contains(e->pos())) {
d->sloppyAction = action;
QMenuPrivate::sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this)*6);
// If the timer is already running then don't start a new one unless the action is the same
if (d->sloppyAction != action && QMenuPrivate::sloppyDelayTimer != 0) {
killTimer(QMenuPrivate::sloppyDelayTimer);
QMenuPrivate::sloppyDelayTimer = 0;
}
if (QMenuPrivate::sloppyDelayTimer == 0) {
d->sloppyAction = action;
QMenuPrivate::sloppyDelayTimer = startTimer(style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this) * 6);
}
} else if (action != d->currentAction) {
d->setCurrentAction(action, style()->styleHint(QStyle::SH_Menu_SubMenuPopupDelay, 0, this));
}