1/*
2 Copyright (c) 2007 Tobias Koenig <tokoe@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_ITEM_VIEW
21#define AKONADI_ITEM_VIEW
22
23#include "akonadi_export.h"
24#include <QTreeView>
25
26class KXmlGuiWindow;
27class KXMLGUIClient;
28namespace Akonadi {
29
30class Item;
31
32/**
33 * @short A view to show an item list provided by an ItemModel.
34 *
35 * When a KXmlGuiWindow is set, the XMLGUI defined context menu
36 * @c akonadi_itemview_contextmenu is used if available.
37 *
38 * Example:
39 *
40 * @code
41 *
42 * class MyWindow : public KXmlGuiWindow
43 * {
44 * public:
45 * MyWindow()
46 * : KXmlGuiWindow()
47 * {
48 * Akonadi::ItemView *view = new Akonadi::ItemView( this, this );
49 * setCentralWidget( view );
50 *
51 * Akonadi::ItemModel *model = new Akonadi::ItemModel( this );
52 * view->setModel( model );
53 * }
54 * }
55 *
56 * @endcode
57 *
58 * @author Tobias Koenig <tokoe@kde.org>
59 */
60class AKONADI_EXPORT ItemView : public QTreeView
61{
62 Q_OBJECT
63
64public:
65 /**
66 * Creates a new item view.
67 *
68 * @param parent The parent widget.
69 */
70 explicit ItemView(QWidget *parent = 0);
71
72 /**
73 * Creates a new item view.
74 *
75 * @param xmlGuiWindow The KXmlGuiWindow this is used in.
76 * This is needed for the XMLGUI based context menu.
77 * Passing 0 is ok and will disable the builtin context menu.
78 * @param parent The parent widget.
79 */
80 explicit AKONADI_DEPRECATED ItemView(KXmlGuiWindow *xmlGuiWindow, QWidget *parent = 0);
81
82 /**
83 * Creates a new item view.
84 *
85 * @param xmlGuiClient The KXMLGUIClient this is used in.
86 * This is needed for the XMLGUI based context menu.
87 * Passing 0 is ok and will disable the builtin context menu.
88 * @param parent The parent widget.
89 * @since 4.3
90 */
91 explicit ItemView(KXMLGUIClient *xmlGuiClient, QWidget *parent = 0);
92
93 /**
94 * Destroys the item view.
95 */
96 virtual ~ItemView();
97
98 /**
99 * Sets the KXmlGuiWindow which this view is used in.
100 * This is needed if you want to use the built-in context menu.
101 *
102 * @param xmlGuiWindow The KXmlGuiWindow this view is used in.
103 */
104 AKONADI_DEPRECATED void setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow);
105
106 /**
107 * Sets the KXMLGUIFactory which this view is used in.
108 * This is needed if you want to use the built-in context menu.
109 *
110 * @param xmlGuiClient The KXMLGUIClient this view is used in.
111 */
112 void setXmlGuiClient(KXMLGUIClient *xmlGuiClient);
113
114 virtual void setModel(QAbstractItemModel *model);
115
116Q_SIGNALS:
117 /**
118 * This signal is emitted whenever the user has activated
119 * an item in the view.
120 *
121 * @param item The activated item.
122 */
123 void activated(const Akonadi::Item &item);
124
125 /**
126 * This signal is emitted whenever the current item
127 * in the view has changed.
128 *
129 * @param item The current item.
130 */
131 void currentChanged(const Akonadi::Item &item);
132
133 /**
134 * This signal is emitted whenever the user clicked on an item
135 * in the view.
136 *
137 * @param item The item the user clicked on.
138 * @since 4.3
139 */
140 void clicked(const Akonadi::Item &item);
141
142 /**
143 * This signal is emitted whenever the user double clicked on an item
144 * in the view.
145 *
146 * @param item The item the user double clicked on.
147 * @since 4.3
148 */
149 void doubleClicked(const Akonadi::Item &item);
150
151protected:
152 using QTreeView::currentChanged;
153 void contextMenuEvent(QContextMenuEvent *event);
154
155private:
156 //@cond PRIVATE
157 class Private;
158 Private *const d;
159
160 Q_PRIVATE_SLOT(d, void itemActivated(const QModelIndex &))
161 Q_PRIVATE_SLOT(d, void itemCurrentChanged(const QModelIndex &))
162 Q_PRIVATE_SLOT(d, void itemClicked(const QModelIndex &))
163 Q_PRIVATE_SLOT(d, void itemDoubleClicked(const QModelIndex &))
164 //@endcond
165};
166
167}
168
169#endif
170