adding of items now adds slides as well through signal/slot

This commit is contained in:
Chris Cochrun 2023-01-21 07:23:33 -06:00
parent d1e0cc2fc0
commit b40d9e11a6
6 changed files with 107 additions and 104 deletions

View file

@ -277,7 +277,7 @@ 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, SlideModel &slideModel) {
const int &slideNumber) {
qDebug() << "*************************";
qDebug() << "Plain adding item: " << name;
qDebug() << "*************************";
@ -285,36 +285,9 @@ void ServiceItemModel::addItem(const QString &name, const QString &type,
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);
}
} else if (type == "video") {
slideModel.addItem("", type, "", background,
audio, font, fontSize,
"center", "center",
rowCount(), 0, 1);
} else {
slideModel.addItem("", type, background, "",
audio, font, fontSize,
"center", "center",
rowCount(), 0, 1);
}
addItem(item);
emit itemAdded(rowCount() - 1, *item);
qDebug() << "EMITTED ITEM ADDED" << rowCount();
qDebug() << "#################################";
qDebug() << name << type << font << fontSize << slideNumber;
qDebug() << "#################################";
@ -376,8 +349,7 @@ 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,
SlideModel &slideModel) {
const int &fontSize, const int &slideNumber) {
qDebug() << "*************************";
qDebug() << "Inserting serviceItem: " << name << " and index is " << index;
qDebug() << "*************************";
@ -385,43 +357,12 @@ void ServiceItemModel::insertItem(const int &index, const QString &name,
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(), 0, 1);
} else {
slideModel.insertItem(slideModelIdx, type, background, "", "",
audio, font, fontSize,
"center", "center",
rowCount(), 0, 1);
}
insertItem(index, item);
emit itemInserted(index, *item);
qDebug() << "EMITTED ITEM INSERTED";
qDebug() << "#################################";
qDebug() << "INSERTING SERVICE ITEM!";
qDebug() << name << type << font << fontSize << slideNumber << index << slideModelIdx;
qDebug() << name << type << font << fontSize << slideNumber << index;
qDebug() << "#################################";
}
@ -721,7 +662,7 @@ bool ServiceItemModel::save(QUrl file) {
return false;
}
bool ServiceItemModel::load(QUrl file, SlideModel &slideModel) {
bool ServiceItemModel::load(QUrl file) {
qDebug() << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@";
qDebug() << "Loading...";
qDebug() << "File path is: " << file.toString();
@ -827,7 +768,7 @@ bool ServiceItemModel::load(QUrl file, SlideModel &slideModel) {
item.value("backgroundType").toString(),
item.value("text").toStringList(), realAudio,
item.value("font").toString(), item.value("fontSize").toInt(),
item.value("slideNumber").toInt(), slideModel);
item.value("slideNumber").toInt());
}
return true;
@ -843,7 +784,7 @@ void ServiceItemModel::clearAll() {
}
}
bool ServiceItemModel::loadLastSaved(SlideModel &slideModel) {
bool ServiceItemModel::loadLastSaved() {
QSettings settings;
return load(settings.value("lastSaveFile").toUrl(), slideModel);
return load(settings.value("lastSaveFile").toUrl());
}

View file

@ -72,7 +72,7 @@ public:
const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize,
const int &slideNumber, SlideModel &slideModel);
const int &slideNumber);
// Q_INVOKABLE void insertItem(const int &index, const QString &name,
// const QString &type);
// Q_INVOKABLE void insertItem(const int &index, const QString &name,
@ -93,8 +93,7 @@ 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,
SlideModel &slideModel);
const int &fontSize, const int &slideNumber);
Q_INVOKABLE void removeItem(int index);
Q_INVOKABLE bool moveRows(int sourceIndex, int destIndex, int count);
Q_INVOKABLE bool moveDown(int index);
@ -107,19 +106,12 @@ public:
Q_INVOKABLE void clearAll();
Q_INVOKABLE bool save(QUrl file);
Q_INVOKABLE bool load(QUrl file, SlideModel &slideModel);
Q_INVOKABLE bool loadLastSaved(SlideModel &slideModel);
Q_INVOKABLE bool load(QUrl file);
Q_INVOKABLE bool loadLastSaved();
signals:
void itemAdded(const int &index, const QString &type,
const QString &background, const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize, const int &slideNumber);
void itemInserted(const int &index, const QString &type,
const QString &background, const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize, const int &slideNumber);
void itemAdded(const int &, const ServiceItem &);
void itemInserted(const int &, const ServiceItem &);
private:

View file

