]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistcontroller.h
Added the functionality to activate items by pressing 'enter' or 'return' key on...
[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 QGraphicsSceneHoverEvent;
38 class QGraphicsSceneDragDropEvent;
39 class QGraphicsSceneMouseEvent;
40 class QGraphicsSceneResizeEvent;
41 class QGraphicsSceneWheelEvent;
42 class QHideEvent;
43 class QInputMethodEvent;
44 class QKeyEvent;
45 class QMimeData;
46 class QShowEvent;
47 class QTransform;
48
49 /**
50 * @brief Controls the view, model and selection of an item-list.
51 *
52 * For a working item-list it is mandatory to set a compatible view and model
53 * with KItemListController::setView() and KItemListController::setModel().
54 *
55 * @see KItemListView
56 * @see KItemModelBase
57 * @see KItemListSelectionManager
58 */
59 class LIBDOLPHINPRIVATE_EXPORT KItemListController : public QObject
60 {
61 Q_OBJECT
62 Q_ENUMS(SelectionBehavior)
63 Q_PROPERTY(KItemModelBase* model READ model WRITE setModel)
64 Q_PROPERTY(KItemListView *view READ view WRITE setView)
65 Q_PROPERTY(SelectionBehavior selectionBehavior READ selectionBehavior WRITE setSelectionBehavior)
66
67 public:
68 enum SelectionBehavior {
69 NoSelection,
70 SingleSelection,
71 MultiSelection
72 };
73
74 KItemListController(QObject* parent = 0);
75 virtual ~KItemListController();
76
77 void setModel(KItemModelBase* model);
78 KItemModelBase* model() const;
79
80 void setView(KItemListView* view);
81 KItemListView* view() const;
82
83 KItemListSelectionManager* selectionManager() const;
84
85 void setSelectionBehavior(SelectionBehavior behavior);
86 SelectionBehavior selectionBehavior() const;
87
88 virtual bool showEvent(QShowEvent* event);
89 virtual bool hideEvent(QHideEvent* event);
90 virtual bool keyPressEvent(QKeyEvent* event);
91 virtual bool inputMethodEvent(QInputMethodEvent* event);
92 virtual bool mousePressEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
93 virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
94 virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
95 virtual bool mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event, const QTransform& transform);
96 virtual bool dragEnterEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
97 virtual bool dragLeaveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
98 virtual bool dragMoveEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
99 virtual bool dropEvent(QGraphicsSceneDragDropEvent* event, const QTransform& transform);
100 virtual bool hoverEnterEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
101 virtual bool hoverMoveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
102 virtual bool hoverLeaveEvent(QGraphicsSceneHoverEvent* event, const QTransform& transform);
103 virtual bool wheelEvent(QGraphicsSceneWheelEvent* event, const QTransform& transform);
104 virtual bool resizeEvent(QGraphicsSceneResizeEvent* event, const QTransform& transform);
105 virtual bool processEvent(QEvent* event, const QTransform& transform);
106
107 signals:
108 void itemActivated(int index);
109 void itemMiddleClicked(int index);
110 void contextMenuRequested(int index, const QPointF& pos);
111
112 /**
113 * Is emitted if the item with the index \p index gets hovered.
114 */
115 void itemHovered(int index);
116 /**
117 * Is emitted if the item with the index \p index gets unhovered.
118 * It is assured that the signal itemHovered() for this index
119 * has been emitted before.
120 */
121 void itemUnhovered(int index);
122
123 void itemExpansionToggleClicked(int index);
124
125 void modelChanged(KItemModelBase* current, KItemModelBase* previous);
126 void viewChanged(KItemListView* current, KItemListView* previous);
127
128 private slots:
129 void slotViewOffsetChanged(qreal current, qreal previous);
130
131 /**
132 * Is invoked when the rubberband boundaries have been changed and will select
133 * all items that are touched by the rubberband.
134 */
135 void slotRubberBandChanged();
136
137 void slotKeyboardActivationRequested(const QString& text, bool searchFromNextItem);
138
139 private:
140 /**
141 * Creates a QDrag object to start a drag-operation.
142 * @return True if the QDrag object has been created. If false is returned
143 * there is no implementation available for KItemModelBase::createMimeData().
144 */
145 bool startDragging();
146
147 private:
148 bool m_dragging;
149 SelectionBehavior m_selectionBehavior;
150 KItemModelBase* m_model;
151 KItemListView* m_view;
152 KItemListSelectionManager* m_selectionManager;
153 KItemListKeyboardSearchManager* m_keyboardManager;
154 int m_pressedIndex;
155 QPointF m_pressedMousePos;
156
157 /**
158 * When starting a rubberband selection during a Shift- or Control-key has been
159 * pressed the current selection should never be deleted. To be able to restore
160 * the current selection it is remembered in m_oldSelection before
161 * rubberband gets activated.
162 */
163 QSet<int> m_oldSelection;
164 };
165
166 #endif
167
168