From b05af23ffae3456a07735a259232a44a3446f7a3 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 29 Apr 2023 07:13:04 -0500 Subject: [PATCH] feat: reveal.js presentations are viewable in editor I have gotten reveal.js presentations to be viewable. I'll still need to work with how to present them, and fix the presenter piece as well, but for now, it works. --- src/main.cpp | 2 ++ src/qml/presenter/Library.qml | 20 +++++++++++------- src/qml/presenter/Presentation.qml | 2 +- src/qml/presenter/PresentationEditor.qml | 27 +++++++++++++++++++++--- src/rust/presentation_model.rs | 11 +++++++--- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 787dc49..600dd38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,6 +55,7 @@ #include "cxx-qt-gen/slide_model.cxxqt.h" #include "cxx-qt-gen/settings.cxxqt.h" #include "cxx-qt-gen/ytdl.cxxqt.h" +#include "cxx-qt-gen/presentation_model.cxxqt.h" // #include "cxx-qt-gen/image_model.cxxqt.h" static QWindow *windowFromEngine(QQmlApplicationEngine *engine) @@ -201,6 +202,7 @@ int main(int argc, char *argv[]) qmlRegisterType("org.presenter", 1, 0, "VideoProxyModel"); qmlRegisterType("org.presenter", 1, 0, "ImageProxyModel"); qmlRegisterType("org.presenter", 1, 0, "PresentationProxyModel"); + qmlRegisterType("org.presenter", 1, 0, "PresentationModel"); qmlRegisterType("org.presenter", 1, 0, "SongSqlModel"); qmlRegisterType("org.presenter", 1, 0, "VideoSqlModel"); qmlRegisterType("org.presenter", 1, 0, "ImageSqlModel"); diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index c4c1f2e..0c2ff4b 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -315,16 +315,20 @@ Item { function addPres(url) { console.log(pdf.status); - pdf.source = url; - while (pdf.status != 2) { - console.log(pdf.status); - console.log("PAGECOUNT: " + pdf.pageCount); + let pageCount = 1; + if (url.endsWith(".pdf")) { + pdf.source = url; + while (pdf.status != 2) { + console.log(pdf.status); + console.log("PAGECOUNT: " + pdf.pageCount); + pageCount = pdf.pageCount; + } } - presProxyModel.presentationModel.newPresentation(url, pdf.pageCount); + presProxyModel.presentationModel.newItem(url, pageCount); selectedLibrary = "presentation"; - presentationLibraryList.currentIndex = presProxyModel.presentationModel.rowCount(); - console.log(presProxyModel.presentationModel.getPresentation(presentationLibraryList.currentIndex)); - const presentation = presProxyModel.presentationModel.getImage(presentationLibraryList.currentIndex); + presentationLibrary.libraryList.currentIndex = presProxyModel.presentationModel.count(); + console.log(presProxyModel.getPresentation(presentationLibrary.libraryList.currentIndex)); + const presentation = presProxyModel.getPresentation(presentationLibrary.libraryList.currentIndex); showPassiveNotification("newest image: " + presentation.title); if (!editMode) editMode = true; diff --git a/src/qml/presenter/Presentation.qml b/src/qml/presenter/Presentation.qml index c0bdc0a..547bb4c 100644 --- a/src/qml/presenter/Presentation.qml +++ b/src/qml/presenter/Presentation.qml @@ -121,7 +121,7 @@ FocusScope { anchors.centerIn: parent itemType: SlideObject.ty imageSource: SlideObject.imageBackground - webSource: SlideObject.html + webSource: SlideObject.imageBackground.endsWith(".html") ? SlideObject.imageBackground : "" videoSource: SlideObject.videoBackground audioSource: SlideObject.audio chosenFont: SlideObject.font diff --git a/src/qml/presenter/PresentationEditor.qml b/src/qml/presenter/PresentationEditor.qml index f0ed964..5875342 100644 --- a/src/qml/presenter/PresentationEditor.qml +++ b/src/qml/presenter/PresentationEditor.qml @@ -2,6 +2,7 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 as Controls import QtQuick.Dialogs 1.3 import QtQuick.Layouts 1.15 +import QtWebEngine 1.10 import org.kde.kirigami 2.13 as Kirigami import "./" as Presenter @@ -10,6 +11,7 @@ Item { property string type: "presentation" property var presentation + property bool isHtml: presentation.filePath.endsWith(".html") GridLayout { id: mainLayout @@ -112,11 +114,20 @@ Item { Layout.preferredHeight: Layout.preferredWidth / 16 * 9 Layout.alignment: Qt.AlignCenter fillMode: Image.PreserveAspectFit - source: presentation.filePath + source: isHtml ? "" : presentation.filePath Component.onCompleted: { updatePageCount(frameCount); showPassiveNotification(presentation.pageCount); } + visible: !isHtml + } + WebEngineView { + id: webPresentationPreview + Layout.preferredWidth: root.width - Kirigami.Units.largeSpacing + Layout.preferredHeight: Layout.preferredWidth / 16 * 9 + Layout.alignment: Qt.AlignCenter + url: isHtml ? presentation.filePath : "" + visible: isHtml } RowLayout { Layout.fillWidth: true; @@ -127,7 +138,12 @@ Item { id: leftArrow text: "Back" icon.name: "back" - onClicked: presentationPreview.currentFrame = presentationPreview.currentFrame - 1 + onClicked: { + if (isHtml) { + webPresentationPreview.runJavaScript("Reveal.navigatePrev()"); + } else + presentationPreview.currentFrame = presentationPreview.currentFrame - 1 + } } Item { Layout.fillWidth: true @@ -136,7 +152,12 @@ Item { id: rightArrow text: "Next" icon.name: "next" - onClicked: presentationPreview.currentFrame = presentationPreview.currentFrame + 1 + onClicked: { + if (isHtml) { + webPresentationPreview.runJavaScript("Reveal.navigateNext()"); + } else + presentationPreview.currentFrame = presentationPreview.currentFrame + 1 + } } } Item { diff --git a/src/rust/presentation_model.rs b/src/rust/presentation_model.rs index 65e4548..e5fd5f2 100644 --- a/src/rust/presentation_model.rs +++ b/src/rust/presentation_model.rs @@ -36,6 +36,7 @@ mod presentation_model { title: QString, html: bool, path: QString, + page_count: i32, } #[cxx_qt::qobject(base = "QAbstractListModel")] @@ -96,14 +97,15 @@ mod presentation_model { self.as_mut().set_highest_id(presentation.id); } - let img = self::Presentation { + let pres = self::Presentation { id: presentation.id, title: QString::from(&presentation.title), html: false, path: QString::from(&presentation.path), + page_count: 1, }; - self.as_mut().add_presentation(img); + self.as_mut().add_presentation(pres); } println!("--------------------------------------"); println!("{:?}", self.as_mut().presentations()); @@ -149,7 +151,7 @@ mod presentation_model { } #[qinvokable] - pub fn new_item(mut self: Pin<&mut Self>, url: QUrl) { + pub fn new_item(mut self: Pin<&mut Self>, url: QUrl, new_page_count: i32) { println!("LETS INSERT THIS SUCKER!"); let file_path = PathBuf::from(url.path().to_string()); let name = file_path.file_stem().unwrap().to_str().unwrap(); @@ -164,6 +166,7 @@ mod presentation_model { presentation_title, presentation_path, presentation_html, + new_page_count, ) { println!("filename: {:?}", name); self.as_mut().set_highest_id(presentation_id); @@ -179,6 +182,7 @@ mod presentation_model { presentation_title: QString, presentation_path: QString, presentation_html: bool, + new_page_count: i32, ) -> bool { let db = &mut self.as_mut().get_db(); // println!("{:?}", db); @@ -187,6 +191,7 @@ mod presentation_model { title: presentation_title.clone(), html: false, path: presentation_path.clone(), + page_count: new_page_count, }; println!("{:?}", presentation);