Merge branch 'revert-ba25cee5' into 'master'

Revert "setting these two to do the same"

See merge request chriscochrun/church-presenter!1
This commit is contained in:
Chris Cochrun 2023-10-11 20:22:45 +00:00
commit 61440147b1
2 changed files with 398 additions and 405 deletions

View file

@ -2,6 +2,10 @@
// of whether or not a file exists // of whether or not a file exists
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod file_helper { mod file_helper {
use rfd::FileDialog;
use std::path::Path;
use tracing::{debug, debug_span, error, info, instrument};
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -11,47 +15,44 @@ mod file_helper {
type QVariant = cxx_qt_lib::QVariant; type QVariant = cxx_qt_lib::QVariant;
} }
unsafe extern "RustQt" { #[derive(Clone)]
#[qobject] #[cxx_qt::qobject]
#[qml_element] pub struct FileHelper {
#[qproperty(QString, name)] #[qproperty]
#[qproperty(QString, file_path)]
type FileHelper = super::FileHelperRust;
#[qinvokable]
fn validate(self: Pin<&mut FileHelper>, file: QUrl) -> bool;
#[qinvokable]
pub fn save_file(self: Pin<&mut FileHelper>) -> QUrl;
#[qinvokable]
fn load_file(
self: Pin<&mut FileHelper>,
title: QString,
filter: QString,
) -> QUrl;
}
}
use rfd::FileDialog;
use std::path::Path;
use tracing::{debug, debug_span, error, info, instrument};
#[derive(Clone)]
pub struct FileHelperRust {
name: QString, name: QString,
#[qproperty]
file_path: QString, file_path: QString,
} }
impl Default for FileHelperRust { impl Default for FileHelper {
fn default() -> Self { fn default() -> Self {
Self { Self {
name: QString::from(""), name: QString::from(""),
file_path: QString::from(""), file_path: QString::from(""),
} }
} }
} }
impl ffi::FileHelperRust { impl qobject::FileHelper {
// #[qinvokable]
// pub fn save(self: Pin<&mut Self>, file: QUrl, service_list: QVariant) -> bool {
// println!("{}", file);
// match service_list.value() {
// QVariantValue::<QString>(..) => println!("string"),
// QVariantValue::<QUrl>(..) => println!("url"),
// QVariantValue::<QDate>(..) => println!("date"),
// _ => println!("QVariant is..."),
// }
// return true;
// }
#[qinvokable]
pub fn load(self: Pin<&mut Self>, file: QUrl) -> Vec<String> {
println!("{file}");
vec!["hi".to_string()]
}
#[qinvokable]
pub fn validate(self: Pin<&mut Self>, file: QUrl) -> bool { pub fn validate(self: Pin<&mut Self>, file: QUrl) -> bool {
let file_string = file.to_string(); let file_string = file.to_string();
let file_string = file_string.strip_prefix("file://"); let file_string = file_string.strip_prefix("file://");
@ -62,13 +63,15 @@ impl ffi::FileHelperRust {
exists exists
} }
None => { None => {
let exists = Path::new(&file.to_string()).exists(); let exists =
Path::new(&file.to_string()).exists();
println!("{file} exists? {exists}"); println!("{file} exists? {exists}");
exists exists
} }
} }
} }
#[qinvokable]
pub fn save_file(self: Pin<&mut Self>) -> QUrl { pub fn save_file(self: Pin<&mut Self>) -> QUrl {
let file = FileDialog::new() let file = FileDialog::new()
.set_file_name("NVTFC.pres") .set_file_name("NVTFC.pres")
@ -89,16 +92,19 @@ impl ffi::FileHelperRust {
} }
} }
#[qinvokable]
pub fn load_file( pub fn load_file(
self: Pin<&mut Self>, self: Pin<&mut Self>,
title: QString, title: QString,
filter: QString, filter: QString,
) -> QUrl { ) -> QUrl {
let video_filters = [ let video_filters = [
"mp4", "webm", "avi", "mkv", "MP4", "WEBM", "AVI", "MKV", "mp4", "webm", "avi", "mkv", "MP4", "WEBM", "AVI",
"MKV",
]; ];
let image_filters = [ let image_filters = [
"jpg", "png", "gif", "jpeg", "JPG", "PNG", "webp", "gif", "jpg", "png", "gif", "jpeg", "JPG", "PNG", "webp",
"gif",
]; ];
let audio_filters = ["mp3", "opus", "ogg", "flac", "wav"]; let audio_filters = ["mp3", "opus", "ogg", "flac", "wav"];
let title = title.to_string(); let title = title.to_string();
@ -131,4 +137,5 @@ impl ffi::FileHelperRust {
QUrl::default() QUrl::default()
} }
} }
}
} }

View file

