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

KDE's Doxygen guidelines are available online.