• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.10.5 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 
21 #include "itemview.h"
22 
23 #include "control.h"
24 #include "itemmodel.h"
25 
26 #include <KXMLGUIFactory>
27 #include <KXmlGuiWindow>
28 
29 #include <QContextMenuEvent>
30 #include <QHeaderView>
31 #include <QMenu>
32 
33 using namespace Akonadi;
34 
38 class ItemView::Private
39 {
40  public:
41  Private( ItemView *parent ) :
42  xmlGuiClient( 0 ),
43  mParent( parent )
44  {
45  }
46 
47  void init();
48  void itemActivated( const QModelIndex& );
49  void itemCurrentChanged( const QModelIndex& );
50  void itemClicked( const QModelIndex& );
51  void itemDoubleClicked( const QModelIndex& );
52 
53  Item itemForIndex( const QModelIndex& );
54 
55  KXMLGUIClient *xmlGuiClient;
56 
57  private:
58  ItemView *mParent;
59 };
60 
61 void ItemView::Private::init()
62 {
63  mParent->setRootIsDecorated( false );
64 
65  mParent->header()->setClickable( true );
66  mParent->header()->setStretchLastSection( true );
67 
68  mParent->connect( mParent, SIGNAL(activated(QModelIndex)),
69  mParent, SLOT(itemActivated(QModelIndex)) );
70  mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
71  mParent, SLOT(itemClicked(QModelIndex)) );
72  mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
73  mParent, SLOT(itemDoubleClicked(QModelIndex)) );
74 
75  Control::widgetNeedsAkonadi( mParent );
76 }
77 
78 Item ItemView::Private::itemForIndex( const QModelIndex &index )
79 {
80  if ( !index.isValid() )
81  return Item();
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  const QString remoteId = index.sibling( index.row(), ItemModel::RemoteId ).data( ItemModel::IdRole ).toString();
88  const QString mimeType = index.sibling( index.row(), ItemModel::MimeType ).data( ItemModel::MimeTypeRole ).toString();
89 
90  Item item( currentItem );
91  item.setRemoteId( remoteId );
92  item.setMimeType( mimeType );
93 
94  return item;
95 }
96 
97 void ItemView::Private::itemActivated( const QModelIndex &index )
98 {
99  const Item item = itemForIndex( index );
100 
101  if ( !item.isValid() )
102  return;
103 
104  emit mParent->activated( item );
105 }
106 
107 void ItemView::Private::itemCurrentChanged( const QModelIndex &index )
108 {
109  const Item item = itemForIndex( index );
110 
111  if ( !item.isValid() )
112  return;
113 
114  emit mParent->currentChanged( item );
115 }
116 
117 void ItemView::Private::itemClicked( const QModelIndex &index )
118 {
119  const Item item = itemForIndex( index );
120 
121  if ( !item.isValid() )
122  return;
123 
124  emit mParent->clicked( item );
125 }
126 
127 void ItemView::Private::itemDoubleClicked( const QModelIndex &index )
128 {
129  const Item item = itemForIndex( index );
130 
131  if ( !item.isValid() )
132  return;
133 
134  emit mParent->doubleClicked( item );
135 }
136 
137 ItemView::ItemView( QWidget * parent ) :
138  QTreeView( parent ),
139  d( new Private( this ) )
140 {
141  d->init();
142 }
143 
144 ItemView::ItemView(KXmlGuiWindow * xmlGuiWindow, QWidget * parent) :
145  QTreeView( parent ),
146  d( new Private( this ) )
147 {
148  d->xmlGuiClient = static_cast<KXMLGUIClient*>( xmlGuiWindow );
149  d->init();
150 }
151 
152 ItemView::ItemView(KXMLGUIClient * xmlGuiClient, QWidget * parent) :
153  QTreeView( parent ),
154  d( new Private( this ) )
155 {
156  d->xmlGuiClient = xmlGuiClient;
157  d->init();
158 }
159 
160 ItemView::~ItemView()
161 {
162  delete d;
163 }
164 
165 void ItemView::setModel( QAbstractItemModel * model )
166 {
167  QTreeView::setModel( model );
168 
169  connect( selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
170  this, SLOT(itemCurrentChanged(QModelIndex)) );
171 }
172 
173 void ItemView::contextMenuEvent(QContextMenuEvent * event)
174 {
175  if ( !d->xmlGuiClient )
176  return;
177  QMenu *popup = static_cast<QMenu*>( d->xmlGuiClient->factory()->container(
178  QLatin1String( "akonadi_itemview_contextmenu" ), d->xmlGuiClient ) );
179  if ( popup )
180  popup->exec( event->globalPos() );
181 }
182 
183 void ItemView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow)
184 {
185  d->xmlGuiClient = static_cast<KXMLGUIClient*>( xmlGuiWindow );
186 }
187 
188 void ItemView::setXmlGuiClient(KXMLGUIClient * xmlGuiClient)
189 {
190  d->xmlGuiClient = xmlGuiClient;
191 }
192 
193 #include "moc_itemview.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:38 by doxygen 1.8.3.1 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-4.10.5 API Reference

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