Edit dialog via double click
This commit is contained in:
parent
3d2e182d4f
commit
c4d2fa3ffa
4 changed files with 22 additions and 16 deletions
|
|
@ -40,6 +40,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(aceStepWorker, &AceStepWorker::generationError, this, &MainWindow::generationError);
|
connect(aceStepWorker, &AceStepWorker::generationError, this, &MainWindow::generationError);
|
||||||
connect(aceStepWorker, &AceStepWorker::progressUpdate, ui->progressBar, &QProgressBar::setValue);
|
connect(aceStepWorker, &AceStepWorker::progressUpdate, ui->progressBar, &QProgressBar::setValue);
|
||||||
|
|
||||||
|
// Connect double-click on song list for editing
|
||||||
|
connect(ui->songListView, &QListView::doubleClicked, this, &MainWindow::on_songListView_doubleClicked);
|
||||||
|
|
||||||
// Connect audio player error signal
|
// Connect audio player error signal
|
||||||
connect(audioPlayer, &AudioPlayer::playbackError, [this](const QString &error) {
|
connect(audioPlayer, &AudioPlayer::playbackError, [this](const QString &error) {
|
||||||
QMessageBox::warning(this, "Playback Error", "Failed to play audio: " + error);
|
QMessageBox::warning(this, "Playback Error", "Failed to play audio: " + error);
|
||||||
|
|
@ -57,6 +60,9 @@ void MainWindow::setupUI()
|
||||||
// Setup song list view
|
// Setup song list view
|
||||||
ui->songListView->setModel(songModel);
|
ui->songListView->setModel(songModel);
|
||||||
|
|
||||||
|
// Make sure the list view is read-only (no inline editing)
|
||||||
|
ui->songListView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
||||||
|
|
||||||
// Add some default songs
|
// Add some default songs
|
||||||
SongItem defaultSong1("Upbeat pop rock anthem with driving electric guitars", "");
|
SongItem defaultSong1("Upbeat pop rock anthem with driving electric guitars", "");
|
||||||
SongItem defaultSong2("Chill electronic music with smooth synths and relaxing beats", "");
|
SongItem defaultSong2("Chill electronic music with smooth synths and relaxing beats", "");
|
||||||
|
|
@ -151,7 +157,6 @@ void MainWindow::updateControls()
|
||||||
ui->skipButton->setEnabled(isPlaying);
|
ui->skipButton->setEnabled(isPlaying);
|
||||||
ui->stopButton->setEnabled(isPlaying);
|
ui->stopButton->setEnabled(isPlaying);
|
||||||
ui->addSongButton->setEnabled(true);
|
ui->addSongButton->setEnabled(true);
|
||||||
ui->editSongButton->setEnabled(hasSongs && ui->songListView->currentIndex().isValid());
|
|
||||||
ui->removeSongButton->setEnabled(hasSongs && ui->songListView->currentIndex().isValid());
|
ui->removeSongButton->setEnabled(hasSongs && ui->songListView->currentIndex().isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -240,12 +245,15 @@ void MainWindow::on_addSongButton_clicked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_editSongButton_clicked()
|
void MainWindow::on_songListView_doubleClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
QModelIndex currentIndex = ui->songListView->currentIndex();
|
if (!index.isValid()) return;
|
||||||
if (!currentIndex.isValid()) return;
|
|
||||||
|
|
||||||
int row = currentIndex.row();
|
// Temporarily disconnect the signal to prevent multiple invocations
|
||||||
|
// This happens when the dialog closes and triggers another double-click event
|
||||||
|
disconnect(ui->songListView, &QListView::doubleClicked, this, &MainWindow::on_songListView_doubleClicked);
|
||||||
|
|
||||||
|
int row = index.row();
|
||||||
SongItem song = songModel->getSong(row);
|
SongItem song = songModel->getSong(row);
|
||||||
|
|
||||||
SongDialog dialog(this, song.caption, song.lyrics);
|
SongDialog dialog(this, song.caption, song.lyrics);
|
||||||
|
|
@ -258,6 +266,9 @@ void MainWindow::on_editSongButton_clicked()
|
||||||
songModel->setData(songModel->index(row, 0), caption, SongListModel::CaptionRole);
|
songModel->setData(songModel->index(row, 0), caption, SongListModel::CaptionRole);
|
||||||
songModel->setData(songModel->index(row, 0), lyrics, SongListModel::LyricsRole);
|
songModel->setData(songModel->index(row, 0), lyrics, SongListModel::LyricsRole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reconnect the signal after dialog is closed
|
||||||
|
connect(ui->songListView, &QListView::doubleClicked, this, &MainWindow::on_songListView_doubleClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_removeSongButton_clicked()
|
void MainWindow::on_removeSongButton_clicked()
|
||||||
|
|
@ -476,4 +487,4 @@ void MainWindow::on_positionSlider_sliderMoved(int position)
|
||||||
// Seek to the new position when slider is moved
|
// Seek to the new position when slider is moved
|
||||||
audioPlayer->setPosition(position);
|
audioPlayer->setPosition(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,11 @@ private slots:
|
||||||
void updatePosition(int position);
|
void updatePosition(int position);
|
||||||
void updateDuration(int duration);
|
void updateDuration(int duration);
|
||||||
void on_addSongButton_clicked();
|
void on_addSongButton_clicked();
|
||||||
void on_editSongButton_clicked();
|
|
||||||
void on_removeSongButton_clicked();
|
void on_removeSongButton_clicked();
|
||||||
void on_advancedSettingsButton_clicked();
|
void on_advancedSettingsButton_clicked();
|
||||||
|
|
||||||
|
void on_songListView_doubleClicked(const QModelIndex &index);
|
||||||
|
|
||||||
void songGenerated(const QString &filePath);
|
void songGenerated(const QString &filePath);
|
||||||
void playNextSong();
|
void playNextSong();
|
||||||
void playbackStarted();
|
void playbackStarted();
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed</set>
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -48,13 +48,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="editSongButton">
|
|
||||||
<property name="text">
|
|
||||||
<string>Edit Song</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="removeSongButton">
|
<widget class="QPushButton" name="removeSongButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,8 @@ Qt::ItemFlags SongListModel::flags(const QModelIndex &index) const
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return Qt::NoItemFlags;
|
return Qt::NoItemFlags;
|
||||||
|
|
||||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
|
// Remove ItemIsEditable to prevent inline editing and double-click issues
|
||||||
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SongListModel::addSong(const SongItem &song)
|
void SongListModel::addSong(const SongItem &song)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue