• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • KDE-PIM Libraries
  • Sitemap
  • Contact Us
 

akonadi

itemview.cpp

00001 /*
00002     Copyright (c) 2007 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 
00021 #include "itemview.h"
00022 
00023 #include "control.h"
00024 #include "itemmodel.h"
00025 
00026 #include <KXMLGUIFactory>
00027 #include <KXmlGuiWindow>
00028 
00029 #include <QtGui/QContextMenuEvent>
00030 #include <QtGui/QHeaderView>
00031 #include <QtGui/QMenu>
00032 
00033 using namespace Akonadi;
00034 
00038 class ItemView::Private
00039 {
00040   public:
00041     Private( ItemView *parent ) :
00042       xmlGuiWindow( 0 ),
00043       mParent( parent )
00044     {
00045     }
00046 
00047     void init();
00048     void itemActivated( const QModelIndex& );
00049     void itemCurrentChanged( const QModelIndex& );
00050 
00051     KXmlGuiWindow *xmlGuiWindow;
00052 
00053   private:
00054     ItemView *mParent;
00055 };
00056 
00057 void ItemView::Private::init()
00058 {
00059   mParent->setRootIsDecorated( false );
00060 
00061   mParent->header()->setClickable( true );
00062   mParent->header()->setStretchLastSection( true );
00063 
00064   mParent->connect( mParent, SIGNAL( activated( const QModelIndex& ) ),
00065                     mParent, SLOT( itemActivated( const QModelIndex& ) ) );
00066 
00067   Control::widgetNeedsAkonadi( mParent );
00068 }
00069 
00070 void ItemView::Private::itemActivated( const QModelIndex &index )
00071 {
00072   if ( !index.isValid() )
00073     return;
00074 
00075   const Item::Id currentItem = index.sibling(index.row(),ItemModel::Id).data(ItemModel::IdRole).toLongLong();
00076   if ( currentItem <= 0 )
00077     return;
00078 
00079   const QString remoteId = index.sibling(index.row(),ItemModel::RemoteId).data(ItemModel::IdRole).toString();
00080 
00081   Item item( currentItem );
00082   item.setRemoteId( remoteId );
00083 
00084   emit mParent->activated( item );
00085 }
00086 
00087 void ItemView::Private::itemCurrentChanged( const QModelIndex &index )
00088 {
00089   if ( !index.isValid() )
00090     return;
00091 
00092   const Item::Id currentItem = index.sibling(index.row(),ItemModel::Id).data(ItemModel::IdRole).toLongLong();
00093   if ( currentItem <= 0 )
00094     return;
00095 
00096   const QString remoteId = index.sibling(index.row(),ItemModel::RemoteId).data(ItemModel::IdRole).toString();
00097 
00098   Item item( currentItem );
00099   item.setRemoteId( remoteId );
00100 
00101   emit mParent->currentChanged( item );
00102 }
00103 
00104 ItemView::ItemView( QWidget * parent ) :
00105     QTreeView( parent ),
00106     d( new Private( this ) )
00107 {
00108   d->init();
00109 }
00110 
00111 ItemView::ItemView(KXmlGuiWindow * xmlGuiWindow, QWidget * parent) :
00112     QTreeView( parent ),
00113     d( new Private( this ) )
00114 {
00115   d->xmlGuiWindow = xmlGuiWindow;
00116   d->init();
00117 }
00118 
00119 ItemView::~ItemView()
00120 {
00121   delete d;
00122 }
00123 
00124 void ItemView::setModel( QAbstractItemModel * model )
00125 {
00126   QTreeView::setModel( model );
00127 
00128   connect( selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
00129            this, SLOT( itemCurrentChanged( const QModelIndex& ) ) );
00130 }
00131 
00132 void ItemView::contextMenuEvent(QContextMenuEvent * event)
00133 {
00134   if ( !d->xmlGuiWindow )
00135     return;
00136   QMenu *popup = static_cast<QMenu*>( d->xmlGuiWindow->guiFactory()->container(
00137                                       QLatin1String("akonadi_itemview_contextmenu"), d->xmlGuiWindow ) );
00138   if ( popup )
00139     popup->exec( event->globalPos() );
00140 }
00141 
00142 void ItemView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow)
00143 {
00144   d->xmlGuiWindow = xmlGuiWindow;
00145 }
00146 
00147 #include "itemview.moc"

akonadi

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

KDE-PIM Libraries

Skip menu "KDE-PIM Libraries"
  • akonadi
  • kabc
  • kblog
  • kcal
  • kimap
  • kioslave
  •   imap4
  •   mbox
  • kldap
  • kmime
  • kpimidentities
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.8
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal