testy
This commit is contained in:
parent
504b4bc944
commit
b56425c671
4 changed files with 142 additions and 0 deletions
17
smdview/blah/Cargo.toml
Normal file
17
smdview/blah/Cargo.toml
Normal file
|
@ -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"
|
||||
|
12
smdview/blah/build.rs
Normal file
12
smdview/blah/build.rs
Normal file
|
@ -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();
|
||||
}
|
42
smdview/blah/src/main.rs
Normal file
42
smdview/blah/src/main.rs
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
71
smdview/blah/src/qml/main.qml
Normal file
71
smdview/blah/src/qml/main.qml
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue