2022-01-20 10:08:17 +08:00
|
|
|
#include "playwin.h"
|
|
|
|
#include "digiclock.h"
|
2022-08-25 18:37:24 +08:00
|
|
|
#include "eleanaclock.h"
|
|
|
|
#include "eleborder.h"
|
2022-01-20 10:08:17 +08:00
|
|
|
#include "elegif.h"
|
2022-08-25 18:37:24 +08:00
|
|
|
#include "eleimg.h"
|
2022-01-20 10:08:17 +08:00
|
|
|
#include "elemultipng.h"
|
2022-08-25 18:37:24 +08:00
|
|
|
#include "elescroll.h"
|
|
|
|
#include "eletimer.h"
|
2022-01-20 10:08:17 +08:00
|
|
|
#include "elevideo.h"
|
|
|
|
#include "gqt.h"
|
2022-08-25 18:37:24 +08:00
|
|
|
#include "posdlg.h"
|
|
|
|
#include <QFileInfo>
|
2022-01-20 10:08:17 +08:00
|
|
|
#include <QJsonArray>
|
2022-08-25 18:37:24 +08:00
|
|
|
#include <QJsonObject>
|
2022-01-20 10:08:17 +08:00
|
|
|
#include <QLabel>
|
2022-08-25 18:37:24 +08:00
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QMovie>
|
2022-01-20 10:08:17 +08:00
|
|
|
#include <QThread>
|
2022-08-25 18:37:24 +08:00
|
|
|
#include <QWebEngineView>
|
|
|
|
|
|
|
|
PlayWin* PlayWin::self = nullptr;
|
2022-01-20 10:08:17 +08:00
|
|
|
|
|
|
|
Page::Page(QWidget *parent) : QWidget{parent} {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-08-25 18:37:24 +08:00
|
|
|
PlayWin::PlayWin(QString dir, int x, int y, int width, int height, const QJsonObject &aprog, QWidget *parent) : QWidget(parent) {
|
2022-01-20 10:08:17 +08:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose);
|
2022-08-25 18:37:24 +08:00
|
|
|
setAttribute(Qt::WA_QuitOnClose, false);
|
|
|
|
setWindowFlag(Qt::FramelessWindowHint);
|
|
|
|
setWindowFlag(Qt::WindowStaysOnTopHint);
|
2022-01-20 10:08:17 +08:00
|
|
|
setGeometry(x, y, width, height);
|
|
|
|
QPalette plt = palette();
|
|
|
|
plt.setColor(QPalette::Window, QColor(0,0,0));
|
|
|
|
setPalette(plt);
|
|
|
|
connect(this, &PlayWin::sigSetVisible, this, &PlayWin::sltSetVisible);
|
|
|
|
|
|
|
|
QJsonObject prog = aprog["task"].toObject();
|
|
|
|
QJsonArray pageMaps = prog["items"].toArray();
|
|
|
|
int pageCnt = pageMaps.size();
|
2022-08-25 18:37:24 +08:00
|
|
|
EleBase ele; Page *page;
|
2022-01-20 10:08:17 +08:00
|
|
|
for(int p=0; p<pageCnt; p++) {
|
|
|
|
QJsonObject pageMap = pageMaps[p].toObject()["_program"].toObject();
|
2022-08-25 18:37:24 +08:00
|
|
|
QJsonArray layers = pageMap["layers"].toArray();
|
|
|
|
if(layers.isEmpty()) continue;
|
|
|
|
page = new Page(this);
|
2022-01-20 10:08:17 +08:00
|
|
|
page->setGeometry(0, 0, width, height);
|
|
|
|
page->setVisible(false);
|
2022-08-25 18:37:24 +08:00
|
|
|
for(int ll=layers.size()-1; ll>=0; ll--) {
|
|
|
|
QJsonObject layer = layers[ll].toObject();
|
|
|
|
QJsonArray srcMaps = layer["sources"].toArray();
|
|
|
|
QJsonValue border = layer["border"];
|
|
|
|
EleBorder *bdEle = nullptr;
|
|
|
|
int bdWidth = 0, startTime = 0xffff, endTime = 0;
|
|
|
|
if(! border.isNull()) {
|
|
|
|
bdEle = new EleBorder(dir+"/"+border["img"].toString(), border["eff"].toString(), border["speed"].toInt(), page);
|
|
|
|
bdWidth = bdEle->img.height();
|
|
|
|
}
|
|
|
|
foreach(auto srcMap, srcMaps) {
|
2022-01-20 10:08:17 +08:00
|
|
|
ele.type = srcMap["_type"].toString();
|
|
|
|
if(ele.type.isEmpty()) continue;
|
|
|
|
ele.timeSpan = srcMap["timeSpan"].toInt()*1000;
|
2022-08-25 18:37:24 +08:00
|
|
|
if(ele.timeSpan==0) continue;
|
|
|
|
ele.x = srcMap["left"].toInt()+bdWidth;
|
|
|
|
ele.y = srcMap["top"].toInt()+bdWidth;
|
|
|
|
ele.w = srcMap["width"].toInt()-bdWidth-bdWidth;
|
|
|
|
ele.h = srcMap["height"].toInt()-bdWidth-bdWidth;
|
|
|
|
bool notAudio = ele.type!="Audio";
|
|
|
|
if((ele.w<=0 || ele.h<=0) && notAudio) continue;
|
2022-01-20 10:08:17 +08:00
|
|
|
ele.startTime = srcMap["playTime"].toInt()*1000;
|
2022-08-25 18:37:24 +08:00
|
|
|
if(startTime > ele.startTime) startTime = ele.startTime;
|
2022-01-20 10:08:17 +08:00
|
|
|
ele.endTime = ele.startTime + ele.timeSpan;
|
2022-08-25 18:37:24 +08:00
|
|
|
if(endTime < ele.endTime) endTime = ele.endTime;
|
|
|
|
if(ele.endTime > page->timeSpan && notAudio) page->timeSpan = ele.endTime;
|
2022-01-20 10:08:17 +08:00
|
|
|
ele.id = srcMap["id"].toString();
|
|
|
|
ele.wgt = nullptr;
|
|
|
|
if(ele.type=="Image") {
|
2022-08-25 18:37:24 +08:00
|
|
|
if(srcMap["mime"].toString().endsWith("gif")) ele.wgt = new EleGif(dir+"/"+ele.id, page);
|
|
|
|
else ele.wgt = new EleImg(dir+"/"+ele.id, page);
|
2022-01-20 10:08:17 +08:00
|
|
|
} else if(ele.type.startsWith("Environ")) {
|
2022-08-25 18:37:24 +08:00
|
|
|
QJsonValue arrayPics = srcMap["arrayPics"];
|
|
|
|
for(int i=arrayPics.toArray().size()-1; i>=0; i--) if(arrayPics[i]["name"].toString() == "previewTmp") {
|
|
|
|
if(srcMap["bSingleScroll"].toBool()) ele.wgt = new EleScroll(page, dir+"/" + arrayPics[i]["id"].toString(), 'l', srcMap["iScrollSpeed"].toDouble());
|
|
|
|
else ele.wgt = new EleScroll(page, dir+"/"+arrayPics[i]["id"].toString());
|
2022-01-20 10:08:17 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if(ele.type=="MultiPng") {
|
|
|
|
QJsonArray imgs = srcMap["arrayPics"].toArray();
|
|
|
|
if(imgs.isEmpty()) continue;
|
2022-08-25 18:37:24 +08:00
|
|
|
if(imgs.size()==1 && imgs.at(0)["picDuration"].toInt()==0) ele.wgt = new EleScroll(page, dir+"/", imgs[0].toObject());
|
|
|
|
else ele.wgt = new EleMultiPng(dir+"/", imgs, page);
|
|
|
|
} else if(ele.type=="DigitalClockNew") ele.wgt = new DigiClock(dir+"/", srcMap.toObject(), page);
|
|
|
|
else if(ele.type=="AnalogClock") ele.wgt = new EleAnaClock(dir+"/"+ele.id, srcMap.toObject(), page);
|
|
|
|
else if(ele.type=="Video" || ele.type=="Audio") {
|
|
|
|
auto video = new EleVideo(dir+"/"+ele.id, page);
|
|
|
|
auto vol = srcMap["vol"].toInt(100);
|
|
|
|
if(vol<100) video->player->setVol(vol/100.0);
|
|
|
|
ele.wgt = video;
|
|
|
|
} else if(ele.type=="WebURL") {
|
|
|
|
auto web = new QWebEngineView(page);
|
|
|
|
web->load(QUrl(srcMap["url"].toString()));
|
|
|
|
ele.wgt = web;
|
|
|
|
}
|
|
|
|
else if(ele.type=="Timer") ele.wgt = new EleTimer(srcMap.toObject(), page);
|
2022-01-20 10:08:17 +08:00
|
|
|
else continue;
|
|
|
|
if(ele.wgt==nullptr) continue;
|
2022-08-25 18:37:24 +08:00
|
|
|
if(ele.startTime>0) ele.wgt->setVisible(false);
|
|
|
|
ele.wgt->setGeometry(ele.x, ele.y, ele.w, ele.h);
|
|
|
|
page->eles.append(ele);
|
|
|
|
}
|
|
|
|
if(bdEle!=nullptr && srcMaps.size()>0) {
|
|
|
|
QJsonArray geometry = border["geometry"].toArray();
|
|
|
|
ele.x = geometry[0].toInt();
|
|
|
|
ele.y = geometry[1].toInt();
|
|
|
|
ele.w = geometry[2].toInt();
|
|
|
|
ele.h = geometry[3].toInt();
|
|
|
|
ele.startTime = startTime;
|
|
|
|
ele.endTime = endTime;
|
|
|
|
ele.timeSpan = endTime - startTime;
|
|
|
|
ele.wgt = bdEle;
|
|
|
|
if(ele.startTime>0) ele.wgt->setVisible(false);
|
2022-01-20 10:08:17 +08:00
|
|
|
ele.wgt->setGeometry(ele.x, ele.y, ele.w, ele.h);
|
|
|
|
page->eles.append(ele);
|
|
|
|
}
|
|
|
|
}
|
2022-08-25 18:37:24 +08:00
|
|
|
if(page->timeSpan>0) pages.append(page);
|
2022-01-20 10:08:17 +08:00
|
|
|
}
|
|
|
|
setVisible(true);
|
2022-08-25 18:37:24 +08:00
|
|
|
Page* page0 = pages[0];
|
2022-01-20 10:08:17 +08:00
|
|
|
EleBase* eleptr;
|
|
|
|
for(int ee=0; ee<page0->eles.size(); ee++) if((eleptr = &page0->eles[ee])->startTime > 0 || eleptr->endTime < page0->timeSpan) {
|
|
|
|
if(eleptr->startTime > 0) timerMap.insert(startTimer(eleptr->startTime), TimerValue(eleptr->wgt, true));
|
|
|
|
timerMap.insert(startTimer(eleptr->endTime), TimerValue(eleptr->wgt, false));
|
|
|
|
}
|
|
|
|
|
2022-08-25 18:37:24 +08:00
|
|
|
menu = new QMenu(this);
|
|
|
|
auto act = menu->addAction(tr("Move to Top Left"));
|
|
|
|
connect(act, &QAction::triggered, this, [this] {
|
|
|
|
move(0,0);
|
|
|
|
});
|
|
|
|
act = menu->addAction(tr("Set Position"));
|
|
|
|
connect(act, &QAction::triggered, this, [this] {
|
|
|
|
PosDlg dlg(this);
|
|
|
|
dlg.exec();
|
|
|
|
});
|
|
|
|
act = menu->addAction(tr("Close"));
|
|
|
|
connect(act, &QAction::triggered, this, [this] {
|
|
|
|
if(self==this) self = nullptr;
|
|
|
|
close();
|
|
|
|
});
|
|
|
|
}
|
2022-01-20 10:08:17 +08:00
|
|
|
void PlayWin::sltNext() {
|
|
|
|
if(isVisible()) {
|
2022-08-25 18:37:24 +08:00
|
|
|
pages[cur]->setVisible(false);
|
|
|
|
if(cur+2 > pages.size()) cur = 0;
|
2022-01-20 10:08:17 +08:00
|
|
|
else cur++;
|
2022-08-25 18:37:24 +08:00
|
|
|
Page* page = pages[cur];
|
2022-01-20 10:08:17 +08:00
|
|
|
if(timer!=nullptr) timer->inter = page->timeSpan;
|
|
|
|
EleBase* ele;
|
|
|
|
for(int ee=0; ee<page->eles.size(); ee++) if((ele = &page->eles[ee])->startTime > 0 || ele->endTime < page->timeSpan) {
|
|
|
|
if(ele->startTime > 0) timerMap.insert(startTimer(ele->startTime), TimerValue(ele->wgt, true));
|
|
|
|
else ele->wgt->setVisible(true);
|
|
|
|
timerMap.insert(startTimer(ele->endTime), TimerValue(ele->wgt, false));
|
|
|
|
}
|
|
|
|
page->setVisible(true);
|
|
|
|
} else if(timer!=nullptr) {
|
|
|
|
timer->stop();
|
|
|
|
timer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PlayWin::timerEvent(QTimerEvent *e){
|
|
|
|
int id = e->timerId();
|
|
|
|
killTimer(id);
|
|
|
|
TimerValue value = timerMap[id];
|
|
|
|
if(value.ele!=nullptr){
|
|
|
|
timerMap.remove(id);
|
|
|
|
value.ele->setVisible(value.visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PlayWin::paintEvent(QPaintEvent *e){
|
|
|
|
if(timer==nullptr && isVisible()) {
|
|
|
|
if(cur!=0) {
|
2022-08-25 18:37:24 +08:00
|
|
|
pages[cur]->setVisible(false);
|
2022-01-20 10:08:17 +08:00
|
|
|
cur = 0;
|
|
|
|
}
|
2022-08-25 18:37:24 +08:00
|
|
|
pages[cur]->setVisible(true);
|
|
|
|
timer = new SyncTimer(pages[cur]->timeSpan);
|
2022-01-20 10:08:17 +08:00
|
|
|
connect(timer, &SyncTimer::timeout, this, &PlayWin::sltNext, Qt::BlockingQueuedConnection);
|
|
|
|
timer->start();
|
|
|
|
}
|
|
|
|
QWidget::paintEvent(e);
|
|
|
|
}
|
2022-08-25 18:37:24 +08:00
|
|
|
|
|
|
|
void PlayWin::mousePressEvent(QMouseEvent *e) {
|
|
|
|
if(e->button() == Qt::LeftButton) {
|
|
|
|
mPressRel = pos() - e->globalPos();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PlayWin::mouseReleaseEvent(QMouseEvent *e) {
|
|
|
|
if(e->button() == Qt::LeftButton) mPressRel.setX(INT_MAX);
|
|
|
|
}
|
|
|
|
void PlayWin::mouseMoveEvent(QMouseEvent *e) {
|
|
|
|
if(e->buttons() & Qt::LeftButton) {
|
|
|
|
if(mPressRel.x()==INT_MAX) return;
|
|
|
|
move(mPressRel + e->globalPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void PlayWin::leaveEvent(QEvent *) {
|
|
|
|
mPressRel.setX(INT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlayWin::contextMenuEvent(QContextMenuEvent *event){
|
|
|
|
menu->exec(event->globalPos());
|
|
|
|
}
|
|
|
|
void PlayWin::closeEvent(QCloseEvent *) {
|
|
|
|
if(self==this) self = nullptr;
|
|
|
|
}
|