1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
4 * Based on the Itemviews NG project from Trolltech Labs: *
5 * http://qt.gitorious.org/qt-labs/itemviews-ng *
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. *
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. *
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 ***************************************************************************/
23 #ifndef KITEMLISTCONTROLLER_H
24 #define KITEMLISTCONTROLLER_H
26 #include <libdolphin_export.h>
31 class KItemListSelectionManager
;
33 class QGraphicsSceneHoverEvent
;
34 class QGraphicsSceneDragDropEvent
;
35 class QGraphicsSceneMouseEvent
;
36 class QGraphicsSceneResizeEvent
;
37 class QGraphicsSceneWheelEvent
;
39 class QInputMethodEvent
;
45 * @brief Controls the view, model and selection of an item-list.
47 * For a working item-list it is mandatory to set a compatible view and model
48 * with KItemListController::setView() and KItemListController::setModel().
52 * @see KItemListSelectionManager
54 class LIBDOLPHINPRIVATE_EXPORT KItemListController
: public QObject
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
)
63 enum SelectionBehavior
{
69 KItemListController(QObject
* parent
= 0);
70 virtual ~KItemListController();
72 void setModel(KItemModelBase
* model
);
73 KItemModelBase
* model() const;
75 void setView(KItemListView
* view
);
76 KItemListView
* view() const;
78 KItemListSelectionManager
* selectionManager() const;
80 void setSelectionBehavior(SelectionBehavior behavior
);
81 SelectionBehavior
selectionBehavior() const;
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
);
103 void itemClicked(int index
, Qt::MouseButton button
);
106 * Is emitted if the item with the index \p index gets hovered.
108 void itemHovered(int index
);
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.
115 void itemUnhovered(int index
);
117 void itemExpansionToggleClicked(int index
);
119 void modelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
120 void viewChanged(KItemListView
* current
, KItemListView
* previous
);
123 SelectionBehavior m_selectionBehavior
;
124 KItemModelBase
* m_model
;
125 KItemListView
* m_view
;
126 KItemListSelectionManager
* m_selectionManager
;