trying to move slide building to more backend focused

This commit is contained in:
Chris Cochrun 2024-10-02 10:38:40 -05:00
parent 836c997e97
commit 6052cd01ac
6 changed files with 113 additions and 20 deletions

View file

@ -20,6 +20,14 @@ pub mod slide_model {
type QList_QString = cxx_qt_lib::QList<QString>;
include!("cxx-qt-gen/slide_object.cxxqt.h");
type SlideObject = crate::slide_object::slide_object::SlideObject;
include!("cxx-qt-gen/song_model.cxxqt.h");
type SongModel = crate::songs::song_model::song_model::SongModel;
include!("cxx-qt-gen/video_model.cxxqt.h");
type VideoModel = crate::video_model::video_model::VideoModel;
include!("cxx-qt-gen/image_model.cxxqt.h");
type ImageModel = crate::image_model::image_model::ImageModel;
include!("cxx-qt-gen/presentation_model.cxxqt.h");
type PresentationModel = crate::presentation_model::presentation_model::PresentationModel;
}
#[qenum(SlideModel)]
@ -52,6 +60,10 @@ pub mod slide_model {
#[qml_element]
#[qproperty(i32, count)]
#[qproperty(*mut SlideObject, slide_object)]
// #[qproperty(*mut SongModel, song_model)]
// #[qproperty(*mut VideoModel, video_model)]
// #[qproperty(*mut ImageModel, image_model)]
// #[qproperty(*mut PresentationModel, presentation_model)]
type SlideModel = super::SlideModelRust;
#[inherit]
@ -90,6 +102,7 @@ pub mod slide_model {
self: Pin<&mut SlideModel>,
index: i32,
service_item: &QMap_QString_QVariant,
id: i32,
);
#[qinvokable]
@ -97,6 +110,7 @@ pub mod slide_model {
self: Pin<&mut SlideModel>,
index: i32,
service_item: &QMap_QString_QVariant,
id: i32,
);
#[qinvokable]
@ -214,9 +228,16 @@ pub mod slide_model {
}
}
use crate::image_model::image_model::ImageModel;
use crate::presentation_model::presentation_model::PresentationModel;
use crate::songs::song_model::song_model::SongModel;
use crate::songs::song_model::SongModelRust;
use crate::video_model::video_model::VideoModel;
use crate::video_model::VideoModelRust;
use crate::{ffmpeg, slide_types::SlideType};
use crate::obs::Obs;
use crate::slide_model::slide_model::QList_QString;
use color_eyre::owo_colors::OwoColorize;
use cxx_qt::{CxxQtType, Threading};
use cxx_qt_lib::{
CaseSensitivity, QByteArray, QModelIndex, QString, QStringList, QVariant
@ -283,11 +304,15 @@ impl Default for Slide {
#[derive(Debug)]
pub struct SlideModelRust {
id: i32,
current_index: i32,
slides: Vec<Slide>,
obs: Option<Obs>,
count: i32,
slide_object: *mut SlideObject,
// song_model: *mut SongModel,
// video_model: *mut VideoModel,
// image_model: *mut ImageModel,
// presentation_model: *mut PresentationModel,
}
impl Default for SlideModelRust {
@ -303,11 +328,15 @@ impl Default for SlideModelRust {
}
});
Self {
id: 0,
current_index: 0,
slides: Vec::new(),
obs,
count: 0,
slide_object: std::ptr::null_mut(),
// song_model: std::ptr::null_mut(),
// video_model: std::ptr::null_mut(),
// image_model: std::ptr::null_mut(),
// presentation_model: std::ptr::null_mut(),
}
}
}
@ -471,6 +500,7 @@ impl slide_model::SlideModel {
mut self: Pin<&mut Self>,
index: i32,
service_item: &QMap_QString_QVariant,
id: i32,
) {
debug!(index, "Inserting slide from service insert");
for (key, data) in service_item.iter() {
@ -634,11 +664,31 @@ impl slide_model::SlideModel {
pub fn add_item_from_service(
mut self: Pin<&mut Self>,
index: i32,
service_item: &QMap_QString_QVariant,
id: i32,
kind: &QString,
) {
debug!("add rust slide {:?}", index);
let mut slide = Slide::default();
let iter = service_item.iter();
if let Ok(kind) = SlideType::try_from(kind) {
match kind {
SlideType::Song => {
let song = SongModelRust::get_song(id)?;
},
SlideType::Video => {
let video = VideoModelRust::get_video(id)?;
},
SlideType::Image => {
let image = ImageModelRust::get_image(id)?;
},
SlideType::Content => {
todo!()
},
SlideType::Presentation(_) => {
let presentation = PresentationModelRust::get_presentation(id)?;
}
}
}
for (key, _value) in iter {
debug!(?key);
@ -1124,11 +1174,11 @@ impl slide_model::SlideModel {
pub fn next(mut self: Pin<&mut Self>) -> bool {
if let Some(object) = unsafe { self.slide_object.as_mut() } {
let object = unsafe { Pin::new_unchecked(object) };
let id = self.as_ref().id + 1;
let id = self.as_ref().current_index + 1;
if let Some(slide) = self.rust().slides.get(id as usize) {
object.set_slide(slide);
self.as_mut().activate(id);
self.as_mut().rust_mut().id = id;
self.as_mut().rust_mut().current_index = id;
true
} else {
false
@ -1141,11 +1191,11 @@ impl slide_model::SlideModel {
pub fn prev(mut self: Pin<&mut Self>) -> bool {
if let Some(object) = unsafe { self.slide_object.as_mut() } {
let object = unsafe { Pin::new_unchecked(object) };
let id = self.as_ref().id - 1;
let id = self.as_ref().current_index - 1;
if let Some(slide) = self.rust().slides.get(id as usize) {
object.set_slide(slide);
self.as_mut().activate(id);
self.as_mut().rust_mut().id = id;
self.as_mut().rust_mut().current_index = id;
true
} else {
false