slide_obj.rs working
This commit finally has a working basic slide_obj implemented in Rust! There are likely still some things that need to be tweaked and massaged in order for things to translate back and forth from QML to Rust. The key was to make the old SlideObject written in C++ to act as a bridge between QML and Rust. QML can't seem to understand CXX-QT's QMap_QString_QVariant type as a QVariantMap and thus didn't translate the Javascript object properly. Having the call first go into a C++ class translated it and then was trivial to pass into Rust.
This commit is contained in:
parent
0936490bee
commit
0caadfc5c8
6 changed files with 55 additions and 17 deletions
|
@ -60,6 +60,12 @@ bool SlideObject::loop() const
|
||||||
return m_loop;
|
return m_loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SlideObject::chngSlide(QVariantMap item, int index, SlideObj *slideObj) {
|
||||||
|
qDebug() << "Here is the pointer to the slideObj" << slideObj;
|
||||||
|
qDebug() << "Here is the item" << item;
|
||||||
|
slideObj->changeSlide(item, index);
|
||||||
|
}
|
||||||
|
|
||||||
void SlideObject::changeSlide(QVariantMap item, int index)
|
void SlideObject::changeSlide(QVariantMap item, int index)
|
||||||
{
|
{
|
||||||
// QVariantMap serviceItem = serviceItemModel->getItem(item.value("serviceItemId").toInt());
|
// QVariantMap serviceItem = serviceItemModel->getItem(item.value("serviceItemId").toInt());
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <qobject.h>
|
#include <qobject.h>
|
||||||
|
#include "cxx-qt-gen/slide_obj.cxxqt.h"
|
||||||
|
|
||||||
class SlideObject : public Slide
|
class SlideObject : public Slide
|
||||||
{
|
{
|
||||||
|
@ -33,6 +34,7 @@ public:
|
||||||
bool loop() const;
|
bool loop() const;
|
||||||
|
|
||||||
Q_INVOKABLE void changeSlide(QVariantMap item, int index);
|
Q_INVOKABLE void changeSlide(QVariantMap item, int index);
|
||||||
|
Q_INVOKABLE void chngSlide(QVariantMap item, int index, SlideObj *slideObj);
|
||||||
Q_INVOKABLE void play();
|
Q_INVOKABLE void play();
|
||||||
Q_INVOKABLE void pause();
|
Q_INVOKABLE void pause();
|
||||||
Q_INVOKABLE void playPause();
|
Q_INVOKABLE void playPause();
|
||||||
|
|
|
@ -189,6 +189,7 @@ int main(int argc, char *argv[])
|
||||||
qmlRegisterType<PresentationSqlModel>("org.presenter", 1, 0, "PresentationSqlModel");
|
qmlRegisterType<PresentationSqlModel>("org.presenter", 1, 0, "PresentationSqlModel");
|
||||||
qmlRegisterType<FileHelper>("org.presenter", 1, 0, "FileHelper");
|
qmlRegisterType<FileHelper>("org.presenter", 1, 0, "FileHelper");
|
||||||
qmlRegisterType<ServiceThing>("org.presenter", 1, 0, "ServiceThing");
|
qmlRegisterType<ServiceThing>("org.presenter", 1, 0, "ServiceThing");
|
||||||
|
qmlRegisterType<SlideObject>("org.presenter", 1, 0, "SlideHelper");
|
||||||
qmlRegisterSingletonInstance("org.presenter", 1, 0,
|
qmlRegisterSingletonInstance("org.presenter", 1, 0,
|
||||||
"ServiceItemModel", serviceItemModel.get());
|
"ServiceItemModel", serviceItemModel.get());
|
||||||
qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideModel", slideModel.get());
|
qmlRegisterSingletonInstance("org.presenter", 1, 0, "SlideModel", slideModel.get());
|
||||||
|
|
|
@ -138,6 +138,7 @@ Controls.Page {
|
||||||
VideoProxyModel { id: videoProxyModel }
|
VideoProxyModel { id: videoProxyModel }
|
||||||
ServiceThing { id: serviceThing }
|
ServiceThing { id: serviceThing }
|
||||||
FileHelper { id: fileHelper }
|
FileHelper { id: fileHelper }
|
||||||
|
SlideHelper { id: slideHelper }
|
||||||
|
|
||||||
function changeServiceItem(index) {
|
function changeServiceItem(index) {
|
||||||
const item = ServiceItemModel.getItem(index);
|
const item = ServiceItemModel.getItem(index);
|
||||||
|
@ -154,7 +155,11 @@ Controls.Page {
|
||||||
/* presentation.itemType = item.type; */
|
/* presentation.itemType = item.type; */
|
||||||
|
|
||||||
ServiceItemModel.activate(index);
|
ServiceItemModel.activate(index);
|
||||||
SlideObject.changeSlide(slide, slideId);
|
console.log("%%%%%%%%%");
|
||||||
|
console.log(slide);
|
||||||
|
slideHelper.chngSlide(slide, slideId, SlideObject);
|
||||||
|
console.log("%%%%%%%%%");
|
||||||
|
/* SlideObject.changeSlide(slide, slideId); */
|
||||||
|
|
||||||
/* if (item.backgroundType === "video") */
|
/* if (item.backgroundType === "video") */
|
||||||
/* { */
|
/* { */
|
||||||
|
@ -182,7 +187,7 @@ Controls.Page {
|
||||||
console.log("Time to start changing");
|
console.log("Time to start changing");
|
||||||
|
|
||||||
ServiceItemModel.activate(currentServiceItem);
|
ServiceItemModel.activate(currentServiceItem);
|
||||||
SlideObject.changeSlide(item, index);
|
slideHelper.chngSlide(item, index, SlideObject);
|
||||||
presentation.textIndex = 0;
|
presentation.textIndex = 0;
|
||||||
console.log("Slide changed to: " + index);
|
console.log("Slide changed to: " + index);
|
||||||
}
|
}
|
||||||
|
|
|
@ -174,8 +174,8 @@ FocusScope {
|
||||||
Controls.Switch {
|
Controls.Switch {
|
||||||
id: loopSwitch
|
id: loopSwitch
|
||||||
text: "Loop"
|
text: "Loop"
|
||||||
checked: SlideObject.loop
|
checked: SlideObject.looping
|
||||||
onToggled: SlideObject.setLoop(!SlideObject.loop)
|
onToggled: SlideObject.setLooping(!SlideObject.looping)
|
||||||
Keys.onLeftPressed: previousSlideAction()
|
Keys.onLeftPressed: previousSlideAction()
|
||||||
Keys.onRightPressed: nextSlideAction()
|
Keys.onRightPressed: nextSlideAction()
|
||||||
Keys.onUpPressed: previousSlideAction()
|
Keys.onUpPressed: previousSlideAction()
|
||||||
|
|
|
@ -82,6 +82,7 @@ mod slide_obj {
|
||||||
let text = item.get(&QString::from("text")).unwrap();
|
let text = item.get(&QString::from("text")).unwrap();
|
||||||
if let Some(txt) = text.value::<QString>() {
|
if let Some(txt) = text.value::<QString>() {
|
||||||
if &txt != self.as_ref().text() {
|
if &txt != self.as_ref().text() {
|
||||||
|
println!("{}", &txt);
|
||||||
self.as_mut().set_text(txt);
|
self.as_mut().set_text(txt);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -91,20 +92,29 @@ mod slide_obj {
|
||||||
self.as_mut().set_audio(audio);
|
self.as_mut().set_audio(audio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let ty = item.get(&QString::from("ty")).unwrap();
|
let ty = item.get(&QString::from("type"));
|
||||||
if let Some(ty) = ty.value::<QString>() {
|
if let Some(ty) = ty {
|
||||||
if &ty != self.as_ref().ty() {
|
if let Some(ty) = ty.value::<QString>() {
|
||||||
self.as_mut().set_ty(ty);
|
if &ty != self.as_ref().ty() {
|
||||||
|
self.as_mut().set_ty(ty);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Type wasn't a sting");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
println!("Type was incorrect");
|
||||||
}
|
}
|
||||||
let image_background = item.get(&QString::from("image_background")).unwrap();
|
|
||||||
|
let image_background = item
|
||||||
|
.get(&QString::from("imageBackground"))
|
||||||
|
.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() {
|
||||||
self.as_mut().set_image_background(image_background);
|
self.as_mut().set_image_background(image_background);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let video_background = item
|
let video_background = item
|
||||||
.get(&QString::from("video_background"))
|
.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() {
|
||||||
|
@ -119,25 +129,33 @@ mod slide_obj {
|
||||||
self.as_mut().set_font(font);
|
self.as_mut().set_font(font);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let vtext_alignment = item.get(&QString::from("vtext_alignment")).unwrap();
|
let vtext_alignment = item
|
||||||
|
.get(&QString::from("vtext_alignment"))
|
||||||
|
.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() {
|
||||||
self.as_mut().set_vtext_alignment(vtext_alignment);
|
self.as_mut().set_vtext_alignment(vtext_alignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let htext_alignment = item.get(&QString::from("htext_alignment")).unwrap();
|
let htext_alignment = item
|
||||||
|
.get(&QString::from("htext_alignment"))
|
||||||
|
.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() {
|
||||||
self.as_mut().set_htext_alignment(htext_alignment);
|
self.as_mut().set_htext_alignment(htext_alignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let font_size = item.get(&QString::from("font_size")).unwrap();
|
let font_size = item
|
||||||
|
.get(&QString::from("font_size"))
|
||||||
|
.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() {
|
||||||
self.as_mut().set_font_size(font_size);
|
self.as_mut().set_font_size(font_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let looping = item.get(&QString::from("looping")).unwrap();
|
let looping = item
|
||||||
|
.get(&QString::from("looping"))
|
||||||
|
.unwrap_or(QVariant::from(&false));
|
||||||
if let Some(looping) = looping.value::<bool>() {
|
if let Some(looping) = looping.value::<bool>() {
|
||||||
if &looping != self.as_ref().looping() {
|
if &looping != self.as_ref().looping() {
|
||||||
self.as_mut().set_looping(looping);
|
self.as_mut().set_looping(looping);
|
||||||
|
@ -145,17 +163,23 @@ mod slide_obj {
|
||||||
self.as_mut().emit(Signals::LoopChanged { looping: &lp });
|
self.as_mut().emit(Signals::LoopChanged { looping: &lp });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let slide_size = item.get(&QString::from("slide_size")).unwrap();
|
let slide_size = item
|
||||||
|
.get(&QString::from("slide_size"))
|
||||||
|
.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() {
|
||||||
self.as_mut().set_slide_size(slide_size);
|
self.as_mut().set_slide_size(slide_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let icount = item.get(&QString::from("imageCount")).unwrap();
|
let icount = item
|
||||||
|
.get(&QString::from("imageCount"))
|
||||||
|
.unwrap_or(QVariant::from(&1));
|
||||||
if let Some(int) = icount.value::<i32>() {
|
if let Some(int) = icount.value::<i32>() {
|
||||||
self.as_mut().set_image_count(int);
|
self.as_mut().set_image_count(int);
|
||||||
}
|
}
|
||||||
let slindex = item.get(&QString::from("slide_index")).unwrap();
|
let slindex = item
|
||||||
|
.get(&QString::from("slide_index"))
|
||||||
|
.unwrap_or(QVariant::from(&0));
|
||||||
if let Some(int) = slindex.value::<i32>() {
|
if let Some(int) = slindex.value::<i32>() {
|
||||||
self.as_mut().set_slide_index(int);
|
self.as_mut().set_slide_index(int);
|
||||||
let si = int;
|
let si = int;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue