1/*
2 Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org>
3 Copyright (c) 2008 Stephen Kelly <steveire@gmail.com>
4 Copyright (c) 2012 Laurent Montel <montel@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_ENTITYTREEVIEW_H
23#define AKONADI_ENTITYTREEVIEW_H
24
25#include "akonadi_export.h"
26
27#include <QTreeView>
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 tree 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 * EntityTreeView *view = new EntityTreeView( this, this );
58 * setCentralWidget( view );
59 *
60 * EntityTreeModel *model = new EntityTreeModel( ... );
61 * view->setModel( model );
62 * }
63 * }
64 *
65 * @endcode
66 *
67 * @author Volker Krause <vkrause@kde.org>
68 * @author Stephen Kelly <steveire@gmail.com>
69 * @since 4.4
70 */
71class AKONADI_EXPORT EntityTreeView : public QTreeView
72{
73 Q_OBJECT
74
75public:
76 /**
77 * Creates a new entity tree view.
78 *
79 * @param parent The parent widget.
80 */
81 explicit EntityTreeView(QWidget *parent = 0);
82
83 /**
84 * Creates a new entity tree view.
85 *
86 * @param xmlGuiClient The KXMLGUIClient the view is used in.
87 * This is needed for the XMLGUI based context menu.
88 * Passing 0 is ok and will disable the builtin context menu.
89 * @param parent The parent widget.
90 */
91 explicit EntityTreeView(KXMLGUIClient *xmlGuiClient, QWidget *parent = 0);
92
93 /**
94 * Destroys the entity tree view.
95 */
96 virtual ~EntityTreeView();
97
98 /**
99 * Sets the XML GUI client which the view is used in.
100 *
101 * This is needed if you want to use the built-in context menu.
102 *
103 * @param xmlGuiClient The KXMLGUIClient the view is used in.
104 */
105 void setXmlGuiClient(KXMLGUIClient *xmlGuiClient);
106
107 /**
108 * Return the XML GUI client which the view is used in.
109 * @since 4.12
110 */
111 KXMLGUIClient *xmlGuiClient() const;
112
113 /**
114 * @reimp
115 * @param model the model to set
116 */
117 virtual void setModel(QAbstractItemModel *model);
118
119 /**
120 * Sets whether the drop action menu is @p enabled and will
121 * be shown on drop operation.
122 * @param enabled enables drop action menu if set as @c true
123 * @since 4.5
124 */
125 void setDropActionMenuEnabled(bool enabled);
126
127 /**
128 * Returns whether the drop action menu is enabled and will
129 * be shown on drop operation.
130 *
131 * @since 4.5
132 */
133 bool isDropActionMenuEnabled() const;
134
135 /**
136 * Return true if we use an manual sorting
137 * Necessary to fix dnd menu
138 * We must show just move when we move item between two items
139 * When automatic no show dnd menu between two items.
140 * @since 4.8.1
141 */
142 bool isManualSortingActive() const;
143
144 /**
145 * Set true if we automatic sorting
146 * @param active enables automatic sorting if set as @c true
147 * @since 4.8.1
148 */
149 void setManualSortingActive(bool active);
150
151 /**
152 * Set the name of the default popup menu (retrieved from the
153 * application's XMLGUI file).
154 *
155 * This menu is used as a fallback if the context of the menu request
156 * is neither an item nor a collection, e.g. the click is on an empty
157 * area inside the view. If the click is over an entry in the view,
158 * the menu which is applicable to the clicked entry (either an Item
159 * or a Collection) is used.
160 *
161 * @param name The name of the popup menu
162 *
163 * @since 4.9
164 * @note For backwards compatibility, the default is the standard
165 * collection popup menu, "akonadi_collectionview_contextmenu".
166 * @see KXMLGUIClient, KXMLGUIFactory::container()
167 */
168 void setDefaultPopupMenu(const QString &name);
169
170Q_SIGNALS:
171 /**
172 * This signal is emitted whenever the user has clicked
173 * a collection in the view.
174 *
175 * @param collection The clicked collection.
176 */
177 void clicked(const Akonadi::Collection &collection);
178
179 /**
180 * This signal is emitted whenever the user has clicked
181 * an item in the view.
182 *
183 * @param item The clicked item.
184 */
185 void clicked(const Akonadi::Item &item);
186
187 /**
188 * This signal is emitted whenever the user has double clicked
189 * a collection in the view.
190 *
191 * @param collection The double clicked collection.
192 */
193 void doubleClicked(const Akonadi::Collection &collection);
194
195 /**
196 * This signal is emitted whenever the user has double clicked
197 * an item in the view.
198 *
199 * @param item The double clicked item.
200 */
201 void doubleClicked(const Akonadi::Item &item);
202
203 /**
204 * This signal is emitted whenever the current collection
205 * in the view has changed.
206 *
207 * @param collection The new current collection.
208 */
209 void currentChanged(const Akonadi::Collection &collection);
210
211 /**
212 * This signal is emitted whenever the current item
213 * in the view has changed.
214 *
215 * @param item The new current item.
216 */
217 void currentChanged(const Akonadi::Item &item);
218
219protected:
220 using QTreeView::currentChanged;
221#ifndef QT_NO_DRAGANDDROP
222 virtual void startDrag(Qt::DropActions supportedActions);
223 virtual void dragMoveEvent(QDragMoveEvent *event);
224 virtual void dropEvent(QDropEvent *event);
225#endif
226 virtual void timerEvent(QTimerEvent *event);
227#ifndef QT_NO_CONTEXTMENU
228 virtual void contextMenuEvent(QContextMenuEvent *event);
229#endif
230
231private:
232 //@cond PRIVATE
233 class Private;
234 Private *const d;
235
236 Q_PRIVATE_SLOT(d, void itemClicked(const QModelIndex &))
237 Q_PRIVATE_SLOT(d, void itemDoubleClicked(const QModelIndex &))
238 Q_PRIVATE_SLOT(d, void itemCurrentChanged(const QModelIndex &))
239 Q_PRIVATE_SLOT(d, void slotSelectionChanged(const QItemSelection &, const QItemSelection &))
240 //@endcond
241};
242
243}
244
245#endif
246