From a0692aeadf654682caa2811afc81322c6b4b07f9 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 19 May 2023 09:53:08 -0500 Subject: [PATCH] planned: add presentation_window.rs I'm going to try to subclass QQuickWindow or View in order to control the PresentationWindow from rust and just call the appropriate functions from QML. --- src/rust/presentation_window.rs | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/rust/presentation_window.rs diff --git a/src/rust/presentation_window.rs b/src/rust/presentation_window.rs new file mode 100644 index 0000000..2b0be12 --- /dev/null +++ b/src/rust/presentation_window.rs @@ -0,0 +1,51 @@ +#[cxx_qt::bridge] +mod image_model { + + unsafe extern "C++" { + include!(< QQuickWindow >); + include!("cxx-qt-lib/qhash.h"); + type QHash_i32_QByteArray = cxx_qt_lib::QHash; + include!("cxx-qt-lib/qmap.h"); + type QMap_QString_QVariant = cxx_qt_lib::QMap; + include!("cxx-qt-lib/qvariant.h"); + type QVariant = cxx_qt_lib::QVariant; + include!("cxx-qt-lib/qstring.h"); + type QString = cxx_qt_lib::QString; + include!("cxx-qt-lib/qurl.h"); + type QUrl = cxx_qt_lib::QUrl; + include!("cxx-qt-lib/qmodelindex.h"); + type QModelIndex = cxx_qt_lib::QModelIndex; + include!("cxx-qt-lib/qvector.h"); + type QVector_i32 = cxx_qt_lib::QVector; + include!("cxx-qt-lib/qstringlist.h"); + type QStringList = cxx_qt_lib::QStringList; + include!("cxx-qt-lib/qlist.h"); + type QList_QString = cxx_qt_lib::QList; + } + + #[cxx_qt::qobject(base = "QQuickView")] + #[derive(Default, Debug)] + pub struct PresentationWindow { + highest_id: i32, + } + + impl qobject::PresentationWindow { + #[qinvokable] + pub fn show(mut self: Pin<&mut Self>, url: &QUrl) { + self.set_source(url); + self.base_show(); + } + } + + // Create Rust bindings for C++ functions of the base class (QAbstractItemModel) + #[cxx_qt::inherit] + extern "C++" {} + + #[cxx_qt::inherit] + unsafe extern "C++" { + #[cxx_name = "setSource"] + fn set_source(self: &qobject::PresentationWindow, url: &QUrl); + #[cxx_name = "showFullscreen"] + fn show_fullscreen(self: &qobject::PresentationWindow); + } +}