From 964eefb7deb808c3eae89243fd249ca2adc8936c Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Fri, 15 Jul 2022 16:33:54 -0500 Subject: [PATCH] moving more functions to slide class --- src/main.cpp | 3 +-- src/qml/presenter/MainWindow.qml | 25 +++++--------------- src/slide.cpp | 40 +++++++++++++++++++++++++------- src/slide.h | 9 +++++-- 4 files changed, 45 insertions(+), 32 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 908eb2e..87bc7b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -94,8 +94,7 @@ int main(int argc, char *argv[]) qDebug() << QIcon::themeName(); //Need to instantiate our slide - ServiceItemModel services(); - QScopedPointer slide(new Slide("", "", "", "", "", "", "", 0)); + QScopedPointer slide(new Slide); // apparently mpv needs this class set // let's register mpv as well diff --git a/src/qml/presenter/MainWindow.qml b/src/qml/presenter/MainWindow.qml index 487692d..865116b 100644 --- a/src/qml/presenter/MainWindow.qml +++ b/src/qml/presenter/MainWindow.qml @@ -121,30 +121,17 @@ Controls.Page { function changeServiceItem(index) { const item = serviceItemModel.getItem(index); print("index grabbed: " + index); - + print(item); presentation.stopVideo() presentation.itemType = item.type; print("Time to start changing"); - - if (item.backgroundType === "image") { - print("The slides backgorund is: " + SlideObject.imageBackground); - SlideObject.setVideoBackground(""); - SlideObject.setImageBackground(item.background); - } else { - print("The slides backgorund is: " + SlideObject.videoBackground); - SlideObject.setImageBackground(""); - SlideObject.setVideoBackground(item.background); - presentation.loadVideo() - } - print("text length: " + item.text.length); - print("text: " + item.text); - if (item.text.length === 0) { - SlideObject.setText(""); - } - else - SlideObject.setText(item.text[0]); + SlideObject.changeSlide(item); + + if (item.backgroundType === "video") + presentation.loadVideo(); + presentation.textIndex = 0; presentation.changeSlide(); diff --git a/src/slide.cpp b/src/slide.cpp index b8e192d..9463e28 100644 --- a/src/slide.cpp +++ b/src/slide.cpp @@ -12,10 +12,10 @@ Slide::Slide(QObject *parent) Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground, const QString &horizontalTextAlignment, const QString &verticalTextAlignment, const QString &font, - const int &fontSize, QObject *parent) + const int &fontSize, const QString &type, QObject *parent) : QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground), m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment), - m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),m_fontSize(fontSize) + m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),m_fontSize(fontSize),m_type(type) { qDebug() << "Initializing slide with defaults"; qDebug() << m_imageBackground; @@ -25,6 +25,10 @@ QString Slide::text() const { return m_text; } +QString Slide::type() const { + return m_type; +} + QString Slide::audio() const { return m_audio; } @@ -69,6 +73,16 @@ void Slide::setText(QString text) emit textChanged(m_text); } +void Slide::setType(QString type) +{ + qDebug() << "####changing type to: " << type; + if (m_type == type) + return; + + m_type = type; + emit typeChanged(m_type); +} + void Slide::setAudio(QString audio) { if (m_audio == audio) @@ -134,18 +148,26 @@ void Slide::setFontSize(int fontSize) emit fontSizeChanged(m_fontSize); } -void Slide::changeSlide(int index) +void Slide::changeSlide(QVariantMap item) { - QVariantMap item = services.getItem(index); - if (item.backgroundType == "image") { - setImageBackground(item.background); + setType(item.value("type").toString()); + + if (item.value("backgroundType") == "image") { + setImageBackground(item.value("background").toString()); setVideoBackground(""); } else { - setVideoBackground(item.background); + setVideoBackground(item.value("background").toString()); setImageBackground(""); } - if (item.text.length < 1) - setText(item.text[0]); + + QStringList text = item.value("text").toStringList(); + if (text.isEmpty()) + setText(""); + else { + setText(text[0]); + } + + qDebug() << "MAP: " << item.value("text"); } void Slide::nextSlide() diff --git a/src/slide.h b/src/slide.h index 4f7b952..f4aae1c 100644 --- a/src/slide.h +++ b/src/slide.h @@ -10,6 +10,7 @@ class Slide : public QObject { Q_OBJECT Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) + Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged) Q_PROPERTY(QString imageBackground READ imageBackground WRITE setImageBackground NOTIFY imageBackgroundChanged) Q_PROPERTY(QString videoBackground READ videoBackground WRITE setVideoBackground NOTIFY videoBackgroundChanged) @@ -25,9 +26,10 @@ public: explicit Slide(QObject *parent = nullptr); Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground, const QString &horizontalTextAlignment, const QString &verticalTextAlignment, - const QString &font, const int &fontSize, QObject * parent = nullptr); + const QString &font, const int &fontSize, const QString &type, QObject * parent = nullptr); QString text() const; + QString type() const; QString audio() const; QString imageBackground() const; QString videoBackground() const; @@ -37,6 +39,7 @@ public: int fontSize() const; Q_INVOKABLE void setText(QString text); + Q_INVOKABLE void setType(QString type); Q_INVOKABLE void setAudio(QString audio); Q_INVOKABLE void setImageBackground(QString imageBackground); Q_INVOKABLE void setVideoBackground(QString videoBackground); @@ -45,11 +48,12 @@ public: Q_INVOKABLE void setFont(QString font); Q_INVOKABLE void setFontSize(int fontSize); - Q_INVOKABLE void changeSlide(int index); + Q_INVOKABLE void changeSlide(QVariantMap item); Q_INVOKABLE void nextSlide(); signals: Q_INVOKABLE void textChanged(QString text); + Q_INVOKABLE void typeChanged(QString type); Q_INVOKABLE void audioChanged(QString audio); Q_INVOKABLE void imageBackgroundChanged(QString imageBackground); Q_INVOKABLE void videoBackgroundChanged(QString videoBackground); @@ -61,6 +65,7 @@ signals: private: int m_id; QString m_text; + QString m_type; QString m_audio; QString m_imageBackground; QString m_videoBackground;