Improve song edit dialog

This commit is contained in:
Carl Philipp Klemm 2026-03-04 19:59:04 +01:00
parent 56660fe0b5
commit 82182425e6
2 changed files with 20 additions and 22 deletions

View file

@ -17,6 +17,8 @@ add_executable(${PROJECT_NAME}
main.cpp
MainWindow.ui
MainWindow.cpp
SongDialog.ui
SongDialog.cpp
SongListModel.cpp
AudioPlayer.cpp
AceStepWorker.cpp

View file

@ -1,5 +1,6 @@
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "SongDialog.h"
#include <QMessageBox>
#include <QInputDialog>
#include <QFileDialog>
@ -230,13 +231,12 @@ void MainWindow::on_shuffleButton_clicked()
void MainWindow::on_addSongButton_clicked()
{
bool ok;
QString caption = QInputDialog::getText(this, "Add Song", "Enter song caption:", QLineEdit::Normal, "", &ok);
SongDialog dialog(this);
if (ok && !caption.isEmpty()) {
QString lyrics = QInputDialog::getMultiLineText(this, "Add Song", "Enter lyrics (optional):", "", &ok);
if (dialog.exec() == QDialog::Accepted) {
QString caption = dialog.getCaption();
QString lyrics = dialog.getLyrics();
if (ok) {
SongItem newSong(caption, lyrics);
songModel->addSong(newSong);
@ -245,7 +245,6 @@ void MainWindow::on_addSongButton_clicked()
ui->songListView->setCurrentIndex(newIndex);
}
}
}
void MainWindow::on_editSongButton_clicked()
{
@ -255,20 +254,17 @@ void MainWindow::on_editSongButton_clicked()
int row = currentIndex.row();
SongItem song = songModel->getSong(row);
bool ok;
QString caption = QInputDialog::getText(this, "Edit Song", "Enter song caption:", QLineEdit::Normal, song.caption, &ok);
SongDialog dialog(this, song.caption, song.lyrics);
if (ok && !caption.isEmpty()) {
QString lyrics = QInputDialog::getMultiLineText(this, "Edit Song", "Enter lyrics (optional):", song.lyrics, &ok);
if (dialog.exec() == QDialog::Accepted) {
QString caption = dialog.getCaption();
QString lyrics = dialog.getLyrics();
if (ok) {
SongItem editedSong(caption, lyrics);
// Update the model
songModel->setData(songModel->index(row, 0), caption, SongListModel::CaptionRole);
songModel->setData(songModel->index(row, 0), lyrics, SongListModel::LyricsRole);
}
}
}
void MainWindow::on_removeSongButton_clicked()
{