@ -1,5 +1,9 @@
#[cxx_qt::bridge] #[cxx_qt::bridge]
mod slide_obj { mod slide_obj {
// use cxx_qt_lib::QVariantValue;
// use std::path::Path;
// use std::task::Context;
unsafe extern "C++" { unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h"); include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString; type QString = cxx_qt_lib::QString;
@ -10,96 +14,55 @@ mod slide_obj {
type QVariant = cxx_qt_lib::QVariant; type QVariant = cxx_qt_lib::QVariant;
} }
unsafe extern "RustQt" { #[cxx_qt::qsignals(SlideObj)]
#[qobject] pub enum Signals<'a> {
#[qml_element] PlayingChanged { is_playing: &'a bool },
#[qproperty(i32, slide_index)] SlideIndexChanged { slide_index: &'a i32 },
#[qproperty(i32, slide_size)] SlideSizeChanged { slide_size: &'a i32 },
#[qproperty(i32, image_count)] SlideChanged { slide: &'a i32 },
#[qproperty(bool, is_playing)] LoopChanged { looping: &'a bool },
#[qproperty(bool, looping)]
#[qproperty(QString, text)]
#[qproperty(QString, ty)]
#[qproperty(QString, audio)]
#[qproperty(QString, image_background)]
#[qproperty(QString, video_background)]
#[qproperty(QString, html)]
#[qproperty(QString, vtext_alignment)]
#[qproperty(QString, htext_alignment)]
#[qproperty(QString, font)]
#[qproperty(i32, font_size)]
#[qproperty(f32, video_start_time)]
#[qproperty(f32, video_end_time)]
type SlideObj = super::SlideObjectRust;
#[qsignal]
fn playing_changed(
self: Pin<&mut SlideObj>,
is_playing: bool,
);
#[qsignal]
fn slide_index_changed(
self: Pin<&mut SlideObj>,
slide_index: i32,
);
#[qsignal]
fn slide_size_changed(
self: Pin<&mut SlideObj>,
slide_size: i32,
);
#[qsignal]
fn slide_changed(self: Pin<&mut SlideObj>, slide: i32);
#[qsignal]
fn loop_changed(self: Pin<&mut SlideObj>, looping: bool);
#[qinvokable]
fn change_slide(
self: Pin<&mut SlideObj>,
item: QMap_QString_QVariant,
index: i32,
);
#[qinvokable]
fn next(
self: Pin<&mut SlideObj>,
next_item: QMap_QString_QVariant,
) -> bool;
#[qinvokable]
fn previous(
self: Pin<&mut SlideObj>,
prev_item: QMap_QString_QVariant,
) -> bool;
#[qinvokable]
fn play(self: Pin<&mut SlideObj>) -> bool;
#[qinvokable]
fn pause(self: Pin<&mut SlideObj>) -> bool;
#[qinvokable]
fn play_pause(self: Pin<&mut SlideObj>) -> bool;
} }
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SlideObjectRust { #[cxx_qt::qobject]
pub struct SlideObj {
#[qproperty]
slide_index: i32, slide_index: i32,
#[qproperty]
slide_size: i32, slide_size: i32,
#[qproperty]
image_count: i32, image_count: i32,
#[qproperty]
is_playing: bool, is_playing: bool,
#[qproperty]
looping: bool, looping: bool,
#[qproperty]
text: QString, text: QString,
#[qproperty]
ty: QString, ty: QString,
#[qproperty]
audio: QString, audio: QString,
#[qproperty]
image_background: QString, image_background: QString,
#[qproperty]
video_background: QString, video_background: QString,
#[qproperty]
html: QString, html: QString,
#[qproperty]
vtext_alignment: QString, vtext_alignment: QString,
#[qproperty]
htext_alignment: QString, htext_alignment: QString,
#[qproperty]
font: QString, font: QString,
#[qproperty]
font_size: i32, font_size: i32,
#[qproperty]
video_start_time: f32, video_start_time: f32,
#[qproperty]
video_end_time: f32, video_end_time: f32,
} }
impl Default for SlideObjectRust { impl Default for SlideObj {
fn default() -> Self { fn default() -> Self {
Self { Self {
slide_index: 0, slide_index: 0,
@ -121,9 +84,10 @@ impl Default for SlideObjectRust {
video_end_time: 0.0, video_end_time: 0.0,
} }
} }
} }
impl ffi::SlideObjectRust { impl qobject::SlideObj {
#[qinvokable]
pub fn change_slide( pub fn change_slide(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
item: QMap_QString_QVariant, item: QMap_QString_QVariant,
@ -170,9 +134,12 @@ impl ffi::SlideObjectRust {
if let Some(image_background) = if let Some(image_background) =
image_background.value::<QString>() image_background.value::<QString>()
{ {
if &image_background != self.as_ref().image_background() { if &image_background
!= self.as_ref().image_background()
{
println!("image-bg: {image_background}"); println!("image-bg: {image_background}");
self.as_mut().set_image_background(image_background); self.as_mut()
.set_image_background(image_background);
} }
} else { } else {
println!("image-bg: empty"); println!("image-bg: empty");
@ -183,16 +150,19 @@ impl ffi::SlideObjectRust {
if let Some(video_background) = if let Some(video_background) =
video_background.value::<QString>() video_background.value::<QString>()
{ {
if &video_background != self.as_ref().video_background() { if &video_background
!= self.as_ref().video_background()
{
println!("video-bg: {video_background}"); println!("video-bg: {video_background}");
self.as_mut().set_video_background(video_background); self.as_mut()
.set_video_background(video_background);
} }
} else { } else {
println!("video-bg: empty"); println!("video-bg: empty");
} }
let font = item let font = item.get(&QString::from("font")).unwrap_or(
.get(&QString::from("font")) QVariant::from(&QString::from("Quicksand")),
.unwrap_or(QVariant::from(&QString::from("Quicksand"))); );
if let Some(font) = font.value::<QString>() { if let Some(font) = font.value::<QString>() {
if &font != self.as_ref().font() { if &font != self.as_ref().font() {
println!("font: {font}"); println!("font: {font}");
@ -207,9 +177,13 @@ impl ffi::SlideObjectRust {
if let Some(vtext_alignment) = if let Some(vtext_alignment) =
vtext_alignment.value::<QString>() vtext_alignment.value::<QString>()
{ {
if &vtext_alignment != self.as_ref().vtext_alignment() { if &vtext_alignment != self.as_ref().vtext_alignment()
println!("vertical-text-align: {vtext_alignment}"); {
self.as_mut().set_vtext_alignment(vtext_alignment); println!(
"vertical-text-align: {vtext_alignment}"
);
self.as_mut()
.set_vtext_alignment(vtext_alignment);
} }
} else { } else {
println!("vertical-text-align: empty"); println!("vertical-text-align: empty");
@ -220,9 +194,13 @@ impl ffi::SlideObjectRust {
if let Some(htext_alignment) = if let Some(htext_alignment) =
htext_alignment.value::<QString>() htext_alignment.value::<QString>()
{ {
if &htext_alignment != self.as_ref().htext_alignment() { if &htext_alignment != self.as_ref().htext_alignment()
println!("horizontal-text-align: {htext_alignment}"); {
self.as_mut().set_htext_alignment(htext_alignment); println!(
"horizontal-text-align: {htext_alignment}"
);
self.as_mut()
.set_htext_alignment(htext_alignment);
} }
} else { } else {
println!("horizontal-text-align: empty"); println!("horizontal-text-align: empty");
@ -246,7 +224,8 @@ impl ffi::SlideObjectRust {
println!("looping: {looping}"); println!("looping: {looping}");
self.as_mut().set_looping(looping); self.as_mut().set_looping(looping);
let lp = looping; let lp = looping;
self.as_mut().loop_changed(&lp); self.as_mut()
.emit(Signals::LoopChanged { looping: &lp });
} }
} else { } else {
println!("looping: empty") println!("looping: empty")
@ -279,10 +258,12 @@ impl ffi::SlideObjectRust {
println!("New slide index = {}", int); println!("New slide index = {}", int);
self.as_mut().set_slide_index(int); self.as_mut().set_slide_index(int);
}; };
self.as_mut().slide_changed(&index); self.as_mut()
.emit(Signals::SlideChanged { slide: &index });
println!("## Slide End ##"); println!("## Slide End ##");
} }
#[qinvokable]
pub fn next( pub fn next(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
next_item: QMap_QString_QVariant, next_item: QMap_QString_QVariant,
@ -291,6 +272,7 @@ impl ffi::SlideObjectRust {
self.as_mut().change_slide(next_item, new_id); self.as_mut().change_slide(next_item, new_id);
true true
} }
#[qinvokable]
pub fn previous( pub fn previous(
mut self: Pin<&mut Self>, mut self: Pin<&mut Self>,
prev_item: QMap_QString_QVariant, prev_item: QMap_QString_QVariant,
@ -299,23 +281,27 @@ impl ffi::SlideObjectRust {
self.as_mut().change_slide(prev_item, new_id); self.as_mut().change_slide(prev_item, new_id);
true true
} }
#[qinvokable]
pub fn play(mut self: Pin<&mut Self>) -> bool { pub fn play(mut self: Pin<&mut Self>) -> bool {
self.as_mut().set_is_playing(true); self.as_mut().set_is_playing(true);
self.as_mut().playing_changed(&true); self.as_mut().emit_playing_changed(&true);
true true
} }
#[qinvokable]
pub fn pause(mut self: Pin<&mut Self>) -> bool { pub fn pause(mut self: Pin<&mut Self>) -> bool {
self.as_mut().set_is_playing(false); self.as_mut().set_is_playing(false);
self.as_mut().playing_changed(&false); self.as_mut().emit_playing_changed(&false);
false false
} }
#[qinvokable]
pub fn play_pause(mut self: Pin<&mut Self>) -> bool { pub fn play_pause(mut self: Pin<&mut Self>) -> bool {
let playing = self.as_ref().is_playing().clone(); let playing = self.as_ref().is_playing().clone();
match playing { match playing {
true => self.as_mut().set_is_playing(false), true => self.as_mut().set_is_playing(false),
false => self.as_mut().set_is_playing(true), false => self.as_mut().set_is_playing(true),
} }
self.as_mut().playing_changed(&!playing); self.as_mut().emit_playing_changed(&!playing);
!playing !playing
} }
}
} }