From c33b5af5889ac46fe6ed88974b443e89da2704e6 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Mon, 1 May 2023 06:20:45 -0500 Subject: [PATCH] basic implementation of having reveal.js slides working There is still a lot of work needed to be done here, but the basics are laid out. --- flake.lock | 12 ++--- src/qml/presenter/Library.qml | 53 ++++++++++++++++--- src/qml/presenter/MainWindow.qml | 2 +- src/qml/presenter/Presentation.qml | 3 +- src/qml/presenter/PresentationEditor.qml | 6 +-- .../presenter/PreviewSlideListDelegate.qml | 18 ++++++- src/qml/presenter/Slide.qml | 9 +++- src/rust/presentation_model.rs | 9 +++- 8 files changed, 88 insertions(+), 24 deletions(-) diff --git a/flake.lock b/flake.lock index c2927e8..11349f5 100644 --- a/flake.lock +++ b/flake.lock @@ -38,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1682566018, - "narHash": "sha256-HPzPRFiy2o/7k7mtnwfM1E6NVZHiFbPdmYCMoIpkHO4=", + "lastModified": 1682779028, + "narHash": "sha256-tFfSbwSLobpHRznAa35KEU3R+fsFWTlmpFhTUdXq8RE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8e3b64db39f2aaa14b35ee5376bd6a2e707cadc2", + "rev": "54abe781c482f51ff4ff534ebaba77db5bd97442", "type": "github" }, "original": { @@ -52,11 +52,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1682526928, - "narHash": "sha256-2cKh4O6t1rQ8Ok+v16URynmb0rV7oZPEbXkU0owNLQs=", + "lastModified": 1682692304, + "narHash": "sha256-9/lyXN2BpHw+1xE+D2ySBSLMCHWqiWu5tPHBMRDib8M=", "owner": "nixos", "repo": "nixpkgs", - "rev": "d6b863fd9b7bb962e6f9fdf292419a775e772891", + "rev": "937a9d1ee7b1351d8c55fff6611a8edf6e7c1c37", "type": "github" }, "original": { diff --git a/src/qml/presenter/Library.qml b/src/qml/presenter/Library.qml index 0c2ff4b..2fb5524 100644 --- a/src/qml/presenter/Library.qml +++ b/src/qml/presenter/Library.qml @@ -4,6 +4,7 @@ import QtQuick.Layouts 1.15 import Qt.labs.platform 1.1 as Labs import QtQuick.Pdf 5.15 import QtQml.Models 2.15 +import QtWebEngine 1.10 import org.kde.kirigami 2.13 as Kirigami import "./" as Presenter import org.presenter 1.0 @@ -17,6 +18,8 @@ Item { property var imgexts: ["jpg", "png", "gif", "jpeg", "JPG", "PNG", "webp", "gif"] property var presexts: ["pdf", "PDF", "odp", "pptx", "html"] + property bool htmlLoaded: false + Kirigami.Theme.colorSet: Kirigami.Theme.View Rectangle { @@ -316,13 +319,11 @@ Item { function addPres(url) { console.log(pdf.status); 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; - } + pdf.source = url; + while (pdf.status != 2) { + console.log(pdf.status); + console.log("PAGECOUNT: " + pdf.pageCount); + pageCount = pdf.pageCount; } presProxyModel.presentationModel.newItem(url, pageCount); selectedLibrary = "presentation"; @@ -360,7 +361,10 @@ Item { } if (presexts.includes(extension)) { - addPres(file); + if (file.endsWith(".html")) { + web.url = file; + } else + addPres(file); } } @@ -400,5 +404,38 @@ Item { PdfDocument { id: pdf } + + WebEngineView { + id: web + height: 0 + width: 0 + onLoadingChanged: { + if (loadRequest.status == 2) + addHtml(url); + } + } + } + + function addHtml(url) { + console.log("adding an html"); + var pageCount = 1; + web.runJavaScript("Reveal.getSlides()", function(result) { + let str = ''; + for (const [p, val] of Object.entries(result[0])) { + str += `${p}::${val}\n`; + } + console.log(str); + pageCount = result.length; + console.log(pageCount); + presProxyModel.presentationModel.newItem(url, pageCount); + selectedLibrary = "presentation"; + 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; + editSwitch("presentation", presentation); + }); } } diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index af7cdb2..16506a6 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -192,7 +192,7 @@ Controls.Page { slideHelper.chngSlide(item, index, SlideObject); /* SlideMod.activate(index); */ presentation.textIndex = 0; - console.log("Slide changed to: " + index); + console.log("Slide changed to: ", item.imageBackground); activeServiceItem = ServiceItemModel.getItem(currentServiceItem).name; } diff --git a/src/qml/presenter/Presentation.qml b/src/qml/presenter/Presentation.qml index 547bb4c..ea1a701 100644 --- a/src/qml/presenter/Presentation.qml +++ b/src/qml/presenter/Presentation.qml @@ -120,8 +120,9 @@ FocusScope { implicitHeight: width / 16 * 9 anchors.centerIn: parent itemType: SlideObject.ty - imageSource: SlideObject.imageBackground + imageSource: SlideObject.imageBackground.endsWith(".html") ? "" : SlideObject.imageBackground webSource: SlideObject.imageBackground.endsWith(".html") ? SlideObject.imageBackground : "" + htmlVisible: SlideObject.imageBackground.endsWith(".html") videoSource: SlideObject.videoBackground audioSource: SlideObject.audio chosenFont: SlideObject.font diff --git a/src/qml/presenter/PresentationEditor.qml b/src/qml/presenter/PresentationEditor.qml index 5875342..cf534a0 100644 --- a/src/qml/presenter/PresentationEditor.qml +++ b/src/qml/presenter/PresentationEditor.qml @@ -140,7 +140,7 @@ Item { icon.name: "back" onClicked: { if (isHtml) { - webPresentationPreview.runJavaScript("Reveal.navigatePrev()"); + webPresentationPreview.runJavaScript("Reveal.prev()"); } else presentationPreview.currentFrame = presentationPreview.currentFrame - 1 } @@ -154,9 +154,9 @@ Item { icon.name: "next" onClicked: { if (isHtml) { - webPresentationPreview.runJavaScript("Reveal.navigateNext()"); + webPresentationPreview.runJavaScript("Reveal.next()"); } else - presentationPreview.currentFrame = presentationPreview.currentFrame + 1 + presentationPreview.currentFrame = presentationPreview.currentFrame + 1 } } } diff --git a/src/qml/presenter/PreviewSlideListDelegate.qml b/src/qml/presenter/PreviewSlideListDelegate.qml index cef3389..7e23760 100644 --- a/src/qml/presenter/PreviewSlideListDelegate.qml +++ b/src/qml/presenter/PreviewSlideListDelegate.qml @@ -1,6 +1,7 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 as Controls import QtQuick.Layouts 1.15 +import QtWebEngine 1.10 import org.kde.kirigami 2.13 as Kirigami import "./" as Presenter import org.presenter 1.0 @@ -36,12 +37,27 @@ Item { implicitHeight: parent.height - Kirigami.Units.smallSpacing * 2 textSize: model.fontSize itemType: model.type - imageSource: model.videoBackground != "" ? model.videoThumbnail : model.imageBackground + imageSource: { + if (model.videoBackground != "") { + return model.videoThumbnail; + } else if (model.imageBackground.endsWith(".html")) { + return ""; + } else + return model.imageBackground; + } chosenFont: model.font text: model.text pdfIndex: model.slideIndex } + WebEngineView { + id: web + anchors.centerIn: parent + implicitWidth: height / 9 * 16 + implicitHeight: parent.height - Kirigami.Units.smallSpacing * 2 + url: model.imageBackground.endsWith(".html") ? model.imageBackground : "" + visible: model.imageBackground.endsWith(".html") + } } Controls.Label { diff --git a/src/qml/presenter/Slide.qml b/src/qml/presenter/Slide.qml index c95821f..11383c8 100644 --- a/src/qml/presenter/Slide.qml +++ b/src/qml/presenter/Slide.qml @@ -20,6 +20,7 @@ Item { property bool dropShadow: false property url imageSource property url webSource + property bool htmlVisible: false property url videoSource property url audioSource property bool vidLoop @@ -128,7 +129,7 @@ Item { source: imageSource fillMode: itemType == "song" ? Image.PreserveAspectCrop : Image.PreserveAspectFit clip: true - visible: true + visible: webSource.length == 0 currentFrame: pdfIndex } @@ -172,7 +173,11 @@ Item { id: web anchors.fill: parent url: webSource - visible: false + visible: htmlVisible + onLoadingChanged: { + if (loadRequest.status == 2) + showPassiveNotification("YAHOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO!!"); + } } } diff --git a/src/rust/presentation_model.rs b/src/rust/presentation_model.rs index e5fd5f2..0fcddbc 100644 --- a/src/rust/presentation_model.rs +++ b/src/rust/presentation_model.rs @@ -61,6 +61,7 @@ mod presentation_model { PathRole, TitleRole, HtmlRole, + PageCountRole, } // use crate::entities::{presentations, prelude::Presentations}; @@ -100,9 +101,9 @@ mod presentation_model { let pres = self::Presentation { id: presentation.id, title: QString::from(&presentation.title), - html: false, + html: presentation.path.ends_with(".html"), path: QString::from(&presentation.path), - page_count: 1, + page_count: presentation.page_count.unwrap(), }; self.as_mut().add_presentation(pres); @@ -201,6 +202,7 @@ mod presentation_model { title.eq(&presentation_title.to_string()), path.eq(&presentation_path.to_string()), html.eq(&presentation_html), + page_count.eq(&presentation.page_count), )) .execute(db); println!("{:?}", result); @@ -256,6 +258,7 @@ mod presentation_model { Role::TitleRole => 1, Role::PathRole => 2, Role::HtmlRole => 3, + Role::PageCountRole => 4, _ => 0, } } @@ -307,6 +310,7 @@ mod presentation_model { 1 => QVariant::from(&presentation.title), 2 => QVariant::from(&presentation.path), 3 => QVariant::from(&presentation.html), + 4 => QVariant::from(&presentation.page_count), _ => QVariant::default(), }; } @@ -327,6 +331,7 @@ mod presentation_model { 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.insert(4, cxx_qt_lib::QByteArray::from("pageCount")); roles }