]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistcontroller.h
Move drawing of textbackground to KItemListWidget
[dolphin.git] / src / kitemviews / kitemlistcontroller.h
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
21 ***************************************************************************/
22
23 #ifndef KITEMLISTCONTROLLER_H
24 #define KITEMLISTCONTROLLER_H
25
26 #include <libdolphin_export.h>
27
28 #include <QObject>
29
30 class KItemModelBase;
31 class KItemListSelectionManager;
32 class KItemListView;
33 class QGraphicsSceneHoverEvent;
34 class QGraphicsSceneDragDropEvent;
35 class QGraphicsSceneMouseEvent;
36 class QGraphicsSceneResizeEvent;
37 class QGraphicsSceneWheelEvent;
38 class QHideEvent;
39 class QInputMethodEvent;
40 class QKeyEvent;
41 class QShowEvent;
42 class QTransform;
43
44 /**
45 * @brief Controls the view, model and selection of an item-list.
46 *
47 * For a working item-list it is mandatory to set a compatible view and model
48 * with KItemListController::setView() and KItemListController::setModel().
49 *
50 * @see KItemListView
51 * @see KItemModelBase
52 * @see KItemListSelectionManager
53 */
54 class LIBDOLPHINPRIVATE_EXPORT KItemListController : public QObject
55 {
56 Q_OBJECT
57 Q_ENUMS(SelectionBehavior)
58 Q_PROPERTY(KItemModelBase* model READ model WRITE setModel)
59 Q_PROPERTY(KItemListView *view READ view WRITE setView)
60 Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
61
62 public:
63 enum SelectionBehavior {
64 NoSelection,
65 SingleSelection,
66 MultiSelection
67 };
68
69 KItemListController(QObject* parent = 0);
70 virtual ~KItemListController();
71
72 void setModel(KItemModelBase* model);
73 KItemModelBase* model() const;
74
75 void setView(KItemListView* view);
76 KItemListView* view() const;
77
78 KItemListSelectionManager* selectionManager() const;
79
80 void setSelectionBehavior(SelectionBehavior behavior);
81 SelectionBehavior selectionBehavior() const;
82
83 virtual bool showEvent(QShowEvent* event);
84 virtual bool hideEvent(QHideEvent* event);
85 virtual bool keyPressEvent(QKeyEvent* event);
86 virtual bool inputMethodEvent(QInputMethodEvent* event);
87 virtual bool mousePressEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
88 virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
89 virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
90 virtual bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
91 virtual bool dragEnterEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
92 virtual bool dragLeaveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
93 virtual bool dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
94 virtual bool dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
95 virtual bool hoverEnterEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
96 virtual bool hoverMoveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
97 virtual bool hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
98 virtual bool wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform);
99 virtual bool resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform);
100 virtual bool processEvent(QEvent* event, const QTransform& transform);
101
102 signals:
103 void itemClicked(int index, Qt::MouseButton button);
104
105 /**
106 * Is emitted if the item with the index \p index gets hovered.
107 */
108 void itemHovered(int index);
109
110 /**
111 * Is emitted if the item with the index \p index gets unhovered.
112 * It is assured that the signal itemHovered() for this index
113 * has been emitted before.
114 */
115 void itemUnhovered(int index);
116
117 void itemExpansionToggleClicked(int index);
118
119 void modelChanged(KItemModelBase* current, KItemModelBase* previous);
120 void viewChanged(KItemListView* current, KItemListView* previous);
121
122 private:
123 SelectionBehavior m_selectionBehavior;
124 KItemModelBase* m_model;
125 KItemListView* m_view;
126 KItemListSelectionManager* m_selectionManager;
127 int m_pressedIndex;
128 };
129
130 #endif
131
132