update to make song_editor ready

This commit is contained in:
Chris Cochrun 2023-10-09 13:53:09 -05:00
parent e1cfa5e843
commit 96d5bdac73
5 changed files with 93 additions and 85 deletions

View file

@ -145,8 +145,8 @@ Controls.Page {
FileHelper { id: fileHelper }
SlideHelper { id: slideHelper }
SongEditor {
id: songEditor
songModel: songProxyModel.songModel()
id: songEditorModel
/* songModel: songProxyModel.songModel() */
}
function changeServiceItem(index) {

View file

@ -10,7 +10,7 @@ Item {
id: root
property int songIndex
property var song
property var song: songEditorModel
GridLayout {
id: mainLayout
@ -445,8 +445,8 @@ Item {
Presenter.SongEditorSlideList {
id: songList
imageBackground: song.backgroundType === "image" ? song.background : ""
videoBackground: song.backgroundType === "video" ? song.background : ""
imageBackground: songEditorModel.backgroundType === "image" ? songEditor.background : ""
videoBackground: songEditorModel.backgroundType === "video" ? songEditor.background : ""
Layout.preferredWidth: 500
Layout.fillWidth: true
Layout.fillHeight: true
@ -471,54 +471,6 @@ Item {
}
}
FileDialog {
id: audioFileDialog
title: "Please choose an audio file"
folder: shortcuts.home
selectMultiple: false
nameFilters: ["Audio files (*.mp3 *.flac *.wav *.opus *.MP3 *.FLAC *.WAV *.OPUS)"]
onAccepted: {
updateAudioFile(audioFileDialog.fileUrls[0]);
console.log("audio = " + audioFileDialog.fileUrls[0]);
}
onRejected: {
console.log("Canceled")
}
}
FileDialog {
id: videoFileDialog
title: "Please choose a background"
folder: shortcuts.home
selectMultiple: false
nameFilters: ["Video files (*.mp4 *.mkv *.mov *.wmv *.avi *.MP4 *.MOV *.MKV)"]
onAccepted: {
updateBackground(videoFileDialog.fileUrls[0], "video");
console.log("video background = " + videoFileDialog.fileUrls[0]);
}
onRejected: {
console.log("Canceled")
}
}
FileDialog {
id: imageFileDialog
title: "Please choose a background"
folder: shortcuts.home
selectMultiple: false
nameFilters: ["Image files (*.jpg *.jpeg *.png *.JPG *.JPEG *.PNG)"]
onAccepted: {
updateBackground(imageFileDialog.fileUrls[0], "image");
console.log("image background = " + imageFileDialog.fileUrls[0]);
}
onRejected: {
console.log("Canceled")
}
}
function newSong(index) {
clearSlides();
song = songProxyModel.getSong(index);
@ -534,7 +486,20 @@ Item {
function changeSong(index) {
clearSlides();
song = songProxyModel.getSong(index);
const updatedSong = songProxyModel.getSong(index);
console.log(updatedSong.verseOrder + " " + updatedSong.title);
songEditorModel.title = updatedSong.title;
songEditorModel.lyrics = updatedSong.lyrics;
songEditorModel.author = updatedSong.author;
songEditorModel.ccli = updatedSong.ccli;
songEditorModel.audio = updatedSong.audio;
songEditorModel.verseOrder = updatedSong.verseOrder;
songEditorModel.background = updatedSong.background;
songEditorModel.backgroundType = updatedSong.backgroundType;
songEditorModel.horizontalTextAlignment = updatedSong.horizontalTextAlignment;
songEditorModel.verticalTextAlignment = updatedSong.verticalTextAlignment;
songEditorModel.font = updatedSong.font;
songEditorModel.fontSize = updatedSong.fontSize;
songIndex = song.id;
changeSlideHAlignment(song.horizontalTextAlignment);
@ -577,26 +542,17 @@ Item {
function updateAudioFile() {
const file = fileHelper.loadFile("Pick Audio", "audio");
songEditorModel.audio = file
songProxyModel.songModel.updateAudio(songIndex, file);
}
function updateBackground(backgroundType) {
song.backgroundType = backgroundType;
songEditorModel.backgroundType = backgroundType;
const file = fileHelper.loadFile("Pick Background", backgroundType);
song.background = file;
songEditorModel.background = file;
songProxyModel.songModel.updateBackground(songIndex, file);
songProxyModel.songModel.updateBackgroundType(songIndex, backgroundType);
console.log("changed background");
/* if (backgroundType === "image") { */
/* //todo */
/* songList.videoBackground = ""; */
/* songList.imageBackground = background; */
/* } else { */
/* //todo */
/* songList.imageBackground = ""; */
/* songList.videoBackground = background; */
/* songList.loadVideo(); */
/* } */
}
@ -674,7 +630,6 @@ Item {
}
function changeSlideText(id) {
/* console.log("Here are the verses: " + verses); */
const verses = songProxyModel.getLyricList(id);
verses.forEach(songList.appendVerse);
/* songList.loadVideo(); */

View file

@ -1,6 +1,5 @@
#[cxx_qt::bridge]
mod song_editor {
use crate::songs::song_model::qobject::SongModel;
pub mod song_editor {
unsafe extern "C++" {
include!("cxx-qt-lib/qmap.h");
@ -16,8 +15,8 @@ mod song_editor {
type QStringList = cxx_qt_lib::QStringList;
include!("cxx-qt-lib/qlist.h");
type QList_QString = cxx_qt_lib::QList<QString>;
#[cxx_name = "SongModel"]
type CxxSongs = SongModel;
// #[cxx_name = "SongModel"]
// type CxxSongs = crate::songs::song_model::qobject::SongModel;
}
#[derive(Clone, Debug)]
@ -49,8 +48,8 @@ mod song_editor {
font: QString,
#[qproperty]
font_size: i32,
#[qproperty]
song_model: *mut CxxSongs,
// #[qproperty]
// song_model: *mut CxxSongs,
}
impl Default for SongEditor {
@ -69,17 +68,50 @@ mod song_editor {
vertical_text_alignment: QString::default(),
font: QString::default(),
font_size: 50,
song_model: std::ptr::null_mut(),
// song_model: std::ptr::null_mut(),
}
}
}
impl SongEditor {
impl qobject::SongEditor {
fn idk(mut self: Pin<&mut Self>) {
let mut model = self.song_model().as_mut().unwrap();
let pinned_model = Pin::new_unchecked(model);
pinned_model.update_ccli(0, QString::from("idk"));
todo!();
// let mut model = self.song_model().as_mut().unwrap();
// let pinned_model = Pin::new_unchecked(model);
// pinned_model.update_ccli(0, QString::from("idk"));
todo!()
}
// #[qinvokable]
// fn set_song(
// mut self: Pin<&mut Self>,
// title: QString,
// lyrics: QString,
// author: QString,
// ccli: QString,
// audio: QUrl,
// verse_order: QString,
// background: QUrl,
// background_type: QString,
// horizontal_text_alignment: QString,
// vertical_text_alignment: QString,
// font: QString,
// font_size: i32,
// ) -> bool {
// self.as_mut().set_title(title);
// self.as_mut().set_lyrics(lyrics);
// self.as_mut().set_author(author);
// self.as_mut().set_ccli(ccli);
// self.as_mut().set_audio(audio);
// self.as_mut().set_verse_order(verse_order);
// self.as_mut().set_background(background);
// self.as_mut().set_background_type(background_type);
// self.as_mut().set_horizontal_text_alignment(
// horizontal_text_alignment,
// );
// self.as_mut()
// .set_vertical_text_alignment(vertical_text_alignment);
// self.as_mut().set_font(font);
// self.as_mut().set_font_size(font_size);
// true
// }
}
}

View file

@ -286,11 +286,11 @@ pub mod song_model {
.get_mut(index as usize)
{
song.title = updated_title.to_string();
self.as_mut().emit(Signals::DataChanged {
top_left: &model_index,
bottom_right: &model_index,
roles: &vector_roles,
});
self.as_mut().emit_data_changed(
model_index,
model_index,
&vector_roles,
);
self.as_mut().emit_title_changed();
true
} else {
@ -793,6 +793,7 @@ pub mod song_model {
let role_names_iter = role_names.iter();
if let Some(song) = self.rust().songs.get(index as usize)
{
debug!(song);
for i in role_names_iter {
qvariantmap.insert(
QString::from(&i.1.to_string()),