210 lines
8.0 KiB
C++
210 lines
8.0 KiB
C++
#include "progitem.h"
|
||
#include "tools.h"
|
||
#include "progeditorwin.h"
|
||
#include "mconverter.h"
|
||
#include "LoUIClass/loemptydialog.h"
|
||
#include "usbdetectdialog.h"
|
||
#include <globaldefine.h>
|
||
#include "sendprogramdialog.h"
|
||
#include "mainwindow.h"
|
||
|
||
ProgItem::ProgItem(const QString &pRoot, const QString &name, int w, int h, const QString &remarks, LoQTreeWidget *parent,QWidget *pWnd) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
|
||
m_name = name;
|
||
m_width = w;
|
||
m_height = h;
|
||
m_remarks = remarks;
|
||
m_fsize = 0;
|
||
m_last = QDateTime::currentDateTime();
|
||
m_strSavePath = pRoot;
|
||
mProgDir = pRoot + MACRO_FENGEFU + m_name;
|
||
m_orgName = m_name;
|
||
m_pWnd = pWnd;
|
||
init();
|
||
}
|
||
|
||
ProgItem::ProgItem(const QString &pRoot, const QJsonObject &json, LoQTreeWidget *parent,QWidget *pWnd) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
|
||
m_name = json["name"].toString();
|
||
m_width = json["resolution"]["w"].toInt();
|
||
m_height = json["resolution"]["h"].toInt();
|
||
m_remarks = json["remarks"].toString();
|
||
m_fsize = json["file_size"].toDouble();
|
||
m_last = QDateTime::fromString(json["last_edit"].toString(), "yyyy-MM-dd hh:mm:ss");
|
||
m_strSavePath = pRoot;
|
||
mProgDir = pRoot + MACRO_FENGEFU + m_name;
|
||
m_orgName = m_name;
|
||
m_pWnd = pWnd;
|
||
init();
|
||
}
|
||
|
||
void ProgItem::init()
|
||
{
|
||
auto cfg = Tools::getInstance();
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_NAME, 0,m_name);
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, 0, QString("%1 x %2").arg(m_width).arg(m_height));
|
||
if(m_fsize<=0)
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize((qint64)100));
|
||
else
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize(m_fsize));
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, 0, m_last.toString("yyyy-MM-dd hh:mm:ss"));
|
||
setTextAlignment(ENUM_PROGRAMLISTHEADERITEM_NAME, Qt::AlignLeft | Qt::AlignVCenter);
|
||
for(int i=1; i<ENUM_PROGRAMLISTHEADERITEM_END; i++) {
|
||
setTextAlignment(i, Qt::AlignCenter);
|
||
}
|
||
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
||
setCheckState(0, Qt::Unchecked);
|
||
m_parent->insertTopLevelItem(0,this);
|
||
|
||
m_bnName = new QPushButton(m_name);
|
||
m_bnName->setStyleSheet(R"delimiter(
|
||
QPushButton{border-radius: 4px;}
|
||
QPushButton:hover {
|
||
background-color: #cccccc;
|
||
text-decoration: underline;
|
||
}
|
||
)delimiter");
|
||
|
||
m_bnName->setCursor(QCursor(Qt::PointingHandCursor));
|
||
m_parent->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_NAME, m_bnName);
|
||
connect(m_bnName, SIGNAL(clicked()), this, SLOT(onEditProgram()));
|
||
m_bnExport = new QPushButton();
|
||
m_bnExport->setCursor(QCursor(Qt::PointingHandCursor));
|
||
m_bnExport->setToolTip(tr("ExportButtonTip"));
|
||
m_bnExport->setStyleSheet(R"rrr(
|
||
QPushButton {
|
||
border-radius: 4px;
|
||
image: url(:/res/ProgramManager/bnExport_u.png);
|
||
}
|
||
QPushButton:pressed{image: url(:/res/ProgramManager/bnExport_s.png);}
|
||
QPushButton:hover{background-color: #cccccc;}
|
||
)rrr");
|
||
|
||
m_parent->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, m_bnExport);
|
||
connect(m_bnExport, SIGNAL(clicked()), this, SLOT(onUsbExportProgram()));
|
||
|
||
m_bnSend = new QPushButton();
|
||
m_bnSend->setCursor(QCursor(Qt::PointingHandCursor));
|
||
m_bnSend->setToolTip(tr("SendButtonTip"));
|
||
m_bnSend->setStyleSheet(R"rrr(
|
||
QPushButton{
|
||
border-radius: 4px;
|
||
image: url(:/res/ProgramManager/bnSend_u.png);
|
||
}
|
||
QPushButton:pressed{image: url(:/res/ProgramManager/bnSend_s.png);}
|
||
QPushButton:hover{background-color: #cccccc;}
|
||
)rrr");
|
||
|
||
m_parent->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_SEND, m_bnSend);
|
||
connect(m_bnSend, SIGNAL(clicked()), this, SLOT(onSendProgram()));
|
||
}
|
||
void ProgItem::refreshLable()
|
||
{
|
||
m_bnExport->setToolTip(tr("ExportButtonTip"));
|
||
m_bnSend->setToolTip(tr("SendButtonTip"));
|
||
|
||
}
|
||
QJsonObject ProgItem::jRoot()
|
||
{
|
||
QJsonObject oRoot;
|
||
QJsonObject oSize;
|
||
oRoot["name"] = m_name;
|
||
oSize["w"] = m_width;
|
||
oSize["h"] = m_height;
|
||
oRoot["resolution"] = oSize;
|
||
oRoot["remarks"] = m_remarks;
|
||
oRoot["file_size"] = m_fsize;
|
||
oRoot["last_edit"] = m_last.toString("yyyy-MM-dd hh:mm:ss");
|
||
return oRoot;
|
||
}
|
||
|
||
void ProgItem::save() {
|
||
QDir dRoot(mProgDir);
|
||
QDir dParent(m_strSavePath);
|
||
if(!dRoot.exists()) {
|
||
dParent.mkdir(m_name);
|
||
} else if(m_name != m_orgName) {
|
||
dParent.rename(m_orgName, m_name);
|
||
m_orgName = m_name;
|
||
mProgDir = m_strSavePath + MACRO_FENGEFU + m_name;
|
||
}
|
||
|
||
dRoot = QDir(mProgDir);
|
||
if(dRoot.exists()) {
|
||
QJsonDocument json(jRoot());
|
||
QFile f(mProgDir + MACRO_FENGEFU+"pro.json");
|
||
f.open(QIODevice::WriteOnly);
|
||
f.write(json.toJson());
|
||
f.close();
|
||
}
|
||
}
|
||
|
||
void ProgItem::del()
|
||
{
|
||
QDir dRoot(mProgDir);
|
||
if(dRoot.exists()) {
|
||
dRoot.removeRecursively();
|
||
}
|
||
}
|
||
//设置列表项的值
|
||
void ProgItem::onSetProgram()
|
||
{
|
||
auto cfg = Tools::getInstance();
|
||
m_bnName->setText(m_name);
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, 0, QString("%1 x %2").arg(m_width).arg(m_height));
|
||
if(m_fsize<=0)
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize(100));
|
||
else
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize(m_fsize));
|
||
setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, 0, m_last.toString("yyyy-MM-dd hh:mm:ss"));
|
||
save();
|
||
}
|
||
|
||
void ProgItem::onEditProgram() {
|
||
auto editor = new ProgEditorWin(m_name, m_width, m_height, m_remarks, mProgDir, m_strSavePath, gMainWin);
|
||
connect(editor, &ProgEditorWin::sProgramChanged, this, [this]{
|
||
m_last = QDateTime::currentDateTime();
|
||
m_fsize = dirFileSize(mProgDir);
|
||
onSetProgram();
|
||
});//编辑窗口发送节目变化信号到该ITEM响应属性变化槽函数
|
||
connect(editor, &ProgEditorWin::sProgramSaveAs, (ProgPanel*)m_pWnd, &ProgPanel::onCreateNewProgramOnOpenEditProgramWidget);//编辑窗口另存为按钮触发后发送信号到播放列表增加一行
|
||
editor->show();
|
||
}
|
||
|
||
void ProgItem::onUsbExportProgram(){
|
||
auto pDlg = new UsbDetectDialog(gMainWin);
|
||
connect(pDlg, &UsbDetectDialog::acceptData, this, &ProgItem::onUsbExportProgramPro);
|
||
pDlg->exec();
|
||
}
|
||
void ProgItem::onUsbExportProgramPro(QString strPath, QString strPassword){
|
||
LoEmptyDialog * msgbox = new LoEmptyDialog(m_pWnd);
|
||
QString strUsbProgramName = m_name;
|
||
auto converter = new mConverter(strUsbProgramName, strPath + (strPath.endsWith('/') ? "program.zip" : "/program.zip"), strPassword, this);
|
||
connect(converter, &QThread::finished, converter, &QThread::deleteLater);
|
||
//转换结束,发送信号触发converter释放内存
|
||
connect(converter, SIGNAL(finished()), msgbox, SLOT(unlock()));
|
||
connect(converter, SIGNAL(finished()), this, SLOT(UsbExportFinished()));
|
||
//链接转换进度信号到进度条槽函数
|
||
connect(converter, SIGNAL(sProgress(QString,int,bool)), msgbox->mIndicator, SLOT(onProgress(QString,int,bool)));
|
||
//链接进度对话框启动信号到转换开始槽函数
|
||
connect(msgbox, SIGNAL(startUp()), converter, SLOT(start()));
|
||
msgbox->lock(tr("Convertering")+"...",tr("USB Export Successed"),tr("USB Export TimeOut"));
|
||
msgbox->exec();
|
||
}
|
||
|
||
void ProgItem::onSendProgram(){
|
||
LoEmptyDialog * msgbox = new LoEmptyDialog(m_pWnd);
|
||
//转换节目
|
||
auto converter = new mConverter(m_name, "", "", this);
|
||
connect(converter, &QThread::finished, converter, &QThread::deleteLater);
|
||
//转换结束,发送信号触发converter释放内存
|
||
connect(converter, SIGNAL(finished()), msgbox, SLOT(unlock()));
|
||
//链接转换进度信号到进度条槽函数
|
||
connect(converter, SIGNAL(sProgress(QString,int,bool)), msgbox->mIndicator, SLOT(onProgress(QString,int,bool)));
|
||
//链接进度对话框启动信号到转换开始槽函数
|
||
connect(msgbox, SIGNAL(startUp()), converter, SLOT(start()));
|
||
msgbox->lock(tr("Convertering")+"...",tr("Converter Successed"),tr("Converter TimeOut"));
|
||
msgbox->exec();
|
||
|
||
auto dlg = new SendProgramDialog(m_pWnd, m_name, programsDir());
|
||
dlg->show();
|
||
}
|