tweaks to the slide class to allow better inheritance
This commit is contained in:
parent
fd76b1f17c
commit
b0f807d3bb
2 changed files with 19 additions and 251 deletions
|
@ -1,10 +1,8 @@
|
||||||
#include "slide.h"
|
#include "slide.h"
|
||||||
#include "serviceitemmodel.h"
|
#include "serviceitemmodel.h"
|
||||||
|
|
||||||
#include <podofo/podofo.h>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
using namespace PoDoFo;
|
|
||||||
Slide::Slide(QObject *parent)
|
Slide::Slide(QObject *parent)
|
||||||
: QObject{parent}
|
: QObject{parent}
|
||||||
{
|
{
|
||||||
|
@ -14,13 +12,12 @@ Slide::Slide(QObject *parent)
|
||||||
Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground,
|
Slide::Slide(const QString &text, const QString &audio, const QString &imageBackground,
|
||||||
const QString &videoBackground, const QString &horizontalTextAlignment,
|
const QString &videoBackground, const QString &horizontalTextAlignment,
|
||||||
const QString &verticalTextAlignment, const QString &font,
|
const QString &verticalTextAlignment, const QString &font,
|
||||||
const int &fontSize, const int &imageCount, const int &pdfIndex,
|
const int &fontSize, const int &imageCount,
|
||||||
const bool &isPlaying, const QString &type, QObject *parent)
|
const QString &type, QObject *parent)
|
||||||
: QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground),
|
: QObject(parent),m_text(text),m_audio(audio),m_imageBackground(imageBackground),
|
||||||
m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment),
|
m_videoBackground(videoBackground),m_verticalTextAlignment(verticalTextAlignment),
|
||||||
m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),
|
m_horizontalTextAlignment(horizontalTextAlignment),m_font(font),
|
||||||
m_fontSize(fontSize),m_imageCount(imageCount),m_pdfIndex(pdfIndex),
|
m_fontSize(fontSize),m_imageCount(imageCount),m_type(type)
|
||||||
m_isPlaying(isPlaying),m_type(type),m_slideIndex(0)
|
|
||||||
{
|
{
|
||||||
qDebug() << "Initializing slide with defaults";
|
qDebug() << "Initializing slide with defaults";
|
||||||
}
|
}
|
||||||
|
@ -33,8 +30,8 @@ QString Slide::type() const {
|
||||||
return m_type;
|
return m_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap Slide::serviceItem() const {
|
int Slide::serviceItemId() const {
|
||||||
return m_serviceItem;
|
return m_serviceItemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Slide::audio() const {
|
QString Slide::audio() const {
|
||||||
|
@ -76,21 +73,6 @@ int Slide::imageCount() const
|
||||||
return m_imageCount;
|
return m_imageCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Slide::pdfIndex() const
|
|
||||||
{
|
|
||||||
return m_pdfIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Slide::slideIndex() const
|
|
||||||
{
|
|
||||||
return m_slideIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Slide::isPlaying() const
|
|
||||||
{
|
|
||||||
return m_isPlaying;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slide::setText(QString text)
|
void Slide::setText(QString text)
|
||||||
{
|
{
|
||||||
if (m_text == text)
|
if (m_text == text)
|
||||||
|
@ -111,14 +93,14 @@ void Slide::setType(QString type)
|
||||||
emit typeChanged(m_type);
|
emit typeChanged(m_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slide::setServiceItem(QVariantMap serviceItem)
|
void Slide::setServiceItemId(int serviceItemId)
|
||||||
{
|
{
|
||||||
if (m_serviceItem == serviceItem)
|
if (m_serviceItemId == serviceItemId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qDebug() << "####changing serviceItem to: " << serviceItem;
|
qDebug() << "####changing serviceItemId to: " << serviceItemId;
|
||||||
m_serviceItem = serviceItem;
|
m_serviceItemId = serviceItemId;
|
||||||
emit serviceItemChanged(m_serviceItem);
|
emit serviceItemIdChanged(m_serviceItemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slide::setAudio(QString audio)
|
void Slide::setAudio(QString audio)
|
||||||
|
@ -196,194 +178,3 @@ void Slide::setImageCount(int imageCount)
|
||||||
m_imageCount = imageCount;
|
m_imageCount = imageCount;
|
||||||
emit imageCountChanged(m_imageCount);
|
emit imageCountChanged(m_imageCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Slide::setPdfIndex(int pdfIndex)
|
|
||||||
{
|
|
||||||
if (m_pdfIndex == pdfIndex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qDebug() << "####changing pdfIndex to: " << pdfIndex;
|
|
||||||
m_pdfIndex = pdfIndex;
|
|
||||||
emit pdfIndexChanged(m_pdfIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slide::setSlideIndex(int slideIndex)
|
|
||||||
{
|
|
||||||
if (m_slideIndex == slideIndex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qDebug() << "####changing slideIndex to: " << slideIndex;
|
|
||||||
m_slideIndex = slideIndex;
|
|
||||||
emit slideIndexChanged(m_slideIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slide::changeSlide(QVariantMap item)
|
|
||||||
{
|
|
||||||
setServiceItem(item);
|
|
||||||
setType(m_serviceItem.value("type").toString());
|
|
||||||
qDebug() << "#$% SLIDE TYPE: " << type() << " %$#";
|
|
||||||
|
|
||||||
// First let's clear the text and then set
|
|
||||||
// the size and index of a basic slide
|
|
||||||
// then we'll build the rest
|
|
||||||
setText("");
|
|
||||||
m_slideSize = 1;
|
|
||||||
m_slideIndex = 1;
|
|
||||||
setPdfIndex(0);
|
|
||||||
|
|
||||||
qDebug() << serviceItem().value("backgroundType").toString();
|
|
||||||
if (serviceItem().value("backgroundType") == "image") {
|
|
||||||
setImageBackground(m_serviceItem.value("background").toString());
|
|
||||||
setVideoBackground("");
|
|
||||||
} else {
|
|
||||||
setVideoBackground(m_serviceItem.value("background").toString());
|
|
||||||
setImageBackground("");
|
|
||||||
}
|
|
||||||
|
|
||||||
setFont(m_serviceItem.value("font").toString());
|
|
||||||
setFontSize(m_serviceItem.value("fontSize").toInt());
|
|
||||||
setAudio("");
|
|
||||||
|
|
||||||
if (type() == "presentation") {
|
|
||||||
qDebug() << "#$#$#$#$ THIS PDF $#$#$#$#";
|
|
||||||
int pageCount;
|
|
||||||
QString str = imageBackground().remove(0,6);
|
|
||||||
qDebug() << str;
|
|
||||||
std::string file = str.toStdString();
|
|
||||||
// qDebug() << file;
|
|
||||||
const char * doc = file.c_str();
|
|
||||||
qDebug() << doc;
|
|
||||||
try {
|
|
||||||
PdfMemDocument pdf = PdfMemDocument(doc);
|
|
||||||
pageCount = pdf.GetPageCount();
|
|
||||||
} catch ( const PdfError & eCode ) {
|
|
||||||
eCode.PrintErrorMsg();
|
|
||||||
eCode.GetError();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setImageCount(pageCount);
|
|
||||||
qDebug() << m_imageCount;
|
|
||||||
m_slideSize = m_imageCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList text = m_serviceItem.value("text").toStringList();
|
|
||||||
if (type() == "song") {
|
|
||||||
qDebug() << "TEXT LENGTH: " << text.length();
|
|
||||||
m_slideSize = text.length();
|
|
||||||
m_slideIndex = 1;
|
|
||||||
setText(text[0]);
|
|
||||||
setAudio(serviceItem().value("audio").toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << "MAP: " << m_serviceItem.value("text");
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Slide::next(QVariantMap nextItem)
|
|
||||||
{
|
|
||||||
qDebug() << "Starting to go to next item.";
|
|
||||||
qDebug() << "Slide Index: " << m_slideIndex << " Slide Size: " << m_slideSize;
|
|
||||||
QStringList text = m_serviceItem.value("text").toStringList();
|
|
||||||
if (m_slideIndex == m_slideSize) {
|
|
||||||
// changeSlide(nextItem);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
qDebug() << m_type;
|
|
||||||
// since the string list is 0 indexed m_slideIndex actually
|
|
||||||
// maps to the next item.
|
|
||||||
if (m_type == "song") {
|
|
||||||
int nextTextIndex = m_slideIndex;
|
|
||||||
qDebug() << nextTextIndex;
|
|
||||||
qDebug() << text[nextTextIndex];
|
|
||||||
setText(text[nextTextIndex]);
|
|
||||||
m_slideIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_type == "presentation") {
|
|
||||||
qDebug() << "prev slide index: " << m_pdfIndex;
|
|
||||||
setPdfIndex(m_pdfIndex + 1);
|
|
||||||
qDebug() << "new slide index: " << m_pdfIndex;
|
|
||||||
m_slideIndex++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Slide::previous(QVariantMap prevItem)
|
|
||||||
{
|
|
||||||
qDebug() << "Starting to go to previous item.";
|
|
||||||
qDebug() << "Slide Index: " << m_slideIndex << " Slide Size: " << m_slideSize;
|
|
||||||
QStringList text = m_serviceItem.value("text").toStringList();
|
|
||||||
if (m_slideIndex == 1) {
|
|
||||||
// changeSlide(prevItem);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// since the string list is 0 indexed m_slideIndex actually
|
|
||||||
// maps to the next item. So the prev text is minus 2
|
|
||||||
if (m_type == "song") {
|
|
||||||
int prevTextIndex = m_slideIndex - 2;
|
|
||||||
qDebug() << prevTextIndex;
|
|
||||||
qDebug() << text[prevTextIndex];
|
|
||||||
setText(text[prevTextIndex]);
|
|
||||||
m_slideIndex--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_type == "presentation") {
|
|
||||||
qDebug() << "prev slide index: " << m_pdfIndex;
|
|
||||||
setPdfIndex(m_pdfIndex - 1);
|
|
||||||
qDebug() << "new slide index: " << m_pdfIndex;
|
|
||||||
m_slideIndex--;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Slide::changeSlideIndex(int index)
|
|
||||||
{
|
|
||||||
qDebug() << "Starting to change slide index.";
|
|
||||||
qDebug() << "Slide Index: " << m_slideIndex << " Slide Size: " << m_slideSize;
|
|
||||||
QStringList text = m_serviceItem.value("text").toStringList();
|
|
||||||
if (index > m_slideSize - 1 || index < 0) {
|
|
||||||
qDebug() << "index is invalid: " << index;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// since the string list is 0 indexed m_slideIndex actually
|
|
||||||
// maps to the next item. So the prev text is minus 2
|
|
||||||
if (m_type == "song") {
|
|
||||||
int textIndex = index;
|
|
||||||
qDebug() << textIndex;
|
|
||||||
qDebug() << text[textIndex];
|
|
||||||
setText(text[textIndex]);
|
|
||||||
m_slideIndex = index;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_type == "presentation") {
|
|
||||||
qDebug() << "prev slide index: " << m_pdfIndex;
|
|
||||||
setPdfIndex(index);
|
|
||||||
qDebug() << "new slide index: " << m_pdfIndex;
|
|
||||||
m_slideIndex = index;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slide::play()
|
|
||||||
{
|
|
||||||
m_isPlaying = true;
|
|
||||||
emit isPlayingChanged(m_isPlaying);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slide::pause()
|
|
||||||
{
|
|
||||||
m_isPlaying = false;
|
|
||||||
emit isPlayingChanged(m_isPlaying);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Slide::playPause()
|
|
||||||
{
|
|
||||||
m_isPlaying = !m_isPlaying;
|
|
||||||
emit isPlayingChanged(m_isPlaying);
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ class Slide : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
|
||||||
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
|
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
|
||||||
Q_PROPERTY(QVariantMap serviceItem READ serviceItem WRITE setServiceItem
|
Q_PROPERTY(QVariantMap serviceItemId READ serviceItemId WRITE setServiceItemId
|
||||||
NOTIFY serviceItemChanged)
|
NOTIFY serviceItemIdChanged)
|
||||||
Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged)
|
Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged)
|
||||||
Q_PROPERTY(QString imageBackground READ imageBackground WRITE setImageBackground
|
Q_PROPERTY(QString imageBackground READ imageBackground WRITE setImageBackground
|
||||||
NOTIFY imageBackgroundChanged)
|
NOTIFY imageBackgroundChanged)
|
||||||
|
@ -25,22 +25,19 @@ class Slide : public QObject
|
||||||
Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
|
Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged)
|
||||||
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
|
||||||
Q_PROPERTY(int imageCount READ imageCount WRITE setImageCount NOTIFY imageCountChanged)
|
Q_PROPERTY(int imageCount READ imageCount WRITE setImageCount NOTIFY imageCountChanged)
|
||||||
Q_PROPERTY(int pdfIndex READ pdfIndex WRITE setPdfIndex NOTIFY pdfIndexChanged)
|
|
||||||
Q_PROPERTY(int slideIndex READ slideIndex WRITE setSlideIndex NOTIFY slideIndexChanged)
|
|
||||||
Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged)
|
|
||||||
// QML_ELEMENT
|
// QML_ELEMENT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Slide(QObject *parent = nullptr);
|
explicit Slide(QObject *parent = nullptr);
|
||||||
Slide(const QString &text, const QString &audio, const QString &imageBackground, const QString &videoBackground,
|
Slide(const QString &text, const QString &audio,
|
||||||
|
const QString &imageBackground, const QString &videoBackground,
|
||||||
const QString &horizontalTextAlignment, const QString &verticalTextAlignment,
|
const QString &horizontalTextAlignment, const QString &verticalTextAlignment,
|
||||||
const QString &font, const int &fontSize, const int &imageCount,
|
const QString &font, const int &fontSize, const int &imageCount,
|
||||||
const int &pdfIndex, const bool &isPlaying, const QString &type,
|
const QString &type,
|
||||||
QObject * parent = nullptr);
|
QObject * parent = nullptr);
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
QString type() const;
|
QString type() const;
|
||||||
QVariantMap serviceItem() const;
|
|
||||||
QString audio() const;
|
QString audio() const;
|
||||||
QString imageBackground() const;
|
QString imageBackground() const;
|
||||||
QString videoBackground() const;
|
QString videoBackground() const;
|
||||||
|
@ -49,13 +46,11 @@ public:
|
||||||
QString font() const;
|
QString font() const;
|
||||||
int fontSize() const;
|
int fontSize() const;
|
||||||
int imageCount() const;
|
int imageCount() const;
|
||||||
int pdfIndex() const;
|
int serviceItemId() const;
|
||||||
int slideIndex() const;
|
|
||||||
bool isPlaying() const;
|
|
||||||
|
|
||||||
Q_INVOKABLE void setText(QString text);
|
Q_INVOKABLE void setText(QString text);
|
||||||
Q_INVOKABLE void setType(QString type);
|
Q_INVOKABLE void setType(QString type);
|
||||||
Q_INVOKABLE void setServiceItem(QVariantMap serviceItem);
|
Q_INVOKABLE void setServiceItemId(int serviceItemId);
|
||||||
Q_INVOKABLE void setAudio(QString audio);
|
Q_INVOKABLE void setAudio(QString audio);
|
||||||
Q_INVOKABLE void setImageBackground(QString imageBackground);
|
Q_INVOKABLE void setImageBackground(QString imageBackground);
|
||||||
Q_INVOKABLE void setVideoBackground(QString videoBackground);
|
Q_INVOKABLE void setVideoBackground(QString videoBackground);
|
||||||
|
@ -64,21 +59,11 @@ public:
|
||||||
Q_INVOKABLE void setFont(QString font);
|
Q_INVOKABLE void setFont(QString font);
|
||||||
Q_INVOKABLE void setFontSize(int fontSize);
|
Q_INVOKABLE void setFontSize(int fontSize);
|
||||||
Q_INVOKABLE void setImageCount(int imageCount);
|
Q_INVOKABLE void setImageCount(int imageCount);
|
||||||
Q_INVOKABLE void setPdfIndex(int pdfIndex);
|
|
||||||
Q_INVOKABLE void setSlideIndex(int slideIndex);
|
|
||||||
|
|
||||||
Q_INVOKABLE void changeSlide(QVariantMap item);
|
|
||||||
Q_INVOKABLE void play();
|
|
||||||
Q_INVOKABLE void pause();
|
|
||||||
Q_INVOKABLE void playPause();
|
|
||||||
Q_INVOKABLE bool next(QVariantMap nextItem);
|
|
||||||
Q_INVOKABLE bool previous(QVariantMap prevItem);
|
|
||||||
Q_INVOKABLE bool changeSlideIndex(int index);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
Q_INVOKABLE void textChanged(QString text);
|
Q_INVOKABLE void textChanged(QString text);
|
||||||
Q_INVOKABLE void typeChanged(QString type);
|
Q_INVOKABLE void typeChanged(QString type);
|
||||||
Q_INVOKABLE void serviceItemChanged(QVariantMap serviceItem);
|
Q_INVOKABLE void serviceItemIdChanged(int serviceItemId);
|
||||||
Q_INVOKABLE void audioChanged(QString audio);
|
Q_INVOKABLE void audioChanged(QString audio);
|
||||||
Q_INVOKABLE void imageBackgroundChanged(QString imageBackground);
|
Q_INVOKABLE void imageBackgroundChanged(QString imageBackground);
|
||||||
Q_INVOKABLE void videoBackgroundChanged(QString videoBackground);
|
Q_INVOKABLE void videoBackgroundChanged(QString videoBackground);
|
||||||
|
@ -87,15 +72,12 @@ signals:
|
||||||
Q_INVOKABLE void fontChanged(QString font);
|
Q_INVOKABLE void fontChanged(QString font);
|
||||||
Q_INVOKABLE void fontSizeChanged(int fontSize);
|
Q_INVOKABLE void fontSizeChanged(int fontSize);
|
||||||
Q_INVOKABLE void imageCountChanged(int imageCount);
|
Q_INVOKABLE void imageCountChanged(int imageCount);
|
||||||
Q_INVOKABLE void pdfIndexChanged(int pdfIndex);
|
|
||||||
Q_INVOKABLE void slideIndexChanged(int slideIndex);
|
|
||||||
Q_INVOKABLE void isPlayingChanged(bool isPlaying);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_id;
|
int m_id;
|
||||||
QString m_text;
|
QString m_text;
|
||||||
QString m_type;
|
QString m_type;
|
||||||
QVariantMap m_serviceItem;
|
int m_serviceItemId;
|
||||||
QString m_audio;
|
QString m_audio;
|
||||||
QString m_imageBackground;
|
QString m_imageBackground;
|
||||||
QString m_videoBackground;
|
QString m_videoBackground;
|
||||||
|
@ -104,11 +86,6 @@ private:
|
||||||
QString m_font;
|
QString m_font;
|
||||||
int m_fontSize;
|
int m_fontSize;
|
||||||
int m_imageCount;
|
int m_imageCount;
|
||||||
int m_pdfIndex;
|
|
||||||
bool m_isPlaying;
|
|
||||||
|
|
||||||
int m_slideIndex;
|
|
||||||
int m_slideSize;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //SLIDE_H
|
#endif //SLIDE_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue