adding a basic other struct in rust... well trying...
This commit is contained in:
parent
7eba697dc2
commit
9644631f7c
11 changed files with 124 additions and 36 deletions
|
@ -72,7 +72,7 @@ if(NOT Corrosion_FOUND)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(src)
|
add_subdirectory(src)
|
||||||
set(CRATE qml-minimal)
|
set(CRATE libre-presenter)
|
||||||
|
|
||||||
# Corrosion creates a CMake target with the same name as the crate.
|
# Corrosion creates a CMake target with the same name as the crate.
|
||||||
corrosion_import_crate(MANIFEST_PATH src/rust/Cargo.toml CRATES ${CRATE})
|
corrosion_import_crate(MANIFEST_PATH src/rust/Cargo.toml CRATES ${CRATE})
|
||||||
|
|
14
default.nix
14
default.nix
|
@ -85,16 +85,7 @@ stdenv.mkDerivation rec {
|
||||||
|
|
||||||
RUST_BACKTRACE = 1;
|
RUST_BACKTRACE = 1;
|
||||||
# preConfigure = ''
|
# preConfigure = ''
|
||||||
# # local modulepath=$(kf5-config --install module)
|
# "${cargo-download}
|
||||||
# # local datapath=$(kf5-config --install data)
|
|
||||||
# # local servicespath=$(kf5-config --install services)
|
|
||||||
# # substituteInPlace CMakeLists.txt \
|
|
||||||
# # --replace "\''${MODULEPATH}" "$out/''${modulepath#/nix/store/*/}" \
|
|
||||||
# # --replace "\''${DATAPATH}" "$out/''${datapath#/nix/store/*/}"
|
|
||||||
|
|
||||||
# # substituteInPlace CMakeLists.txt \
|
|
||||||
# # --replace "\''${MODULEPATH}" "$out/qt-5.15.3/plugins" \
|
|
||||||
# # --replace "\''${DATAPATH}" "$out/share"
|
|
||||||
# '';
|
# '';
|
||||||
|
|
||||||
# postConfigure = ''
|
# postConfigure = ''
|
||||||
|
@ -104,7 +95,8 @@ stdenv.mkDerivation rec {
|
||||||
# '';
|
# '';
|
||||||
|
|
||||||
# buildPhase = ''
|
# buildPhase = ''
|
||||||
# rm -rf ~/.cache/librepresenter/Libre\ Presenter/qmlcache/
|
# cmake -B build/ -DCMAKE_BUILD_TYPE=Debug
|
||||||
|
# make -j8 --dir build/
|
||||||
# '';
|
# '';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
|
|
|
@ -18,13 +18,11 @@
|
||||||
src = ./.;
|
src = ./.;
|
||||||
rustPkgs = pkgs.rustBuilder.makePackageSet {
|
rustPkgs = pkgs.rustBuilder.makePackageSet {
|
||||||
rustVersion = "1.61.0";
|
rustVersion = "1.61.0";
|
||||||
packageFun = import ./Cargo.nix;
|
packageFun = import ./cargo.nix;
|
||||||
};
|
};
|
||||||
|
|
||||||
in rec
|
in rec
|
||||||
{
|
{
|
||||||
libre-presenter = (rustPkgs.workspace.libre-presenter {}).bin;
|
|
||||||
|
|
||||||
devShell = import ./shell.nix { inherit pkgs; };
|
devShell = import ./shell.nix { inherit pkgs; };
|
||||||
defaultPackage = pkgs.libsForQt5.callPackage ./default.nix {};
|
defaultPackage = pkgs.libsForQt5.callPackage ./default.nix {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ add_executable(presenter main.cpp resources.qrc)
|
||||||
|
|
||||||
target_sources(presenter
|
target_sources(presenter
|
||||||
PRIVATE
|
PRIVATE
|
||||||
cpp/main.cpp resources.qrc
|
main.cpp resources.qrc
|
||||||
cpp/songsqlmodel.cpp cpp/songsqlmodel.h
|
cpp/songsqlmodel.cpp cpp/songsqlmodel.h
|
||||||
cpp/serviceitemmodel.cpp cpp/serviceitemmodel.h
|
cpp/serviceitemmodel.cpp cpp/serviceitemmodel.h
|
||||||
cpp/serviceitem.cpp cpp/serviceitem.h
|
cpp/serviceitem.cpp cpp/serviceitem.h
|
||||||
|
|
|
@ -34,17 +34,18 @@
|
||||||
#include <qsqlquery.h>
|
#include <qsqlquery.h>
|
||||||
#include <qstringliteral.h>
|
#include <qstringliteral.h>
|
||||||
|
|
||||||
#include "mpv/mpvobject.h"
|
#include "cpp/mpv/mpvobject.h"
|
||||||
#include "serviceitemmodel.h"
|
#include "cpp/serviceitemmodel.h"
|
||||||
#include "songsqlmodel.h"
|
#include "cpp/songsqlmodel.h"
|
||||||
#include "videosqlmodel.h"
|
#include "cpp/videosqlmodel.h"
|
||||||
#include "imagesqlmodel.h"
|
#include "cpp/imagesqlmodel.h"
|
||||||
#include "presentationsqlmodel.h"
|
#include "cpp/presentationsqlmodel.h"
|
||||||
#include "filemanager.h"
|
#include "cpp/filemanager.h"
|
||||||
#include "slide.h"
|
#include "cpp/slide.h"
|
||||||
|
|
||||||
// RUST
|
// RUST
|
||||||
#include "cxx-qt-gen/my_object.cxxqt.h"
|
#include "cxx-qt-gen/my_object.cxxqt.h"
|
||||||
|
#include "cxx-qt-gen/service_thing.cxxqt.h"
|
||||||
|
|
||||||
static void connectToDatabase() {
|
static void connectToDatabase() {
|
||||||
// let's setup our sql database
|
// let's setup our sql database
|
||||||
|
@ -132,6 +133,7 @@ int main(int argc, char *argv[])
|
||||||
qmlRegisterType<PresentationSqlModel>("org.presenter", 1, 0, "PresentationSqlModel");
|
qmlRegisterType<PresentationSqlModel>("org.presenter", 1, 0, "PresentationSqlModel");
|
||||||
qmlRegisterType<ServiceItemModel>("org.presenter", 1, 0, "ServiceItemModel");
|
qmlRegisterType<ServiceItemModel>("org.presenter", 1, 0, "ServiceItemModel");
|
||||||
qmlRegisterType<MyObject>("org.presenter", 1, 0, "MyObject");
|
qmlRegisterType<MyObject>("org.presenter", 1, 0, "MyObject");
|
||||||
|
qmlRegisterType<ServiceThing>("org.presenter", 1, 0, "ServiceThing");
|
||||||
qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slide.get());
|
qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideObject", slide.get());
|
||||||
qmlRegisterSingletonInstance("org.presenter", 1, 0, "FileManager", filemanager.get());
|
qmlRegisterSingletonInstance("org.presenter", 1, 0, "FileManager", filemanager.get());
|
||||||
|
|
|
@ -45,6 +45,7 @@ FocusScope {
|
||||||
text: "Solo"
|
text: "Solo"
|
||||||
icon.name: "viewimage"
|
icon.name: "viewimage"
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
onClicked: myObject.slapVariantAround(imagesqlmodel.getImage(1).title);
|
||||||
}
|
}
|
||||||
Controls.ToolButton {
|
Controls.ToolButton {
|
||||||
text: "Grid"
|
text: "Grid"
|
||||||
|
@ -130,15 +131,12 @@ FocusScope {
|
||||||
anchors.horizontalCenter: previewSlide.horizontalCenter
|
anchors.horizontalCenter: previewSlide.horizontalCenter
|
||||||
/* Layout.columnSpan: 3 */
|
/* Layout.columnSpan: 3 */
|
||||||
visible: itemType === "video";
|
visible: itemType === "video";
|
||||||
Kirigami.Icon {
|
Controls.ToolButton {
|
||||||
source: previewSlide.mpvIsPlaying ? "media-pause" : "media-play"
|
|
||||||
Layout.preferredWidth: 25
|
Layout.preferredWidth: 25
|
||||||
Layout.preferredHeight: 25
|
Layout.preferredHeight: 25
|
||||||
MouseArea {
|
icon.name: previewSlide.mpvIsPlaying ? "media-pause" : "media-play"
|
||||||
anchors.fill: parent
|
hoverEnabled: true
|
||||||
onPressed: SlideObject.playPause();
|
onClicked: SlideObject.playPause();
|
||||||
cursorShape: Qt.PointingHandCursor
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Controls.Slider {
|
Controls.Slider {
|
||||||
id: videoSlider
|
id: videoSlider
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "qml-minimal"
|
name = "libre-presenter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = [
|
authors = [
|
||||||
"Chris Cochrun <chris@cochrun.xyz>"
|
"Chris Cochrun <chris@cochrun.xyz>"
|
||||||
]
|
]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "GPL-3.0"
|
||||||
|
|
||||||
# This will instruct Cargo to create a static
|
# This will instruct Cargo to create a static
|
||||||
# library which CMake can link against
|
# library which CMake can link against
|
||||||
|
|
|
@ -2,4 +2,5 @@ use cxx_qt_build::CxxQtBuilder;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
CxxQtBuilder::new().file("src/cxxqt_object.rs").build();
|
CxxQtBuilder::new().file("src/cxxqt_object.rs").build();
|
||||||
|
CxxQtBuilder::new().file("src/service_thing.rs").build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
#[cxx_qt::bridge]
|
#[cxx_qt::bridge]
|
||||||
mod my_object {
|
mod my_object {
|
||||||
|
use cxx_qt_lib::QVariantValue;
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
type QString = cxx_qt_lib::QString;
|
type QString = cxx_qt_lib::QString;
|
||||||
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::qobject]
|
#[cxx_qt::qobject]
|
||||||
|
@ -31,11 +34,24 @@ mod my_object {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn say_hi(&self, string: &QString, number: i32) {
|
pub fn say_hi(self: Pin<&mut Self>, string: &QString, number: i32) {
|
||||||
println!(
|
println!(
|
||||||
"Hi from Rust! String is '{}' and number is {}",
|
"Hi from Rust! String is '{}' and number is {}",
|
||||||
string, number
|
string, number
|
||||||
);
|
);
|
||||||
|
println!("length is: {}", string.to_string().len());
|
||||||
|
let mut nstr: String = string.to_string();
|
||||||
|
nstr.push_str(" hi");
|
||||||
|
self.set_string(QString::from(nstr.as_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) {
|
||||||
|
println!("wow!");
|
||||||
|
match variant.value() {
|
||||||
|
QVariantValue::QString(string) => self.set_string(string),
|
||||||
|
_ => println!("Unknown QVariant type"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,3 +14,4 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod cxxqt_object;
|
mod cxxqt_object;
|
||||||
|
mod service_thing;
|
||||||
|
|
80
src/rust/src/service_thing.rs
Normal file
80
src/rust/src/service_thing.rs
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
#[cxx_qt::bridge]
|
||||||
|
mod service_thing {
|
||||||
|
use cxx_qt_lib::QVariantValue;
|
||||||
|
|
||||||
|
unsafe extern "C++" {
|
||||||
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
type QString = cxx_qt_lib::QString;
|
||||||
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cxx_qt::qobject]
|
||||||
|
pub struct ServiceThing {
|
||||||
|
#[qproperty]
|
||||||
|
name: QString,
|
||||||
|
#[qproperty]
|
||||||
|
kind: QString,
|
||||||
|
#[qproperty]
|
||||||
|
background: QString,
|
||||||
|
#[qproperty]
|
||||||
|
background_type: QString,
|
||||||
|
#[qproperty]
|
||||||
|
text: QString,
|
||||||
|
#[qproperty]
|
||||||
|
audio: QString,
|
||||||
|
#[qproperty]
|
||||||
|
font: QString,
|
||||||
|
#[qproperty]
|
||||||
|
font_size: QString,
|
||||||
|
#[qproperty]
|
||||||
|
active: bool,
|
||||||
|
#[qproperty]
|
||||||
|
selected: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ServiceThing {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
name: QString::from(""),
|
||||||
|
kind: QString::from(""),
|
||||||
|
background: QString::from(""),
|
||||||
|
background_type: QString::from(""),
|
||||||
|
text: QString::from(""),
|
||||||
|
audio: QString::from(""),
|
||||||
|
font: QString::from(""),
|
||||||
|
font_size: QString::from(""),
|
||||||
|
active: false,
|
||||||
|
selected: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl qobject::ServiceThing {
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn activate(self: Pin<&mut Self>) {
|
||||||
|
self.set_active(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn say_hi(self: Pin<&mut Self>, string: &QString, number: i32) {
|
||||||
|
println!(
|
||||||
|
"Hi from Rust! String is '{}' and number is {}",
|
||||||
|
string, number
|
||||||
|
);
|
||||||
|
println!("length is: {}", string.to_string().len());
|
||||||
|
let mut nstr: String = string.to_string();
|
||||||
|
nstr.push_str(" hi");
|
||||||
|
self.set_name(QString::from(nstr.as_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) {
|
||||||
|
println!("wow!");
|
||||||
|
match variant.value() {
|
||||||
|
QVariantValue::QString(string) => self.set_name(string),
|
||||||
|
_ => println!("Unknown QVariant type"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue