• 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     void itemClicked( const QModelIndex& );
00051     void itemDoubleClicked( const QModelIndex& );
00052 
00053     Item itemForIndex( const QModelIndex& );
00054 
00055     KXmlGuiWindow *xmlGuiWindow;
00056 
00057   private:
00058     ItemView *mParent;
00059 };
00060 
00061 void ItemView::Private::init()
00062 {
00063   mParent->setRootIsDecorated( false );
00064 
00065   mParent->header()->setClickable( true );
00066   mParent->header()->setStretchLastSection( true );
00067 
00068   mParent->connect( mParent, SIGNAL( activated( const QModelIndex& ) ),
00069                     mParent, SLOT( itemActivated( const QModelIndex& ) ) );
00070   mParent->connect( mParent, SIGNAL( clicked( const QModelIndex& ) ),
00071                     mParent, SLOT( itemClicked( const QModelIndex& ) ) );
00072   mParent->connect( mParent, SIGNAL( doubleClicked( const QModelIndex& ) ),
00073                     mParent, SLOT( itemDoubleClicked( const QModelIndex& ) ) );
00074 
00075   Control::widgetNeedsAkonadi( mParent );
00076 }
00077 
00078 Item ItemView::Private::itemForIndex( const QModelIndex &index )
00079 {
00080   if ( !index.isValid() )
00081     return Item();
00082 
00083   const Item::Id currentItem = index.sibling( index.row(), ItemModel::Id ).data( ItemModel::IdRole ).toLongLong();
00084   if ( currentItem <= 0 )
00085     return Item();
00086 
00087   const QString remoteId = index.sibling( index.row(), ItemModel::RemoteId ).data( ItemModel::IdRole ).toString();
00088   const QString mimeType = index.sibling( index.row(), ItemModel::MimeType ).data( ItemModel::MimeTypeRole ).toString();
00089 
00090   Item item( currentItem );
00091   item.setRemoteId( remoteId );
00092   item.setMimeType( mimeType );
00093 
00094   return item;
00095 }
00096 
00097 void ItemView::Private::itemActivated( const QModelIndex &index )
00098 {
00099   const Item item = itemForIndex( index );
00100 
00101   if ( !item.isValid() )
00102     return;
00103 
00104   emit mParent->activated( item );
00105 }
00106 
00107 void ItemView::Private::itemCurrentChanged( const QModelIndex &index )
00108 {
00109   const Item item = itemForIndex( index );
00110 
00111   if ( !item.isValid() )
00112     return;
00113 
00114   emit mParent->currentChanged( item );
00115 }
00116 
00117 void ItemView::Private::itemClicked( const QModelIndex &index )
00118 {
00119   const Item item = itemForIndex( index );
00120 
00121   if ( !item.isValid() )
00122     return;
00123 
00124   emit mParent->clicked( item );
00125 }
00126 
00127 void ItemView::Private::itemDoubleClicked( const QModelIndex &index )
00128 {
00129   const Item item = itemForIndex( index );
00130 
00131   if ( !item.isValid() )
00132     return;
00133 
00134   emit mParent->doubleClicked( item );
00135 }
00136 
00137 ItemView::ItemView( QWidget * parent ) :
00138     QTreeView( parent ),
00139     d( new Private( this ) )
00140 {
00141   d->init();
00142 }
00143 
00144 ItemView::ItemView(KXmlGuiWindow * xmlGuiWindow, QWidget * parent) :
00145     QTreeView( parent ),
00146     d( new Private( this ) )
00147 {
00148   d->xmlGuiWindow = xmlGuiWindow;
00149   d->init();
00150 }
00151 
00152 ItemView::~ItemView()
00153 {
00154   delete d;
00155 }
00156 
00157 void ItemView::setModel( QAbstractItemModel * model )
00158 {
00159   QTreeView::setModel( model );
00160 
00161   connect( selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ),
00162            this, SLOT( itemCurrentChanged( const QModelIndex& ) ) );
00163 }
00164 
00165 void ItemView::contextMenuEvent(QContextMenuEvent * event)
00166 {
00167   if ( !d->xmlGuiWindow )
00168     return;
00169   QMenu *popup = static_cast<QMenu*>( d->xmlGuiWindow->guiFactory()->container(
00170                                       QLatin1String("akonadi_itemview_contextmenu"), d->xmlGuiWindow ) );
00171   if ( popup )
00172     popup->exec( event->globalPos() );
00173 }
00174 
00175 void ItemView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow)
00176 {
00177   d->xmlGuiWindow = xmlGuiWindow;
00178 }
00179 
00180 #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.7
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