1/*
2 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3 Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
4 Copyright (c) 2009 Kevin Ottens <ervin@kde.org>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#ifndef AKONADI_ENTITYLISTVIEW_H
23#define AKONADI_ENTITYLISTVIEW_H
24
25#include "akonadi_export.h"
26
27#include <QListView>
28
29class KXMLGUIClient;
30class QDragMoveEvent;
31
32namespace Akonadi
33{
34
35class Collection;
36class Item;
37
38/**
39 * @short A view to show an item/collection list provided by an EntityTreeModel.
40 *
41 * When a KXmlGuiWindow is passed to the constructor, the XMLGUI
42 * defined context menu @c akonadi_collectionview_contextmenu or
43 * @c akonadi_itemview_contextmenu is used if available.
44 *
45 * Example:
46 *
47 * @code
48 *
49 * using namespace Akonadi;
50 *
51 * class MyWindow : public KXmlGuiWindow
52 * {
53 * public:
54 * MyWindow()
55 * : KXmlGuiWindow()
56 * {
57 * EntityListView *view = new EntityListView( this, this );
58 * setCentralWidget( view );
59 *
60 * EntityTreeModel *model = new EntityTreeModel( ... );
61 *
62 * KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
63 * flatModel->setSourceModel( model );
64 *
65 * view->setModel( flatModel );
66 * }
67 * }
68 *
69 * @endcode
70 *
71 * @author Volker Krause <vkrause@kde.org>
72 * @author Stephen Kelly <steveire@gmail.com>
73 * @since 4.4
74 */
75class AKONADI_EXPORT EntityListView : public QListView
76{
77 Q_OBJECT
78
79public:
80 /**
81 * Creates a new favorite collections view.
82 *
83 * @param parent The parent widget.
84 */
85 explicit EntityListView(QWidget *parent = 0);
86
87 /**
88 * Creates a new favorite collections view.
89 *
90 * @param xmlGuiClient The KXMLGUIClient the view is used in.
91 * This is needed for the XMLGUI based context menu.
92 * Passing 0 is ok and will disable the builtin context menu.
93 * @param parent The parent widget.
94 */
95 explicit EntityListView(KXMLGUIClient *xmlGuiClient, QWidget *parent = 0);
96
97 /**
98 * Destroys the favorite collections view.
99 */
100 virtual ~EntityListView();
101
102 /**
103 * Sets the XML GUI client which the view is used in.
104 *
105 * This is needed if you want to use the built-in context menu.
106 *
107 * @param xmlGuiClient The KXMLGUIClient the view is used in.
108 */
109 void setXmlGuiClient(KXMLGUIClient *xmlGuiClient);
110
111 /**
112 * Return the XML GUI client which the view is used in.
113 * @since 4.12
114 */
115 KXMLGUIClient *xmlGuiClient() const;
116
117 /**
118 * @reimp
119 * @param model the model to set
120 */
121 virtual void setModel(QAbstractItemModel *model);
122
123 /**
124 * Sets whether the drop action menu is @p enabled and will
125 * be shown on drop operation.
126 * @param enabled enables drop action menu if set as @c true
127 * @since 4.7
128 */
129 void setDropActionMenuEnabled(bool enabled);
130
131 /**
132 * Returns whether the drop action menu is enabled and will
133 * be shown on drop operation.
134 *
135 * @since 4.7
136 */
137 bool isDropActionMenuEnabled() const;
138
139Q_SIGNALS:
140 /**
141 * This signal is emitted whenever the user has clicked
142 * a collection in the view.
143 *
144 * @param collection The clicked collection.
145 */
146 void clicked(const Akonadi::Collection &collection);
147
148 /**
149 * This signal is emitted whenever the user has clicked
150 * an item in the view.
151 *
152 * @param item The clicked item.
153 */
154 void clicked(const Akonadi::Item &item);
155
156 /**
157 * This signal is emitted whenever the user has double clicked
158 * a collection in the view.
159 *
160 * @param collection The double clicked collection.
161 */
162 void doubleClicked(const Akonadi::Collection &collection);
163
164 /**
165 * This signal is emitted whenever the user has double clicked
166 * an item in the view.
167 *
168 * @param item The double clicked item.
169 */
170 void doubleClicked(const Akonadi::Item &item);
171
172 /**
173 * This signal is emitted whenever the current collection
174 * in the view has changed.
175 *
176 * @param collection The new current collection.
177 */
178 void currentChanged(const Akonadi::Collection &collection);
179
180 /**
181 * This signal is emitted whenever the current item
182 * in the view has changed.
183 *
184 * @param item The new current item.
185 */
186 void currentChanged(const Akonadi::Item &item);
187
188protected:
189 using QListView::currentChanged;
190#ifndef QT_NO_DRAGANDDROP
191 virtual void startDrag(Qt::DropActions supportedActions);
192 virtual void dropEvent(QDropEvent *event);
193 virtual void dragMoveEvent(QDragMoveEvent *event);
194#endif
195
196#ifndef QT_NO_CONTEXTMENU
197 virtual void contextMenuEvent(QContextMenuEvent *event);
198#endif
199
200private:
201 //@cond PRIVATE
202 class Private;
203 Private *const d;
204
205 Q_PRIVATE_SLOT(d, void itemClicked(const QModelIndex &))
206 Q_PRIVATE_SLOT(d, void itemDoubleClicked(const QModelIndex &))
207 Q_PRIVATE_SLOT(d, void itemCurrentChanged(const QModelIndex &))
208 //@endcond
209};
210
211}
212
213#endif
214