* make handles disapear reliably

* don't pop them immediately so just moving the mouse around the screen doesn't cause tons of flickering handles

based on a patch by Cody. thanks, guy!
CCMAL:fjctracy@gmail.com

svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=759079
This commit is contained in:
Aaron J. Seigo 2008-01-09 23:43:49 +00:00
parent 15320f2733
commit a36c114b4f
3 changed files with 45 additions and 19 deletions

View File

@ -84,10 +84,15 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet)
matrix.rotateRadians(m_angle);
matrix.translate(-center.x(), -center.y());
setTransform(matrix);
m_hoverTimer = new QTimer(this);
m_hoverTimer->setSingleShot(true);
m_hoverTimer->setInterval(300);
connect(m_hoverTimer, SIGNAL(timeout()), this, SLOT(fadeIn()));
connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed()));
setAcceptsHoverEvents(true);
startFading(FadeIn);
m_hoverTimer->start();
}
AppletHandle::~AppletHandle()
@ -452,13 +457,14 @@ void AppletHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
//kDebug() << "hover enter";
startFading(FadeIn);
m_hoverTimer->start();
}
void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{
Q_UNUSED(event);
//kDebug() << "hover leave";
m_hoverTimer->stop();
startFading(FadeOut);
}
@ -478,6 +484,11 @@ void AppletHandle::fadeAnimation(qreal progress)
update();
}
void AppletHandle::fadeIn()
{
startFading(FadeIn);
}
void AppletHandle::appletDestroyed()
{
m_applet = 0;
@ -493,15 +504,16 @@ void AppletHandle::appletResized()
void AppletHandle::startFading(FadeType anim)
{
if (m_animId!=0) {
if (m_animId != 0) {
Phase::self()->stopCustomAnimation(m_animId);
}
qreal time = 250;
if (anim==FadeIn) {
if (anim == FadeIn) {
time *= 1.0-m_opacity;
} else {
m_hoverTimer->stop();
time *= m_opacity;
}

View File

@ -22,6 +22,7 @@
#include <QtCore/QObject>
#include <QtGui/QGraphicsItem>
#include <QTimer>
#include "phase.h"
#include "svg.h"
@ -33,7 +34,7 @@ class Containment;
class AppletHandle : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_OBJECT
public:
enum FadeType { FadeIn, FadeOut };
enum ButtonType { NoButton, MoveButton, RotateButton, ConfigureButton, RemoveButton, ResizeButton };
@ -45,6 +46,7 @@ class AppletHandle : public QObject, public QGraphicsItem
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
void startFading(FadeType anim);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
@ -61,16 +63,16 @@ class AppletHandle : public QObject, public QGraphicsItem
void fadeAnimation(qreal progress);
void appletDestroyed();
void appletResized();
void fadeIn();
private:
static const int HANDLE_WIDTH = 5;
static const int ICON_SIZE = 16;
static const int ICON_MARGIN = 8;
void startFading(FadeType anim);
void forceDisappear();
void calculateSize();
ButtonType mapToButton(const QPointF &point) const;
void forceDisappear();
QRectF m_rect;
bool m_buttonsOnRight;
@ -85,6 +87,7 @@ class AppletHandle : public QObject, public QGraphicsItem
qreal m_scaleWidth;
qreal m_scaleHeight;
QColor m_gradientColor;
QTimer *m_hoverTimer;
};
}

View File

@ -776,7 +776,6 @@ void Containment::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
{
Applet *applet = qgraphicsitem_cast<Applet*>(watched);
//QEvent::GraphicsSceneHoverEnter
// Otherwise we're watching something we shouldn't be...
//kDebug() << "got sceneEvent";
@ -787,19 +786,31 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
switch (event->type()) {
case QEvent::GraphicsSceneHoverEnter:
//kDebug() << "got hoverenterEvent" << isImmutable << " " << applet->isImmutable();
if (!isImmutable() && !applet->isImmutable() && !d->handles.contains(applet)) {
//kDebug() << "generated applet handle";
//TODO: there should be a small delay on showing these. they pop up too quickly/easily
// right now
AppletHandle *handle = new AppletHandle(this, applet);
d->handles[applet] = handle;
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
this, SLOT(handleDisappeared(AppletHandle*)));
connect(applet, SIGNAL(geometryChanged()),
handle, SLOT(appletResized()));
//kDebug() << "got hoverenterEvent" << isImmutable() << " " << applet->isImmutable();
if (!isImmutable() && !applet->isImmutable()) {
if (d->handles.contains(applet)) {
d->handles[applet]->startFading(AppletHandle::FadeIn);
} else {
//kDebug() << "generated applet handle";
//TODO: there should be a small delay on showing these. they pop up too quickly/easily
// right now
AppletHandle *handle = new AppletHandle(this, applet);
d->handles[applet] = handle;
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
this, SLOT(handleDisappeared(AppletHandle*)));
connect(applet, SIGNAL(geometryChanged()),
handle, SLOT(appletResized()));
}
}
break;
case QEvent::GraphicsSceneHoverLeave:
//kDebug() << "got hoverLeaveEvent";
if (d->handles.contains(applet)) {
QGraphicsSceneHoverEvent *he = static_cast<QGraphicsSceneHoverEvent *>(event);
if (!d->handles[applet]->boundingRect().contains(he->scenePos())) {
d->handles[applet]->startFading(AppletHandle::FadeOut);
}
}
default:
break;
}