]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistcontroller.h
Bring back the selection-markers
[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 #include <QPixmap>
30 #include <QPointF>
31 #include <QSet>
32
33 class KItemModelBase;
34 class KItemListKeyboardSearchManager;
35 class KItemListSelectionManager;
36 class KItemListView;
37 class KItemListWidget;
38 class QGraphicsSceneHoverEvent;
39 class QGraphicsSceneDragDropEvent;
40 class QGraphicsSceneMouseEvent;
41 class QGraphicsSceneResizeEvent;
42 class QGraphicsSceneWheelEvent;
43 class QHideEvent;
44 class QInputMethodEvent;
45 class QKeyEvent;
46 class QMimeData;
47 class QShowEvent;
48 class QTransform;
49
50 /**
51 * @brief Controls the view, model and selection of an item-list.
52 *
53 * For a working item-list it is mandatory to set a compatible view and model
54 * with KItemListController::setView() and KItemListController::setModel().
55 *
56 * @see KItemListView
57 * @see KItemModelBase
58 * @see KItemListSelectionManager
59 */
60 class LIBDOLPHINPRIVATE_EXPORT KItemListController : public QObject
61 {
62 Q_OBJECT
63 Q_ENUMS(SelectionBehavior)
64 Q_PROPERTY(KItemModelBase* model READ model WRITE setModel)
65 Q_PROPERTY(KItemListView *view READ view WRITE setView)
66 Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
67
68 public:
69 enum SelectionBehavior {
70 NoSelection,
71 SingleSelection,
72 MultiSelection
73 };
74
75 KItemListController(QObject* parent = 0);
76 virtual ~KItemListController();
77
78 void setModel(KItemModelBase* model);
79 KItemModelBase* model() const;
80
81 void setView(KItemListView* view);
82 KItemListView* view() const;
83
84 KItemListSelectionManager* selectionManager() const;
85
86 void setSelectionBehavior(SelectionBehavior behavior);
87 SelectionBehavior selectionBehavior() const;
88
89 virtual bool showEvent(QShowEvent* event);
90 virtual bool hideEvent(QHideEvent* event);
91 virtual bool keyPressEvent(QKeyEvent* event);
92 virtual bool inputMethodEvent(QInputMethodEvent* event);
93 virtual bool mousePressEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
94 virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
95 virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
96 virtual bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
97 virtual bool dragEnterEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
98 virtual bool dragLeaveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
99 virtual bool dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
100 virtual bool dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
101 virtual bool hoverEnterEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
102 virtual bool hoverMoveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
103 virtual bool hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
104 virtual bool wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform);
105 virtual bool resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform);
106 virtual bool processEvent(QEvent* event, const QTransform& transform);
107
108 signals:
109 void itemActivated(int index);
110 void itemMiddleClicked(int index);
111
112 /**
113 * Emitted if a context-menu is requested for the item with
114 * the index \a index. It is assured that the index is valid.
115 */
116 void itemContextMenuRequested(int index, const QPointF& pos);
117
118 /**
119 * Emitted if a context-menu is requested for the KItemListView.
120 */
121 void viewContextMenuRequested(const QPointF& pos);
122
123 /**
124 * Emitted if a context-menu is requested for the header of the KItemListView.
125 */
126 void headerContextMenuRequested(const QPointF& pos);
127
128 /**
129 * Is emitted if the item with the index \p index gets hovered.
130 */
131 void itemHovered(int index);
132
133 /**
134 * Is emitted if the item with the index \p index gets unhovered.
135 * It is assured that the signal itemHovered() for this index
136 * has been emitted before.
137 */
138 void itemUnhovered(int index);
139
140 void itemExpansionToggleClicked(int index);
141
142 /**
143 * Is emitted if a drop event is done above the item with the index
144 * \a index. If \a index is < 0 the drop event is done above an
145 * empty area of the view.
146 */
147 void itemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
148
149 void modelChanged(KItemModelBase* current, KItemModelBase* previous);
150 void viewChanged(KItemListView* current, KItemListView* previous);
151
152 private slots:
153 void slotViewScrollOffsetChanged(qreal current, qreal previous);
154
155 /**
156 * Is invoked when the rubberband boundaries have been changed and will select
157 * all items that are touched by the rubberband.
158 */
159 void slotRubberBandChanged();
160
161 void slotChangeCurrentItem(const QString& text, bool searchFromNextItem);
162
163 private:
164 /**
165 * Creates a QDrag object and initiates a drag-operation.
166 */
167 void startDragging();
168
169 /**
170 * @return Widget that is currently in the hovered state. 0 is returned
171 * if no widget is marked as hovered.
172 */
173 KItemListWidget* hoveredWidget() const;
174
175 /**
176 * @return Widget that is below the position \a pos. 0 is returned
177 * if no widget is below the position.
178 */
179 KItemListWidget* widgetForPos(const QPointF& pos) const;
180
181 private:
182 bool m_selectionTogglePressed;
183 SelectionBehavior m_selectionBehavior;
184 KItemModelBase* m_model;
185 KItemListView* m_view;
186 KItemListSelectionManager* m_selectionManager;
187 KItemListKeyboardSearchManager* m_keyboardManager;
188 int m_pressedIndex;
189 QPointF m_pressedMousePos;
190
191 /**
192 * When starting a rubberband selection during a Shift- or Control-key has been
193 * pressed the current selection should never be deleted. To be able to restore
194 * the current selection it is remembered in m_oldSelection before
195 * rubberband gets activated.
196 */
197 QSet<int> m_oldSelection;
198 };
199
200 #endif
201
202