the new slidemodel and slideobject classes

This commit is contained in:
Chris Cochrun 2023-01-18 15:57:31 -06:00
parent 95bbb12d8a
commit d94b17f0d5
4 changed files with 976 additions and 0 deletions

573
src/cpp/slidemodel.cpp Normal file
View file

@ -0,0 +1,573 @@
#include "slidemodel.h"
#include "slide.h"
#include <qabstractitemmodel.h>
#include <qglobal.h>
#include <qnamespace.h>
#include <qvariant.h>
#include <QDebug>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
#include <QMap>
#include <QTemporaryFile>
#include <QDir>
#include <QUrl>
#include <QSettings>
#include <QStandardPaths>
#include <QImage>
SlideModel::SlideModel(QObject *parent)
: QAbstractListModel(parent) {
if (!loadLastSaved()) {
addItem(new Slide("10,000 Reasons", "song",
"file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg",
"image", QStringList("Yip Yip"),
"file:/home/chris/nextcloud/tfc/openlp/music/Eden-Phil Wickham [lyrics].mp3"));
addItem(new Slide("Marvelous Light", "song",
"file:/home/chris/nextcloud/tfc/openlp/Fire Embers_Loop.mp4",
"video", QStringList("Hallelujah!")));
addItem(new Slide("BP Text", "video",
"file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4",
"video", QStringList()));
}
}
int SlideModel::rowCount(const QModelIndex &parent) const {
// For list models only the root node (an invalid parent) should return the
// list's size. For all other (valid) parents, rowCount() should return 0 so
// that it does not become a tree model.
if (parent.isValid())
return 0;
// FIXME: Implement me!
return m_items.size();
}
QVariant SlideModel::data(const QModelIndex &index, int role) const {
if (!index.isValid())
return QVariant();
Slide *item = m_items[index.row()];
switch (role) {
case NameRole:
return item->name();
case TypeRole:
return item->type();
case BackgroundRole:
return item->background();
case BackgroundTypeRole:
return item->backgroundType();
case TextRole:
return item->text();
case AudioRole:
return item->audio();
case FontRole:
return item->font();
case FontSizeRole:
return item->fontSize();
case ServiceItemIdRole:
return item->serviceItemId();
case HorizontalTextAlignmentRole:
return item->horizontalTextAlignment();
case VerticalTextAlignmentRole:
return item->verticalTextAlignment();
case ActiveRole:
return item->active();
case SelectedRole:
return item->selected();
default:
return QVariant();
}
}
QHash<int, QByteArray> SlideModel::roleNames() const {
static QHash<int, QByteArray> mapping{
{NameRole, "name"},
{TypeRole, "type"},
{BackgroundRole, "background"},
{BackgroundTypeRole, "backgroundType"},
{TextRole, "text"},
{AudioRole, "audio"},
{FontRole, "font"},
{FontSizeRole, "fontSize"},
{ServiceItemIdRole, "serviceItemId"},
{HorizontalTextAlignmentRole, "horizontalTextAlignment"},
{VerticalTextAlignmentRole, "verticalTextAlignment"},
{ActiveRole, "active"},
{SelectedRole, "selected"}
};
return mapping;
}
bool SlideModel::setData(const QModelIndex &index, const QVariant &value,
int role) {
Slide *item = m_items[index.row()];
bool somethingChanged = false;
switch (role) {
case TypeRole:
if (item->type() != value.toString()) {
item->setType(value.toString());
somethingChanged = true;
}
break;
case BackgroundRole:
if (item->background() != value.toString()) {
item->setBackground(value.toString());
somethingChanged = true;
}
break;
case BackgroundTypeRole:
if (item->backgroundType() != value.toString()) {
item->setBackgroundType(value.toString());
somethingChanged = true;
}
break;
case TextRole:
if (item->text() != value.toString()) {
item->setText(value.toString());
somethingChanged = true;
}
break;
case AudioRole:
if (item->audio() != value.toString()) {
item->setAudio(value.toString());
somethingChanged = true;
}
break;
case FontRole:
if (item->font() != value.toString()) {
item->setFont(value.toString());
somethingChanged = true;
}
break;
case FontSizeRole:
if (item->fontSize() != value.toInt()) {
item->setFontSize(value.toInt());
somethingChanged = true;
}
break;
case ServiceItemIdRole:
if (item->serviceItemId() != value.toInt()) {
item->setServiceItemId(value.toInt());
somethingChanged = true;
}
break;
case HorizontalTextAlignmentRole:
if (item->horizontalTextAlignment() != value.toString()) {
item->setHorizontalTextAlignment(value.toString());
somethingChanged = true;
}
break;
case VerticalTextAlignmentRole:
if (item->verticalTextAlignment() != value.toString()) {
item->setVerticalTextAlignment(value.toString());
somethingChanged = true;
}
break;
case ActiveRole:
if (item->active() != value.toBool()) {
item->setActive(value.toBool());
somethingChanged = true;
}
break;
case SelectedRole:
if (item->selected() != value.toBool()) {
item->setSelected(value.toBool());
somethingChanged = true;
}
break;
if (somethingChanged) {
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
}
return false;
}
Qt::ItemFlags SlideModel::flags(const QModelIndex &index) const {
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
// int SlideModel::index(int row, int column, const QModelIndex &parent) {
// if (!hasIndex(row, column, parent))
// return QModelIndex();
// Slide *parentItem;
// if (!parent.isValid())
// parentItem = rootItem;
// else
// parentItem = static_cast<Slide*>(parent.internalPointer());
// Slide *childItem = parentItem->child(row);
// if (childItem)
// return createIndex(row, column, childItem);
// return QModelIndex();
// }
void SlideModel::addItem(Slide *item) {
const int index = m_items.size();
qDebug() << index;
// foreach (item, m_items) {
// qDebug() << item;
// }
beginInsertRows(QModelIndex(), index, index);
m_items.append(item);
endInsertRows();
}
void SlideModel::insertItem(const int &index, Slide *item) {
beginInsertRows(this->index(index).parent(), index, index);
m_items.insert(index, item);
endInsertRows();
qDebug() << "Success";
}
void SlideModel::addItem(const QString &text, const QString &type) {
Slide *item = new Slide(name, type);
item->setSelected(false);
item->setActive(false);
addItem(item);
}
void SlideModel::addItem(const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground) {
Slide *item = new Slide(name, type, imageBackground, videoBackground);
item->setSelected(false);
item->setActive(false);
addItem(item);
}
void SlideModel::addItem(const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground,
const QStringList &text) {
Slide *item = new Slide(name, type, imageBackground, videoBackground, text);
item->setSelected(false);
item->setActive(false);
addItem(item);
qDebug() << name << type << imageBackground;
}
void SlideModel::addItem(const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground,
const QStringList &text, const QString &audio) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio);
item->setSelected(false);
item->setActive(false);
addItem(item);
qDebug() << name << type << imageBackground;
}
void SlideModel::addItem(const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio, font, fontSize);
item->setSelected(false);
item->setActive(false);
addItem(item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize;
qDebug() << "#################################";
}
void SlideModel::addItem(const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio, font, fontSize, horizontalTextAlignment,
verticalTextAlignment);
item->setSelected(false);
item->setActive(false);
addItem(item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize;
qDebug() << "#################################";
}
void SlideModel::addItem(const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment,
const int &serviceItemId) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio, font, fontSize, horizontalTextAlignment,
verticalTextAlignment);
item->setSelected(false);
item->setActive(false);
item->setServiceItemId(serviceItemId);
addItem(item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize << serviceItemId;
qDebug() << "#################################";
}
void SlideModel::insertItem(const int &index, const QString &name, const QString &type) {
Slide *item = new Slide(name, type);
item->setSelected(false);
item->setActive(false);
insertItem(index, item);
qDebug() << name << type;
}
void SlideModel::insertItem(const int &index, const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground) {
Slide *item = new Slide(name, type, imageBackground, videoBackground);
item->setSelected(false);
item->setActive(false);
insertItem(index, item);
qDebug() << name << type << imageBackground;
}
void SlideModel::insertItem(const int &index, const QString &name, const QString &type,
const QString &imageBackground, const QString &videoBackground,
const QStringList &text) {
Slide *item = new Slide(name, type, imageBackground, videoBackground, text);
insertItem(index, item);
qDebug() << name << type << imageBackground << text;
}
void SlideModel::insertItem(const int &index, const QString &name,
const QString &type,const QString &imageBackground,
const QString &videoBackground,const QStringList &text,
const QString &audio) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio);
item->setSelected(false);
item->setActive(false);
insertItem(index, item);
qDebug() << name << type << imageBackground << text;
}
void SlideModel::insertItem(const int &index, const QString &name,
const QString &type,const QString &imageBackground,
const QString &videoBackground,const QStringList &text,
const QString &audio, const QString &font,
const int &fontSize) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio, font, fontSize);
item->setSelected(false);
item->setActive(false);
insertItem(index, item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize;
qDebug() << "#################################";
}
void SlideModel::insertItem(const int &index, const QString &name,
const QString &type,const QString &imageBackground,
const QString &videoBackground,const QStringList &text,
const QString &audio, const QString &font,
const int &fontSize, const int &slideNumber) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio, font, fontSize, slideNumber);
item->setSelected(false);
item->setActive(false);
insertItem(index, item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize << slideNumber;
qDebug() << "#################################";
}
void SlideModel::removeItem(int index) {
beginRemoveRows(QModelIndex(), index, index);
m_items.removeAt(index);
endRemoveRows();
}
bool SlideModel::moveRows(int sourceIndex, int destIndex, int count) {
qDebug() << index(sourceIndex).row();
qDebug() << index(destIndex).row();
const int lastIndex = rowCount() - 1;
if (sourceIndex == destIndex
|| (sourceIndex < 0 || sourceIndex > lastIndex)
|| (destIndex < 0 || destIndex > lastIndex)) {
return false;
}
const QModelIndex parent = index(sourceIndex).parent();
const bool isMoveDown = destIndex > sourceIndex;
if (!beginMoveRows(parent, sourceIndex, sourceIndex + count - 1,
parent, isMoveDown ? destIndex + 2 : destIndex)) {
qDebug() << "Can't move rows";
return false;
}
qDebug() << "starting move: " << "source: " << sourceIndex << "dest: " << destIndex;
m_items.move(sourceIndex, isMoveDown ? destIndex + 1 : destIndex);
endMoveRows();
return true;
}
bool SlideModel::moveDown(int id) {
qDebug() << index(id).row();
qDebug() << index(id + 1).row();
QModelIndex parent = index(id).parent();
bool begsuc = beginMoveRows(parent, id,
id, parent, id + 2);
if (begsuc) {
int dest = id + 1;
if (dest >= m_items.size())
{
qDebug() << "dest too big, moving to end";
m_items.move(id, m_items.size() - 1);
}
else
m_items.move(id, dest);
endMoveRows();
return true;
}
return false;
}
bool SlideModel::moveUp(int id) {
qDebug() << index(id).row();
qDebug() << index(id - 1).row();
QModelIndex parent = index(id).parent();
bool begsuc = beginMoveRows(parent, id,
id, parent, id - 1);
if (begsuc) {
int dest = id - 1;
if (dest <= -1)
{
qDebug() << "dest too big, moving to beginning";
m_items.move(id, 0);
}
else
m_items.move(id, dest);
endMoveRows();
return true;
}
return false;
}
QVariantMap SlideModel::getItem(int index) const {
QVariantMap data;
const QModelIndex idx = this->index(index,0);
// qDebug() << idx;
if( !idx.isValid() )
return data;
const QHash<int,QByteArray> rn = roleNames();
// qDebug() << rn;
QHashIterator<int,QByteArray> it(rn);
while (it.hasNext()) {
it.next();
qDebug() << it.key() << ":" << it.value();
data[it.value()] = idx.data(it.key());
}
return data;
}
QVariantList SlideModel::getItems() {
QVariantList data;
Slide * item;
foreach (item, m_items) {
qDebug() << item->serviceItemId();
QVariantMap itm;
itm["type"] = item->type();
itm["imageBackground"] = item->imageBackground();
itm["videoBackground"] = item->videoBackground();
itm["text"] = item->text();
itm["audio"] = item->audio();
itm["font"] = item->font();
itm["fontSize"] = item->fontSize();
itm["horizontalTextAlignment"] = item->horizontalTextAlignment();
itm["verticalTextAlignment"] = item->verticalTextAlignment();
itm["serviceItemId"] = item->seviceItemId();
itm["selected"] = item->selected();
itm["active"] = item->active();
data.append(itm);
}
qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$";
qDebug() << data;
qDebug() << "$$$$$$$$$$$$$$$$$$$$$$$$$$$";
return data;
}
bool SlideModel::select(int id) {
for (int i = 0; i < m_items.length(); i++) {
QModelIndex idx = index(i);
Slide *item = m_items[idx.row()];
if (item->selected()) {
item->setSelected(false);
qDebug() << "################";
qDebug() << "deselected" << item->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << SelectedRole);
}
}
QModelIndex idx = index(id);
Slide *item = m_items[idx.row()];
item->setSelected(true);
qDebug() << "################";
qDebug() << "selected" << item->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << SelectedRole);
return true;
}
bool SlideModel::activate(int id) {
QModelIndex idx = index(id);
Slide *item = m_items[idx.row()];
for (int i = 0; i < m_items.length(); i++) {
QModelIndex idx = index(i);
Slide *itm = m_items[idx.row()];
if (itm->active()) {
itm->setActive(false);
qDebug() << "################";
qDebug() << "deactivated" << itm->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << ActiveRole);
}
}
item->setActive(true);
qDebug() << "################";
qDebug() << "activated" << item->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << ActiveRole);
return true;
}
bool SlideModel::deactivate(int id) {
QModelIndex idx = index(id);
Slide *item = m_items[idx.row()];
item->setActive(false);
qDebug() << "################";
qDebug() << "deactivated" << item->name();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << ActiveRole);
return true;
}
void SlideModel::clearAll() {
for (int i = m_items.size(); i >= 0; i--) {
removeItem(i);
}
}

