Improve song edit dialog
This commit is contained in:
parent
56660fe0b5
commit
82182425e6
2 changed files with 20 additions and 22 deletions
|
|
@ -17,6 +17,8 @@ add_executable(${PROJECT_NAME}
|
||||||
main.cpp
|
main.cpp
|
||||||
MainWindow.ui
|
MainWindow.ui
|
||||||
MainWindow.cpp
|
MainWindow.cpp
|
||||||
|
SongDialog.ui
|
||||||
|
SongDialog.cpp
|
||||||
SongListModel.cpp
|
SongListModel.cpp
|
||||||
AudioPlayer.cpp
|
AudioPlayer.cpp
|
||||||
AceStepWorker.cpp
|
AceStepWorker.cpp
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "ui_MainWindow.h"
|
#include "ui_MainWindow.h"
|
||||||
|
#include "SongDialog.h"
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
@ -230,20 +231,18 @@ void MainWindow::on_shuffleButton_clicked()
|
||||||
|
|
||||||
void MainWindow::on_addSongButton_clicked()
|
void MainWindow::on_addSongButton_clicked()
|
||||||
{
|
{
|
||||||
bool ok;
|
SongDialog dialog(this);
|
||||||
QString caption = QInputDialog::getText(this, "Add Song", "Enter song caption:", QLineEdit::Normal, "", &ok);
|
|
||||||
|
|
||||||
if (ok && !caption.isEmpty()) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
QString lyrics = QInputDialog::getMultiLineText(this, "Add Song", "Enter lyrics (optional):", "", &ok);
|
QString caption = dialog.getCaption();
|
||||||
|
QString lyrics = dialog.getLyrics();
|
||||||
|
|
||||||
if (ok) {
|
SongItem newSong(caption, lyrics);
|
||||||
SongItem newSong(caption, lyrics);
|
songModel->addSong(newSong);
|
||||||
songModel->addSong(newSong);
|
|
||||||
|
|
||||||
// Select the new item
|
// Select the new item
|
||||||
QModelIndex newIndex = songModel->index(songModel->rowCount() - 1, 0);
|
QModelIndex newIndex = songModel->index(songModel->rowCount() - 1, 0);
|
||||||
ui->songListView->setCurrentIndex(newIndex);
|
ui->songListView->setCurrentIndex(newIndex);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,18 +254,15 @@ void MainWindow::on_editSongButton_clicked()
|
||||||
int row = currentIndex.row();
|
int row = currentIndex.row();
|
||||||
SongItem song = songModel->getSong(row);
|
SongItem song = songModel->getSong(row);
|
||||||
|
|
||||||
bool ok;
|
SongDialog dialog(this, song.caption, song.lyrics);
|
||||||
QString caption = QInputDialog::getText(this, "Edit Song", "Enter song caption:", QLineEdit::Normal, song.caption, &ok);
|
|
||||||
|
|
||||||
if (ok && !caption.isEmpty()) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
QString lyrics = QInputDialog::getMultiLineText(this, "Edit Song", "Enter lyrics (optional):", song.lyrics, &ok);
|
QString caption = dialog.getCaption();
|
||||||
|
QString lyrics = dialog.getLyrics();
|
||||||
|
|
||||||
if (ok) {
|
// Update the model
|
||||||
SongItem editedSong(caption, lyrics);
|
songModel->setData(songModel->index(row, 0), caption, SongListModel::CaptionRole);
|
||||||
// Update the model
|
songModel->setData(songModel->index(row, 0), lyrics, SongListModel::LyricsRole);
|
||||||
songModel->setData(songModel->index(row, 0), caption, SongListModel::CaptionRole);
|
|
||||||
songModel->setData(songModel->index(row, 0), lyrics, SongListModel::LyricsRole);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue