Fix handle possibly moving to the other side if the cursor exist for a short time.

Remove the handle if the cursor goes away before we even appear, previously the handle
was kept invisible until the cursor next entered.

svn path=/trunk/KDE/kdelibs/; revision=929233
This commit is contained in:
Ambroz Bizjak 2009-02-20 23:23:55 +00:00
parent 8fbb555bbd
commit 205a1700b2
2 changed files with 21 additions and 23 deletions

View File

@ -105,7 +105,7 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet, const QPointF &h
m_leaveTimer->setSingleShot(true);
m_leaveTimer->setInterval(500);
connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(fadeIn()));
connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
connect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed()));
@ -148,7 +148,7 @@ void AppletHandle::detachApplet ()
return;
}
disconnect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(fadeIn()));
disconnect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(hoverTimeout()));
disconnect(m_leaveTimer, SIGNAL(timeout()), this, SLOT(leaveTimeout()));
m_applet->disconnect(this);
@ -772,29 +772,29 @@ void AppletHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
//kDebug() << "hover enter";
//if a disappear was scheduled stop the timer
if (m_leaveTimer->isActive()) {
m_leaveTimer->stop();
}
// if we're already fading out, fade back in
if (m_animId != 0 && m_anim == FadeOut) {
startFading(FadeIn, m_entryPos);
} else {
//schedule appear
m_hoverTimer->start();
else if (m_animId != 0 && m_anim == FadeOut) {
startFading(FadeIn, m_entryPos, true);
}
}
void AppletHandle::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
m_leaveTimer->stop();
hoverEnterEvent(event);
}
void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
m_hoverTimer->stop();
if (m_pressedButton != NoButton) {
// if we haven't even showed up yet, remove the handle
if (m_hoverTimer->isActive()) {
m_hoverTimer->stop();
QTimer::singleShot(0, this, SLOT(emitDisappear()));
} else if (m_pressedButton != NoButton) {
m_pendingFade = true;
} else {
//wait a moment to hide the handle in order to recheck the mouse position
@ -830,7 +830,7 @@ void AppletHandle::fadeAnimation(qreal progress)
update();
}
void AppletHandle::fadeIn()
void AppletHandle::hoverTimeout()
{
startFading(FadeIn, m_entryPos);
}
@ -857,20 +857,16 @@ void AppletHandle::setHoverPos(const QPointF &hoverPos)
m_entryPos = hoverPos;
}
void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos)
void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide)
{
if (m_animId != 0) {
Animator::self()->stopCustomAnimation(m_animId);
}
m_hoverTimer->stop();
m_leaveTimer->stop();
m_entryPos = hoverPos;
qreal time = 100;
if (!m_applet || (anim == FadeOut && m_hoverTimer->isActive())) {
// fading out before we've started fading in
if (!m_applet) {
m_anim = FadeOut;
fadeAnimation(1.0);
return;
@ -880,7 +876,9 @@ void AppletHandle::startFading(FadeType anim, const QPointF &hoverPos)
//kDebug() << m_entryPos.x() << m_applet->pos().x();
prepareGeometryChange();
bool wasOnRight = m_buttonsOnRight;
if (!preserveSide) {
m_buttonsOnRight = m_entryPos.x() > (m_applet->size().width() / 2);
}
calculateSize();
QPolygonF region = mapToParent(m_rect).intersected(parentWidget()->boundingRect());
//kDebug() << region << m_rect << mapToParent(m_rect) << parentWidget()->boundingRect();

View File

@ -63,7 +63,7 @@ class AppletHandle : public QObject, public QGraphicsItem
QRectF boundingRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void startFading(FadeType anim, const QPointF &hoverPos);
void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
void setHoverPos(const QPointF &hoverPos);
protected:
@ -83,7 +83,7 @@ class AppletHandle : public QObject, public QGraphicsItem
void fadeAnimation(qreal progress);
void appletDestroyed();
void appletResized();
void fadeIn();
void hoverTimeout();
void leaveTimeout();
void emitDisappear();