backend now uses the new classes and compiles some functions

might still need reworking
This commit is contained in:
Chris Cochrun 2023-01-20 07:05:51 -06:00
parent 9bee92a9e4
commit f503622287
9 changed files with 401 additions and 363 deletions

View file

@ -25,9 +25,8 @@
#include <QImage>
ServiceItemModel::ServiceItemModel(QObject *parent, SlideModel *slideModel)
ServiceItemModel::ServiceItemModel(QObject *parent)
: QAbstractListModel(parent) {
if (!loadLastSaved()) {
addItem(new ServiceItem("10,000 Reasons", "song",
"file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg",
"image", QStringList("Yip Yip"),
@ -38,7 +37,6 @@ ServiceItemModel::ServiceItemModel(QObject *parent, SlideModel *slideModel)
addItem(new ServiceItem("BP Text", "video",
"file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4",
"video", QStringList()));
}
}
int ServiceItemModel::rowCount(const QModelIndex &parent) const {
@ -279,11 +277,30 @@ void ServiceItemModel::addItem(const QString &name, const QString &type,
const QString &background, const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize,
const int &slideNumber) {
const int &slideNumber, SlideModel &slideModel) {
ServiceItem *item = new ServiceItem(name, type, background, backgroundType,
text, audio, font, fontSize, slideNumber);
item->setSelected(false);
item->setActive(false);
if (type == "song") {
for (int i = 0; i < text.size(); i++) {
if (backgroundType == "image") {
slideModel.addItem(text[i], type, background, "", audio, font, fontSize,
"horizontalTextAlignment", "verticalTextAlignment",
rowCount(), i, 0);
} else {
slideModel.addItem(text[i], type, "", background, audio, font, fontSize,
"horizontalTextAlignment", "verticalTextAlignment",
rowCount(), i, 0);
}
}
} else if (type == "presentation") {
for (int i = 0; i < slideNumber; i++) {
slideModel.addItem("", type, background, "", audio, font, fontSize,
"horizontalTextAlignment", "verticalTextAlignment",
rowCount(), i, slideNumber);
}
}
addItem(item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize << slideNumber;
@ -345,11 +362,45 @@ void ServiceItemModel::insertItem(const int &index, const QString &name,
const QString &type,const QString &background,
const QString &backgroundType,const QStringList &text,
const QString &audio, const QString &font,
const int &fontSize, const int &slideNumber) {
const int &fontSize, const int &slideNumber,
SlideModel &slideModel) {
ServiceItem *item = new ServiceItem(name, type, background, backgroundType,
text, audio, font, fontSize, slideNumber);
item->setSelected(false);
item->setActive(false);
int slideModelIdx = slideModel.findSlideIdFromServItm(index);
if (type == "song") {
for (int i = 0; i < text.size(); i++) {
if (backgroundType == "image") {
slideModel.insertItem(slideModelIdx, type, background, "",
text[i], audio, font, fontSize,
"center", "center",
rowCount(), i, 0);
} else {
slideModel.insertItem(slideModelIdx, type, "", background,
text[i], audio, font, fontSize,
"center", "center",
rowCount(), i, 0);
}
}
} else if (type == "presentation") {
for (int i = 0; i < slideNumber; i++) {
slideModel.insertItem(slideModelIdx, type, background, "",
"", audio, font, fontSize,
"center", "center",
rowCount(), i, slideNumber);
}
} else if (type == "video") {
slideModel.insertItem(slideModelIdx, type, "", background, "",
audio, font, fontSize,
"center", "center",
rowCount(), 1, 1);
} else {
slideModel.insertItem(slideModelIdx, type, background, "", "",
audio, font, fontSize,
"center", "center",
rowCount(), 1, 1);
}
insertItem(index, item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize << slideNumber;
@ -652,7 +703,7 @@ bool ServiceItemModel::save(QUrl file) {
return false;
}
bool ServiceItemModel::load(QUrl file) {
bool ServiceItemModel::load(QUrl file, SlideModel &slideModel) {
qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
qDebug() << "Loading...";
qDebug() << "File path is: " << file.toString();
@ -758,7 +809,7 @@ bool ServiceItemModel::load(QUrl file) {
item.value("backgroundType").toString(),
item.value("text").toStringList(), realAudio,
item.value("font").toString(), item.value("fontSize").toInt(),
item.value("slideNumber").toInt());
item.value("slideNumber").toInt(), slideModel);
}
return true;
@ -774,7 +825,7 @@ void ServiceItemModel::clearAll() {
}
}
bool ServiceItemModel::loadLastSaved() {
bool ServiceItemModel::loadLastSaved(SlideModel &slideModel) {
QSettings settings;
return load(settings.value("lastSaveFile").toUrl());
return load(settings.value("lastSaveFile").toUrl(), slideModel);
}

View file

@ -13,7 +13,7 @@ class ServiceItemModel : public QAbstractListModel {
Q_OBJECT
public:
explicit ServiceItemModel(QObject *parent = nullptr, SlideModel *slideModel = nullptr);
explicit ServiceItemModel(QObject *parent = nullptr);
enum Roles {
NameRole = Qt::UserRole,
@ -72,7 +72,7 @@ public:
const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize,
const int &slideNumber);
const int &slideNumber, SlideModel &slideModel);
Q_INVOKABLE void insertItem(const int &index, const QString &name,
const QString &type);
Q_INVOKABLE void insertItem(const int &index, const QString &name,
@ -93,7 +93,8 @@ public:
const QString &type, const QString &background,
const QString &backgroundType, const QStringList &text,
const QString &audio, const QString &font,
const int &fontSize, const int &slideNumber);
const int &fontSize, const int &slideNumber,
SlideModel &slideModel);
Q_INVOKABLE void removeItem(int index);
Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count);
Q_INVOKABLE bool moveDown(int index);
@ -106,10 +107,11 @@ public:
Q_INVOKABLE void clearAll();
Q_INVOKABLE bool save(QUrl file);
Q_INVOKABLE bool load(QUrl file);
Q_INVOKABLE bool loadLastSaved();
Q_INVOKABLE bool load(QUrl file, SlideModel &slideModel);
Q_INVOKABLE bool loadLastSaved(SlideModel &slideModel);
private:
QList<ServiceItem *> m_items;
};

View file

@ -13,11 +13,12 @@ Slide::Slide(const QString &text, const QString &audio, const QString &imageBack
const QString &videoBackground, const QString &horizontalTextAlignment,
const QString &verticalTextAlignment, const QString &font,
const int &fontSize, const int &imageCount,
const QString &type, QObject *parent)
const QString &type, const int &slideIndex, 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_type(type)
m_fontSize(fontSize),m_imageCount(imageCount),m_type(type),
m_slideIndex(slideIndex),m_active(false),m_selected(false)
{
qDebug() << "Initializing slide with defaults";
}
@ -73,6 +74,19 @@ int Slide::imageCount() const
return m_imageCount;
}
int Slide::slideIndex() const
{
return m_slideIndex;
}
bool Slide::active() const {
return m_active;
}
bool Slide::selected() const {
return m_selected;
}
void Slide::setText(QString text)
{
if (m_text == text)
@ -178,3 +192,33 @@ void Slide::setImageCount(int imageCount)
m_imageCount = imageCount;
emit imageCountChanged(m_imageCount);
}
void Slide::setSlideIndex(int slideIndex)
{
if (m_slideIndex == slideIndex)
return;
qDebug() << "####changing slideIndex to: " << slideIndex;
m_slideIndex = slideIndex;
emit slideIndexChanged(m_slideIndex);
}
void Slide::setActive(bool active)
{
qDebug() << "::::::::::::::::::::";
qDebug() << "CHANGE ME!";
if (m_active == active)
return;
m_active = active;
emit activeChanged(m_active);
}
void Slide::setSelected(bool selected)
{
if (m_selected == selected)
return;
m_selected = selected;
emit selectedChanged(m_selected);
}

View file

@ -11,7 +11,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(QVariantMap serviceItemId READ serviceItemId WRITE setServiceItemId
Q_PROPERTY(int serviceItemId READ serviceItemId WRITE setServiceItemId
NOTIFY serviceItemIdChanged)
Q_PROPERTY(QString audio READ audio WRITE setAudio NOTIFY audioChanged)
Q_PROPERTY(QString imageBackground READ imageBackground WRITE setImageBackground
@ -25,6 +25,9 @@ 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 slideIndex READ slideIndex WRITE setSlideIndex NOTIFY slideIndexChanged)
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
Q_PROPERTY(bool selected READ selected WRITE setSelected NOTIFY selectedChanged)
// QML_ELEMENT
public:
@ -33,7 +36,7 @@ public:
const QString &imageBackground, const QString &videoBackground,
const QString &horizontalTextAlignment, const QString &verticalTextAlignment,
const QString &font, const int &fontSize, const int &imageCount,
const QString &type,
const QString &type, const int &slideIndex,
QObject * parent = nullptr);
QString text() const;
@ -46,7 +49,10 @@ public:
QString font() const;
int fontSize() const;
int imageCount() const;
int slideIndex() const;
int serviceItemId() const;
bool active() const;
bool selected() const;
Q_INVOKABLE void setText(QString text);
Q_INVOKABLE void setType(QString type);
@ -59,33 +65,42 @@ public:
Q_INVOKABLE void setFont(QString font);
Q_INVOKABLE void setFontSize(int fontSize);
Q_INVOKABLE void setImageCount(int imageCount);
Q_INVOKABLE void setSlideIndex(int slideIndex);
Q_INVOKABLE void setActive(bool active);
Q_INVOKABLE void setSelected(bool selected);
signals:
Q_INVOKABLE void textChanged(QString text);
Q_INVOKABLE void typeChanged(QString type);
Q_INVOKABLE void serviceItemIdChanged(int serviceItemId);
Q_INVOKABLE void audioChanged(QString audio);
Q_INVOKABLE void imageBackgroundChanged(QString imageBackground);
Q_INVOKABLE void videoBackgroundChanged(QString videoBackground);
Q_INVOKABLE void horizontalTextAlignmentChanged(QString horizontalTextAlignment);
Q_INVOKABLE void verticalTextAlignmentChanged(QString verticalTextAlignment);
Q_INVOKABLE void fontChanged(QString font);
Q_INVOKABLE void fontSizeChanged(int fontSize);
Q_INVOKABLE void imageCountChanged(int imageCount);
Q_INVOKABLE void textChanged(QString text);
Q_INVOKABLE void typeChanged(QString type);
Q_INVOKABLE void serviceItemIdChanged(int serviceItemId);
Q_INVOKABLE void audioChanged(QString audio);
Q_INVOKABLE void imageBackgroundChanged(QString imageBackground);
Q_INVOKABLE void videoBackgroundChanged(QString videoBackground);
Q_INVOKABLE void horizontalTextAlignmentChanged(QString horizontalTextAlignment);
Q_INVOKABLE void verticalTextAlignmentChanged(QString verticalTextAlignment);
Q_INVOKABLE void fontChanged(QString font);
Q_INVOKABLE void fontSizeChanged(int fontSize);
Q_INVOKABLE void imageCountChanged(int imageCount);
Q_INVOKABLE void slideIndexChanged(int slideIndex);
Q_INVOKABLE void activeChanged(bool active);
Q_INVOKABLE void selectedChanged(bool selected);
private:
int m_id;
QString m_text;
QString m_type;
int m_serviceItemId;
QString m_audio;
QString m_imageBackground;
QString m_videoBackground;
QString m_horizontalTextAlignment;
QString m_verticalTextAlignment;
QString m_font;
int m_fontSize;
int m_imageCount;
int m_id;
QString m_text;
QString m_type;
int m_serviceItemId;
QString m_audio;
QString m_imageBackground;
QString m_videoBackground;
QString m_horizontalTextAlignment;
QString m_verticalTextAlignment;
QString m_font;
int m_fontSize;
int m_imageCount;
int m_slideIndex;
bool m_active;
bool m_selected;
};
#endif //SLIDE_H

View file

@ -20,18 +20,18 @@
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()));
}
// if () {
// addItem(new Slide("10,000 Reasons", "song",
// "file:/home/chris/nextcloud/tfc/openlp/CMG - Nature King 21.jpg",
// "image", QString("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", QString("Hallelujah!")));
// addItem(new Slide("BP Text", "video",
// "file:/home/chris/nextcloud/tfc/openlp/videos/test.mp4",
// "video", QString()));
// }
}
int SlideModel::rowCount(const QModelIndex &parent) const {
@ -51,16 +51,14 @@ QVariant SlideModel::data(const QModelIndex &index, int role) const {
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 TypeRole:
return item->type();
case ImageBackgroundRole:
return item->imageBackground();
case VideoBackgroundRole:
return item->videoBackground();
case AudioRole:
return item->audio();
case FontRole:
@ -69,6 +67,8 @@ QVariant SlideModel::data(const QModelIndex &index, int role) const {
return item->fontSize();
case ServiceItemIdRole:
return item->serviceItemId();
case SlideIndexRole:
return item->slideIndex();
case HorizontalTextAlignmentRole:
return item->horizontalTextAlignment();
case VerticalTextAlignmentRole:
@ -83,18 +83,18 @@ QVariant SlideModel::data(const QModelIndex &index, int role) const {
}
QHash<int, QByteArray> SlideModel::roleNames() const {
static QHash<int, QByteArray> mapping{
{NameRole, "name"},
{TypeRole, "type"},
{BackgroundRole, "background"},
{BackgroundTypeRole, "backgroundType"},
static QHash<int, QByteArray> mapping {
{TextRole, "text"},
{TypeRole, "type"},
{ImageBackgroundRole, "imageBackground"},
{VideoBackgroundRole, "videoBackground"},
{AudioRole, "audio"},
{FontRole, "font"},
{FontSizeRole, "fontSize"},
{ServiceItemIdRole, "serviceItemId"},
{HorizontalTextAlignmentRole, "horizontalTextAlignment"},
{VerticalTextAlignmentRole, "verticalTextAlignment"},
{SlideIndexRole, "slideIndex"},
{ActiveRole, "active"},
{SelectedRole, "selected"}
};
@ -115,15 +115,15 @@ bool SlideModel::setData(const QModelIndex &index, const QVariant &value,
somethingChanged = true;
}
break;
case BackgroundRole:
if (item->background() != value.toString()) {
item->setBackground(value.toString());
case ImageBackgroundRole:
if (item->imageBackground() != value.toString()) {
item->setImageBackground(value.toString());
somethingChanged = true;
}
break;
case BackgroundTypeRole:
if (item->backgroundType() != value.toString()) {
item->setBackgroundType(value.toString());
case VideoBackgroundRole:
if (item->videoBackground() != value.toString()) {
item->setVideoBackground(value.toString());
somethingChanged = true;
}
break;
@ -157,6 +157,12 @@ bool SlideModel::setData(const QModelIndex &index, const QVariant &value,
somethingChanged = true;
}
break;
case SlideIndexRole:
if (item->slideIndex() != value.toInt()) {
item->setSlideIndex(value.toInt());
somethingChanged = true;
}
break;
case HorizontalTextAlignmentRole:
if (item->horizontalTextAlignment() != value.toString()) {
item->setHorizontalTextAlignment(value.toString());
@ -232,156 +238,44 @@ void SlideModel::insertItem(const int &index, Slide *item) {
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,
void SlideModel::addItem(const QString &text, 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 &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);
const int &serviceItemId, const int &slideIndex,
const int &imageCount) {
Slide *item = new Slide(text, audio, imageBackground, videoBackground,
horizontalTextAlignment,
verticalTextAlignment,
font, fontSize, imageCount, type, slideIndex );
item->setSelected(false);
item->setActive(false);
item->setServiceItemId(serviceItemId);
addItem(item);
qDebug() << "#################################";
qDebug() << name << type << font << fontSize << serviceItemId;
qDebug() << 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,
void SlideModel::insertItem(const int &index,
const QString &type, const QString &imageBackground,
const QString &videoBackground, const QString &text,
const QString &audio, const QString &font,
const int &fontSize) {
Slide *item = new Slide(name, type, imageBackground, videoBackground,
text, audio, font, fontSize);
const int &fontSize, const QString &horizontalTextAlignment,
const QString &verticalTextAlignment,
const int &serviceItemId, const int &slideIndex,
const int &imageCount) {
Slide *item = new Slide(text, audio, imageBackground, videoBackground,
horizontalTextAlignment, verticalTextAlignment, font, fontSize,
imageCount, type, slideIndex);
item->setSelected(false);
item->setActive(false);
item->setServiceItemId(serviceItemId);
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() << type << font << fontSize << slideIndex;
qDebug() << "#################################";
}
@ -497,7 +391,7 @@ QVariantList SlideModel::getItems() {
itm["fontSize"] = item->fontSize();
itm["horizontalTextAlignment"] = item->horizontalTextAlignment();
itm["verticalTextAlignment"] = item->verticalTextAlignment();
itm["serviceItemId"] = item->seviceItemId();
itm["serviceItemId"] = item->serviceItemId();
itm["selected"] = item->selected();
itm["active"] = item->active();
data.append(itm);
@ -515,7 +409,7 @@ bool SlideModel::select(int id) {
if (item->selected()) {
item->setSelected(false);
qDebug() << "################";
qDebug() << "deselected" << item->name();
qDebug() << "deselected" << item->slideIndex();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << SelectedRole);
}
@ -524,7 +418,7 @@ bool SlideModel::select(int id) {
Slide *item = m_items[idx.row()];
item->setSelected(true);
qDebug() << "################";
qDebug() << "selected" << item->name();
qDebug() << "selected" << item->slideIndex();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << SelectedRole);
return true;
@ -540,7 +434,7 @@ bool SlideModel::activate(int id) {
if (itm->active()) {
itm->setActive(false);
qDebug() << "################";
qDebug() << "deactivated" << itm->name();
qDebug() << "deactivated" << itm->slideIndex();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << ActiveRole);
}
@ -548,7 +442,7 @@ bool SlideModel::activate(int id) {
item->setActive(true);
qDebug() << "################";
qDebug() << "activated" << item->name();
qDebug() << "activated" << item->slideIndex();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << ActiveRole);
return true;
@ -560,7 +454,7 @@ bool SlideModel::deactivate(int id) {
item->setActive(false);
qDebug() << "################";
qDebug() << "deactivated" << item->name();
qDebug() << "deactivated" << item->slideIndex();
qDebug() << "################";
emit dataChanged(idx, idx, QVector<int>() << ActiveRole);
return true;
@ -571,3 +465,13 @@ void SlideModel::clearAll() {
removeItem(i);
}
}
int SlideModel::findSlideIdFromServItm(int index) {
for (int i = 0; i < m_items.size(); i++) {
Slide *itm = m_items[i];
if (itm->serviceItemId() == index) {
return i;
}
}
return -1;
}

View file

@ -25,6 +25,8 @@ public:
FontRole,
FontSizeRole,
ServiceItemIdRole,
SlideIndexRole,
ImageCountRole,
ActiveRole,
SelectedRole
};
@ -48,26 +50,6 @@ public:
// 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,
@ -75,28 +57,9 @@ public:
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);
const int &serviceItemId,
const int &slideIndex,
const int &imageCount);
Q_INVOKABLE void insertItem(const int &index, const QString &text,
const QString &type, const QString &imageBackground,
const QString &videoBackground,
@ -104,7 +67,9 @@ public:
const int &fontSize,
const QString &horizontalTextAlignment,
const QString &verticalTextAlignment,
const int &serviceItemId);
const int &serviceItemId,
const int &slideIndex,
const int &imageCount);
Q_INVOKABLE void removeItem(int index);
Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count);
Q_INVOKABLE bool moveDown(int index);
@ -115,6 +80,7 @@ public:
Q_INVOKABLE QVariantMap getItem(int index) const;
Q_INVOKABLE QVariantList getItems();
Q_INVOKABLE void clearAll();
Q_INVOKABLE int findSlideIdFromServItm(int index);
private:
QList<Slide *> m_items;

View file

@ -1,5 +1,6 @@
#include "slideobject.h"
#include "serviceitemmodel.h"
#include "slidemodel.h"
#include <podofo/podofo.h>
#include <QDebug>
@ -54,128 +55,178 @@ int SlideObject::slideSize() const
return m_slideSize;
}
void SlideObject::changeSlide(QVariantMap item)
void SlideObject::changeSlide(QVariantMap item, ServiceItemModel *serviceItemModel)
{
setServiceItem(item);
setType(serviceItemId().value("type").toString());
qDebug() << "#$% SLIDE TYPE: " << type() << " %$#";
// 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;
// // 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("");
}
// 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("");
// 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();
}
// 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());
}
// 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");
//New implementation
QVariantMap serviceItem = serviceItemModel->getItem(item.value("serviceItemId").toInt());
setText(item.value("text").toString());
setType(item.value("type").toString());
setAudio(item.value("audio").toString());
setImageBackground(item.value("imageBackground").toString());
setVideoBackground(item.value("videoBackground").toString());
setVerticalTextAlignment(item.value("verticalTextAlignment").toString());
setHorizontalTextAlignment(item.value("horizontalTextAlignment").toString());
setFont(item.value("font").toString());
setFontSize(item.value("fontSize").toInt());
setImageCount(item.value("imageCount").toInt());
setSlideIndex(item.value("slideIndex").toInt());
m_slideSize = serviceItem.value("slideNumber").toInt();
qDebug() << "MAP: " << serviceItemId().value("text");
emit slideIndexChanged(m_slideIndex);
emit slideSizeChanged(m_slideSize);
}
bool SlideObject::next(QVariantMap nextItem)
bool SlideObject::next(QVariantMap nextItem, ServiceItemModel *serviceItemModel)
{
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() << "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);
}
// 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();
}
// if (type() == "presentation") {
// qDebug() << "prev slide index: " << slideIndex();
// m_slideIndex++;
// emit slideIndexChanged(m_slideIndex);
// qDebug() << "new slide index: " << slideIndex();
// }
//new implementation
QVariantMap serviceItem = serviceItemModel->getItem(nextItem.value("serviceItemId").toInt());
setText(nextItem.value("text").toString());
setType(nextItem.value("type").toString());
setAudio(nextItem.value("audio").toString());
setImageBackground(nextItem.value("imageBackground").toString());
setVideoBackground(nextItem.value("videoBackground").toString());
setVerticalTextAlignment(nextItem.value("verticalTextAlignment").toString());
setHorizontalTextAlignment(nextItem.value("horizontalTextAlignment").toString());
setFont(nextItem.value("font").toString());
setFontSize(nextItem.value("fontSize").toInt());
setImageCount(nextItem.value("imageCount").toInt());
setSlideIndex(nextItem.value("slideIndex").toInt());
m_slideSize = serviceItem.value("slideNumber").toInt();
emit slideSizeChanged(m_slideSize);
return false;
}
bool SlideObject::previous(QVariantMap prevItem)
bool SlideObject::previous(QVariantMap prevItem, ServiceItemModel *serviceItemModel)
{
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;
}
// 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);
}
// // 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();
}
// if (type() == "presentation") {
// qDebug() << "prev slide index: " << slideIndex();
// m_slideIndex--;
// emit slideIndexChanged(m_slideIndex);
// qDebug() << "new slide index: " << slideIndex();
// }
//new implementation
QVariantMap serviceItem = serviceItemModel->getItem(prevItem.value("serviceItemId").toInt());
setText(prevItem.value("text").toString());
setType(prevItem.value("type").toString());
setAudio(prevItem.value("audio").toString());
setImageBackground(prevItem.value("imageBackground").toString());
setVideoBackground(prevItem.value("videoBackground").toString());
setVerticalTextAlignment(prevItem.value("verticalTextAlignment").toString());
setHorizontalTextAlignment(prevItem.value("horizontalTextAlignment").toString());
setFont(prevItem.value("font").toString());
setFontSize(prevItem.value("fontSize").toInt());
setImageCount(prevItem.value("imageCount").toInt());
setSlideIndex(prevItem.value("slideIndex").toInt());
m_slideSize = serviceItem.value("slideNumber").toInt();
emit slideSizeChanged(m_slideSize);
return false;
}
@ -183,7 +234,7 @@ bool SlideObject::changeSlideIndex(int index)
{
qDebug() << "Starting to change slide index.";
qDebug() << "SlideObject Index: " << slideIndex() << " SlideObject Size: " << slideSize();
QStringList text = serviceItemId().value("text").toStringList();
// QStringList text = serviceItemId().value("text").toStringList();
if (index > slideSize() - 1 || index < 0) {
qDebug() << "index is invalid: " << index;
return false;
@ -194,8 +245,8 @@ bool SlideObject::changeSlideIndex(int index)
if (type() == "song") {
int textIndex = index;
qDebug() << textIndex;
qDebug() << text[textIndex];
setText(text[textIndex]);
// qDebug() << text[textIndex];
// setText(text[textIndex]);
m_slideIndex = index;
emit slideIndexChanged(m_slideIndex);
return true;

View file

@ -1,7 +1,9 @@
#ifndef SLIDEOBJECT_H
#define SLIDEOBJECT_H
#include "serviceitemmodel.h"
#include "slide.h"
#include "slidemodel.h"
#include <qobjectdefs.h>
#include <qqml.h>
#include <QObject>
@ -28,12 +30,12 @@ public:
int slideIndex() const;
int slideSize() const;
Q_INVOKABLE void changeSlide(QVariantMap item);
Q_INVOKABLE void changeSlide(QVariantMap item, ServiceItemModel *serviceItemModel);
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 next(QVariantMap nextItem, ServiceItemModel *serviceItemModel);
Q_INVOKABLE bool previous(QVariantMap prevItem, ServiceItemModel *serviceItemModel);
Q_INVOKABLE bool changeSlideIndex(int index);
signals: