24 #include "itemmodel.h"
26 #include <KXMLGUIFactory>
27 #include <KXmlGuiWindow>
29 #include <QContextMenuEvent>
30 #include <QHeaderView>
33 using namespace Akonadi;
38 class ItemView::Private
48 void itemActivated(
const QModelIndex& );
49 void itemCurrentChanged(
const QModelIndex& );
50 void itemClicked(
const QModelIndex& );
51 void itemDoubleClicked(
const QModelIndex& );
53 Item itemForIndex(
const QModelIndex& );
55 KXMLGUIClient *xmlGuiClient;
61 void ItemView::Private::init()
63 mParent->setRootIsDecorated(
false );
65 mParent->header()->setClickable(
true );
66 mParent->header()->setStretchLastSection(
true );
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)) );
78 Item ItemView::Private::itemForIndex(
const QModelIndex &index )
80 if ( !index.isValid() )
84 if ( currentItem <= 0 )
90 Item item( currentItem );
91 item.setRemoteId( remoteId );
92 item.setMimeType( mimeType );
97 void ItemView::Private::itemActivated(
const QModelIndex &index )
99 const Item item = itemForIndex( index );
104 emit mParent->activated( item );
107 void ItemView::Private::itemCurrentChanged(
const QModelIndex &index )
109 const Item item = itemForIndex( index );
114 emit mParent->currentChanged( item );
117 void ItemView::Private::itemClicked(
const QModelIndex &index )
119 const Item item = itemForIndex( index );
124 emit mParent->clicked( item );
127 void ItemView::Private::itemDoubleClicked(
const QModelIndex &index )
129 const Item item = itemForIndex( index );
134 emit mParent->doubleClicked( item );
139 d( new Private( this ) )
146 d( new Private( this ) )
148 d->xmlGuiClient =
static_cast<KXMLGUIClient*
>( xmlGuiWindow );
154 d( new Private( this ) )
156 d->xmlGuiClient = xmlGuiClient;
165 void ItemView::setModel( QAbstractItemModel * model )
167 QTreeView::setModel( model );
169 connect( selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
170 this, SLOT(itemCurrentChanged(QModelIndex)) );
173 void ItemView::contextMenuEvent(QContextMenuEvent * event)
175 if ( !d->xmlGuiClient )
177 QMenu *popup =
static_cast<QMenu*
>( d->xmlGuiClient->factory()->container(
178 QLatin1String(
"akonadi_itemview_contextmenu" ), d->xmlGuiClient ) );
180 popup->exec( event->globalPos() );
185 d->xmlGuiClient =
static_cast<KXMLGUIClient*
>( xmlGuiWindow );
190 d->xmlGuiClient = xmlGuiClient;
193 #include "moc_itemview.cpp"