2008-11-04 00:08:39 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 by Kevin Ottens <ervin@kde.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLASMA_APPLETHANDLE_P_H
|
|
|
|
#define PLASMA_APPLETHANDLE_P_H
|
|
|
|
|
|
|
|
#include <QtCore/QObject>
|
2009-10-14 20:59:44 +02:00
|
|
|
#include <QtGui/QGraphicsObject>
|
2008-11-04 00:08:39 +01:00
|
|
|
#include <QTimer>
|
2010-01-19 18:59:24 +01:00
|
|
|
#include <QWeakPointer>
|
|
|
|
#include <QPropertyAnimation>
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
#include "animator.h"
|
|
|
|
#include "svg.h"
|
|
|
|
|
|
|
|
class QGraphicsView;
|
|
|
|
|
|
|
|
namespace Plasma
|
|
|
|
{
|
|
|
|
class Applet;
|
|
|
|
class Containment;
|
|
|
|
class FrameSvg;
|
|
|
|
class View;
|
|
|
|
|
2009-10-14 20:59:44 +02:00
|
|
|
class AppletHandle : public QGraphicsObject
|
2008-11-04 00:08:39 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
2010-01-25 15:09:38 +01:00
|
|
|
Q_PROPERTY(qreal fadeAnimation READ fadeAnimation WRITE setFadeAnimation)
|
2009-09-20 14:53:16 +02:00
|
|
|
Q_INTERFACES(QGraphicsItem)
|
2008-11-04 00:08:39 +01:00
|
|
|
public:
|
|
|
|
enum FadeType {
|
|
|
|
FadeIn,
|
|
|
|
FadeOut
|
|
|
|
};
|
|
|
|
enum ButtonType {
|
|
|
|
NoButton,
|
|
|
|
MoveButton,
|
|
|
|
RotateButton,
|
|
|
|
ConfigureButton,
|
|
|
|
RemoveButton,
|
2009-09-16 19:08:45 +02:00
|
|
|
ResizeButton,
|
|
|
|
MaximizeButton
|
2008-11-04 00:08:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
AppletHandle(Containment *parent, Applet *applet, const QPointF &hoverPos);
|
|
|
|
virtual ~AppletHandle();
|
|
|
|
|
|
|
|
void detachApplet ();
|
|
|
|
|
|
|
|
Applet *applet() const;
|
|
|
|
|
|
|
|
QRectF boundingRect() const;
|
|
|
|
QPainterPath shape() const;
|
|
|
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
|
2009-02-21 00:23:55 +01:00
|
|
|
void startFading(FadeType anim, const QPointF &hoverPos, bool preserveSide = false);
|
2008-11-11 01:57:08 +01:00
|
|
|
void setHoverPos(const QPointF &hoverPos);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
|
2009-11-14 18:33:00 +01:00
|
|
|
bool sceneEvent(QEvent*);
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void disappearDone(AppletHandle *self);
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2010-01-19 18:59:24 +01:00
|
|
|
void setFadeAnimation(qreal progress);
|
|
|
|
qreal fadeAnimation() const;
|
2008-11-04 00:08:39 +01:00
|
|
|
void appletDestroyed();
|
|
|
|
void appletResized();
|
2009-02-21 00:23:55 +01:00
|
|
|
void hoverTimeout();
|
2008-11-04 00:08:39 +01:00
|
|
|
void leaveTimeout();
|
|
|
|
void emitDisappear();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int HANDLE_MARGIN = 3;
|
|
|
|
|
|
|
|
void calculateSize();
|
|
|
|
ButtonType mapToButton(const QPointF &point) const;
|
|
|
|
void forceDisappear();
|
|
|
|
int minimumHeight();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* move our applet to another containment
|
|
|
|
* @param containment the containment to move to
|
|
|
|
* @param pos the (scene-relative) position to place it at
|
|
|
|
*/
|
|
|
|
void switchContainment(Containment *containment, const QPointF &pos);
|
|
|
|
bool leaveCurrentView(const QPoint &pos) const;
|
|
|
|
|
|
|
|
QRectF m_rect;
|
|
|
|
QRectF m_decorationRect;
|
|
|
|
QRectF m_totalRect;
|
|
|
|
ButtonType m_pressedButton;
|
|
|
|
Containment *m_containment;
|
|
|
|
Applet *m_applet;
|
|
|
|
int m_iconSize;
|
|
|
|
qreal m_opacity;
|
2010-01-25 15:09:38 +01:00
|
|
|
FadeType m_animType;
|
2010-01-19 18:59:24 +01:00
|
|
|
QWeakPointer<QPropertyAnimation> m_anim;
|
2008-11-04 00:08:39 +01:00
|
|
|
qreal m_angle;
|
|
|
|
QColor m_gradientColor;
|
|
|
|
QTimer *m_hoverTimer;
|
|
|
|
QTimer *m_leaveTimer;
|
|
|
|
QPixmap *m_backgroundBuffer;
|
|
|
|
QGraphicsView *m_currentView;
|
|
|
|
|
|
|
|
Svg *m_configureIcons;
|
|
|
|
FrameSvg *m_background;
|
|
|
|
|
|
|
|
QPoint m_mousePos; //mousepos relative to applet
|
|
|
|
QPointF m_entryPos; //where the hover in event occurred
|
|
|
|
qreal m_zValue; //current zValue of the applet, so it can be restored after drag.
|
2009-02-09 16:09:28 +01:00
|
|
|
QRectF m_originalGeom;
|
|
|
|
QTransform m_originalTransform;
|
2008-12-24 16:13:09 +01:00
|
|
|
|
|
|
|
// used for both resize and rotate
|
|
|
|
QPointF m_origAppletCenter;
|
|
|
|
QPointF m_origAppletSize;
|
|
|
|
|
|
|
|
// used for resize
|
|
|
|
QPointF m_resizeStaticPoint;
|
|
|
|
QPointF m_resizeGrabPoint;
|
|
|
|
// used for rotate
|
|
|
|
qreal m_rotateAngleOffset; // applet angle minus cursor angle
|
2008-11-04 00:08:39 +01:00
|
|
|
|
|
|
|
bool m_buttonsOnRight : 1;
|
|
|
|
bool m_pendingFade : 1;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // multiple inclusion guard
|