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

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • 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 
32 using namespace Akonadi;
33 
37 class ItemView::Private
38 {
39 public:
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 
56 private:
57  ItemView *mParent;
58 };
59 
60 void 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 
77 Item 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 
98 void 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 
109 void 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 
120 void 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 
131 void 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 
142 ItemView::ItemView(QWidget *parent)
143  : QTreeView(parent)
144  , d(new Private(this))
145 {
146  d->init();
147 }
148 
149 ItemView::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 
157 ItemView::ItemView(KXMLGUIClient *xmlGuiClient, QWidget *parent)
158  : QTreeView(parent)
159  , d(new Private(this))
160 {
161  d->xmlGuiClient = xmlGuiClient;
162  d->init();
163 }
164 
165 ItemView::~ItemView()
166 {
167  delete d;
168 }
169 
170 void ItemView::setModel(QAbstractItemModel *model)
171 {
172  QTreeView::setModel(model);
173 
174  connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
175  this, SLOT(itemCurrentChanged(QModelIndex)));
176 }
177 
178 void 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 
190 void ItemView::setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow)
191 {
192  d->xmlGuiClient = static_cast<KXMLGUIClient *>(xmlGuiWindow);
193 }
194 
195 void ItemView::setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
196 {
197  d->xmlGuiClient = xmlGuiClient;
198 }
199 
200 #include "moc_itemview.cpp"
QModelIndex
QWidget
QAbstractItemView::selectionModel
QItemSelectionModel * selectionModel() const
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
ItemView(QWidget *parent=0)
Creates a new item view.
Definition: itemview.cpp:142
QContextMenuEvent::globalPos
const QPoint & globalPos() const
QModelIndex::isValid
bool isValid() const
Akonadi::ItemModel::IdRole
The id of the item.
Definition: itemmodel.h:74
QContextMenuEvent
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::MimeType
The item's mime type.
Definition: itemmodel.h:67
QModelIndex::row
int row() const
Akonadi::ItemModel::RemoteId
The remote identifier.
Definition: itemmodel.h:66
Akonadi::ItemModel::Id
The unique id.
Definition: itemmodel.h:65
Akonadi::ItemView::setXmlGuiWindow
AKONADI_DEPRECATED void setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow)
Sets the KXmlGuiWindow which this view is used in.
Definition: itemview.cpp:190
QString
QMenu::exec
QAction * exec()
Akonadi::ItemModel::MimeTypeRole
The mime type of the item.
Definition: itemmodel.h:76
QMenu
Akonadi::ItemView
A view to show an item list provided by an ItemModel.
Definition: itemview.h:60
Akonadi::ItemView::~ItemView
virtual ~ItemView()
Destroys the item view.
Definition: itemview.cpp:165
QLatin1String
QTreeView
QModelIndex::sibling
QModelIndex sibling(int row, int column) const
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
QAbstractItemModel
Akonadi::ItemView::setXmlGuiClient
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the KXMLGUIFactory which this view is used in.
Definition: itemview.cpp:195
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject::parent
QObject * parent() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 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
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs 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

Search



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