123
src/cpp/slidemodel.h Normal file
View file

@ -0,0 +1,123 @@
#ifndef SLIDEMODEL_H
#define SLIDEMODEL_H
#include "slide.h"
#include <QAbstractListModel>
#include <qabstractitemmodel.h>
#include <qnamespace.h>
#include <qobjectdefs.h>
#include <qsize.h>
class SlideModel : public QAbstractListModel {
Q_OBJECT
public:
explicit SlideModel(QObject *parent = nullptr);
enum Roles {
TypeRole = Qt::UserRole,
TextRole,
AudioRole,
ImageBackgroundRole,
VideoBackgroundRole,
HorizontalTextAlignmentRole,
VerticalTextAlignmentRole,
FontRole,
FontSizeRole,
ServiceItemIdRole,
ActiveRole,
SelectedRole
};
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
// int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index,
int role = Qt::DisplayRole) const override;
QHash<int, QByteArray> roleNames() const override;
// Q_INVOKABLE int index(int row, int column,
// const QModelIndex &parent = QModelIndex()) const override;
// Q_INVOKABLE QModelIndex parent(const QModelIndex &index) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value,
int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
// Helper methods
void addItem(Slide *item);
void insertItem(const int &index, Slide *item);
Q_INVOKABLE void addItem(const QString &name, const QString &type);
Q_INVOKABLE void addItem(const QString &text, const QString &type,
const QString &imageBackground,
const QString &videoBackground);
Q_INVOKABLE void addItem(const QString &text, const QString &type,
const QString &imageBackground,
const QString &videoBackground,
const QString &audio);
Q_INVOKABLE void addItem(const QString &text, const QString &type,
const QString &imageBackground,
const QString &videoBackground,
const QString &audio,
const QString &font, const int &fontSize);
Q_INVOKABLE void addItem(const QString &text, const QString &type,
const QString &imageBackground,
const QString &videoBackground,
const QString &audio,
const QString &font, const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment);
Q_INVOKABLE void addItem(const QString &text, const QString &type,
const QString &imageBackground,
const QString &videoBackground,
const QString &audio,
const QString &font, const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment,
const int &serviceItemId);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type, const QString &imageBackground,
const QString &videoBackground);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type, const QString &imageBackground,
const QString &videoBackground,
const QString &audio);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type, const QString &imageBackground,
const QString &videoBackground,
const QString &audio, const QString &font,
const int &fontSize);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type, const QString &imageBackground,
const QString &videoBackground,
const QString &audio, const QString &font,
const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type, const QString &imageBackground,
const QString &videoBackground,
const QString &audio, const QString &font,
const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment,
const int &serviceItemId);
Q_INVOKABLE void removeItem(int index);
Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count);
Q_INVOKABLE bool moveDown(int index);
Q_INVOKABLE bool moveUp(int index);
Q_INVOKABLE bool select(int id);
Q_INVOKABLE bool activate(int id);
Q_INVOKABLE bool deactivate(int id);
Q_INVOKABLE QVariantMap getItem(int index) const;
Q_INVOKABLE QVariantList getItems();
Q_INVOKABLE void clearAll();
private:
QList<Slide *> m_items;
};
#endif // SLIDEMODEL_H

