• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
itemview.cpp
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#include "itemview.h"
21
22#include "control.h"
23#include "itemmodel.h"
24
25#include <KXMLGUIFactory>
26#include <KXmlGuiWindow>
27
28#include <QContextMenuEvent>
29#include <QHeaderView>
30#include <QMenu>
31
32using namespace Akonadi;
33
37class ItemView::Private
38{
39public:
40 Private(ItemView *parent)
41 : xmlGuiClient(0)
42 , mParent(parent)
43 {
44 }
45
46 void init();
47 void itemActivated(const QModelIndex &index);
48 void itemCurrentChanged(const QModelIndex &index);
49 void itemClicked(const QModelIndex &index);
50 void itemDoubleClicked(const QModelIndex &index);
51
52 Item itemForIndex(const QModelIndex &index);
53
54 KXMLGUIClient *xmlGuiClient;
55
56private:
57 ItemView *mParent;
58};
59
60void ItemView::Private::init()
61{
62 mParent->setRootIsDecorated(false);
63
64 mParent->header()->setClickable(true);
65 mParent->header()->setStretchLastSection(true);
66
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)));
73
74 Control::widgetNeedsAkonadi(mParent);
75}
76
77Item ItemView::Private::itemForIndex(const QModelIndex &index)
78{
79 if (!index.isValid()) {
80 return Item();
81 }
82
83 const Item::Id currentItem = index.sibling(index.row(), ItemModel::Id).data(ItemModel::IdRole).toLongLong();
84 if (currentItem <= 0) {
85 return Item();
86 }
87
88 const QString remoteId = index.sibling(index.row(), ItemModel::RemoteId).data(ItemModel::IdRole).toString();
89 const QString mimeType = index.sibling(index.row(), ItemModel::MimeType).data(ItemModel::MimeTypeRole).toString();
90
91 Item item(currentItem);
92 item.setRemoteId(remoteId);
93 item.setMimeType(mimeType);
94
95 return item;
96}
97
98void ItemView::Private::itemActivated(const QModelIndex &index)
99{
100 const Item item = itemForIndex(index);
101
102 if (!item.isValid()) {
103 return;
104 }
105
106 emit mParent->activated(item);
107}
108
109void ItemView::Private::itemCurrentChanged(const QModelIndex &index)
110{
111 const Item item = itemForIndex(index);
112
113 if (!item.isValid()) {
114 return;
115 }
116
117 emit mParent->currentChanged(item);
118}
119
120void ItemView::Private::itemClicked(const QModelIndex &index)
121{
122 const Item item = itemForIndex(index);
123
124 if (!item.isValid()) {
125 return;
126 }
127
128 emit mParent->clicked(item);
129}
130
131void ItemView::Private::itemDoubleClicked(const QModelIndex &index)
132{
133 const Item item = itemForIndex(index);
134
135 if (!item.isValid()) {
136 return;
137 }
138
139 emit mParent->doubleClicked(item);
140}
141
142ItemView::ItemView(QWidget *parent)
143 : QTreeView(parent)
144 , d(new Private(this))
145{
146 d->init();
147}
148
149ItemView::ItemView(KXmlGuiWindow *xmlGuiWindow, QWidget *parent)
150 : QTreeView(parent)
151 , d(new Private(this))
152{
153 d->xmlGuiClient = static_cast<KXMLGUIClient *>(xmlGuiWindow);
154 d->init();
155}
156
157ItemView::ItemView(KXMLGUIClient *xmlGuiClient, QWidget *parent)
158 : QTreeView(parent)
159 , d(new Private(this))
160{
161 d->xmlGuiClient = xmlGuiClient;
162 d->init();
163}
164
165ItemView::~ItemView()
166{
167 delete d;
168}
169
170void ItemView::setModel(QAbstractItemModel *model)
171{
172 QTreeView::setModel(model);
173
174 connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
175 this, SLOT(itemCurrentChanged(QModelIndex)));
176}
177
178void ItemView::contextMenuEvent(QContextMenuEvent *event)
179{
180 if (!d->xmlGuiClient) {
181 return;
182 }
183 QMenu *popup = static_cast<QMenu *>(d->xmlGuiClient->factory()->container(
184 QLatin1String("akonadi_itemview_contextmenu"), d->xmlGuiClient));
185 if (popup) {
186 popup->exec(event->globalPos());
187 }
188}
189
190void ItemView::setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow)
191{
192 d->xmlGuiClient = static_cast<KXMLGUIClient *>(xmlGuiWindow);
193}
194
195void ItemView::setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
196{
197 d->xmlGuiClient = xmlGuiClient;
198}
199
200#include "moc_itemview.cpp"
Akonadi::Control::widgetNeedsAkonadi
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
Definition control.cpp:264
Akonadi::ItemModel::IdRole
@ IdRole
The id of the item.
Definition itemmodel.h:74
Akonadi::ItemModel::MimeTypeRole
@ MimeTypeRole
The mime type of the item.
Definition itemmodel.h:76
Akonadi::ItemModel::Id
@ Id
The unique id.
Definition itemmodel.h:65
Akonadi::ItemModel::RemoteId
@ RemoteId
The remote identifier.
Definition itemmodel.h:66
Akonadi::ItemModel::MimeType
@ MimeType
The item's mime type.
Definition itemmodel.h:67
Akonadi::ItemView
A view to show an item list provided by an ItemModel.
Definition itemview.h:61
Akonadi::ItemView::doubleClicked
void doubleClicked(const Akonadi::Item &item)
This signal is emitted whenever the user double clicked on an item in the view.
Akonadi::ItemView::currentChanged
void currentChanged(const Akonadi::Item &item)
This signal is emitted whenever the current item in the view has changed.
Akonadi::ItemView::~ItemView
virtual ~ItemView()
Destroys the item view.
Definition itemview.cpp:165
Akonadi::ItemView::activated
void activated(const Akonadi::Item &item)
This signal is emitted whenever the user has activated an item in the view.
Akonadi::ItemView::clicked
void clicked(const Akonadi::Item &item)
This signal is emitted whenever the user clicked on an item in the view.
Akonadi::ItemView::ItemView
ItemView(QWidget *parent=0)
Creates a new item view.
Definition itemview.cpp:142
Akonadi::ItemView::setXmlGuiClient
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the KXMLGUIFactory which this view is used in.
Definition itemview.cpp:195
Akonadi::ItemView::setXmlGuiWindow
AKONADI_DEPRECATED void setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow)
Sets the KXmlGuiWindow which this view is used in.
Definition itemview.cpp:190
Akonadi
FreeBusyManager::Singleton.
Definition actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal