From 1de00586461b8575e4d0a2afff219867f933dc7d Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Wed, 29 Nov 2023 09:48:09 -0600 Subject: [PATCH] some possible ideas for how obs should work --- src/rust/presentation_model.rs | 46 ++++++++++++++++++++++++++++++++++ src/rust/slide_model.rs | 45 +++++++++++++++++++++++++++++++-- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/rust/presentation_model.rs b/src/rust/presentation_model.rs index e56465a..f8871fd 100644 --- a/src/rust/presentation_model.rs +++ b/src/rust/presentation_model.rs @@ -70,6 +70,9 @@ mod presentation_model { // index: i32, // updated_path: QString, // ) -> bool; + // #[qinvokable] + // fn duplicate_item(self: Pin<&mut Self>, index: i32) -> bool; + #[qinvokable] fn get_item( self: Pin<&mut PresentationModel>, @@ -409,6 +412,34 @@ impl presentation_model::PresentationModel { } } + // fn insert_presentation( + // mut self: Pin<&mut Self>, + // presentation: Presentation, + // index: i32, + // ) { + // unsafe { + // self.as_mut().begin_insert_rows( + // &QModelIndex::default(), + // index, + // index, + // ); + // self.as_mut() + // .rust_mut() + // .presentations + // .insert(index as usize, presentation); + // self.as_mut().end_insert_rows(); + // } + // let iter = self + // .as_mut() + // .presentations + // .iter() + // .enumerate() + // .filter(|p| p.id > index); + // for p in iter { + // p.id = p.id + 1; + // } + // } + pub fn get_item( self: Pin<&mut Self>, index: i32, @@ -434,6 +465,21 @@ impl presentation_model::PresentationModel { qvariantmap } + pub fn duplicate_item( + mut self: Pin<&mut Self>, + index: i32, + ) -> bool { + let binding = self.as_mut(); + let pres = binding.presentations.get(index as usize).clone(); + if let Some(item) = pres { + let item = item.clone(); + binding.add_presentation(item); + true + } else { + false + } + } + pub fn update_title( mut self: Pin<&mut Self>, index: i32, diff --git a/src/rust/slide_model.rs b/src/rust/slide_model.rs index b9bd2df..dea0593 100644 --- a/src/rust/slide_model.rs +++ b/src/rust/slide_model.rs @@ -227,6 +227,7 @@ pub struct Slide { video_start_time: f32, video_end_time: f32, html: bool, + obs_scene: QString, } impl Default for Slide { @@ -251,6 +252,7 @@ impl Default for Slide { video_start_time: 0.0, video_end_time: 0.0, html: false, + obs_scene: QString::default(), } } } @@ -259,6 +261,7 @@ impl Default for Slide { pub struct SlideModelRust { id: i32, slides: Vec, + obs: Option, count: i32, } @@ -605,6 +608,35 @@ impl slide_model::SlideModel { service_item: &QMap_QString_QVariant, ) { println!("add rust slide {:?}", index); + let mut slide = Slide::default(); + let iter = service_item.iter(); + + for (key, value) in iter { + debug!(?key); + match key.to_string().to_str() { + "ty" => slide.ty = QString::from(value), + "background" => { + slide.background = QString::from(value) + } + "backgroundType" => { + slide.background_type = QString::from(value) + } + "audio" => slide.audio = QString::from(value), + "font" => slide.font = QString::from(value), + "fontSize" => slide.font_size = QString::from(value), + "looping" => slide.looping = QString::from(value), + "slideCount" => { + slide.slide_count = QString::from(value) + } + "videoEndTime" => { + slide.video_end_time = QString::from(value) + } + "videoStartTime" => { + slide.video_end_time = QString::from(value) + } + } + } + let ty = service_item .get(&QString::from("ty")) .unwrap_or(QVariant::from(&QString::from(""))) @@ -632,8 +664,6 @@ impl slide_model::SlideModel { Vec::::from(&QList_QString::from(&textlist)); // let vec_slize: &[usize] = &text_vec; - let mut slide = Slide::default(); - slide.ty = service_item .get(&QString::from("type")) .unwrap_or(QVariant::from(&QString::from(""))) @@ -1014,6 +1044,9 @@ impl slide_model::SlideModel { // println!("slide is deactivating {:?}", i); slide.active = false; } + + let obs = self.as_mut().obs.clone(); + if let Some(slide) = self.as_mut().rust_mut().slides.get_mut(index as usize) { @@ -1034,6 +1067,14 @@ impl slide_model::SlideModel { // ); slide.active = true; self.as_mut().data_changed(tl, br, &vector_roles); + + if let Some(obs) = obs { + match obs.set_scene(slide.obs_scene.to_string()) { + Ok(()) => debug!("Successfully set scene"), + Err(e) => error!(e), + } + } + // We use this signal generated by our signals enum to tell QML that // the active slide has changed which is used to reposition views. self.as_mut().active_change(&index);