230
src/cpp/slideobject.cpp Normal file
View file

@ -0,0 +1,230 @@
#include "slideobject.h"
#include "serviceitemmodel.h"
#include <podofo/podofo.h>
#include <QDebug>
using namespace PoDoFo;
SlideObject::SlideObject(QObject *parent)
: Slide{parent}
{
qDebug() << "Initializing slide";
}
SlideObject::SlideObject(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)
: Slide(parent),
m_isPlaying(isPlaying),
m_slideIndex(0)
{
setText(text);
setAudio(audio),
setImageBackground(imageBackground),
setVideoBackground(videoBackground),
setVerticalTextAlignment(verticalTextAlignment),
setHorizontalTextAlignment(horizontalTextAlignment),
setFont(font),
setFontSize(fontSize),
setImageCount(imageCount),
setType(type),
qDebug() << "Initializing slide with defaults";
}
bool SlideObject::isPlaying() const
{
return m_isPlaying;
}
int SlideObject::slideIndex() const
{
return m_slideIndex;
}
int SlideObject::slideSize() const
{
return m_slideSize;
}
void SlideObject::changeSlide(QVariantMap item)
{
setServiceItem(item);
setType(serviceItemId().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;
qDebug() << serviceItemId().value("backgroundType").toString();
if (serviceItemId().value("backgroundType") == "image") {
setImageBackground(serviceItemId().value("background").toString());
setVideoBackground("");
} else {
setVideoBackground(serviceItemId().value("background").toString());
setImageBackground("");
}
setFont(serviceItemId().value("font").toString());
setFontSize(serviceItemId().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() << imageCount();
m_slideSize = imageCount();
}
QStringList text = serviceItemId().value("text").toStringList();
if (type() == "song") {
qDebug() << "TEXT LENGTH: " << text.length();
m_slideSize = text.length();
m_slideIndex = 1;
setText(text[0]);
setAudio(serviceItemId().value("audio").toString());
}
qDebug() << "MAP: " << serviceItemId().value("text");
emit slideIndexChanged(m_slideIndex);
emit slideSizeChanged(m_slideSize);
}
bool SlideObject::next(QVariantMap nextItem)
{
qDebug() << "Starting to go to next item.";
qDebug() << "SlideObject Index: " << slideIndex() << " SlideObject Size: " << slideSize();
QStringList text = serviceItemId().value("text").toStringList();
if (slideIndex() == slideSize()) {
// changeSlideObject(nextItem);
return true;
}
qDebug() << type();
// since the string list is 0 indexed m_slideIndex actually
// maps to the next item.
if (type() == "song") {
int nextTextIndex = slideIndex();
qDebug() << nextTextIndex;
qDebug() << text[nextTextIndex];
setText(text[nextTextIndex]);
m_slideSize++;
emit slideIndexChanged(m_slideIndex);
}
if (type() == "presentation") {
qDebug() << "prev slide index: " << slideIndex();
m_slideIndex++;
emit slideIndexChanged(m_slideIndex);
qDebug() << "new slide index: " << slideIndex();
}
return false;
}
bool SlideObject::previous(QVariantMap prevItem)
{
qDebug() << "Starting to go to previous item.";
qDebug() << "SlideObject Index: " << slideIndex() << " SlideObject Size: " << slideSize();
QStringList text = serviceItemId().value("text").toStringList();
if (slideIndex() == 1) {
// changeSlideObject(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 (type() == "song") {
int prevTextIndex = slideIndex() - 2;
qDebug() << prevTextIndex;
qDebug() << text[prevTextIndex];
setText(text[prevTextIndex]);
m_slideIndex--;
emit slideIndexChanged(m_slideIndex);
}
if (type() == "presentation") {
qDebug() << "prev slide index: " << slideIndex();
m_slideIndex--;
emit slideIndexChanged(m_slideIndex);
qDebug() << "new slide index: " << slideIndex();
}
return false;
}
bool SlideObject::changeSlideIndex(int index)
{
qDebug() << "Starting to change slide index.";
qDebug() << "SlideObject Index: " << slideIndex() << " SlideObject Size: " << slideSize();
QStringList text = serviceItemId().value("text").toStringList();
if (index > 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 (type() == "song") {
int textIndex = index;
qDebug() << textIndex;
qDebug() << text[textIndex];
setText(text[textIndex]);
m_slideIndex = index;
emit slideIndexChanged(m_slideIndex);
return true;
}
if (type() == "presentation") {
qDebug() << "prev slide index: " << slideIndex();
m_slideIndex = index;
qDebug() << "new slide index: " << slideIndex();
emit slideIndexChanged(m_slideIndex);
return true;
}
return false;
}
void SlideObject::play()
{
m_isPlaying = true;
emit isPlayingChanged(m_isPlaying);
}
void SlideObject::pause()
{
m_isPlaying = false;
emit isPlayingChanged(m_isPlaying);
}
void SlideObject::playPause()
{
m_isPlaying = !m_isPlaying;
emit isPlayingChanged(m_isPlaying);
}

50
src/cpp/slideobject.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef SLIDEOBJECT_H
#define SLIDEOBJECT_H
#include "slide.h"
#include <qobjectdefs.h>
#include <qqml.h>
#include <QObject>
#include <qobject.h>
class SlideObject : public Slide
{
Q_OBJECT
Q_PROPERTY(bool isPlaying READ isPlaying NOTIFY isPlayingChanged)
Q_PROPERTY(int slideIndex READ slideIndex NOTIFY slideIndexChanged)
Q_PROPERTY(int slideSize READ slideSize NOTIFY slideSizeChanged)
// QML_ELEMENT
public:
explicit SlideObject(QObject *parent = nullptr);
SlideObject(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);
bool isPlaying() const;
int slideIndex() const;
int slideSize() const;
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:
Q_INVOKABLE void isPlayingChanged(bool isPlaying);
Q_INVOKABLE void slideIndexChanged(int slideIndex);
Q_INVOKABLE void slideSizeChanged(int slideSize);
private:
bool m_isPlaying;
int m_slideIndex;
int m_slideSize;
};
#endif //SLIDEOBJECT_H