From b56425c671a08783084d46a7beaccfd01cd6454a Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 25 Jul 2025 15:19:31 -0500 Subject: [PATCH] testy --- smdview/blah/Cargo.toml | 17 +++++++++ smdview/blah/build.rs | 12 ++++++ smdview/blah/src/main.rs | 42 +++++++++++++++++++++ smdview/blah/src/qml/main.qml | 71 +++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 smdview/blah/Cargo.toml create mode 100644 smdview/blah/build.rs create mode 100644 smdview/blah/src/main.rs create mode 100644 smdview/blah/src/qml/main.qml diff --git a/smdview/blah/Cargo.toml b/smdview/blah/Cargo.toml new file mode 100644 index 0000000..1a4e1ef --- /dev/null +++ b/smdview/blah/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "blah" +version = "0.1.0" +edition = "2024" + +[dependencies] +cxx = "1.0.122" +cxx-qt = "0.7.1" +cxx-qt-lib = { version = "0.7.1", features = [ "qt_full" ] } +cxx-qt-lib-extras = "0.7.1" +markdown = "=1.0.0-alpha.17" + +[build-dependencies] +# The link_qt_object_files feature is required for statically linking Qt 6. +cxx-qt-build = { version = "0.7.1", features = [ "link_qt_object_files" ] } +qt-build-utils = "0.7.1" + diff --git a/smdview/blah/build.rs b/smdview/blah/build.rs new file mode 100644 index 0000000..c67706d --- /dev/null +++ b/smdview/blah/build.rs @@ -0,0 +1,12 @@ +use cxx_qt_build::{CxxQtBuilder, QmlModule}; + +fn main() { + CxxQtBuilder::new() + .qml_module(QmlModule { + uri: "org.kde.simplemdviewer", + qml_files: &["src/qml/Main.qml"], + rust_files: &["src/main.rs"], + ..Default::default() + }) + .build(); +} diff --git a/smdview/blah/src/main.rs b/smdview/blah/src/main.rs new file mode 100644 index 0000000..c79e764 --- /dev/null +++ b/smdview/blah/src/main.rs @@ -0,0 +1,42 @@ +#[cxx_qt::bridge] +mod ffi { + extern "RustQt" { + #[qobject] + type DummyQObject = super::DummyRustStruct; + } +} + +#[derive(Default)] +pub struct DummyRustStruct; + +use cxx_qt_lib::{ + QGuiApplication, QQmlApplicationEngine, QQuickStyle, QString, + QUrl, +}; +use cxx_qt_lib_extras::QApplication; +use std::env; + +fn main() { + let mut app = QApplication::new(); + + // To associate the executable to the installed desktop file + QGuiApplication::set_desktop_file_name(&QString::from( + "org.kde.simplemdviewer", + )); + + // To ensure the style is set correctly + if env::var("QT_QUICK_CONTROLS_STYLE").is_err() { + QQuickStyle::set_style(&QString::from("org.kde.desktop")); + } + + let mut engine = QQmlApplicationEngine::new(); + if let Some(engine) = engine.as_mut() { + engine.load(&QUrl::from( + "qrc:/qt/qml/org/kde/simplemdviewer/src/qml/Main.qml", + )); + } + + if let Some(app) = app.as_mut() { + app.exec(); + } +} diff --git a/smdview/blah/src/qml/main.qml b/smdview/blah/src/qml/main.qml new file mode 100644 index 0000000..077a11e --- /dev/null +++ b/smdview/blah/src/qml/main.qml @@ -0,0 +1,71 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls as Controls +import org.kde.kirigami as Kirigami + +Kirigami.ApplicationWindow { + id: root + + title: "Simple Markdown Viewer in Rust 🦀" + + minimumWidth: Kirigami.Units.gridUnit * 20 + minimumHeight: Kirigami.Units.gridUnit * 20 + width: minimumWidth + height: minimumHeight + + pageStack.initialPage: initPage + + Component { + id: initPage + + Kirigami.Page { + title: "Markdown Viewer" + + ColumnLayout { + anchors { + top: parent.top + left: parent.left + right: parent.right + } + Controls.TextArea { + id: sourceArea + + placeholderText: "Write some Markdown code here" + wrapMode: Text.WrapAnywhere + Layout.fillWidth: true + Layout.minimumHeight: Kirigami.Units.gridUnit * 5 + } + + RowLayout { + Layout.fillWidth: true + + Controls.Button { + text: "Format" + + onClicked: formattedText.text = sourceArea.text + } + + Controls.Button { + text: "Clear" + + onClicked: { + sourceArea.text = "" + formattedText.text = "" + } + } + } + + Controls.Label { + id: formattedText + + textFormat: Text.RichText + wrapMode: Text.WordWrap + text: sourceArea.text + + Layout.fillWidth: true + Layout.minimumHeight: Kirigami.Units.gridUnit * 5 + } + } + } + } +}