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>
34 class KItemListKeyboardSearchManager
;
35 class KItemListSelectionManager
;
37 class QGraphicsSceneHoverEvent
;
38 class QGraphicsSceneDragDropEvent
;
39 class QGraphicsSceneMouseEvent
;
40 class QGraphicsSceneResizeEvent
;
41 class QGraphicsSceneWheelEvent
;
43 class QInputMethodEvent
;
50 * @brief Controls the view, model and selection of an item-list.
52 * For a working item-list it is mandatory to set a compatible view and model
53 * with KItemListController::setView() and KItemListController::setModel().
57 * @see KItemListSelectionManager
59 class LIBDOLPHINPRIVATE_EXPORT KItemListController
: public QObject
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
)
68 enum SelectionBehavior
{
74 KItemListController(QObject
* parent
= 0);
75 virtual ~KItemListController();
77 void setModel(KItemModelBase
* model
);
78 KItemModelBase
* model() const;
80 void setView(KItemListView
* view
);
81 KItemListView
* view() const;
83 KItemListSelectionManager
* selectionManager() const;
85 void setSelectionBehavior(SelectionBehavior behavior
);
86 SelectionBehavior
selectionBehavior() const;
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
);
108 void itemActivated(int index
);
109 void itemMiddleClicked(int index
);
110 void contextMenuRequested(int index
, const QPointF
& pos
);
113 * Is emitted if the item with the index \p index gets hovered.
115 void itemHovered(int index
);
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.
121 void itemUnhovered(int index
);
123 void itemExpansionToggleClicked(int index
);
125 void modelChanged(KItemModelBase
* current
, KItemModelBase
* previous
);
126 void viewChanged(KItemListView
* current
, KItemListView
* previous
);
129 void slotViewOffsetChanged(qreal current
, qreal previous
);
132 * Is invoked when the rubberband boundaries have been changed and will select
133 * all items that are touched by the rubberband.
135 void slotRubberBandChanged();
137 void slotKeyboardActivationRequested(const QString
& text
, bool searchFromNextItem
);
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().
145 bool startDragging();
149 SelectionBehavior m_selectionBehavior
;
150 KItemModelBase
* m_model
;
151 KItemListView
* m_view
;
152 KItemListSelectionManager
* m_selectionManager
;
153 KItemListKeyboardSearchManager
* m_keyboardManager
;
155 QPointF m_pressedMousePos
;
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.
163 QSet
<int> m_oldSelection
;