void MainWindow::showSongsContextMenu(QPoint point) { QTreeView *songs = (QTreeView*)ui->tvSongs; if(songs->indexAt(point).isValid()) { QList<QAction *> actions; QAction *action = new QAction(songs); action->setText(tr("Play")); connect(action, SIGNAL(triggered()), this, SLOT(playAudio())); actions.append(action); action = new QAction(songs); action->setText(tr("Delete")); connect(action, SIGNAL(triggered()), this, SLOT(deleteAudio())); actions.append(action); action = new QAction(songs); action->setSeparator(true); actions.append(action); QList<Playlist> pls = dp->getPlaylists(); int n = pls.count(); QSignalMapper* signalMapper = new QSignalMapper (this); for( int i=0; i<n; i++ ) { action = new QAction(songs); action->setText("Add to " + pls[i].title); connect(action, SIGNAL(triggered()), signalMapper, SLOT(map())); signalMapper->setMapping (action, pls[i].id) ; actions.append(action); } connect (signalMapper, SIGNAL(mapped(int)), this, SLOT(addAudioToPlaylist(int))); QMenu::exec(actions, songs->mapToGlobal(point)); }
void MainWindow::showPlaylistsContextMenu(QPoint point) { QTreeView *playlists = (QTreeView*)ui->tvPlaylists; if(playlists->indexAt(point).isValid()) { QStandardItemModel *model = (QStandardItemModel*)playlists->model(); QStandardItem *item = model->itemFromIndex(playlists->indexAt(point)); int data = item->data(DATA_KEY_PLAYLIST).toInt(); QList<QAction *> actions; QAction *action; switch(data) { case DATA_SEARCH: break; case DATA_EMPTY: action = new QAction(playlists); action->setText(tr("Add")); connect(action, SIGNAL(triggered()), this, SLOT(addPlaylist())); actions.append(action); break; case DATA_HISTORY: break; default: action = new QAction(playlists); action->setText(tr("Delete")); connect(action, SIGNAL(triggered()), this, SLOT(deletePlaylist())); actions.append(action); break; } if(actions.count() > 0) { point.setX(point.x()-10); point.setY(point.y()+30); QMenu::exec(actions, playlists->mapToGlobal(point)); } } }