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

« back to all changes in this revision

Viewing changes to plasma/generic/applets/quicklaunch/popuplauncherlist.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) 2010 - 2011 by Ingomar Wesp <ingomar@wesp.name>         *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
 
18
 ***************************************************************************/
 
19
#ifndef QUICKLAUNCH_POPUPLAUNCHERLIST_H
 
20
#define QUICKLAUNCH_POPUPLAUNCHERLIST_H
 
21
 
 
22
// Qt
 
23
#include <Qt>
 
24
#include <QtGlobal>
 
25
#include <QtCore/QList>
 
26
#include <QtCore/QPointF>
 
27
#include <QtGui/QGraphicsWidget>
 
28
 
 
29
// KDE
 
30
#include <KUrl>
 
31
 
 
32
// Plasma
 
33
#include <Plasma/Plasma>
 
34
 
 
35
// Own
 
36
#include "launcherdata.h"
 
37
 
 
38
class QAction;
 
39
class QEvent;
 
40
class QGraphicsItem;
 
41
class QGraphicsLayout;
 
42
class QGraphicsLinearLayout;
 
43
class QGraphicsSceneResizeEvent;
 
44
class QGraphicsSceneDragDropEvent;
 
45
class QGraphicsSceneMouseEvent;
 
46
 
 
47
namespace Plasma {
 
48
    class IconWidget;
 
49
}
 
50
 
 
51
namespace Quicklaunch {
 
52
 
 
53
class DropMarker;
 
54
class Launcher;
 
55
 
 
56
/**
 
57
 * The PopupLauncherList is a QGraphicsWidget that displays and manages the
 
58
 * launchers on Quicklaunch's popup.
 
59
 * Since all launchers are managed by the PopupLauncherList and its layout,
 
60
 * they should not be accessed directly, but rather added or removed by
 
61
 * passing LauncherData objects.
 
62
 *
 
63
 * PopupLauncherList also takes care of drag & drop handling.
 
64
 */
 
65
class PopupLauncherList : public QGraphicsWidget
 
66
{
 
67
    Q_OBJECT
 
68
 
 
69
public:
 
70
 
 
71
    /**
 
72
     * Creates a new PopupLauncherList with the given parent item.
 
73
     *
 
74
     * @param parent the parent QGraphicsItem
 
75
     */
 
76
    explicit PopupLauncherList(QGraphicsItem *parent = 0);
 
77
 
 
78
    void setPreferredIconSize(int size);
 
79
 
 
80
    /**
 
81
     * Indicates whether this PopupLauncherList is locked and thus does not allow
 
82
     * adding, removing or reordering launchers by drag & drop.
 
83
     */
 
84
    bool locked() const;
 
85
 
 
86
    /**
 
87
     * Locks or unlocks this PopupLauncherList.
 
88
     *
 
89
     * @param enable whether this PopupLauncherList should be locked, thereby
 
90
     * disabling adding, removing or reordering launchers by drag & drop.
 
91
     */
 
92
    void setLocked(bool enable);
 
93
 
 
94
    QGraphicsLinearLayout *layout() const;
 
95
 
 
96
    int launcherCount() const;
 
97
 
 
98
    void clear();
 
99
    void insert(int index, const LauncherData &launcherData);
 
100
    void insert(int index, const QList<LauncherData> &launcherDataList);
 
101
    void removeAt(int index);
 
102
    LauncherData launcherAt(int index) const;
 
103
    int launcherIndexAtPosition(const QPointF& pos) const;
 
104
 
 
105
    bool eventFilter(QObject *watched, QEvent *event);
 
106
 
 
107
Q_SIGNALS:
 
108
    /**
 
109
     * Indicates a change to one or more of the displayed launchers.
 
110
     */
 
111
    void launchersChanged();
 
112
 
 
113
    /**
 
114
     * Indicates that one of the launcher items was clicked.
 
115
     */
 
116
    void launcherClicked();
 
117
 
 
118
protected:
 
119
    void dragEnterEvent(QGraphicsSceneDragDropEvent *event);
 
120
    void dragMoveEvent(QGraphicsSceneDragDropEvent *event);
 
121
    void dragLeaveEvent(QGraphicsSceneDragDropEvent *event);
 
122
    void dropEvent(QGraphicsSceneDragDropEvent *event);
 
123
 
 
124
private Q_SLOTS:
 
125
    void onPlaceHolderActivated();
 
126
 
 
127
private:
 
128
    void initPlaceHolder();
 
129
    void deletePlaceHolder();
 
130
    int determineDropMarkerIndex(const QPointF &localPos) const;
 
131
 
 
132
    QList<Launcher*> m_launchers;
 
133
    QSizeF m_preferredIconSize;
 
134
    bool m_locked;
 
135
 
 
136
    QGraphicsLinearLayout *m_layout;
 
137
 
 
138
    QPointF m_mousePressedPos;
 
139
    DropMarker *m_dropMarker;
 
140
    int m_dropMarkerIndex;
 
141
    Plasma::IconWidget *m_placeHolder;
 
142
};
 
143
}
 
144
 
 
145
#endif /* QUICKLAUNCH_POPUPLAUNCHERLIST_H */