• Skip to content
  • Skip to link menu
KDE 4.1 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 "itemmodel.h"
00024 
00025 #include <KXMLGUIFactory>
00026 #include <KXmlGuiWindow>
00027 
00028 #include <QtGui/QHeaderView>
00029 #include <QContextMenuEvent>
00030 #include <QMenu>
00031 
00032 using namespace Akonadi;
00033 
00037 class ItemView::Private
00038 {
00039   public:
00040     Private( ItemView *parent ) :
00041       xmlGuiWindow( 0 ),
00042       mParent( parent )
00043     {
00044     }
00045 
00046     void init();
00047     void itemActivated( const QModelIndex& );
00048     void itemCurrentChanged( const QModelIndex& );
00049 
00050     KXmlGuiWindow *xmlGuiWindow;
00051 
00052   private:
00053     ItemView *mParent;
00054 };
00055 
00056 void ItemView::Private::init()
00057 {
00058   mParent->setRootIsDecorated( false );
00059 
00060   mParent->header()->setClickable( true );
00061   mParent->header()->setStretchLastSection( true );
00062 
00063   mParent->connect( mParent, SIGNAL( activated( const QModelIndex& ) ),
00064                     mParent, SLOT( itemActivated( const QModelIndex& ) ) );
00065 }
00066 
00067 void ItemView::Private::itemActivated( const QModelIndex &index )
00068 {
00069   if ( !index.isValid() )
00070     return;
00071 
00072   const Item::Id currentItem = index.sibling(index.row(),ItemModel::Id).data(ItemModel::IdRole).toLongLong();
00073   if ( currentItem <= 0 )
00074     return;
00075 
00076   const QString remoteId = index.sibling(index.row(),ItemModel::RemoteId).data(ItemModel::IdRole).toString();
00077 
00078   Item item( currentItem );
00079   item.setRemoteId( remoteId );
00080 
00081   emit mParent->activated( item );
00082 }
00083 
00084 void ItemView::Private::itemCurrentChanged( const QModelIndex &index )
00085 {
00086   if ( !index.isValid() )
00087     return;
00088 
00089   const Item::Id currentItem = index.sibling(index.row(),ItemModel::Id).data(ItemModel::IdRole).toLongLong();
00090   if ( currentItem <= 0 )
00091     return;
00092 
00093   const QString remoteId = index.sibling(index.row(),ItemModel::RemoteId).data(ItemModel::IdRole).toString();
00094 
00095   Item item( currentItem );
00096   item.setRemoteId( remoteId );
00097 
00098   emit mParent->currentChanged( item );
00099 }
00100 
00101 ItemView::ItemView( QWidget * parent ) :
00102     QTreeView( parent ),
00103     d( new Private( this ) )
00104 {
00105   d->init();
00106 }
00107 
00108 ItemView::ItemView(KXmlGuiWindow * xmlGuiWindow, QWidget * parent) :
00109     QTreeView( parent ),
00110     d( new Private( this ) )
00111 {
00112   d->xmlGuiWindow = xmlGuiWindow;
00113   d->init();
00114 }
00115 
00116 ItemView::~ItemView()
00117 {
00118   delete d;
00119 }
00120 
00121 void ItemView::setModel( QAbstractItemModel * model )
00122 {
00123   QTreeView::setModel( model );
00124 
00125   connect( selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
00126            this, SLOT( itemCurrentChanged( const QModelIndex& ) ) );
00127 }
00128 
00129 void ItemView::contextMenuEvent(QContextMenuEvent * event)
00130 {
00131   if ( !d->xmlGuiWindow )
00132     return;
00133   QMenu *popup = static_cast<QMenu*>( d->xmlGuiWindow->guiFactory()->container(
00134                                       QLatin1String("akonadi_itemview_contextmenu"), d->xmlGuiWindow ) );
00135   if ( popup )
00136     popup->exec( event->globalPos() );
00137 }
00138 
00139 void ItemView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow)
00140 {
00141   d->xmlGuiWindow = xmlGuiWindow;
00142 }
00143 
00144 #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
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Generated for KDE-PIM Libraries by doxygen 1.5.4
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