attempting to switch the next button to using slibe_object for a
cleaner interaction
This commit is contained in:
parent
8c31678b4e
commit
791bcc146e
4 changed files with 130 additions and 39 deletions
11
TODO.org
11
TODO.org
|
@ -4,7 +4,7 @@
|
|||
:CATEGORY: dev
|
||||
:END:
|
||||
|
||||
* Tasks [62%] [48/77]
|
||||
* Tasks [61%] [48/78]
|
||||
** TODO Write a function to handle switching to the next fragment in revealjs
|
||||
[[file:~/dev/lumina/src/qml/presenter/Slide.qml::WebEngineView {]]
|
||||
|
||||
|
@ -15,6 +15,15 @@ In order to achieve this, I have to do some of the logic in qml as opposed to ru
|
|||
- Maybe signal handlers?
|
||||
|
||||
I've written this with signal handlers now. It's working sorta.
|
||||
** TODO Figure out how to nest qobjects
|
||||
|
||||
This is supposed to be covered in the examples and the book.
|
||||
- https://github.com/KDAB/cxx-qt/blob/main/examples/qml_features/rust/src/nested_qobjects.rs
|
||||
- https://kdab.github.io/cxx-qt/book/concepts/nested_objects.html
|
||||
|
||||
But, I can't seem to get it to compile. I'll keep tinkering but this would be huge for allowing me to have a single object that can get passed into functions of other objects to be able to call inner functions from the outer call. This would mean I could have obs and slides talk. I could have the slide_object talk to the model. And more...
|
||||
|
||||
Maybe an alternative to this would be connecting them through signals, but idk yet....
|
||||
|
||||
** TODO Possibly add better handling of data through enums
|
||||
[[file:~/dev/lumina/src/rust/image_model.rs::impl FromStr for Role {]]
|
||||
|
|
|
@ -465,17 +465,22 @@ FocusScope {
|
|||
|
||||
function nextSlideAction() {
|
||||
keyHandler.forceActiveFocus();
|
||||
console.log(currentServiceItem);
|
||||
console.log(totalSlides);
|
||||
console.log(imageBackground);
|
||||
const nextSlideIdx = currentSlide + 1;
|
||||
if (!SlideObject.imageBackground.endsWith(".html") &&
|
||||
(nextSlideIdx > totalSlides || nextSlideIdx < 0))
|
||||
return;
|
||||
const nextSlide = SlideModel.getItem(nextSlideIdx);
|
||||
/* if (!SlideObject.imageBackground.endsWith(".html") && */
|
||||
/* (nextSlideIdx > totalSlides || nextSlideIdx < 0)) */
|
||||
/* return; */
|
||||
console.log("currentServiceItem " + currentServiceItem);
|
||||
console.log("totalSlides " + totalSlides);
|
||||
console.log("currentSlide " + currentSlide);
|
||||
console.log("nextSlideIdx " + nextSlideIdx);
|
||||
changeSlide(nextSlideIdx);
|
||||
for (var prop in nextSlide)
|
||||
console.log(prop += " (" + typeof(nextSlide[prop]) + ") = " + nextSlide[prop]);
|
||||
/* changeSlide(nextSlideIdx); */
|
||||
if (SlideObject.next(nextSlide)) {
|
||||
currentSlide = nextSlideIdx;
|
||||
currentServiceItem = nextSlide.serviceItemId;
|
||||
}
|
||||
}
|
||||
|
||||
function nextSlide() {
|
||||
|
|
|
@ -584,19 +584,26 @@ impl slide_model::SlideModel {
|
|||
}
|
||||
Some(ty) if ty == QString::from("presentation") => {
|
||||
debug!(?slide, "Inserting presentation slide");
|
||||
for i in 0..slide.slide_count {
|
||||
slide.ty = ty.clone();
|
||||
if background.ends_with(
|
||||
if background.clone().ends_with(
|
||||
&QString::from(".html"),
|
||||
CaseSensitivity::CaseInsensitive,
|
||||
) {
|
||||
slide.ty = ty.clone();
|
||||
slide.html = true;
|
||||
}
|
||||
slide.image_background = background.clone();
|
||||
slide.video_background = QString::from("");
|
||||
slide.slide_index = i;
|
||||
self.as_mut()
|
||||
.insert_slide(&slide, slide_index + i);
|
||||
} else {
|
||||
for i in 0..slide.slide_count {
|
||||
slide.ty = ty.clone();
|
||||
slide.image_background = background.clone();
|
||||
slide.video_background = QString::from("");
|
||||
slide.slide_index = i;
|
||||
self.as_mut()
|
||||
.insert_slide(&slide, slide_index + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => println!("It's somethign else!"),
|
||||
|
@ -717,7 +724,7 @@ impl slide_model::SlideModel {
|
|||
.value()
|
||||
.unwrap_or(0);
|
||||
slide.slide_count = service_item
|
||||
.get(&QString::from("imageCount"))
|
||||
.get(&QString::from("slideCount"))
|
||||
.unwrap_or(QVariant::from(&1))
|
||||
.value()
|
||||
.unwrap_or(1);
|
||||
|
@ -771,7 +778,18 @@ impl slide_model::SlideModel {
|
|||
self.as_mut().add_slide(&slide);
|
||||
}
|
||||
Some(ty) if ty == QString::from("presentation") => {
|
||||
debug!(slides = ?slide.slide_count);
|
||||
debug!(?slide, "Inserting presentation slide");
|
||||
if background.clone().ends_with(
|
||||
&QString::from(".html"),
|
||||
CaseSensitivity::CaseInsensitive,
|
||||
) {
|
||||
slide.ty = ty.clone();
|
||||
slide.html = true;
|
||||
slide.image_background = background.clone();
|
||||
slide.video_background = QString::from("");
|
||||
slide.slide_index = i;
|
||||
self.as_mut().add_slide(&slide);
|
||||
} else {
|
||||
for i in 0..slide.slide_count {
|
||||
slide.ty = ty.clone();
|
||||
slide.image_background = background.clone();
|
||||
|
@ -780,6 +798,7 @@ impl slide_model::SlideModel {
|
|||
self.as_mut().add_slide(&slide);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => println!("It's somethign else!"),
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ mod slide_object {
|
|||
cxx_qt_lib::QMap<cxx_qt_lib::QMapPair_QString_QVariant>;
|
||||
include!("cxx-qt-lib/qvariant.h");
|
||||
type QVariant = cxx_qt_lib::QVariant;
|
||||
// #[cxx_name = "SlideModel"]
|
||||
// type SlideModel = crate::slide_model::SlideModelRust;
|
||||
}
|
||||
|
||||
unsafe extern "RustQt" {
|
||||
|
@ -54,6 +56,7 @@ mod slide_object {
|
|||
#[qproperty(i32, font_size)]
|
||||
#[qproperty(f32, video_start_time)]
|
||||
#[qproperty(f32, video_end_time)]
|
||||
// #[qproperty(*mut SlideModel, slide_model)]
|
||||
type SlideObject = super::SlideObjectRust;
|
||||
|
||||
#[qinvokable]
|
||||
|
@ -84,7 +87,7 @@ mod slide_object {
|
|||
use std::pin::Pin;
|
||||
|
||||
use cxx_qt::CxxQtType;
|
||||
use cxx_qt_lib::{QString, QVariant};
|
||||
use cxx_qt_lib::{CaseSensitivity, QString, QVariant};
|
||||
use tracing::debug;
|
||||
|
||||
use self::slide_object::QMap_QString_QVariant;
|
||||
|
@ -108,6 +111,7 @@ pub struct SlideObjectRust {
|
|||
font_size: i32,
|
||||
video_start_time: f32,
|
||||
video_end_time: f32,
|
||||
// slide_model: *mut qobject::SlideModel,
|
||||
}
|
||||
|
||||
impl Default for SlideObjectRust {
|
||||
|
@ -130,6 +134,7 @@ impl Default for SlideObjectRust {
|
|||
image_count: 0,
|
||||
video_start_time: 0.0,
|
||||
video_end_time: 0.0,
|
||||
// slide_model: std::ptr::null_mut(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -151,25 +156,26 @@ impl slide_object::SlideObject {
|
|||
.unwrap_or(QVariant::from(&0));
|
||||
let slide_index = slindex.value::<i32>().unwrap_or_default();
|
||||
|
||||
let html = item
|
||||
.get(&QString::from("html"))
|
||||
.unwrap_or(QVariant::from(&false));
|
||||
if let Some(html) = html.value::<bool>() {
|
||||
if html {
|
||||
debug!(?html, count, slide_index);
|
||||
if slide_index > 0 && slide_index < count - 1 {
|
||||
if current_index < &index {
|
||||
self.as_mut().reveal_next();
|
||||
debug!("RevealNext");
|
||||
return;
|
||||
} else if slide_index > 0 {
|
||||
self.as_mut().reveal_prev();
|
||||
debug!("RevealPrev");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// let html = item
|
||||
// .get(&QString::from("html"))
|
||||
// .unwrap_or(QVariant::from(&false));
|
||||
// if let Some(html) = html.value::<bool>() {
|
||||
// if html {
|
||||
// debug!(?html, count, slide_index);
|
||||
// if slide_index > 0 && slide_index < count - 1 {
|
||||
// if current_index < &index {
|
||||
// self.as_mut().reveal_next();
|
||||
// debug!("RevealNext");
|
||||
// return;
|
||||
// } else if slide_index > 0 {
|
||||
// self.as_mut().reveal_prev();
|
||||
// debug!("RevealPrev");
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
debug!(index, "Changing slide");
|
||||
|
||||
println!("## Slide Details ##");
|
||||
let text = item
|
||||
|
@ -322,15 +328,67 @@ impl slide_object::SlideObject {
|
|||
mut self: Pin<&mut Self>,
|
||||
next_item: QMap_QString_QVariant,
|
||||
) -> bool {
|
||||
debug!(
|
||||
item = ?next_item.get(&QString::from("type")).unwrap().value::<QString>(),
|
||||
ibg = ?next_item.get(&QString::from("imageBackground")).unwrap().value::<QString>(),
|
||||
vbg = ?next_item.get(&QString::from("videoBackground")).unwrap().value::<QString>(),
|
||||
"advancing to next slide"
|
||||
);
|
||||
let new_id = self.as_ref().slide_index() + 1;
|
||||
self.as_mut().change_slide(next_item, new_id);
|
||||
let html = self.as_ref().image_background.ends_with(
|
||||
&QString::from(".html"),
|
||||
CaseSensitivity::CaseInsensitive,
|
||||
);
|
||||
let service_item = next_item
|
||||
.get(&QString::from("serviceItemId"))
|
||||
.unwrap()
|
||||
.value::<i32>()
|
||||
.unwrap_or_default();
|
||||
if html {
|
||||
// Check to see if current slide is at the end
|
||||
// if not, advance to the next one.
|
||||
debug!(
|
||||
currentIndex = self.as_ref().slide_index,
|
||||
newIndex = new_id,
|
||||
slide_count = self.as_ref().image_count
|
||||
);
|
||||
if self.as_ref().slide_index
|
||||
< self.as_ref().image_count - 1
|
||||
{
|
||||
self.as_mut().set_slide_index(new_id);
|
||||
self.as_mut().reveal_next();
|
||||
debug!("returning false");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
self.as_mut().change_slide(next_item, service_item);
|
||||
debug!(service_item, "returning true");
|
||||
true
|
||||
}
|
||||
pub fn previous(
|
||||
mut self: Pin<&mut Self>,
|
||||
prev_item: QMap_QString_QVariant,
|
||||
) -> bool {
|
||||
debug!(
|
||||
item = ?prev_item.get(&QString::from("type")).unwrap().value::<QString>(),
|
||||
ibg = ?prev_item.get(&QString::from("imageBackground")).unwrap().value::<QString>(),
|
||||
vbg = ?prev_item.get(&QString::from("videoBackground")).unwrap().value::<QString>(),
|
||||
"backing to previous slide"
|
||||
);
|
||||
let new_id = self.as_ref().slide_index() - 1;
|
||||
let html = self.as_ref().image_background.ends_with(
|
||||
&QString::from(".html"),
|
||||
CaseSensitivity::CaseInsensitive,
|
||||
);
|
||||
if html {
|
||||
// Check to see if current slide is at the beginning
|
||||
// if not, go back to the previous one.
|
||||
if self.as_ref().slide_index > 0 {
|
||||
self.as_mut().set_slide_index(new_id);
|
||||
self.as_mut().reveal_prev();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
self.as_mut().change_slide(prev_item, new_id);
|
||||
true
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue