1 | /* |
2 | Copyright (c) 2006 - 2007 Volker Krause <vkrause@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef AKONADI_COLLECTION_VIEW |
21 | #define AKONADI_COLLECTION_VIEW |
22 | |
23 | #include "akonadi_export.h" |
24 | #include <QTreeView> |
25 | |
26 | class KXMLGUIClient; |
27 | class KXmlGuiWindow; |
28 | class QDragMoveEvent; |
29 | |
30 | namespace Akonadi { |
31 | |
32 | class Collection; |
33 | |
34 | /** |
35 | * @short A view to show a collection tree provided by a CollectionModel. |
36 | * |
37 | * When a KXmlGuiWindow is passed to the constructor, the XMLGUI |
38 | * defined context menu @c akonadi_collectionview_contextmenu is |
39 | * used if available. |
40 | * |
41 | * Example: |
42 | * |
43 | * @code |
44 | * |
45 | * class MyWindow : public KXmlGuiWindow |
46 | * { |
47 | * public: |
48 | * MyWindow() |
49 | * : KXmlGuiWindow() |
50 | * { |
51 | * Akonadi::CollectionView *view = new Akonadi::CollectionView( this, this ); |
52 | * setCentralWidget( view ); |
53 | * |
54 | * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this ); |
55 | * view->setModel( model ); |
56 | * } |
57 | * } |
58 | * |
59 | * @endcode |
60 | * |
61 | * @author Volker Krause <vkrause@kde.org> |
62 | */ |
63 | class AKONADI_EXPORT CollectionView : public QTreeView |
64 | { |
65 | Q_OBJECT |
66 | |
67 | public: |
68 | /** |
69 | * Creates a new collection view. |
70 | * |
71 | * @param parent The parent widget. |
72 | */ |
73 | explicit CollectionView(QWidget *parent = 0); |
74 | |
75 | /** |
76 | * Creates a new collection view. |
77 | * |
78 | * @param xmlGuiWindow The KXmlGuiWindow the view is used in. |
79 | * This is needed for the XMLGUI based context menu. |
80 | * Passing 0 is ok and will disable the builtin context menu. |
81 | * @param parent The parent widget. |
82 | */ |
83 | explicit AKONADI_DEPRECATED CollectionView(KXmlGuiWindow *xmlGuiWindow, QWidget *parent = 0); |
84 | |
85 | /** |
86 | * Creates a new collection view. |
87 | * |
88 | * @param xmlGuiClient The KXmlGuiClient the view is used in. |
89 | * This is needed for the XMLGUI based context menu. |
90 | * Passing 0 is ok and will disable the builtin context menu. |
91 | * @param parent The parent widget. |
92 | */ |
93 | explicit CollectionView(KXMLGUIClient *xmlGuiClient, QWidget *parent = 0); |
94 | |
95 | /** |
96 | * Destroys the collection view. |
97 | */ |
98 | virtual ~CollectionView(); |
99 | |
100 | /** |
101 | * Sets the KXmlGuiWindow which the view is used in. |
102 | * This is needed if you want to use the built-in context menu. |
103 | * |
104 | * @param xmlGuiWindow The KXmlGuiWindow the view is used in. |
105 | */ |
106 | AKONADI_DEPRECATED void setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow); |
107 | |
108 | /** |
109 | * Sets the KXMLGUIClient which the view is used in. |
110 | * This is needed if you want to use the built-in context menu. |
111 | * |
112 | * @param xmlGuiClient The KXMLGUIClient the view is used in. |
113 | * @since 4.3 |
114 | */ |
115 | void setXmlGuiClient(KXMLGUIClient *xmlGuiClient); |
116 | |
117 | virtual void setModel(QAbstractItemModel *model); |
118 | |
119 | Q_SIGNALS: |
120 | /** |
121 | * This signal is emitted whenever the user has clicked |
122 | * a collection in the view. |
123 | * |
124 | * @param collection The clicked collection. |
125 | */ |
126 | void clicked(const Akonadi::Collection &collection); |
127 | |
128 | /** |
129 | * This signal is emitted whenever the current collection |
130 | * in the view has changed. |
131 | * |
132 | * @param collection The new current collection. |
133 | */ |
134 | void currentChanged(const Akonadi::Collection &collection); |
135 | |
136 | protected: |
137 | using QTreeView::currentChanged; |
138 | virtual void dragMoveEvent(QDragMoveEvent *event); |
139 | virtual void dragLeaveEvent(QDragLeaveEvent *event); |
140 | virtual void dropEvent(QDropEvent *event); |
141 | virtual void (QContextMenuEvent *event); |
142 | |
143 | private: |
144 | //@cond PRIVATE |
145 | class Private; |
146 | Private *const d; |
147 | |
148 | Q_PRIVATE_SLOT(d, void dragExpand()) |
149 | Q_PRIVATE_SLOT(d, void itemClicked(const QModelIndex &)) |
150 | Q_PRIVATE_SLOT(d, void itemCurrentChanged(const QModelIndex &)) |
151 | //@endcond |
152 | }; |
153 | |
154 | } |
155 | |
156 | #endif |
157 | |