]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistcontroller.h
Added support for highlighting items by typing their name on the keyboard.
[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 itemClicked(int index, Qt::MouseButton button);
109
110 /**
111 * Is emitted if the item with the index \p index gets hovered.
112 */
113 void itemHovered(int index);
114
115 /**
116 * Is emitted if the item with the index \p index gets unhovered.
117 * It is assured that the signal itemHovered() for this index
118 * has been emitted before.
119 */
120 void itemUnhovered(int index);
121
122 void itemExpansionToggleClicked(int index);
123
124 void modelChanged(KItemModelBase* current, KItemModelBase* previous);
125 void viewChanged(KItemListView* current, KItemListView* previous);
126
127 private slots:
128 void slotViewOffsetChanged(qreal current, qreal previous);
129
130 /**
131 * Is invoked when the rubberband boundaries have been changed and will select
132 * all items that are touched by the rubberband.
133 */
134 void slotRubberBandChanged();
135
136 void slotKeyboardActivationRequested(const QString& text, bool searchFromNextItem);
137
138 private:
139 /**
140 * Creates a QDrag object to start a drag-operation.
141 * @return True if the QDrag object has been created. If false is returned
142 * there is no implementation available for KItemModelBase::createMimeData().
143 */
144 bool startDragging();
145
146 private:
147 bool m_dragging;
148 SelectionBehavior m_selectionBehavior;
149 KItemModelBase* m_model;
150 KItemListView* m_view;
151 KItemListSelectionManager* m_selectionManager;
152 KItemListKeyboardSearchManager* m_keyboardManager;
153 int m_pressedIndex;
154 QPointF m_pressedMousePos;
155
156 /**
157 * When starting a rubberband selection during a Shift- or Control-key has been
158 * pressed the current selection should never be deleted. To be able to restore
159 * the current selection it is remembered in m_oldSelection before
160 * rubberband gets activated.
161 */
162 QSet<int> m_oldSelection;
163 };
164
165 #endif
166
167