* 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:
parent
15320f2733
commit
a36c114b4f
@ -84,10 +84,15 @@ AppletHandle::AppletHandle(Containment *parent, Applet *applet)
|
|||||||
matrix.rotateRadians(m_angle);
|
matrix.rotateRadians(m_angle);
|
||||||
matrix.translate(-center.x(), -center.y());
|
matrix.translate(-center.x(), -center.y());
|
||||||
setTransform(matrix);
|
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()));
|
connect(m_applet, SIGNAL(destroyed(QObject*)), this, SLOT(appletDestroyed()));
|
||||||
|
|
||||||
setAcceptsHoverEvents(true);
|
setAcceptsHoverEvents(true);
|
||||||
startFading(FadeIn);
|
m_hoverTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
AppletHandle::~AppletHandle()
|
AppletHandle::~AppletHandle()
|
||||||
@ -452,13 +457,14 @@ void AppletHandle::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
//kDebug() << "hover enter";
|
//kDebug() << "hover enter";
|
||||||
startFading(FadeIn);
|
m_hoverTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
void AppletHandle::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
//kDebug() << "hover leave";
|
//kDebug() << "hover leave";
|
||||||
|
m_hoverTimer->stop();
|
||||||
startFading(FadeOut);
|
startFading(FadeOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -478,6 +484,11 @@ void AppletHandle::fadeAnimation(qreal progress)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppletHandle::fadeIn()
|
||||||
|
{
|
||||||
|
startFading(FadeIn);
|
||||||
|
}
|
||||||
|
|
||||||
void AppletHandle::appletDestroyed()
|
void AppletHandle::appletDestroyed()
|
||||||
{
|
{
|
||||||
m_applet = 0;
|
m_applet = 0;
|
||||||
@ -493,15 +504,16 @@ void AppletHandle::appletResized()
|
|||||||
|
|
||||||
void AppletHandle::startFading(FadeType anim)
|
void AppletHandle::startFading(FadeType anim)
|
||||||
{
|
{
|
||||||
if (m_animId!=0) {
|
if (m_animId != 0) {
|
||||||
Phase::self()->stopCustomAnimation(m_animId);
|
Phase::self()->stopCustomAnimation(m_animId);
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal time = 250;
|
qreal time = 250;
|
||||||
|
|
||||||
if (anim==FadeIn) {
|
if (anim == FadeIn) {
|
||||||
time *= 1.0-m_opacity;
|
time *= 1.0-m_opacity;
|
||||||
} else {
|
} else {
|
||||||
|
m_hoverTimer->stop();
|
||||||
time *= m_opacity;
|
time *= m_opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtGui/QGraphicsItem>
|
#include <QtGui/QGraphicsItem>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "phase.h"
|
#include "phase.h"
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
@ -33,7 +34,7 @@ class Containment;
|
|||||||
|
|
||||||
class AppletHandle : public QObject, public QGraphicsItem
|
class AppletHandle : public QObject, public QGraphicsItem
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
enum FadeType { FadeIn, FadeOut };
|
enum FadeType { FadeIn, FadeOut };
|
||||||
enum ButtonType { NoButton, MoveButton, RotateButton, ConfigureButton, RemoveButton, ResizeButton };
|
enum ButtonType { NoButton, MoveButton, RotateButton, ConfigureButton, RemoveButton, ResizeButton };
|
||||||
@ -45,6 +46,7 @@ class AppletHandle : public QObject, public QGraphicsItem
|
|||||||
|
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
||||||
|
void startFading(FadeType anim);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
@ -61,16 +63,16 @@ class AppletHandle : public QObject, public QGraphicsItem
|
|||||||
void fadeAnimation(qreal progress);
|
void fadeAnimation(qreal progress);
|
||||||
void appletDestroyed();
|
void appletDestroyed();
|
||||||
void appletResized();
|
void appletResized();
|
||||||
|
void fadeIn();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int HANDLE_WIDTH = 5;
|
static const int HANDLE_WIDTH = 5;
|
||||||
static const int ICON_SIZE = 16;
|
static const int ICON_SIZE = 16;
|
||||||
static const int ICON_MARGIN = 8;
|
static const int ICON_MARGIN = 8;
|
||||||
|
|
||||||
void startFading(FadeType anim);
|
|
||||||
void forceDisappear();
|
|
||||||
void calculateSize();
|
void calculateSize();
|
||||||
ButtonType mapToButton(const QPointF &point) const;
|
ButtonType mapToButton(const QPointF &point) const;
|
||||||
|
void forceDisappear();
|
||||||
|
|
||||||
QRectF m_rect;
|
QRectF m_rect;
|
||||||
bool m_buttonsOnRight;
|
bool m_buttonsOnRight;
|
||||||
@ -85,6 +87,7 @@ class AppletHandle : public QObject, public QGraphicsItem
|
|||||||
qreal m_scaleWidth;
|
qreal m_scaleWidth;
|
||||||
qreal m_scaleHeight;
|
qreal m_scaleHeight;
|
||||||
QColor m_gradientColor;
|
QColor m_gradientColor;
|
||||||
|
QTimer *m_hoverTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -776,7 +776,6 @@ void Containment::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
|
|||||||
bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
||||||
{
|
{
|
||||||
Applet *applet = qgraphicsitem_cast<Applet*>(watched);
|
Applet *applet = qgraphicsitem_cast<Applet*>(watched);
|
||||||
//QEvent::GraphicsSceneHoverEnter
|
|
||||||
|
|
||||||
// Otherwise we're watching something we shouldn't be...
|
// Otherwise we're watching something we shouldn't be...
|
||||||
//kDebug() << "got sceneEvent";
|
//kDebug() << "got sceneEvent";
|
||||||
@ -787,19 +786,31 @@ bool Containment::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
|||||||
|
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::GraphicsSceneHoverEnter:
|
case QEvent::GraphicsSceneHoverEnter:
|
||||||
//kDebug() << "got hoverenterEvent" << isImmutable << " " << applet->isImmutable();
|
//kDebug() << "got hoverenterEvent" << isImmutable() << " " << applet->isImmutable();
|
||||||
if (!isImmutable() && !applet->isImmutable() && !d->handles.contains(applet)) {
|
if (!isImmutable() && !applet->isImmutable()) {
|
||||||
//kDebug() << "generated applet handle";
|
if (d->handles.contains(applet)) {
|
||||||
//TODO: there should be a small delay on showing these. they pop up too quickly/easily
|
d->handles[applet]->startFading(AppletHandle::FadeIn);
|
||||||
// right now
|
} else {
|
||||||
AppletHandle *handle = new AppletHandle(this, applet);
|
//kDebug() << "generated applet handle";
|
||||||
d->handles[applet] = handle;
|
//TODO: there should be a small delay on showing these. they pop up too quickly/easily
|
||||||
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
// right now
|
||||||
this, SLOT(handleDisappeared(AppletHandle*)));
|
AppletHandle *handle = new AppletHandle(this, applet);
|
||||||
connect(applet, SIGNAL(geometryChanged()),
|
d->handles[applet] = handle;
|
||||||
handle, SLOT(appletResized()));
|
connect(handle, SIGNAL(disappearDone(AppletHandle*)),
|
||||||
|
this, SLOT(handleDisappeared(AppletHandle*)));
|
||||||
|
connect(applet, SIGNAL(geometryChanged()),
|
||||||
|
handle, SLOT(appletResized()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user