From d52bbda181ede25a8aba24b45530bc5a305f719b Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Sat, 24 Sep 2022 07:17:52 -0500 Subject: [PATCH] adding a pdfindex to slideobject and moving through index --- src/slide.cpp | 71 +++++++++++++++++++++++++++++++++++++-------------- src/slide.h | 9 ++++++- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/slide.cpp b/src/slide.cpp index 9a81eb4..2c218b8 100644 --- a/src/slide.cpp +++ b/src/slide.cpp @@ -15,12 +15,13 @@ 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, const int &imageCount, const bool &isPlaying, - const QString &type, QObject *parent) + const int &fontSize, const int &imageCount, const int &pdfIndex, + const bool &isPlaying, 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_imageCount(imageCount),m_isPlaying(isPlaying),m_type(type) + m_fontSize(fontSize),m_imageCount(imageCount),m_pdfIndex(pdfIndex), + m_isPlaying(isPlaying),m_type(type) { qDebug() << "Initializing slide with defaults"; } @@ -76,6 +77,11 @@ int Slide::imageCount() const return m_imageCount; } +int Slide::pdfIndex() const +{ + return m_pdfIndex; +} + bool Slide::isPlaying() const { return m_isPlaying; @@ -185,6 +191,15 @@ void Slide::setImageCount(int imageCount) emit imageCountChanged(m_imageCount); } +void Slide::setPdfIndex(int pdfIndex) +{ + if (m_pdfIndex == pdfIndex) + return; + + m_pdfIndex = pdfIndex; + emit pdfIndexChanged(m_pdfIndex); +} + void Slide::changeSlide(QVariantMap item) { setServiceItem(item); @@ -198,6 +213,10 @@ void Slide::changeSlide(QVariantMap item) setImageBackground(""); } + setText(""); + m_slideSize = 1; + m_slideIndex = 1; + if (type() == "pres") { qDebug() << "#$#$#$#$ THIS PDF $#$#$#$#"; int pageCount; @@ -217,15 +236,13 @@ void Slide::changeSlide(QVariantMap item) } setImageCount(pageCount); qDebug() << m_imageCount; + m_slideSize = m_imageCount; + m_slideIndex = 1; + setPdfIndex(1); } QStringList text = m_serviceItem.value("text").toStringList(); - if (text.isEmpty()) { - setText(""); - m_slideSize = 1; - m_slideIndex = 1; - } - else { + if (type() == "song") { qDebug() << "TEXT LENGTH: " << text.length(); m_slideSize = text.length(); m_slideIndex = 1; @@ -245,13 +262,23 @@ bool Slide::next(QVariantMap nextItem) return true; } + qDebug() << m_type; // since the string list is 0 indexed m_slideIndex actually // maps to the next item. - int nextTextIndex = m_slideIndex; - qDebug() << nextTextIndex; - qDebug() << text[nextTextIndex]; - setText(text[nextTextIndex]); - m_slideIndex++; + if (m_type == "song") { + int nextTextIndex = m_slideIndex; + qDebug() << nextTextIndex; + qDebug() << text[nextTextIndex]; + setText(text[nextTextIndex]); + m_slideIndex++; + } + + if (m_type == "pres") { + qDebug() << "prev slide index: " << m_pdfIndex; + setPdfIndex(m_pdfIndex + 1); + qDebug() << "new slide index: " << m_pdfIndex; + m_slideIndex++; + } return false; } @@ -268,11 +295,17 @@ bool Slide::previous(QVariantMap prevItem) // since the string list is 0 indexed m_slideIndex actually // maps to the next item. So the prev text is minus 2 - int prevTextIndex = m_slideIndex - 2; - qDebug() << prevTextIndex; - qDebug() << text[prevTextIndex]; - setText(text[prevTextIndex]); - m_slideIndex--; + if (m_type == "song") { + int prevTextIndex = m_slideIndex - 2; + qDebug() << prevTextIndex; + qDebug() << text[prevTextIndex]; + setText(text[prevTextIndex]); + m_slideIndex--; + } + + if (m_type == "presentation") { + m_slideIndex--; + } return false; } diff --git a/src/slide.h b/src/slide.h index 14f8d17..cbba840 100644 --- a/src/slide.h +++ b/src/slide.h @@ -22,6 +22,7 @@ class Slide : public QObject Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged) Q_PROPERTY(int imageCount READ imageCount WRITE setImageCount NOTIFY imageCountChanged) + Q_PROPERTY(int pdfIndex READ pdfIndex WRITE setPdfIndex NOTIFY pdfIndexChanged) Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged) // QML_ELEMENT @@ -29,7 +30,9 @@ 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, const int &imageCount, const bool &isPlaying, const QString &type, QObject * parent = nullptr); + const QString &font, const int &fontSize, const int &imageCount, + const int &pdfIndex, const bool &isPlaying, const QString &type, + QObject * parent = nullptr); QString text() const; QString type() const; @@ -42,6 +45,7 @@ public: QString font() const; int fontSize() const; int imageCount() const; + int pdfIndex() const; bool isPlaying() const; Q_INVOKABLE void setText(QString text); @@ -55,6 +59,7 @@ public: Q_INVOKABLE void setFont(QString font); Q_INVOKABLE void setFontSize(int fontSize); Q_INVOKABLE void setImageCount(int imageCount); + Q_INVOKABLE void setPdfIndex(int pdfIndex); Q_INVOKABLE void changeSlide(QVariantMap item); Q_INVOKABLE void play(); @@ -75,6 +80,7 @@ signals: Q_INVOKABLE void fontChanged(QString font); Q_INVOKABLE void fontSizeChanged(int fontSize); Q_INVOKABLE void imageCountChanged(int imageCount); + Q_INVOKABLE void pdfIndexChanged(int pdfIndex); Q_INVOKABLE void isPlayingChanged(bool isPlaying); private: @@ -90,6 +96,7 @@ private: QString m_font; int m_fontSize; int m_imageCount; + int m_pdfIndex; bool m_isPlaying; int m_slideIndex;