starting to change slide_model to have the logic of changing slides
In order to make slide_object dumber and and not need to keep track of slide info, we are moving the business logic to slide_model so that the model can keep track of whether presentations are ready to switch and don't need to run reveal_next or something.
This commit is contained in:
parent
4c403d9f3c
commit
8c7f2d794f
4 changed files with 84 additions and 56 deletions
|
@ -16,14 +16,10 @@ pub mod slide_model {
|
|||
type QModelIndex = cxx_qt_lib::QModelIndex;
|
||||
include!("cxx-qt-lib/qvector.h");
|
||||
type QVector_i32 = cxx_qt_lib::QVector<i32>;
|
||||
// include!("cxx-qt-lib/qstringlist.h");
|
||||
// type QStringList = cxx_qt_lib::QStringList;
|
||||
include!("cxx-qt-lib/qlist.h");
|
||||
type QList_QString = cxx_qt_lib::QList<QString>;
|
||||
// #[cxx_name = "Slidey"]
|
||||
// type CxxSlidey = super::qobject::Slidey;
|
||||
// include!("cxx-qt-lib/qvector.h");
|
||||
// type QVector_Slidey = cxx_qt_lib::QVector<Slidey>;
|
||||
include!("cxx-qt-gen/slide_object.cxxqt.h");
|
||||
type SlideObject = crate::slide_object::slide_object::SlideObject;
|
||||
}
|
||||
|
||||
#[qenum(SlideModel)]
|
||||
|
@ -55,6 +51,7 @@ pub mod slide_model {
|
|||
#[base = "QAbstractListModel"]
|
||||
#[qml_element]
|
||||
#[qproperty(i32, count)]
|
||||
#[qproperty(*mut SlideObject, slide_object)]
|
||||
type SlideModel = super::SlideModelRust;
|
||||
|
||||
#[inherit]
|
||||
|
@ -117,7 +114,7 @@ pub mod slide_model {
|
|||
) -> QMap_QString_QVariant;
|
||||
|
||||
#[qinvokable]
|
||||
fn next(self: Pin<&mut SlideModel>) -> QMap_QString_QVariant;
|
||||
fn next(self: Pin<&mut SlideModel>) -> bool;
|
||||
|
||||
#[qinvokable]
|
||||
fn get_slide_from_service(
|
||||
|
@ -221,6 +218,7 @@ use cxx_qt::{CxxQtType, Threading};
|
|||
use cxx_qt_lib::{
|
||||
CaseSensitivity, QByteArray, QModelIndex, QString, QStringList, QVariant
|
||||
};
|
||||
use slide_model::SlideObject;
|
||||
use std::thread;
|
||||
use std::{path::PathBuf, pin::Pin};
|
||||
use tracing::{debug, error};
|
||||
|
@ -232,26 +230,26 @@ use self::slide_model::{
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Slide {
|
||||
text: String,
|
||||
ty: String,
|
||||
audio: String,
|
||||
image_background: String,
|
||||
video_background: String,
|
||||
htext_alignment: String,
|
||||
vtext_alignment: String,
|
||||
font: String,
|
||||
font_size: i32,
|
||||
slide_count: i32,
|
||||
slide_index: i32,
|
||||
service_item_id: i32,
|
||||
active: bool,
|
||||
selected: bool,
|
||||
looping: bool,
|
||||
video_thumbnail: String,
|
||||
video_start_time: f32,
|
||||
video_end_time: f32,
|
||||
html: bool,
|
||||
obs_scene: String,
|
||||
pub text: String,
|
||||
pub ty: String,
|
||||
pub audio: String,
|
||||
pub image_background: String,
|
||||
pub video_background: String,
|
||||
pub htext_alignment: String,
|
||||
pub vtext_alignment: String,
|
||||
pub font: String,
|
||||
pub font_size: i32,
|
||||
pub slide_count: i32,
|
||||
pub slide_index: i32,
|
||||
pub service_item_id: i32,
|
||||
pub active: bool,
|
||||
pub selected: bool,
|
||||
pub looping: bool,
|
||||
pub video_thumbnail: String,
|
||||
pub video_start_time: f32,
|
||||
pub video_end_time: f32,
|
||||
pub html: bool,
|
||||
pub obs_scene: String,
|
||||
}
|
||||
|
||||
impl Default for Slide {
|
||||
|
@ -287,6 +285,7 @@ pub struct SlideModelRust {
|
|||
slides: Vec<Slide>,
|
||||
obs: Option<Obs>,
|
||||
count: i32,
|
||||
slide_object: *mut SlideObject,
|
||||
}
|
||||
|
||||
impl Default for SlideModelRust {
|
||||
|
@ -306,6 +305,7 @@ impl Default for SlideModelRust {
|
|||
slides: Vec::new(),
|
||||
obs,
|
||||
count: 0,
|
||||
slide_object: std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1119,15 +1119,21 @@ impl slide_model::SlideModel {
|
|||
qvariantmap
|
||||
}
|
||||
|
||||
pub fn next(self: Pin<&mut Self>) -> QMap_QString_QVariant {
|
||||
let id = self.id.clone();
|
||||
if let Some(slide) = self.rust().slides.get(self.id as usize) {
|
||||
if slide.html {
|
||||
// conditional logic for html slides
|
||||
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) };
|
||||
if let Some(slide) = self.rust().slides.get(self.id as usize + 1) {
|
||||
object.set_slide(slide);
|
||||
let id = self.as_ref().id + 1;
|
||||
self.as_mut().activate(id);
|
||||
self.as_mut().rust_mut().id = id;
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
return self.get_item(id + 1);
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.get_item(id + 1)
|
||||
}
|
||||
|
||||
pub fn get_slide_from_service(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue