#include "playwin.h" #include "eleanaclock.h" #include "digiclock.h" #include "eleimg.h" #include "elegif.h" #include "elescroll.h" #include "elemultipng.h" #include "elevideo.h" #include "gqt.h" #include #include #include #include #include Page::Page(QWidget *parent) : QWidget{parent} { } PlayWin::PlayWin(QString dir, int x, int y, int width, int height, const QJsonObject &aprog, QWidget *parent) : QWidget(parent, Qt::Window|Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint) { setAttribute(Qt::WA_DeleteOnClose); 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(); EleBase ele; for(int p=0; psetGeometry(0, 0, width, height); page->setVisible(false); page->name = pageMap["name"].toString(); page->dirPre = dir+"/"+page->name+"/"; for(int ll=0; llname<<"-"< page->timeSpan) page->timeSpan = ele.endTime; if(ele.startTime>0) ele.wgt->setVisible(false); ele.id = srcMap["id"].toString(); ele.wgt = nullptr; if(ele.type=="Image") { if(srcMap["mime"].toString().endsWith("gif")) ele.wgt = new EleGif(page->dirPre+ele.id, page); else ele.wgt = new EleImg(page->dirPre+ele.id, page); } else if(ele.type.startsWith("Environ")) { QJsonArray arrayPics = srcMap["arrayPics"].toArray(); for(int i=arrayPics.size()-1; i>=0; i--) if(arrayPics[i].toObject()["name"].toString() == "previewTmp") { ele.wgt = new EleImg(page->dirPre + arrayPics[i].toObject()["id"].toString(), page); break; } } else if(ele.type=="MultiPng") { QJsonArray imgs = srcMap["arrayPics"].toArray(); if(imgs.isEmpty()) continue; if(imgs.size()==1 && imgs[0].toObject()["picDuration"].toInt()==0) ele.wgt = new EleScroll(page->dirPre, imgs[0].toObject(), page); else ele.wgt = new EleMultiPng(page->dirPre, imgs, page); } else if(ele.type=="DigitalClockNew") ele.wgt = new DigiClock(page->dirPre, srcMap, page); else if(ele.type=="AnalogClock") ele.wgt = new EleAnaClock(page->dirPre+ele.id, srcMap, page); else if(ele.type=="Video") ele.wgt = new EleVideo(page->dirPre+ele.id, page); else continue; if(ele.wgt==nullptr) continue; ele.wgt->setGeometry(ele.x, ele.y, ele.w, ele.h); page->eles.append(ele); } } } setVisible(true); Page* page0 = (Page*)children()[0]; EleBase* eleptr; for(int ee=0; eeeles.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)); } } void PlayWin::sltNext() { if(isVisible()) { Page* page = (Page*)children()[cur]; page->setVisible(false); if(cur+2 > children().size()) cur = 0; else cur++; page = (Page*)children()[cur]; if(timer!=nullptr) timer->inter = page->timeSpan; EleBase* ele; for(int ee=0; eeeles.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){ qDebug()<setVisible(value.visible); } } void PlayWin::paintEvent(QPaintEvent *e){ if(timer==nullptr && isVisible()) { if(cur!=0) { ((Page*)children()[cur])->setVisible(false); cur = 0; } Page *page = (Page*)children()[cur]; page->setVisible(true); timer = new SyncTimer(page->timeSpan); connect(timer, &SyncTimer::timeout, this, &PlayWin::sltNext, Qt::BlockingQueuedConnection); timer->start(); } QWidget::paintEvent(e); }