Akonadi

entitytreeview.h
1 /*
2  SPDX-FileCopyrightText: 2006-2007 Volker Krause <[email protected]>
3  SPDX-FileCopyrightText: 2008 Stephen Kelly <[email protected]>
4  SPDX-FileCopyrightText: 2012-2021 Laurent Montel <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #ifndef AKONADI_ENTITYTREEVIEW_H
10 #define AKONADI_ENTITYTREEVIEW_H
11 
12 #include "akonadiwidgets_export.h"
13 
14 #include <QTreeView>
15 
16 class KXMLGUIClient;
17 class QDragMoveEvent;
18 
19 namespace Akonadi
20 {
21 class Collection;
22 class Item;
23 
24 /**
25  * @short A view to show an item/collection tree provided by an EntityTreeModel.
26  *
27  * When a KXmlGuiWindow is passed to the constructor, the XMLGUI
28  * defined context menu @c akonadi_collectionview_contextmenu or
29  * @c akonadi_itemview_contextmenu is used if available.
30  *
31  * Example:
32  *
33  * @code
34  *
35  * using namespace Akonadi;
36  *
37  * class MyWindow : public KXmlGuiWindow
38  * {
39  * public:
40  * MyWindow()
41  * : KXmlGuiWindow()
42  * {
43  * EntityTreeView *view = new EntityTreeView( this, this );
44  * setCentralWidget( view );
45  *
46  * EntityTreeModel *model = new EntityTreeModel( ... );
47  * view->setModel( model );
48  * }
49  * }
50  *
51  * @endcode
52  *
53  * @author Volker Krause <[email protected]>
54  * @author Stephen Kelly <[email protected]>
55  * @since 4.4
56  */
57 class AKONADIWIDGETS_EXPORT EntityTreeView : public QTreeView
58 {
59  Q_OBJECT
60 
61 public:
62  /**
63  * Creates a new entity tree view.
64  *
65  * @param parent The parent widget.
66  */
67  explicit EntityTreeView(QWidget *parent = nullptr);
68 
69  /**
70  * Creates a new entity tree view.
71  *
72  * @param xmlGuiClient The KXMLGUIClient the view is used in.
73  * This is needed for the XMLGUI based context menu.
74  * Passing 0 is ok and will disable the builtin context menu.
75  * @param parent The parent widget.
76  */
77  explicit EntityTreeView(KXMLGUIClient *xmlGuiClient, QWidget *parent = nullptr);
78 
79  /**
80  * Destroys the entity tree view.
81  */
82  ~EntityTreeView() override;
83 
84  /**
85  * Sets the XML GUI client which the view is used in.
86  *
87  * This is needed if you want to use the built-in context menu.
88  *
89  * @param xmlGuiClient The KXMLGUIClient the view is used in.
90  */
91  void setXmlGuiClient(KXMLGUIClient *xmlGuiClient);
92 
93  /**
94  * Return the XML GUI client which the view is used in.
95  * @since 4.12
96  */
97  KXMLGUIClient *xmlGuiClient() const;
98 
99  /**
100  * @reimp
101  * @param model the model to set
102  */
103  void setModel(QAbstractItemModel *model) override;
104 
105  /**
106  * Sets whether the drop action menu is @p enabled and will
107  * be shown on drop operation.
108  * @param enabled enables drop action menu if set as @c true
109  * @since 4.5
110  */
111  void setDropActionMenuEnabled(bool enabled);
112 
113  /**
114  * Returns whether the drop action menu is enabled and will
115  * be shown on drop operation.
116  *
117  * @since 4.5
118  */
119  Q_REQUIRED_RESULT bool isDropActionMenuEnabled() const;
120 
121  /**
122  * Return true if we use an manual sorting
123  * Necessary to fix dnd menu
124  * We must show just move when we move item between two items
125  * When automatic no show dnd menu between two items.
126  * @since 4.8.1
127  */
128  Q_REQUIRED_RESULT bool isManualSortingActive() const;
129 
130  /**
131  * Set true if we automatic sorting
132  * @param active enables automatic sorting if set as @c true
133  * @since 4.8.1
134  */
135  void setManualSortingActive(bool active);
136 
137  /**
138  * Set the name of the default popup menu (retrieved from the
139  * application's XMLGUI file).
140  *
141  * This menu is used as a fallback if the context of the menu request
142  * is neither an item nor a collection, e.g. the click is on an empty
143  * area inside the view. If the click is over an entry in the view,
144  * the menu which is applicable to the clicked entry (either an Item
145  * or a Collection) is used.
146  *
147  * @param name The name of the popup menu
148  *
149  * @since 4.9
150  * @note For backwards compatibility, the default is the standard
151  * collection popup menu, "akonadi_collectionview_contextmenu".
152  * @see KXMLGUIClient, KXMLGUIFactory::container()
153  */
154  void setDefaultPopupMenu(const QString &name);
155 
156 Q_SIGNALS:
157  /**
158  * This signal is emitted whenever the user has clicked
159  * a collection in the view.
160  *
161  * @param collection The clicked collection.
162  */
163  void clicked(const Akonadi::Collection &collection);
164 
165  /**
166  * This signal is emitted whenever the user has clicked
167  * an item in the view.
168  *
169  * @param item The clicked item.
170  */
171  void clicked(const Akonadi::Item &item);
172 
173  /**
174  * This signal is emitted whenever the user has double clicked
175  * a collection in the view.
176  *
177  * @param collection The double clicked collection.
178  */
179  void doubleClicked(const Akonadi::Collection &collection);
180 
181  /**
182  * This signal is emitted whenever the user has double clicked
183  * an item in the view.
184  *
185  * @param item The double clicked item.
186  */
187  void doubleClicked(const Akonadi::Item &item);
188 
189  /**
190  * This signal is emitted whenever the current collection
191  * in the view has changed.
192  *
193  * @param collection The new current collection.
194  */
195  void currentChanged(const Akonadi::Collection &collection);
196 
197  /**
198  * This signal is emitted whenever the current item
199  * in the view has changed.
200  *
201  * @param item The new current item.
202  */
203  void currentChanged(const Akonadi::Item &item);
204 
205 protected:
207 #ifndef QT_NO_DRAGANDDROP
208  void startDrag(Qt::DropActions supportedActions) override;
209  void dragMoveEvent(QDragMoveEvent *event) override;
210  void dropEvent(QDropEvent *event) override;
211 #endif
212  void timerEvent(QTimerEvent *event) override;
213 #ifndef QT_NO_CONTEXTMENU
214  void contextMenuEvent(QContextMenuEvent *event) override;
215 #endif
216 
217 private:
218  /// @cond PRIVATE
219  class Private;
220  Private *const d;
221  /// @endcond
222 };
223 
224 }
225 
226 #endif
virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous) override
Represents a collection of PIM items.
Definition: collection.h:62
A view to show an item/collection tree provided by an EntityTreeModel.
Helper integration between Akonadi and Qt.
typedef DropActions
Represents a PIM item stored in Akonadi storage.
Definition: item.h:101
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Thu Mar 4 2021 23:18:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.