adjusting settings and slide_model.rs
These are trying to get more code written in Rust rather than c++. Not there yet, but I need to sync these to another machine.
This commit is contained in:
parent
ec95ba0d89
commit
236503e877
10 changed files with 387 additions and 108 deletions
89
Cargo.lock
generated
89
Cargo.lock
generated
|
@ -196,7 +196,16 @@ version = "4.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
|
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"dirs-sys",
|
"dirs-sys 0.3.7",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs"
|
||||||
|
version = "5.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dece029acd3353e3a58ac2e3eb3c8d6c35827a892edc6cc4138ef9c33df46ecd"
|
||||||
|
dependencies = [
|
||||||
|
"dirs-sys 0.4.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -210,6 +219,17 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs-sys"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"redox_users",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
|
@ -283,6 +303,7 @@ dependencies = [
|
||||||
"cxx-qt",
|
"cxx-qt",
|
||||||
"cxx-qt-build",
|
"cxx-qt-build",
|
||||||
"cxx-qt-lib",
|
"cxx-qt-lib",
|
||||||
|
"dirs",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
@ -524,6 +545,72 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.45.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.42.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "yaml-rust"
|
name = "yaml-rust"
|
||||||
version = "0.4.5"
|
version = "0.4.5"
|
||||||
|
|
|
@ -20,6 +20,8 @@ serde_derive = "1.0.152"
|
||||||
cxx = "1.0.83"
|
cxx = "1.0.83"
|
||||||
cxx-qt = "0.5.0"
|
cxx-qt = "0.5.0"
|
||||||
cxx-qt-lib = "0.5.0"
|
cxx-qt-lib = "0.5.0"
|
||||||
|
# home = "0.5.4"
|
||||||
|
dirs = "5.0.0"
|
||||||
|
|
||||||
# cxx-qt-build generates C++ code from the `#[cxx_qt::bridge]` module
|
# cxx-qt-build generates C++ code from the `#[cxx_qt::bridge]` module
|
||||||
# and compiles it together with the Rust static library
|
# and compiles it together with the Rust static library
|
||||||
|
|
1
build.rs
1
build.rs
|
@ -6,5 +6,6 @@ fn main() {
|
||||||
.file("src/rust/settings.rs")
|
.file("src/rust/settings.rs")
|
||||||
.file("src/rust/file_helper.rs")
|
.file("src/rust/file_helper.rs")
|
||||||
.file("src/rust/slide_obj.rs")
|
.file("src/rust/slide_obj.rs")
|
||||||
|
.file("src/rust/slide_model.rs")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
25
build.sh
25
build.sh
|
@ -1,5 +1,30 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
function build_debug () {
|
||||||
cmake -B bld/ .
|
cmake -B bld/ .
|
||||||
make -j8 --dir bld/
|
make -j8 --dir bld/
|
||||||
rm -rf ~/.cache/librepresenter/Libre\ Presenter/qmlcache/
|
rm -rf ~/.cache/librepresenter/Libre\ Presenter/qmlcache/
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_release () {
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=Release -B bld/ .
|
||||||
|
make -j8 --dir bld/
|
||||||
|
rm -rf ~/.cache/librepresenter/Libre\ Presenter/qmlcache/
|
||||||
|
}
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-d|--debug)
|
||||||
|
build_debug
|
||||||
|
shift # past value
|
||||||
|
;;
|
||||||
|
-r|--release)
|
||||||
|
build_release
|
||||||
|
shift # past value
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
POSITIONAL_ARGS+=("$1") # save positional arg
|
||||||
|
shift # past argument
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
18
src/main.cpp
18
src/main.cpp
|
@ -51,6 +51,7 @@
|
||||||
#include "cxx-qt-gen/service_thing.cxxqt.h"
|
#include "cxx-qt-gen/service_thing.cxxqt.h"
|
||||||
#include "cxx-qt-gen/file_helper.cxxqt.h"
|
#include "cxx-qt-gen/file_helper.cxxqt.h"
|
||||||
#include "cxx-qt-gen/slide_obj.cxxqt.h"
|
#include "cxx-qt-gen/slide_obj.cxxqt.h"
|
||||||
|
#include "cxx-qt-gen/settings.cxxqt.h"
|
||||||
|
|
||||||
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
|
static QWindow *windowFromEngine(QQmlApplicationEngine *engine)
|
||||||
{
|
{
|
||||||
|
@ -111,7 +112,7 @@ int main(int argc, char *argv[])
|
||||||
QCoreApplication::setOrganizationName(QStringLiteral("librepresenter"));
|
QCoreApplication::setOrganizationName(QStringLiteral("librepresenter"));
|
||||||
QCoreApplication::setOrganizationDomain(QStringLiteral("tfcconnection.org"));
|
QCoreApplication::setOrganizationDomain(QStringLiteral("tfcconnection.org"));
|
||||||
QCoreApplication::setApplicationName(QStringLiteral("Libre Presenter"));
|
QCoreApplication::setApplicationName(QStringLiteral("Libre Presenter"));
|
||||||
qSetMessagePattern("[%{type} %{time h:m:s ap}: %{function} in %{file}]: %{message}\n");
|
// qSetMessagePattern("[%{type} %{time h:m:s ap}: %{function} in %{file}]: %{message}\n");
|
||||||
|
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
QIcon::setFallbackThemeName("breeze");
|
QIcon::setFallbackThemeName("breeze");
|
||||||
|
@ -128,8 +129,8 @@ int main(int argc, char *argv[])
|
||||||
qDebug() << QApplication::platformName();
|
qDebug() << QApplication::platformName();
|
||||||
|
|
||||||
// integrate with commandline argument handling
|
// integrate with commandline argument handling
|
||||||
QCommandLineParser parser;
|
// QCommandLineParser parser;
|
||||||
aboutData.setupCommandLine(&parser);
|
// aboutData.setupCommandLine(&parser);
|
||||||
// setup of app specific commandline args
|
// setup of app specific commandline args
|
||||||
|
|
||||||
//Need to instantiate our slide
|
//Need to instantiate our slide
|
||||||
|
@ -138,6 +139,9 @@ int main(int argc, char *argv[])
|
||||||
// QScopedPointer<QQuickView> preswin(new QQuickView);
|
// QScopedPointer<QQuickView> preswin(new QQuickView);
|
||||||
QScopedPointer<ServiceItemModel> serviceItemModel(new ServiceItemModel);
|
QScopedPointer<ServiceItemModel> serviceItemModel(new ServiceItemModel);
|
||||||
QScopedPointer<SlideObj> slideobject(new SlideObj);
|
QScopedPointer<SlideObj> slideobject(new SlideObj);
|
||||||
|
|
||||||
|
Settings *settings = new Settings;
|
||||||
|
settings->setup();
|
||||||
// preswin->setSource(QUrl(QStringLiteral("qrc:qml/presenter/PresentationWindow.qml")));
|
// preswin->setSource(QUrl(QStringLiteral("qrc:qml/presenter/PresentationWindow.qml")));
|
||||||
|
|
||||||
QObject::connect(serviceItemModel.get(),
|
QObject::connect(serviceItemModel.get(),
|
||||||
|
@ -220,10 +224,10 @@ int main(int argc, char *argv[])
|
||||||
window->setIcon(QIcon::fromTheme(QStringLiteral("system-config-display")));
|
window->setIcon(QIcon::fromTheme(QStringLiteral("system-config-display")));
|
||||||
// KWindowSystem::setMainWindow(window);
|
// KWindowSystem::setMainWindow(window);
|
||||||
// KWindowSystem::activateWindow(window);
|
// KWindowSystem::activateWindow(window);
|
||||||
qDebug() << "00000000000000000000000000000000";
|
// qDebug() << "00000000000000000000000000000000";
|
||||||
qDebug() << KWindowSystem::isPlatformWayland();
|
// qDebug() << KWindowSystem::isPlatformWayland();
|
||||||
qDebug() << KWindowSystem::windows();
|
// qDebug() << KWindowSystem::windows();
|
||||||
qDebug() << "00000000000000000000000000000000";
|
// qDebug() << "00000000000000000000000000000000";
|
||||||
|
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
|
@ -157,7 +157,8 @@ Controls.Page {
|
||||||
ServiceItemModel.activate(index);
|
ServiceItemModel.activate(index);
|
||||||
console.log("%%%%%%%%%");
|
console.log("%%%%%%%%%");
|
||||||
console.log(slide);
|
console.log(slide);
|
||||||
slideHelper.chngSlide(slide, slideId, SlideObject);
|
/* SlideObject.changeSlide(slide, slideId); */
|
||||||
|
slideHelper.chngSlide(item, index, SlideObject);
|
||||||
console.log("%%%%%%%%%");
|
console.log("%%%%%%%%%");
|
||||||
/* SlideObject.changeSlide(slide, slideId); */
|
/* SlideObject.changeSlide(slide, slideId); */
|
||||||
|
|
||||||
|
@ -187,6 +188,7 @@ Controls.Page {
|
||||||
console.log("Time to start changing");
|
console.log("Time to start changing");
|
||||||
|
|
||||||
ServiceItemModel.activate(currentServiceItem);
|
ServiceItemModel.activate(currentServiceItem);
|
||||||
|
/* SlideObject.changeSlide(slide, slideId); */
|
||||||
slideHelper.chngSlide(item, index, SlideObject);
|
slideHelper.chngSlide(item, index, SlideObject);
|
||||||
SlideModel.activate(index);
|
SlideModel.activate(index);
|
||||||
presentation.textIndex = 0;
|
presentation.textIndex = 0;
|
||||||
|
|
|
@ -18,3 +18,4 @@ mod file_helper;
|
||||||
mod service_thing;
|
mod service_thing;
|
||||||
mod settings;
|
mod settings;
|
||||||
mod slide_obj;
|
mod slide_obj;
|
||||||
|
mod slide_model;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
mod settings {
|
mod settings {
|
||||||
|
|
||||||
use configparser::ini::Ini;
|
use configparser::ini::Ini;
|
||||||
// use std::error::Error;
|
use dirs;
|
||||||
|
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!("cxx-qt-lib/qstring.h");
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
@ -16,6 +16,8 @@ mod settings {
|
||||||
screen: QString,
|
screen: QString,
|
||||||
#[qproperty]
|
#[qproperty]
|
||||||
sound_effect: QString,
|
sound_effect: QString,
|
||||||
|
#[qproperty]
|
||||||
|
last_save_file: QString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
|
@ -23,6 +25,7 @@ mod settings {
|
||||||
Self {
|
Self {
|
||||||
screen: QString::from(""),
|
screen: QString::from(""),
|
||||||
sound_effect: QString::from(""),
|
sound_effect: QString::from(""),
|
||||||
|
last_save_file: QString::from(""),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,5 +38,30 @@ mod settings {
|
||||||
|
|
||||||
println!("{}", self.sound_effect());
|
println!("{}", self.sound_effect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn setup(self: Pin<&mut Self>) {
|
||||||
|
let mut config = Ini::new();
|
||||||
|
let home = dirs::config_dir();
|
||||||
|
println!("{:?}", home);
|
||||||
|
if let Some(mut conf) = home {
|
||||||
|
conf.push("librepresenter");
|
||||||
|
conf.push("Libre Presenter.conf");
|
||||||
|
let _map = config.load(conf);
|
||||||
|
|
||||||
|
println!("{:?}", config);
|
||||||
|
println!("{:?}", _map);
|
||||||
|
let sf = config.get("General", "lastSaveFile");
|
||||||
|
println!("{:?}", sf);
|
||||||
|
if let Some(s) = sf {
|
||||||
|
self.set_last_save_file(QString::from(&s));
|
||||||
|
println!("{s}");
|
||||||
|
} else {
|
||||||
|
println!("error loading last save file");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Couldn't find home directory");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,30 +1,51 @@
|
||||||
#[cxx_qt::bridge(cxx_file_stem = "custom_base_class")]
|
#[cxx_qt::bridge]
|
||||||
mod ffi {
|
mod slide_model {
|
||||||
unsafe extern "C++" {
|
unsafe extern "C++" {
|
||||||
include!(< QAbstractListModel >);
|
include!(< QAbstractListModel >);
|
||||||
|
|
||||||
include!("cxx-qt-lib/qhash.h");
|
include!("cxx-qt-lib/qhash.h");
|
||||||
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
type QHash_i32_QByteArray = cxx_qt_lib::QHash<cxx_qt_lib::QHashPair_i32_QByteArray>;
|
||||||
|
|
||||||
include!("cxx-qt-lib/qvariant.h");
|
include!("cxx-qt-lib/qvariant.h");
|
||||||
type QVariant = cxx_qt_lib::QVariant;
|
type QVariant = cxx_qt_lib::QVariant;
|
||||||
|
include!("cxx-qt-lib/qstring.h");
|
||||||
|
type QString = cxx_qt_lib::QString;
|
||||||
include!("cxx-qt-lib/qmodelindex.h");
|
include!("cxx-qt-lib/qmodelindex.h");
|
||||||
type QModelIndex = cxx_qt_lib::QModelIndex;
|
type QModelIndex = cxx_qt_lib::QModelIndex;
|
||||||
|
|
||||||
include!("cxx-qt-lib/qvector.h");
|
include!("cxx-qt-lib/qvector.h");
|
||||||
type QVector_i32 = cxx_qt_lib::QVector<i32>;
|
type QVector_i32 = cxx_qt_lib::QVector<i32>;
|
||||||
|
// include!("cxx-qt-lib/qvector.h");
|
||||||
|
// type QVector_Slide = cxx_qt_lib::QVector<Slide>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cxx_qt::qobject]
|
||||||
|
#[derive(Default, Clone, Debug)]
|
||||||
|
pub struct Slide {
|
||||||
|
text: QString,
|
||||||
|
ty: QString,
|
||||||
|
audio: QString,
|
||||||
|
image_background: QString,
|
||||||
|
video_background: QString,
|
||||||
|
htext_alignment: QString,
|
||||||
|
vtext_alignment: QString,
|
||||||
|
font: QString,
|
||||||
|
font_size: i32,
|
||||||
|
image_count: i32,
|
||||||
|
slide_id: i32,
|
||||||
|
service_item_id: i32,
|
||||||
|
active: bool,
|
||||||
|
selected: bool,
|
||||||
|
looping: bool,
|
||||||
|
video_thumbnail: QString,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::qobject(
|
#[cxx_qt::qobject(
|
||||||
base = "QAbstractListModel",
|
base = "QAbstractListModel",
|
||||||
qml_uri = "com.kdab.cxx_qt.demo",
|
// qml_uri = "com.kdab.cxx_qt.demo",
|
||||||
qml_version = "1.0"
|
// qml_version = "1.0"
|
||||||
)]
|
)]
|
||||||
#[derive(Default)]
|
#[derive(Default, Debug)]
|
||||||
pub struct SlideModel {
|
pub struct SlideModel {
|
||||||
id: i32,
|
id: i32,
|
||||||
vector: Vec<(i32, f64)>,
|
slides: Vec<Slide>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cxx_qt::qsignals(SlideModel)]
|
#[cxx_qt::qsignals(SlideModel)]
|
||||||
|
@ -38,83 +59,165 @@ mod ffi {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl qobject::SlideModel {
|
impl qobject::SlideModel {
|
||||||
#[qinvokable]
|
// #[qinvokable]
|
||||||
pub fn add(self: Pin<&mut Self>) {
|
// pub fn add(self: Pin<&mut Self>) {
|
||||||
self.add_cpp_context();
|
// self.add_cpp_context();
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[qinvokable]
|
// #[qinvokable]
|
||||||
pub fn add_on_thread(self: Pin<&mut Self>, mut counter: i32) {
|
// pub fn add_on_thread(self: Pin<&mut Self>, mut counter: i32) {
|
||||||
let qt_thread = self.qt_thread();
|
// let qt_thread = self.qt_thread();
|
||||||
|
|
||||||
std::thread::spawn(move || {
|
// std::thread::spawn(move || {
|
||||||
while counter > 0 {
|
// while counter > 0 {
|
||||||
counter -= 1;
|
// counter -= 1;
|
||||||
std::thread::sleep(std::time::Duration::from_millis(250));
|
// std::thread::sleep(std::time::Duration::from_millis(250));
|
||||||
|
|
||||||
// Use our add helper to add a row on the Qt event loop
|
// // Use our add helper to add a row on the Qt event loop
|
||||||
// as seen in the threading demo channels could be used to pass info
|
// // as seen in the threading demo channels could be used to pass info
|
||||||
qt_thread
|
// qt_thread
|
||||||
.queue(|custom_base_class| {
|
// .queue(|custom_base_class| {
|
||||||
custom_base_class.add_cpp_context();
|
// custom_base_class.add_cpp_context();
|
||||||
})
|
// })
|
||||||
.unwrap();
|
// .unwrap();
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn add_cpp_context(mut self: Pin<&mut Self>) {
|
// fn add_cpp_context(mut self: Pin<&mut Self>) {
|
||||||
let count = self.vector().len();
|
// let count = self.vector().len();
|
||||||
unsafe {
|
// unsafe {
|
||||||
self.as_mut().begin_insert_rows(
|
// self.as_mut().begin_insert_rows(
|
||||||
&QModelIndex::default(),
|
// &QModelIndex::default(),
|
||||||
count as i32,
|
// count as i32,
|
||||||
count as i32,
|
// count as i32,
|
||||||
);
|
// );
|
||||||
let id = *self.id();
|
// let id = *self.id();
|
||||||
self.as_mut().set_id(id + 1);
|
// self.as_mut().set_id(id + 1);
|
||||||
self.as_mut().vector_mut().push((id, (id as f64) / 3.0));
|
// self.as_mut().vector_mut().push((id, (id as f64) / 3.0));
|
||||||
self.as_mut().end_insert_rows();
|
// self.as_mut().end_insert_rows();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn clear(mut self: Pin<&mut Self>) {
|
pub fn clear(mut self: Pin<&mut Self>) {
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut().begin_reset_model();
|
self.as_mut().begin_reset_model();
|
||||||
self.as_mut().set_id(0);
|
self.as_mut().slides_mut().clear();
|
||||||
self.as_mut().vector_mut().clear();
|
|
||||||
self.as_mut().end_reset_model();
|
self.as_mut().end_reset_model();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn multiply(mut self: Pin<&mut Self>, index: i32, factor: f64) {
|
pub fn remove_item(mut self: Pin<&mut Self>, index: i32) {
|
||||||
if let Some((_, value)) = self.as_mut().vector_mut().get_mut(index as usize) {
|
if index < 0 || (index as usize) >= self.slides().len() {
|
||||||
*value *= factor;
|
|
||||||
|
|
||||||
// Emit dataChanged for the index and value role
|
|
||||||
let model_index = self.index(index, 0, &QModelIndex::default());
|
|
||||||
let mut vector_roles = QVector_i32::default();
|
|
||||||
vector_roles.append(1);
|
|
||||||
self.as_mut().emit(Signals::DataChanged {
|
|
||||||
top_left: &model_index,
|
|
||||||
bottom_right: &model_index,
|
|
||||||
roles: &vector_roles,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[qinvokable]
|
|
||||||
pub fn remove(mut self: Pin<&mut Self>, index: i32) {
|
|
||||||
if index < 0 || (index as usize) >= self.vector().len() {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.begin_remove_rows(&QModelIndex::default(), index, index);
|
.begin_remove_rows(&QModelIndex::default(), index, index);
|
||||||
self.as_mut().vector_mut().remove(index as usize);
|
self.as_mut().slides_mut().remove(index as usize);
|
||||||
|
self.as_mut().end_remove_rows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn add_item(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
text: QString,
|
||||||
|
ty: QString,
|
||||||
|
image_background: QString,
|
||||||
|
video_background: QString,
|
||||||
|
audio: QString,
|
||||||
|
font: QString,
|
||||||
|
font_size: i32,
|
||||||
|
htext_alignment: QString,
|
||||||
|
vtext_alignment: QString,
|
||||||
|
service_item_id: i32,
|
||||||
|
slide_id: i32,
|
||||||
|
image_count: i32,
|
||||||
|
looping: bool,
|
||||||
|
) {
|
||||||
|
let slide = Slide {
|
||||||
|
ty,
|
||||||
|
text,
|
||||||
|
image_background,
|
||||||
|
video_background,
|
||||||
|
audio,
|
||||||
|
font,
|
||||||
|
font_size,
|
||||||
|
htext_alignment,
|
||||||
|
vtext_alignment,
|
||||||
|
service_item_id,
|
||||||
|
slide_id,
|
||||||
|
image_count,
|
||||||
|
looping,
|
||||||
|
active: false,
|
||||||
|
selected: false,
|
||||||
|
video_thumbnail: QString::from(""),
|
||||||
|
};
|
||||||
|
|
||||||
|
self.as_mut().add_slide(&slide);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_slide(mut self: Pin<&mut Self>, slide: &Slide) {
|
||||||
|
let index = self.as_ref().slides().len() as i32;
|
||||||
|
let slide = slide.clone();
|
||||||
|
unsafe {
|
||||||
|
self.as_mut()
|
||||||
|
.begin_insert_rows(&QModelIndex::default(), index, index);
|
||||||
|
self.as_mut().slides_mut().push(slide);
|
||||||
|
self.as_mut().end_remove_rows();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[qinvokable]
|
||||||
|
pub fn insert_item(
|
||||||
|
mut self: Pin<&mut Self>,
|
||||||
|
index: i32,
|
||||||
|
text: QString,
|
||||||
|
ty: QString,
|
||||||
|
image_background: QString,
|
||||||
|
video_background: QString,
|
||||||
|
audio: QString,
|
||||||
|
font: QString,
|
||||||
|
font_size: i32,
|
||||||
|
htext_alignment: QString,
|
||||||
|
vtext_alignment: QString,
|
||||||
|
service_item_id: i32,
|
||||||
|
slide_id: i32,
|
||||||
|
image_count: i32,
|
||||||
|
looping: bool,
|
||||||
|
) {
|
||||||
|
let slide = Slide {
|
||||||
|
ty,
|
||||||
|
text,
|
||||||
|
image_background,
|
||||||
|
video_background,
|
||||||
|
audio,
|
||||||
|
font,
|
||||||
|
font_size,
|
||||||
|
htext_alignment,
|
||||||
|
vtext_alignment,
|
||||||
|
service_item_id,
|
||||||
|
slide_id,
|
||||||
|
image_count,
|
||||||
|
looping,
|
||||||
|
active: false,
|
||||||
|
selected: false,
|
||||||
|
video_thumbnail: QString::from(""),
|
||||||
|
};
|
||||||
|
|
||||||
|
self.as_mut().insert_slide(&slide, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert_slide(mut self: Pin<&mut Self>, slide: &Slide, id: i32) {
|
||||||
|
let slide = slide.clone();
|
||||||
|
unsafe {
|
||||||
|
self.as_mut()
|
||||||
|
.begin_insert_rows(&QModelIndex::default(), id, id);
|
||||||
|
self.as_mut().slides_mut().insert(id as usize, slide);
|
||||||
self.as_mut().end_remove_rows();
|
self.as_mut().end_remove_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,10 +263,24 @@ mod ffi {
|
||||||
impl qobject::SlideModel {
|
impl qobject::SlideModel {
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
fn data(&self, index: &QModelIndex, role: i32) -> QVariant {
|
||||||
if let Some((id, value)) = self.rust().vector.get(index.row() as usize) {
|
if let Some(slide) = self.rust().slides.get(index.row() as usize) {
|
||||||
return match role {
|
return match role {
|
||||||
0 => QVariant::from(id),
|
0 => QVariant::from(&slide.ty),
|
||||||
1 => QVariant::from(value),
|
1 => QVariant::from(&slide.text),
|
||||||
|
2 => QVariant::from(&slide.audio),
|
||||||
|
3 => QVariant::from(&slide.image_background),
|
||||||
|
4 => QVariant::from(&slide.video_background),
|
||||||
|
5 => QVariant::from(&slide.htext_alignment),
|
||||||
|
6 => QVariant::from(&slide.vtext_alignment),
|
||||||
|
7 => QVariant::from(&slide.font),
|
||||||
|
8 => QVariant::from(&slide.font_size),
|
||||||
|
9 => QVariant::from(&slide.service_item_id),
|
||||||
|
10 => QVariant::from(&slide.slide_id),
|
||||||
|
11 => QVariant::from(&slide.image_count),
|
||||||
|
12 => QVariant::from(&slide.active),
|
||||||
|
13 => QVariant::from(&slide.selected),
|
||||||
|
14 => QVariant::from(&slide.looping),
|
||||||
|
15 => QVariant::from(&slide.video_thumbnail),
|
||||||
_ => QVariant::default(),
|
_ => QVariant::default(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -180,14 +297,28 @@ mod ffi {
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
pub fn role_names(&self) -> QHash_i32_QByteArray {
|
pub fn role_names(&self) -> QHash_i32_QByteArray {
|
||||||
let mut roles = QHash_i32_QByteArray::default();
|
let mut roles = QHash_i32_QByteArray::default();
|
||||||
roles.insert(0, cxx_qt_lib::QByteArray::from("id"));
|
roles.insert(0, cxx_qt_lib::QByteArray::from("type"));
|
||||||
roles.insert(1, cxx_qt_lib::QByteArray::from("value"));
|
roles.insert(1, cxx_qt_lib::QByteArray::from("text"));
|
||||||
|
roles.insert(2, cxx_qt_lib::QByteArray::from("audio"));
|
||||||
|
roles.insert(3, cxx_qt_lib::QByteArray::from("imageBackground"));
|
||||||
|
roles.insert(4, cxx_qt_lib::QByteArray::from("videoBackground"));
|
||||||
|
roles.insert(5, cxx_qt_lib::QByteArray::from("hTextAlignment"));
|
||||||
|
roles.insert(6, cxx_qt_lib::QByteArray::from("vTextAlignment"));
|
||||||
|
roles.insert(7, cxx_qt_lib::QByteArray::from("font"));
|
||||||
|
roles.insert(8, cxx_qt_lib::QByteArray::from("fontSize"));
|
||||||
|
roles.insert(9, cxx_qt_lib::QByteArray::from("serviceItemId"));
|
||||||
|
roles.insert(10, cxx_qt_lib::QByteArray::from("slideId"));
|
||||||
|
roles.insert(11, cxx_qt_lib::QByteArray::from("imageCount"));
|
||||||
|
roles.insert(12, cxx_qt_lib::QByteArray::from("active"));
|
||||||
|
roles.insert(13, cxx_qt_lib::QByteArray::from("selected"));
|
||||||
|
roles.insert(14, cxx_qt_lib::QByteArray::from("looping"));
|
||||||
|
roles.insert(15, cxx_qt_lib::QByteArray::from("videoThumbnail"));
|
||||||
roles
|
roles
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable(cxx_override)]
|
#[qinvokable(cxx_override)]
|
||||||
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
|
pub fn row_count(&self, _parent: &QModelIndex) -> i32 {
|
||||||
self.rust().vector.len() as i32
|
self.rust().slides.len() as i32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,18 +102,16 @@ mod slide_obj {
|
||||||
} else {
|
} else {
|
||||||
println!("audio: empty");
|
println!("audio: empty");
|
||||||
}
|
}
|
||||||
let ty = item.get(&QString::from("type"));
|
let ty = item
|
||||||
if let Some(ty) = ty {
|
.get(&QString::from("type"))
|
||||||
|
.unwrap_or(QVariant::from(&QString::from("")));
|
||||||
if let Some(ty) = ty.value::<QString>() {
|
if let Some(ty) = ty.value::<QString>() {
|
||||||
if &ty != self.as_ref().ty() {
|
if &ty != self.as_ref().ty() {
|
||||||
println!("type: {ty}");
|
println!("type: {ty}");
|
||||||
self.as_mut().set_ty(ty);
|
self.as_mut().set_ty(ty);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("Type wasn't a sting");
|
println!("type: empty");
|
||||||
}
|
|
||||||
} else {
|
|
||||||
println!("Type was incorrect");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let image_background = item
|
let image_background = item
|
||||||
|
@ -121,22 +119,22 @@ mod slide_obj {
|
||||||
.unwrap_or(QVariant::from(&QString::from("")));
|
.unwrap_or(QVariant::from(&QString::from("")));
|
||||||
if let Some(image_background) = image_background.value::<QString>() {
|
if let Some(image_background) = image_background.value::<QString>() {
|
||||||
if &image_background != self.as_ref().image_background() {
|
if &image_background != self.as_ref().image_background() {
|
||||||
println!("image bg: {image_background}");
|
println!("image-bg: {image_background}");
|
||||||
self.as_mut().set_image_background(image_background);
|
self.as_mut().set_image_background(image_background);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("image bg: empty");
|
println!("image-bg: empty");
|
||||||
}
|
}
|
||||||
let video_background = item
|
let video_background = item
|
||||||
.get(&QString::from("videoBackground"))
|
.get(&QString::from("videoBackground"))
|
||||||
.unwrap_or(QVariant::from(&QString::from("")));
|
.unwrap_or(QVariant::from(&QString::from("")));
|
||||||
if let Some(video_background) = video_background.value::<QString>() {
|
if let Some(video_background) = video_background.value::<QString>() {
|
||||||
if &video_background != self.as_ref().video_background() {
|
if &video_background != self.as_ref().video_background() {
|
||||||
println!("video bg: {video_background}");
|
println!("video-bg: {video_background}");
|
||||||
self.as_mut().set_video_background(video_background);
|
self.as_mut().set_video_background(video_background);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("video bg: empty");
|
println!("video-bg: empty");
|
||||||
}
|
}
|
||||||
let font = item
|
let font = item
|
||||||
.get(&QString::from("font"))
|
.get(&QString::from("font"))
|
||||||
|
@ -154,33 +152,33 @@ mod slide_obj {
|
||||||
.unwrap_or(QVariant::from(&QString::from("center")));
|
.unwrap_or(QVariant::from(&QString::from("center")));
|
||||||
if let Some(vtext_alignment) = vtext_alignment.value::<QString>() {
|
if let Some(vtext_alignment) = vtext_alignment.value::<QString>() {
|
||||||
if &vtext_alignment != self.as_ref().vtext_alignment() {
|
if &vtext_alignment != self.as_ref().vtext_alignment() {
|
||||||
println!("vertical text align: {vtext_alignment}");
|
println!("vertical-text-align: {vtext_alignment}");
|
||||||
self.as_mut().set_vtext_alignment(vtext_alignment);
|
self.as_mut().set_vtext_alignment(vtext_alignment);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("vertical text align: empty");
|
println!("vertical-text-align: empty");
|
||||||
}
|
}
|
||||||
let htext_alignment = item
|
let htext_alignment = item
|
||||||
.get(&QString::from("horizontalTextAlignment"))
|
.get(&QString::from("horizontalTextAlignment"))
|
||||||
.unwrap_or(QVariant::from(&QString::from("center")));
|
.unwrap_or(QVariant::from(&QString::from("center")));
|
||||||
if let Some(htext_alignment) = htext_alignment.value::<QString>() {
|
if let Some(htext_alignment) = htext_alignment.value::<QString>() {
|
||||||
if &htext_alignment != self.as_ref().htext_alignment() {
|
if &htext_alignment != self.as_ref().htext_alignment() {
|
||||||
println!("horizontal text align: {htext_alignment}");
|
println!("horizontal-text-align: {htext_alignment}");
|
||||||
self.as_mut().set_htext_alignment(htext_alignment);
|
self.as_mut().set_htext_alignment(htext_alignment);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("horizontal text align: empty");
|
println!("horizontal-text-align: empty");
|
||||||
}
|
}
|
||||||
let font_size = item
|
let font_size = item
|
||||||
.get(&QString::from("fontSize"))
|
.get(&QString::from("fontSize"))
|
||||||
.unwrap_or(QVariant::from(&50));
|
.unwrap_or(QVariant::from(&50));
|
||||||
if let Some(font_size) = font_size.value::<i32>() {
|
if let Some(font_size) = font_size.value::<i32>() {
|
||||||
if &font_size != self.as_ref().font_size() {
|
if &font_size != self.as_ref().font_size() {
|
||||||
println!("font size: {font_size}");
|
println!("font-size: {font_size}");
|
||||||
self.as_mut().set_font_size(font_size);
|
self.as_mut().set_font_size(font_size);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println!("font size: empty");
|
println!("font-size: empty");
|
||||||
}
|
}
|
||||||
let looping = item
|
let looping = item
|
||||||
.get(&QString::from("looping"))
|
.get(&QString::from("looping"))
|
||||||
|
@ -200,7 +198,7 @@ mod slide_obj {
|
||||||
.unwrap_or(QVariant::from(&1));
|
.unwrap_or(QVariant::from(&1));
|
||||||
if let Some(slide_size) = slide_size.value::<i32>() {
|
if let Some(slide_size) = slide_size.value::<i32>() {
|
||||||
if &slide_size != self.as_ref().slide_size() {
|
if &slide_size != self.as_ref().slide_size() {
|
||||||
println!("slide size: {slide_size}");
|
println!("slide-size: {slide_size}");
|
||||||
self.as_mut().set_slide_size(slide_size);
|
self.as_mut().set_slide_size(slide_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue