Preparing to add html as a presentation option

This commit is contained in:
Chris Cochrun 2023-04-27 14:17:59 -05:00
parent ff680b9549
commit e8b042df54
8 changed files with 52 additions and 301 deletions

View file

@ -121,6 +121,7 @@ FocusScope {
anchors.centerIn: parent
itemType: SlideObject.ty
imageSource: SlideObject.imageBackground
webSource: SlideObject.html
videoSource: SlideObject.videoBackground
audioSource: SlideObject.audio
chosenFont: SlideObject.font

View file

@ -35,6 +35,7 @@ Window {
id: presentationSlide
anchors.fill: parent
imageSource: SlideObject.imageBackground
webSource: SlideObject.html
videoSource: presentationWindow.visible ? SlideObject.videoBackground : ""
audioSource: SlideObject.audio
text: SlideObject.text

View file

@ -3,6 +3,7 @@ import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.15
import QtMultimedia 5.15
/* import QtAudioEngine 1.15 */
import QtWebEngine 1.10
import QtGraphicalEffects 1.15
import org.kde.kirigami 2.13 as Kirigami
import "./" as Presenter
@ -18,6 +19,7 @@ Item {
property real textSize: 50
property bool dropShadow: false
property url imageSource
property url webSource
property url videoSource
property url audioSource
property bool vidLoop
@ -165,6 +167,12 @@ Item {
}
}
}
WebEngine {
id: web
anchors.fill: parent
source: webSource
}
}
function changeText(text) {

View file

@ -23,6 +23,7 @@ pub struct Presentation {
pub title: String,
pub path: String,
pub page_count: Option<i32>,
pub html: bool,
}
#[derive(Queryable)]

View file

@ -5,6 +5,7 @@ mod presentation_model {
use crate::schema::presentations::dsl::*;
use diesel::sqlite::SqliteConnection;
use diesel::{delete, insert_into, prelude::*};
// use sqlx::Connection;
use std::path::{Path, PathBuf};
unsafe extern "C++" {
@ -33,6 +34,7 @@ mod presentation_model {
pub struct Presentation {
id: i32,
title: QString,
html: bool,
path: QString,
}
@ -57,6 +59,7 @@ mod presentation_model {
IdRole,
PathRole,
TitleRole,
HtmlRole,
}
// use crate::entities::{presentations, prelude::Presentations};
@ -74,6 +77,8 @@ mod presentation_model {
#[qinvokable]
pub fn setup(mut self: Pin<&mut Self>) {
let db = &mut self.as_mut().get_db();
// let table_info = diesel::sql_query("PRAGMA table_info(presentations)").load(db);
// println!("{:?}", table_info);
let results = presentations
.load::<crate::models::Presentation>(db)
.expect("Error loading presentations");
@ -85,6 +90,7 @@ mod presentation_model {
println!("{}", presentation.title);
println!("{}", presentation.id);
println!("{}", presentation.path);
println!("{}", presentation.html);
println!("--------------");
if self.as_mut().highest_id() < &presentation.id {
self.as_mut().set_highest_id(presentation.id);
@ -93,6 +99,7 @@ mod presentation_model {
let img = self::Presentation {
id: presentation.id,
title: QString::from(&presentation.title),
html: false,
path: QString::from(&presentation.path),
};
@ -149,11 +156,15 @@ mod presentation_model {
let presentation_id = self.rust().highest_id + 1;
let presentation_title = QString::from(name);
let presentation_path = url.to_qstring();
println!("{:?}", file_path.extension().unwrap());
let presentation_html = file_path.extension().unwrap() == std::ffi::OsStr::new(".html");
if self
.as_mut()
.add_item(presentation_id, presentation_title, presentation_path)
{
if self.as_mut().add_item(
presentation_id,
presentation_title,
presentation_path,
presentation_html,
) {
println!("filename: {:?}", name);
self.as_mut().set_highest_id(presentation_id);
} else {
@ -167,12 +178,14 @@ mod presentation_model {
presentation_id: i32,
presentation_title: QString,
presentation_path: QString,
presentation_html: bool,
) -> bool {
let db = &mut self.as_mut().get_db();
// println!("{:?}", db);
let presentation = self::Presentation {
id: presentation_id,
title: presentation_title.clone(),
html: false,
path: presentation_path.clone(),
};
println!("{:?}", presentation);
@ -182,6 +195,7 @@ mod presentation_model {
id.eq(&presentation_id),
title.eq(&presentation_title.to_string()),
path.eq(&presentation_path.to_string()),
html.eq(&presentation_html),
))
.execute(db);
println!("{:?}", result);
@ -236,6 +250,7 @@ mod presentation_model {
Role::IdRole => 0,
Role::TitleRole => 1,
Role::PathRole => 2,
Role::HtmlRole => 3,
_ => 0,
}
}
@ -286,6 +301,7 @@ mod presentation_model {
0 => QVariant::from(&presentation.id),
1 => QVariant::from(&presentation.title),
2 => QVariant::from(&presentation.path),
3 => QVariant::from(&presentation.html),
_ => QVariant::default(),
};
}
@ -305,6 +321,7 @@ mod presentation_model {
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
roles.insert(1, cxx_qt_lib::QByteArray::from("title"));
roles.insert(2, cxx_qt_lib::QByteArray::from("filePath"));
roles.insert(3, cxx_qt_lib::QByteArray::from("html"));
roles
}

View file

@ -17,6 +17,7 @@ diesel::table! {
path -> Text,
#[sql_name = "pageCount"]
page_count -> Nullable<Integer>,
html -> Bool,
}
}

View file

@ -46,6 +46,8 @@ mod slide_obj {
#[qproperty]
video_background: QString,
#[qproperty]
html: QString,
#[qproperty]
vtext_alignment: QString,
#[qproperty]
htext_alignment: QString,
@ -70,6 +72,7 @@ mod slide_obj {
ty: QString::from(""),
audio: QString::from(""),
image_background: QString::from(""),
html: QString::from(""),
video_background: QString::from(""),
vtext_alignment: QString::from(""),
htext_alignment: QString::from(""),

View file

@ -33,16 +33,17 @@ mod song_model {
pub struct Song {
id: i32,
title: QString,
lyrics: QString,
author: QString,
ccli: QString,
audio: QString,
verse_order: QString,
background: QString,
background_type: QString,
horizontal_text_alignment: QString,
vertical_text_alignment: QString,
font: QString,
title: String,
lyrics: String,
author: String,
ccli: String,
audio: String,
verse_order: String,
background: String,
background_type: String,
horizontal_text_alignment: String,
vertical_text_alignment: String,
font: String,
font_size: i32,
}
@ -92,7 +93,7 @@ mod song_model {
}
#[qinvokable]
pub fn setup(mut self: Pin<&mut Self>) {
pub fn test_database(mut self: Pin<&mut Self>) {
let db = &mut self.as_mut().get_db();
let results = songs
.load::<crate::models::Song>(db)
@ -124,12 +125,14 @@ mod song_model {
}
#[qinvokable]
pub fn delete_song(mut self: Pin<&mut Self>, index: i32) -> bool {
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) -> bool {
if index < 0 || (index as usize) >= self.songs().len() {
return false;
}
let db = &mut self.as_mut().get_db();
let song_id = self.songs().get(index as usize).unwrap().id;
let result = delete(songs.filter(id.eq(song_id))).execute(db);
match result {
@ -159,11 +162,6 @@ mod song_model {
// self.rust().db = db;
}
#[qinvokable]
pub fn new_song(mut self: Pin<&mut Self>) {
todo!();
}
#[qinvokable]
pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) {
println!("LETS INSERT THIS SUCKER!");
@ -251,102 +249,6 @@ mod song_model {
}
}
#[qinvokable]
pub fn update_lyrics(
mut self: Pin<&mut Self>,
index: i32,
updated_lyrics: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::LyricsRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(lyrics.eq(updated_lyrics.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.lyrics = updated_lyrics;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_audio(mut self: Pin<&mut Self>, index: i32, updated_audio: QString) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::AudioRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(audio.eq(updated_audio.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.audio = updated_audio;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_author(
mut self: Pin<&mut Self>,
index: i32,
updated_author: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::AuthorRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(author.eq(updated_author.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.author = updated_author;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_ccli(mut self: Pin<&mut Self>, index: i32, updated_ccli: QString) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::CcliRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(ccli.eq(updated_ccli.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.ccli = updated_ccli;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_file_path(
mut self: Pin<&mut Self>,
@ -374,190 +276,7 @@ mod song_model {
}
#[qinvokable]
pub fn update_verse_order(
mut self: Pin<&mut Self>,
index: i32,
updated_verse_order: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::VerseOrderRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(verse_order.eq(updated_verse_order.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.verse_order = updated_verse_order;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_background(
mut self: Pin<&mut Self>,
index: i32,
updated_background: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::BackgroundRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(background.eq(updated_background.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.background = updated_background;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_background_type(
mut self: Pin<&mut Self>,
index: i32,
updated_background_type: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::BackgroundTypeRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(background_type.eq(updated_background_type.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.background_type = updated_background_type;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_horizontal_text_alignment(
mut self: Pin<&mut Self>,
index: i32,
updated_horizontal_text_alignment: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::HorizontalTextAlignmentRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(horizontal_text_alignment.eq(updated_horizontal_text_alignment.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.horizontal_text_alignment = updated_horizontal_text_alignment;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_vertical_text_alignment(
mut self: Pin<&mut Self>,
index: i32,
updated_vertical_text_alignment: QString,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::VerticalTextAlignmentRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(vertical_text_alignment.eq(updated_vertical_text_alignment.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.vertical_text_alignment = updated_vertical_text_alignment;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_font(mut self: Pin<&mut Self>, index: i32, updated_font: QString) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::FontRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(font.eq(updated_font.to_string()))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.font = updated_font;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn update_font_size(
mut self: Pin<&mut Self>,
index: i32,
updated_font_size: i32,
) -> bool {
let mut vector_roles = QVector_i32::default();
vector_roles.append(self.as_ref().get_role(Role::FontSizeRole));
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
let db = &mut self.as_mut().get_db();
let result = update(songs.filter(id.eq(index)))
.set(font_size.eq(updated_font_size))
.execute(db);
match result {
Ok(_i) => {
let song = self.as_mut().songs_mut().get_mut(index as usize).unwrap();
song.font_size = updated_font_size;
self.as_mut()
.emit_data_changed(model_index, model_index, &vector_roles);
true
}
Err(_e) => false,
}
}
#[qinvokable]
pub fn get_lyric_list(mut self: Pin<&mut Self>, index: i32) -> QList_QString {
todo!();
}
#[qinvokable]
pub fn get_song(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
pub fn get_item(self: Pin<&mut Self>, index: i32) -> QMap_QString_QVariant {
println!("{index}");
let mut qvariantmap = QMap_QString_QVariant::default();
let idx = self.index(index, 0, &QModelIndex::default());