23 #include "itemmodel.h"
25 #include <KXMLGUIFactory>
26 #include <KXmlGuiWindow>
28 #include <QContextMenuEvent>
29 #include <QHeaderView>
32 using namespace Akonadi;
37 class ItemView::Private
47 void itemActivated(
const QModelIndex &index);
48 void itemCurrentChanged(
const QModelIndex &index);
49 void itemClicked(
const QModelIndex &index);
50 void itemDoubleClicked(
const QModelIndex &index);
52 Item itemForIndex(
const QModelIndex &index);
54 KXMLGUIClient *xmlGuiClient;
60 void ItemView::Private::init()
62 mParent->setRootIsDecorated(
false);
64 mParent->header()->setClickable(
true);
65 mParent->header()->setStretchLastSection(
true);
67 mParent->connect(mParent, SIGNAL(activated(QModelIndex)),
68 mParent, SLOT(itemActivated(QModelIndex)));
69 mParent->connect(mParent, SIGNAL(clicked(QModelIndex)),
70 mParent, SLOT(itemClicked(QModelIndex)));
71 mParent->connect(mParent, SIGNAL(doubleClicked(QModelIndex)),
72 mParent, SLOT(itemDoubleClicked(QModelIndex)));
77 Item ItemView::Private::itemForIndex(
const QModelIndex &index)
79 if (!index.isValid()) {
84 if (currentItem <= 0) {
91 Item item(currentItem);
92 item.setRemoteId(remoteId);
93 item.setMimeType(mimeType);
98 void ItemView::Private::itemActivated(
const QModelIndex &index)
100 const Item item = itemForIndex(index);
102 if (!item.isValid()) {
106 emit mParent->activated(item);
109 void ItemView::Private::itemCurrentChanged(
const QModelIndex &index)
111 const Item item = itemForIndex(index);
113 if (!item.isValid()) {
117 emit mParent->currentChanged(item);
120 void ItemView::Private::itemClicked(
const QModelIndex &index)
122 const Item item = itemForIndex(index);
124 if (!item.isValid()) {
128 emit mParent->clicked(item);
131 void ItemView::Private::itemDoubleClicked(
const QModelIndex &index)
133 const Item item = itemForIndex(index);
135 if (!item.isValid()) {
139 emit mParent->doubleClicked(item);
144 , d(new Private(this))
151 , d(new Private(this))
153 d->xmlGuiClient =
static_cast<KXMLGUIClient *
>(xmlGuiWindow);
159 , d(new Private(this))
161 d->xmlGuiClient = xmlGuiClient;
170 void ItemView::setModel(QAbstractItemModel *model)
172 QTreeView::setModel(model);
174 connect(selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
175 this, SLOT(itemCurrentChanged(QModelIndex)));
178 void ItemView::contextMenuEvent(QContextMenuEvent *event)
180 if (!d->xmlGuiClient) {
183 QMenu *popup =
static_cast<QMenu *
>(d->xmlGuiClient->factory()->container(
184 QLatin1String(
"akonadi_itemview_contextmenu"), d->xmlGuiClient));
186 popup->exec(event->globalPos());
192 d->xmlGuiClient =
static_cast<KXMLGUIClient *
>(xmlGuiWindow);
197 d->xmlGuiClient = xmlGuiClient;
200 #include "moc_itemview.cpp"
void currentChanged(const Akonadi::Item &item)
This signal is emitted whenever the current item in the view has changed.
ItemView(QWidget *parent=0)
Creates a new item view.
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
The item's mime type.
AKONADI_DEPRECATED void setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow)
Sets the KXmlGuiWindow which this view is used in.
The mime type of the item.
A view to show an item list provided by an ItemModel.
virtual ~ItemView()
Destroys the item view.
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the KXMLGUIFactory which this view is used in.