23 #include "itemmodel.h"
25 #include <KXMLGUIFactory>
26 #include <KXmlGuiWindow>
28 #include <QContextMenuEvent>
29 #include <QHeaderView>
32 using namespace Akonadi;
37 class ItemView::Private
47 void itemActivated(
const QModelIndex& );
48 void itemCurrentChanged(
const QModelIndex& );
49 void itemClicked(
const QModelIndex& );
50 void itemDoubleClicked(
const QModelIndex& );
52 Item itemForIndex(
const QModelIndex& );
54 KXMLGUIClient *xmlGuiClient;
60 void ItemView::Private::init()
62 mParent->setRootIsDecorated(
false );
64 mParent->header()->setClickable(
true );
65 mParent->header()->setStretchLastSection(
true );
67 mParent->connect( mParent, SIGNAL(activated(QModelIndex)),
68 mParent, SLOT(itemActivated(QModelIndex)) );
69 mParent->connect( mParent, SIGNAL(clicked(QModelIndex)),
70 mParent, SLOT(itemClicked(QModelIndex)) );
71 mParent->connect( mParent, SIGNAL(doubleClicked(QModelIndex)),
72 mParent, SLOT(itemDoubleClicked(QModelIndex)) );
77 Item ItemView::Private::itemForIndex(
const QModelIndex &index )
79 if ( !index.isValid() )
83 if ( currentItem <= 0 )
89 Item item( currentItem );
90 item.setRemoteId( remoteId );
91 item.setMimeType( mimeType );
96 void ItemView::Private::itemActivated(
const QModelIndex &index )
98 const Item item = itemForIndex( index );
100 if ( !item.isValid() )
103 emit mParent->activated( item );
106 void ItemView::Private::itemCurrentChanged(
const QModelIndex &index )
108 const Item item = itemForIndex( index );
110 if ( !item.isValid() )
113 emit mParent->currentChanged( item );
116 void ItemView::Private::itemClicked(
const QModelIndex &index )
118 const Item item = itemForIndex( index );
120 if ( !item.isValid() )
123 emit mParent->clicked( item );
126 void ItemView::Private::itemDoubleClicked(
const QModelIndex &index )
128 const Item item = itemForIndex( index );
130 if ( !item.isValid() )
133 emit mParent->doubleClicked( item );
138 d( new Private( this ) )
145 d( new Private( this ) )
147 d->xmlGuiClient =
static_cast<KXMLGUIClient*
>( xmlGuiWindow );
153 d( new Private( this ) )
155 d->xmlGuiClient = xmlGuiClient;
164 void ItemView::setModel( QAbstractItemModel * model )
166 QTreeView::setModel( model );
168 connect( selectionModel(), SIGNAL(
currentChanged(QModelIndex,QModelIndex)),
169 this, SLOT(itemCurrentChanged(QModelIndex)) );
172 void ItemView::contextMenuEvent(QContextMenuEvent * event)
174 if ( !d->xmlGuiClient )
176 QMenu *popup =
static_cast<QMenu*
>( d->xmlGuiClient->factory()->container(
177 QLatin1String(
"akonadi_itemview_contextmenu" ), d->xmlGuiClient ) );
179 popup->exec( event->globalPos() );
184 d->xmlGuiClient =
static_cast<KXMLGUIClient*
>( xmlGuiWindow );
189 d->xmlGuiClient = xmlGuiClient;
192 #include "moc_itemview.cpp"
void currentChanged(const Akonadi::Item &item)
This signal is emitted whenever the current item in the view has changed.
ItemView(QWidget *parent=0)
Creates a new item view.
static void widgetNeedsAkonadi(QWidget *widget)
Disable the given widget when Akonadi is not operational and show an error overlay (given enough spac...
AKONADI_DEPRECATED void setXmlGuiWindow(KXmlGuiWindow *xmlGuiWindow)
Sets the KXmlGuiWindow which this view is used in.
The mime type of the item.
A view to show an item list provided by an ItemModel.
virtual ~ItemView()
Destroys the item view.
void setXmlGuiClient(KXMLGUIClient *xmlGuiClient)
Sets the KXMLGUIFactory which this view is used in.