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

akonadi

  • sources
  • kde-4.12
  • 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& );
48  void itemCurrentChanged( const QModelIndex& );
49  void itemClicked( const QModelIndex& );
50  void itemDoubleClicked( const QModelIndex& );
51 
52  Item itemForIndex( const QModelIndex& );
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  const Item::Id currentItem = index.sibling( index.row(), ItemModel::Id ).data( ItemModel::IdRole ).toLongLong();
83  if ( currentItem <= 0 )
84  return Item();
85 
86  const QString remoteId = index.sibling( index.row(), ItemModel::RemoteId ).data( ItemModel::IdRole ).toString();
87  const QString mimeType = index.sibling( index.row(), ItemModel::MimeType ).data( ItemModel::MimeTypeRole ).toString();
88 
89  Item item( currentItem );
90  item.setRemoteId( remoteId );
91  item.setMimeType( mimeType );
92 
93  return item;
94 }
95 
96 void ItemView::Private::itemActivated( const QModelIndex &index )
97 {
98  const Item item = itemForIndex( index );
99 
100  if ( !item.isValid() )
101  return;
102 
103  emit mParent->activated( item );
104 }
105 
106 void ItemView::Private::itemCurrentChanged( const QModelIndex &index )
107 {
108  const Item item = itemForIndex( index );
109 
110  if ( !item.isValid() )
111  return;
112 
113  emit mParent->currentChanged( item );
114 }
115 
116 void ItemView::Private::itemClicked( const QModelIndex &index )
117 {
118  const Item item = itemForIndex( index );
119 
120  if ( !item.isValid() )
121  return;
122 
123  emit mParent->clicked( item );
124 }
125 
126 void ItemView::Private::itemDoubleClicked( const QModelIndex &index )
127 {
128  const Item item = itemForIndex( index );
129 
130  if ( !item.isValid() )
131  return;
132 
133  emit mParent->doubleClicked( item );
134 }
135 
136 ItemView::ItemView( QWidget * parent ) :
137  QTreeView( parent ),
138  d( new Private( this ) )
139 {
140  d->init();
141 }
142 
143 ItemView::ItemView(KXmlGuiWindow * xmlGuiWindow, QWidget * parent) :
144  QTreeView( parent ),
145  d( new Private( this ) )
146 {
147  d->xmlGuiClient = static_cast<KXMLGUIClient*>( xmlGuiWindow );
148  d->init();
149 }
150 
151 ItemView::ItemView(KXMLGUIClient * xmlGuiClient, QWidget * parent) :
152  QTreeView( parent ),
153  d( new Private( this ) )
154 {
155  d->xmlGuiClient = xmlGuiClient;
156  d->init();
157 }
158 
159 ItemView::~ItemView()
160 {
161  delete d;
162 }
163 
164 void ItemView::setModel( QAbstractItemModel * model )
165 {
166  QTreeView::setModel( model );
167 
168  connect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
169  this, SLOT(itemCurrentChanged(QModelIndex)) );
170 }
171 
172 void ItemView::contextMenuEvent(QContextMenuEvent * event)
173 {
174  if ( !d->xmlGuiClient )
175  return;
176  QMenu *popup = static_cast<QMenu*>( d->xmlGuiClient->factory()->container(
177  QLatin1String( "akonadi_itemview_contextmenu" ), d->xmlGuiClient ) );
178  if ( popup )
179  popup->exec( event->globalPos() );
180 }
181 
182 void ItemView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow)
183 {
184  d->xmlGuiClient = static_cast<KXMLGUIClient*>( xmlGuiWindow );
185 }
186 
187 void ItemView::setXmlGuiClient(KXMLGUIClient * xmlGuiClient)
188 {
189  d->xmlGuiClient = xmlGuiClient;
190 }
191 
192 #include "moc_itemview.cpp"
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:136
Akonadi::ItemModel::IdRole
The id of the item.
Definition: itemmodel.h:74
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:265
Akonadi::ItemModel::MimeType
The item's mime type.
Definition: itemmodel.h:67
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:182
Akonadi::ItemModel::MimeTypeRole
The mime type of the item.
Definition: itemmodel.h:76
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:159
Akonadi::ItemView::setXmlGuiClient
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the KXMLGUIFactory which this view is used in.
Definition: itemview.cpp:187
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:27 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
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

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