Hi everybody,

I have a listview. I create a menu for this listview.
The idea from this popup menu is that the user are able to delete songs from the list OR
add songs to a playlist.
But it depends if the user see the playlist or are searching songs..If the user see the playlist,
so he must be able just to "remove songs from the Playlist".
If he are searching songs, he should be able just to "add to Playlist". My popup is dynamic.


My situation now:
I am not able to call the function actionTriggered() on choosing a action from contextMenu2. The function
actionTriggered2 will always called.
I am able to call actionTriggered2() from contextMenu without problem.

How could i call actionTriggered() by choosesing "add to Playlist". And how could i call actionTriggered2() on choosing
"remove from Playlist"?
Thanks

Qt Code:
  1. contextMenu2 = new Q3PopupMenu( this);
  2. contextMenu2 = new Q3PopupMenu( this);
  3.  
  4.  
  5.  
  6. contextMenu = new Q3PopupMenu( this);
  7. contextMenu2 = new Q3PopupMenu( this);
  8.  
  9.  
  10. connect(contextMenu2,SIGNAL(triggered(QAction *)),this,SLOT(actionTriggered(QAction *)));
  11. connect(contextMenu,SIGNAL(triggered(QAction *)),this,SLOT(actionTriggered2(QAction *)));
  12.  
  13.  
  14. void MainWindow::PlaylistMenu( Q3ListViewItem *Item, const QPoint &point, int)
  15. {
  16. contextMenu2->clear();
  17. contextMenu->clear();
  18.  
  19. if( Item )
  20. contextMenu->popup( point );
  21. Q_CHECK_PTR( contextMenu );
  22.  
  23.  
  24. //Die Playlist Funktionen sollen nur angezeigt werden, wenn auch
  25. //eine Playlist gewählt wurde und auch einen song vorhanden ist
  26. if((ui.playlistname_cb->currentText() != "") && (ui.listView->childCount() > 0))
  27. {
  28. contextMenu->insertItem( "&remove from Playlist");
  29. contextMenu->exec( QCursor::pos() );
  30. //delete contextMenu;
  31. return;
  32. }
  33. if((ui.playlistname_cb->currentText() == "") && (ui.listView->childCount() > 0))
  34. {
  35. contextMenu2->setTitle("add to Playlist");
  36. int items = ui.playlistname_cb->count();
  37. for(int i = 1; i < items; i++)
  38. {
  39. QString playlistname = ui.playlistname_cb->itemText(i);
  40. contextMenu2->addAction(playlistname);
  41. contextMenu->addMenu(contextMenu2);
  42. }
  43. contextMenu->exec( QCursor::pos() );
  44. //delete contextMenu;
  45. //delete contextMenu2;
  46. return;
  47. }
  48. }
  49.  
  50.  
  51. void MainWindow::actionTriggered(QAction *a)
  52. {
  53. QString playlistname = a->text();
  54. addToPlaylist(&playlistname);
  55. }
  56.  
  57. void MainWindow::actionTriggered2(QAction *a)
  58. {
  59. QString songname = (ui.listView->currentItem() )->text( 0 );
  60. QString artist = (ui.listView->currentItem() )->text( 1 );
  61. switch( QMessageBox::warning( this, "DSM",
  62. "Remove " + songname + " of " + artist + " from Playlist "
  63. + ui.playlistname_cb->currentText() + " ?\n\n",
  64. "Yes",
  65. "No", 0, 0, 1 ) )
  66. {
  67. case 1:
  68. break;
  69. case 0:
  70. //Song aus der aktuelle Playlist löschen
  71. removeFromPlaylist();
  72. //Aktualisieren
  73. getPlaylist();
  74. }
  75. }
To copy to clipboard, switch view to plain text mode