basic updates to make cxx-qt work with 6.0

This commit is contained in:
Chris Cochrun 2023-11-21 11:44:46 -06:00
parent 6b3559b4ef
commit 5d571a7e6f
2 changed files with 171 additions and 170 deletions

View file

@ -1,7 +1,5 @@
#[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;
@ -9,32 +7,46 @@ mod service_thing {
type QVariant = cxx_qt_lib::QVariant;
}
#[derive(Clone)]
#[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,
}
unsafe extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(QString, name)]
#[qproperty(QString, kind)]
#[qproperty(QString, background)]
#[qproperty(QString, background_type)]
#[qproperty(QString, text)]
#[qproperty(QString, audio)]
#[qproperty(QString, font)]
#[qproperty(QString, font_size)]
#[qproperty(bool, active)]
#[qproperty(bool, selected)]
type ServiceThing = super::ServiceThingRust;
impl Default for ServiceThing {
#[qinvokable]
fn activate(self: Pin<&mut ServiceThing>);
#[qinvokable]
fn check_active(self: Pin<&mut ServiceThing>);
}
}
use cxx_qt_lib::QString;
#[derive(Clone)]
pub struct ServiceThingRust {
name: QString,
kind: QString,
background: QString,
background_type: QString,
text: QString,
audio: QString,
font: QString,
font_size: QString,
active: bool,
selected: bool,
}
impl Default for ServiceThingRust {
fn default() -> Self {
Self {
name: QString::from(""),
@ -49,9 +61,9 @@ mod service_thing {
selected: false,
}
}
}
}
impl qobject::ServiceThing {
impl qobject::ServiceThing {
#[qinvokable]
pub fn activate(self: Pin<&mut Self>) {
println!("{}", self.active());
@ -64,20 +76,4 @@ mod service_thing {
pub fn check_active(self: Pin<&mut Self>) {
println!("Are we active?: {}", self.active());
}
// #[qinvokable]
// pub fn slap_variant_around(self: Pin<&mut Self>, variant: &QVariant) {
// println!("wow!");
// let sname: String;
// match variant.value() {
// QVariantValue::QString(string) => {
// let nstr = string.to_string();
// self.set_name(QString::from(nstr.as_str()));
// sname = nstr;
// println!("New name is: {}", sname);
// }
// _ => println!("Unknown QVariant type"),
// };
// }
}
}

View file

@ -1,10 +1,5 @@
#[cxx_qt::bridge]
mod settings {
use configparser::ini::Ini;
use dirs;
use std::path::PathBuf;
unsafe extern "C++" {
include!("cxx-qt-lib/qstring.h");
type QString = cxx_qt_lib::QString;
@ -12,11 +7,25 @@ mod settings {
type QUrl = cxx_qt_lib::QUrl;
}
// In order for settings to save to the ini file,
// I'll need to create my own setting functions I think.
#[derive(Clone)]
#[cxx_qt::qobject]
pub struct Settings {
unsafe extern "RustQt" {
#[qobject]
#[qml_element]
#[qproperty(QString, screen)]
#[qproperty(QString, sound_effect)]
#[qproperty(QUrl, last_save_file)]
#[qproperty(QUrl, loaded_file)]
type Settings = super::SettingsRust;
}
}
use configparser::ini::Ini;
use dirs;
use std::path::PathBuf;
// In order for settings to save to the ini file,
// I'll need to create my own setting functions I think.
#[derive(Clone)]
pub struct SettingsRust {
config: Ini,
#[qproperty]
@ -27,9 +36,9 @@ mod settings {
last_save_file: QUrl,
#[qproperty]
loaded_file: QUrl,
}
}
impl Default for Settings {
impl Default for SettingsRust {
fn default() -> Self {
Self {
config: Ini::new(),
@ -39,9 +48,9 @@ mod settings {
loaded_file: QUrl::from(""),
}
}
}
}
impl qobject::Settings {
impl qobject::Settings {
#[qinvokable]
pub fn print_sound(self: Pin<&mut Self>) {
let mut config = Ini::new();
@ -68,8 +77,7 @@ mod settings {
if let Some(s) = sf {
self.as_mut()
.set_last_save_file(QUrl::from(&s));
self.as_mut()
.set_loaded_file(QUrl::from(&s));
self.as_mut().set_loaded_file(QUrl::from(&s));
println!("{s}");
} else {
println!("error loading last save file");
@ -108,9 +116,7 @@ mod settings {
}
}
pub fn write(
mut self: Pin<&mut Self>,
) -> std::io::Result<&str> {
pub fn write(mut self: Pin<&mut Self>) -> std::io::Result<&str> {
let mut file = dirs::config_dir().unwrap();
file.push("lumina");
file.push("lumina.conf");
@ -122,5 +128,4 @@ mod settings {
}
}
}
}
}