@ -1,4 +1,5 @@
#include "slidemodel.h"
#include "serviceitem.h"
#include "slide.h"
#include <qabstractitemmodel.h>
#include <qglobal.h>
@ -476,3 +477,74 @@ int SlideModel::findSlideIdFromServItm(int index) {
}
return -1;
}
void SlideModel::addItemFromService(const int &index, const ServiceItem &item) {
qDebug() << "***INSERTING SLIDE FROM SERVICEITEM***";
if (item.type() == "song") {
for (int i = 0; i < item.text().size(); i++) {
if (item.backgroundType() == "image") {
addItem(item.text()[i], item.type(), item.background(), "",
item.audio(), item.font(), item.fontSize(), "center", "center",
index, i, item.text().size());
} else {
addItem(item.text()[i], item.type(), "", item.background(),
item.audio(), item.font(), item.fontSize(), "center", "center",
index, i, item.text().size());
}
}
} else if (item.type() == "presentation") {
for (int i = 0; i < item.slideNumber(); i++) {
addItem("", item.type(), item.background(), "",
item.audio(), item.font(), item.fontSize(),
"center", "center",
index, i, item.slideNumber());
}
} else if (item.type() == "video") {
addItem("", item.type(), "", item.background(),
item.audio(), item.font(), item.fontSize(),
"center", "center",
index, 0, 1);
} else {
addItem("", item.type(), item.background(), "",
item.audio(), item.font(), item.fontSize(),
"center", "center",
index, 0, 1);
}
}
void SlideModel::insertItemFromService(const int &index, const ServiceItem &item) {
qDebug() << "***INSERTING SLIDE FROM SERVICEITEM***";
int slideId = findSlideIdFromServItm(index);
if (item.type() == "song") {
for (int i = 0; i < item.text().size(); i++) {
if (item.backgroundType() == "image") {
insertItem(slideId + i, item.type(), item.background(), "", item.text()[i],
item.audio(), item.font(), item.fontSize(), "center", "center",
index, i, item.text().size());
} else {
insertItem(slideId + i, item.type(), "", item.background(), item.text()[i],
item.audio(), item.font(), item.fontSize(), "center", "center",
index, i, item.text().size());
}
}
} else if (item.type() == "presentation") {
for (int i = 0; i < item.slideNumber(); i++) {
insertItem(slideId + i, item.type(), item.background(), "",
"", item.audio(), item.font(), item.fontSize(),
"center", "center",
index, i, item.slideNumber());
}
} else if (item.type() == "video") {
insertItem(slideId, item.type(), "", item.background(), "",
item.audio(), item.font(), item.fontSize(),
"center", "center",
index, 0, 1);
} else {
insertItem(slideId, item.type(), item.background(), "", "",
item.audio(), item.font(), item.fontSize(),
"center", "center",
index, 0, 1);
}
}

View file

@ -1,6 +1,7 @@
#ifndef SLIDEMODEL_H
#define SLIDEMODEL_H
#include "serviceitem.h"
#include "slide.h"
#include <QAbstractListModel>
#include <qabstractitemmodel.h>
@ -83,15 +84,8 @@ public:
Q_INVOKABLE int findSlideIdFromServItm(int index);
public slots:
void addItemFromService(const int &index, const QString &type,
const QString &background, const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize, const int &slideNumber);
void insertItemFromService(const int &index, const QString &type,
const QString &background, const QString &backgroundType,
const QStringList &text, const QString &audio,
const QString &font, const int &fontSize, const int &slideNumber);
void addItemFromService(const int &index, const ServiceItem &item);
void insertItemFromService(const int &index, const ServiceItem &item);
private:
QList<Slide *> m_items;

View file

@ -139,10 +139,16 @@ int main(int argc, char *argv[])
QScopedPointer<SlideObject> slideobject(new SlideObject);
preswin->setSource(QUrl(QStringLiteral("qrc:qml/presenter/PresentationWindow.qml")));
QObject::connect(serviceItemModel.get(), &ServiceItemModel::itemAdded,
slideModel.get(), &SlideModel::addItem())
QObject::connect(serviceItemModel.get(),
SIGNAL(itemInserted(const int&, const ServiceItem&)),
slideModel.get(),
SLOT(insertItemFromService(const int&, const ServiceItem&)));
QObject::connect(serviceItemModel.get(),
SIGNAL(itemAdded(const int&, const ServiceItem&)),
slideModel.get(),
SLOT(addItemFromService(const int&, const ServiceItem&)));
bool loading = serviceItemModel.get()->loadLastSaved(*slideModel.get());
bool loading = serviceItemModel.get()->loadLastSaved();
// apparently mpv needs this class set
// let's register mpv as well

View file

@ -520,7 +520,7 @@ Item {
ServiceItemModel.insertItem(index, name,
type, background,
backgroundType, newtext,
audio, font, fontSize, newtext.length, SlideModel);
audio, font, fontSize, newtext.length);
/* totalServiceItems++; */
return;
}
@ -529,7 +529,7 @@ Item {
ServiceItemModel.insertItem(index, name,
type, background,
backgroundType, "",
"", "", 0, dragItemSlideNumber, SlideModel);
"", "", 0, dragItemSlideNumber);
/* totalServiceItems++; */
return;
}
@ -537,7 +537,7 @@ Item {
ServiceItemModel.insertItem(index, name,
type, background,
backgroundType, "", "",
"", 0, 0, SlideModel);
"", 0, 0);
/* totalServiceItems++; */
}
@ -552,8 +552,7 @@ Item {
console.log(lyrics);
ServiceItemModel.addItem(name, type, background,
backgroundType, lyrics,
audio, font, fontSize, lyrics.length(),
SlideModel);
audio, font, fontSize, lyrics.length());
/* totalServiceItems++; */
return;
};
@ -565,8 +564,7 @@ Item {
ServiceItemModel.addItem(name, type, background,
backgroundType, "",
audio, font, fontSize,
dragSlideItemNumber,
SlideModel);
dragSlideItemNumber);
/* totalServiceItems++; */
return;
};
@ -575,7 +573,7 @@ Item {
ServiceItemModel.addItem(name, type, background,
backgroundType, [""], "",
"", 0, 0, SlideModel);
"", 0, 0);
/* totalServiceItems++; */
}