void PlaylistBrowserNS::PlaylistBrowserView::contextMenuEvent( QContextMenuEvent *event ) { QModelIndex clickedIdx = indexAt( event->pos() ); QModelIndexList indices; if( clickedIdx.isValid() && selectedIndexes().contains( clickedIdx ) ) indices << selectedIndexes(); else if( clickedIdx.isValid() ) indices << clickedIdx; QActionList actions = actionsFor( indices ); if( actions.isEmpty() ) { resetActionTargets(); return; } KMenu menu; foreach( QAction *action, actions ) menu.addAction( action ); menu.exec( mapToGlobal( event->pos() ) ); // We keep the items that the action need to be applied to. // Clear the data from all actions now that the context menu has executed. resetActionTargets(); }
void OpmlDirectoryView::contextMenuEvent( QContextMenuEvent *event ) { QModelIndex idx = indexAt( event->pos() ); debug() << idx; event->accept(); QVariant data = model()->data( idx, OpmlDirectoryModel::ActionRole ); QActionList actions = data.value<QActionList>(); if( actions.isEmpty() ) { return; } KMenu menu; foreach( QAction *action, actions ) { if( action ) menu.addAction( action ); } menu.exec( mapToGlobal( event->pos() ) ); //We keep the items that the actions need to be applied to in the actions private data. //Clear the data from all actions now that the context menu has executed. foreach( QAction *action, actions ) action->setData( QVariant() ); }