~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to libs/plasmagenericshell/abstracticon.h

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *   Copyright (C) 2009 by Ana Cecília Martins <anaceciliamb@gmail.com>
 
3
 *   Copyright (C) 2010 by Chani Armitage <chani@kde.org>
 
4
 *
 
5
 *   This program is free software; you can redistribute it and/or modify
 
6
 *   it under the terms of the GNU Library/Lesser General Public License
 
7
 *   version 2, or (at your option) any later version, as published by the
 
8
 *   Free Software Foundation
 
9
 *
 
10
 *   This program is distributed in the hope that it will be useful,
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *   GNU General Public License for more details
 
14
 *
 
15
 *   You should have received a copy of the GNU Library/Lesser General Public
 
16
 *   License along with this program; if not, write to the
 
17
 *   Free Software Foundation, Inc.,
 
18
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
19
 */
 
20
 
 
21
#ifndef ABSTRACTICON_H
 
22
#define ABSTRACTICON_H
 
23
 
 
24
#include <QGraphicsWidget>
 
25
#include "plasmagenericshell_export.h"
 
26
 
 
27
class QPropertyAnimation;
 
28
 
 
29
namespace Plasma {
 
30
 
 
31
class FrameSvg;
 
32
 
 
33
class PLASMAGENERICSHELL_EXPORT AbstractIcon : public QGraphicsWidget
 
34
{
 
35
    Q_OBJECT
 
36
    Q_PROPERTY(qreal backgroundFadeAlpha READ backgroundFadeAlpha WRITE setBackgroundFadeAlpha)
 
37
 
 
38
    public:
 
39
        explicit AbstractIcon(QGraphicsItem *parent = 0);
 
40
        ~AbstractIcon();
 
41
 
 
42
        void setIconSize(int height);
 
43
        int iconSize() const;
 
44
 
 
45
        bool isSelected() const;
 
46
        void setSelected(bool selected);
 
47
 
 
48
        void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
 
49
        void paintForeground(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
 
50
        void paintBackground(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
 
51
 
 
52
        QString name() const;
 
53
 
 
54
        void expand();
 
55
        void collapse();
 
56
 
 
57
        /**
 
58
         * return the background image
 
59
         */
 
60
        virtual QPixmap pixmap(const QSize &size) = 0;
 
61
 
 
62
        /**
 
63
         * return the mime data for d&d
 
64
         */
 
65
        virtual QMimeData* mimeData() = 0;
 
66
 
 
67
        static const int DEFAULT_ICON_SIZE = 16;
 
68
 
 
69
    Q_SIGNALS:
 
70
        void hoverEnter(Plasma::AbstractIcon *applet);
 
71
        void hoverLeave(Plasma::AbstractIcon *applet);
 
72
        void dragging(Plasma::AbstractIcon *applet);
 
73
        void clicked(Plasma::AbstractIcon *applet);
 
74
        void doubleClicked(Plasma::AbstractIcon *applet);
 
75
 
 
76
    public Q_SLOTS:
 
77
        void setName(const QString &name);
 
78
 
 
79
    protected Q_SLOTS:
 
80
        void syncTheme();
 
81
 
 
82
    protected:
 
83
        //listen to events and emit signals
 
84
        void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
 
85
        void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
 
86
        void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
 
87
        void mousePressEvent(QGraphicsSceneMouseEvent *event);
 
88
        void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
 
89
        void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
 
90
        void resizeEvent(QGraphicsSceneResizeEvent *);
 
91
        QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint) const;
 
92
 
 
93
        bool isDraggable() const;
 
94
        void setDraggable(bool draggable);
 
95
 
 
96
    private:
 
97
        qreal backgroundFadeAlpha() const;
 
98
        void setBackgroundFadeAlpha(qreal progress);
 
99
        void fadeBackground(int duration);
 
100
 
 
101
        Plasma::FrameSvg *m_background;
 
102
        QPropertyAnimation *m_backgroundFadeAnim;
 
103
        QString m_backgroundPrefix;
 
104
        QString m_oldBackgroundPrefix;
 
105
        QString m_name;
 
106
        int m_iconHeight;
 
107
        QSizeF m_maxSize;
 
108
        qreal m_backgroundAlpha;
 
109
        bool m_selected : 1;
 
110
        bool m_hovered : 1;
 
111
};
 
112
}
 
113
#endif //APPLETICON_H