#include "progpanel.h" #include "globaldefine.h" #include "tools.h" #include "player/playwin.h" #include "tipdialog.h" #include #include #include #include ProgPanel::ProgPanel(QSettings &settings, QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_DeleteOnClose); setAutoFillBackground(true); QPalette pal; pal.setBrush(QPalette::Window, QColor(0xeeeeee)); setPalette(pal); auto vBox = new QVBoxLayout(this); vBox->setContentsMargins(0, 0, 0, 0); vBox->setSpacing(0); auto hBox = new QHBoxLayout(); hBox->setContentsMargins(6,6,6,6); hBox->setSpacing(6); vBox->addLayout(hBox); bnNew = new QPushButton(tr("New")); bnNew->setFixedSize(88, 38); bnNew->setProperty("ssType", "progManageTool"); hBox->addWidget(bnNew); connect(bnNew, &QPushButton::clicked, this, [this] { ProgCreateDlg dlg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"), 512, 512, "", this); if(dlg.exec() != QDialog::Accepted) return; if(checkIfNameRepeated(dlg.fdName->text())) return; auto item = new ProgItem(mProgsDir, dlg.fdName->text(), dlg.fdWidth->value(), dlg.fdHeight->value(), dlg.fdRemark->toPlainText(), dlg.fdSplitWidth->value(), mProgTree, this); item->save();//保存pro.json mProgTree->adjustCheckState(); auto editor = new ProgEditorWin(item, gMainWin); editor->show(); }); bnEdit = new QPushButton(tr("Edit")); bnEdit->setFixedSize(QSize(88, 38)); bnEdit->setProperty("ssType", "progManageTool"); bnEdit->setEnabled(false); hBox->addWidget(bnEdit); connect(bnEdit, SIGNAL(clicked(bool)), this, SLOT(onEditClicked(bool))); bnDelete = new QPushButton(tr("Delete")); bnDelete->setFixedSize(QSize(88, 38)); bnDelete->setProperty("ssType", "progManageTool"); bnDelete->setEnabled(false); hBox->addWidget(bnDelete); connect(bnDelete, SIGNAL(clicked(bool)), this, SLOT(onDeleteClicked(bool))); bnImport = new QPushButton(tr("Import")); bnImport->setFixedSize(QSize(88, 38)); bnImport->setProperty("ssType", "progManageTool"); hBox->addWidget(bnImport); connect(bnImport, &QPushButton::clicked, this, [this] { auto dlg = new TipDialog(this, ENUM_IMPORT_DLG); connect(dlg, SIGNAL(sigAcceptData(QString,QString)), this, SLOT(onImportProgram(QString,QString))); dlg->exec(); }); bnExport = new QPushButton(tr("Export")); bnExport->setFixedSize(QSize(88, 38)); bnExport->setEnabled(false); bnExport->setProperty("ssType", "progManageTool"); hBox->addWidget(bnExport); connect(bnExport, SIGNAL(clicked(bool)), this, SLOT(onExportClicked(bool))); bnSend = new QPushButton(tr("Send")); bnSend->setFixedSize(QSize(88, 38)); bnSend->setProperty("ssType", "progManageTool"); bnSend->setEnabled(false); bnSend->hide(); hBox->addWidget(bnSend); btnPlay = new QPushButton(tr("Play")+"/"+tr("Stop")); btnPlay->setFixedSize(QSize(88, 38)); btnPlay->setProperty("ssType", "progManageTool"); hBox->addWidget(btnPlay); connect(btnPlay, &QPushButton::clicked, this, [this](){ if(PlayWin::self!=nullptr) PlayWin::self->close(); else { int cnt = mProgTree->topLevelItemCount(); for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) { auto item = static_cast(mProgTree->topLevelItem(i)); QString dir = mProgsDir+"/"+item->mName+"_tmp"; QFile file(dir+"/program"); if(! file.open(QIODevice::ReadOnly | QIODevice::Text)) return; QString value = file.readAll(); file.close(); QJsonParseError jsErr; QJsonObject prog = QJsonDocument::fromJson(value.toUtf8(), &jsErr).object(); if(jsErr.error) return; if(PlayWin::self!=nullptr) PlayWin::self->close(); if(item->mSplitWidth==0) PlayWin::self = PlayWin::newIns(item->mWidth, item->mHeight, dir, prog); else { int cnt = (item->mWidth+item->mSplitWidth-1) / item->mSplitWidth; PlayWin::self = PlayWin::newIns(item->mSplitWidth, item->mHeight*cnt, dir, prog); } break; } } }); hBox->addStretch(); auto txtSearch = new QLineEdit(this); txtSearch->setFixedSize(QSize(240, 36)); QAction *search = new QAction(txtSearch); search->setIcon(QIcon(":/res/ProgramManager/bnSearch.png")); txtSearch->addAction(search, QLineEdit::LeadingPosition); txtSearch->setClearButtonEnabled(true); txtSearch->setStyleSheet("border: 2px solid #aaaaaa;"); hBox->addWidget(txtSearch); connect(txtSearch,SIGNAL(textChanged(const QString &)),this,SLOT(FilterProgram(const QString &))); mProgTree = new LoQTreeWidget(); mProgTree->setIndentation(10); mProgTree->setSortingEnabled(true); m_headerItem = new QTreeWidgetItem(); for(int i=1; isetTextAlignment(i, Qt::AlignCenter); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_CHECK, Qt::DisplayRole, ""); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_NAME, Qt::DisplayRole, tr("Name")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, Qt::DisplayRole, tr("Resolution")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, Qt::DisplayRole, tr("File Size")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, Qt::DisplayRole, tr("Last Modify")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, Qt::DisplayRole, tr("Usb playback")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SEND, Qt::DisplayRole, tr("Publish")); mProgTree->setHeaderItem(m_headerItem); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_CHECK, QHeaderView::Fixed); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_NAME, QHeaderView::Stretch); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, QHeaderView::Stretch); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_SIZE, QHeaderView::Stretch); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, QHeaderView::Stretch); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, QHeaderView::Fixed); mProgTree->header()->setSectionResizeMode(ENUM_PROGRAMLISTHEADERITEM_SEND, QHeaderView::Fixed); mProgTree->header()->setStretchLastSection(false); mProgTree->setColumnWidth(ENUM_PROGRAMLISTHEADERITEM_CHECK, 66); mProgTree->setColumnWidth(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, 100); mProgTree->setColumnWidth(ENUM_PROGRAMLISTHEADERITEM_SEND, 72); vBox->addWidget(mProgTree); connect(mProgTree, &LoQTreeWidget::sigCheckStateChanged, this, [this](int f){ switch(f) { case LoQTreeWidget::CheckNone: bnEdit->setEnabled(false); bnDelete->setEnabled(false); bnExport->setEnabled(false); bnSend->setEnabled(false); break; case LoQTreeWidget::CheckOne: bnEdit ->setEnabled(true); bnDelete->setEnabled(true); bnExport->setEnabled(true); bnSend ->setEnabled(true); break; case LoQTreeWidget::CheckMulti: bnEdit ->setEnabled(false); bnDelete->setEnabled(true); bnExport->setEnabled(true); bnSend ->setEnabled(true); break; default: break; } }); QString doc_path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); if(!doc_path.isEmpty()) { QString app_path = doc_path + "/" + QApplication::applicationName(); mProgsDir = app_path + "/NPrograms"; if(!QFileInfo::exists(mProgsDir)) { QDir app_dir(app_path); app_dir.mkdir("NPrograms"); app_dir.mkdir("ApkStore"); } } //connect(search, SIGNAL(triggered(bool)), this, SLOT(FilterProgram())); //查找根路径下的项目文件夹,查找文件夹下的节目pro.json信息,包括节目名称,大小,像素,备注等信息 if(!mProgsDir.isEmpty()) { QDir root_dir(mProgsDir); QStringList pro_list = root_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); foreach(QString pro_name, pro_list) { QDir pro_dir(mProgsDir + "/" + pro_name); if(pro_dir.exists("pro.json")) { QFile fPro(pro_dir.path() + "/pro.json"); fPro.open(QIODevice::ReadOnly); QJsonDocument pro = QJsonDocument::fromJson(fPro.readAll()); fPro.close(); m_pwPorgramItemList.append(new ProgItem(mProgsDir, pro.object(), mProgTree,this)); } } } if(settings.value("ProgramListSortOrder").toInt()==0) mProgTree->sortByColumn(settings.value("ProgramListSortColumn").toInt(),Qt::SortOrder::AscendingOrder); else mProgTree->sortByColumn(settings.value("ProgramListSortColumn").toInt(),Qt::SortOrder::DescendingOrder); // ui->wProgramList->setSortingEnabled( false ); //不使能QT的自动排序 // ui->wProgramList->header()->setSortIndicatorShown( true ); // 设置三角标识符可见 // ui->wProgramList->header()->setSectionsClickable( true ); // 设置标题栏单击响应使能 // connect( ui->wProgramList->header(), SIGNAL( sectionClicked(int) ), this, SLOT( OnClickColumn(int) ) ); } void ProgPanel::OnClickColumn(int iColumn) { if(iColumn!=ENUM_PROGRAMLISTHEADERITEM_CHECK && iColumn!=ENUM_PROGRAMLISTHEADERITEM_SEND) mProgTree->sortByColumn(iColumn, mProgTree->header()->sortIndicatorOrder()); } void ProgPanel::changeEvent(QEvent *event) { QWidget::changeEvent(event); if(event->type() == QEvent::LanguageChange) transUi(); } void ProgPanel::transUi() { m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_CHECK, 0, ""); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_NAME, 0, tr("Name")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, 0, tr("Resolution")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, tr("File Size")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, 0, tr("Last Modify")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, 0, tr("Usb playback")); m_headerItem->setData(ENUM_PROGRAMLISTHEADERITEM_SEND, 0, tr("Publish")); bnNew->setText(tr("New")); bnEdit->setText(tr("Edit")); bnDelete->setText(tr("Delete")); bnImport->setText(tr("Import")); bnExport->setText(tr("Export")); bnSend->setText(tr("Send")); btnPlay->setText(tr("Play")+"/"+tr("Stop")); for(int i=0;irefreshLable(); } void ProgPanel::onEditClicked(bool){ int cnt = mProgTree->topLevelItemCount(); for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) { auto item = static_cast(mProgTree->topLevelItem(i)); auto editor = new ProgEditorWin(item, gMainWin); editor->show(); break; } } } bool ProgPanel::checkIfNameRepeated(const QString &name, QTreeWidgetItem *skip){ int cnt = mProgTree->topLevelItemCount(); for(int i=0; i(mProgTree->topLevelItem(i)); if(item == skip) continue; if(name == item->mName) { QMessageBox::warning(this, tr("Warning"), tr("Program name conflicted")); return true; } } return false; } void ProgPanel::onCreateNewProgramOnOpenEditProgramWidget(QString name, QSize res, QString remarks, int sp) { if(checkIfNameRepeated(name)) return; auto item = new ProgItem(mProgsDir, name, res.width(), res.height(), remarks, sp, mProgTree, this); item->save();//保存pro.json mProgTree->adjustCheckState(); auto editor = new ProgEditorWin(item, gMainWin); editor->show(); } void ProgPanel::onDeleteClicked(bool){ auto res = QMessageBox::information(this, tr("Tip Info"), tr("You will delete the selected solution(s),are you sure?"), QMessageBox::Ok, QMessageBox::Cancel); if(res == QMessageBox::Ok) { int cnt = mProgTree->topLevelItemCount(); QList list; for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) { auto item = static_cast(mProgTree->topLevelItem(i)); list.push_back(item); } } while(!list.isEmpty()) { auto item = list.takeFirst(); item->del(); delete item; } mProgTree->adjustCheckState(); } } void ProgPanel::onImportProgram(QString strImportDir, QString){ if(!strImportDir.isEmpty()){ mProgTree->clear(); //查找根路径下的项目文件夹,查找文件夹下的节目pro.json信息,包括节目名称,大小,像素,备注等信息 if(!mProgsDir.isEmpty()) { QDir root_dir(mProgsDir); QStringList pro_list = root_dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot | QDir::NoSymLinks); foreach(QString pro_name, pro_list) { QDir pro_dir(mProgsDir + MACRO_FENGEFU + pro_name); if(pro_dir.exists("pro.json")) { QFile fPro(pro_dir.path() + MACRO_FENGEFU+"pro.json"); fPro.open(QIODevice::ReadOnly); QJsonDocument pro = QJsonDocument::fromJson(fPro.readAll()); fPro.close(); m_pwPorgramItemList.append(new ProgItem(mProgsDir, pro.object(), mProgTree,this)); } } } } } void ProgPanel::onExportClicked(bool){ int cnt = mProgTree->topLevelItemCount(); QStringList selectProgramlist; for(int i=0; itopLevelItem(i)->checkState(0) == Qt::Checked) { QString string =static_cast(mProgTree->topLevelItem(i))->m_bnName->text(); selectProgramlist.append(string); } } TipDialog *dlg = new TipDialog(this,ENUM_EXPORT_DLG,&selectProgramlist,0); dlg->exec(); } void ProgPanel::FilterProgram(const QString &strtemp){ if (strtemp.isEmpty()) //显示全部 { for (int i = 0; i< mProgTree->topLevelItemCount(); ++i) { QTreeWidgetItem* topItem = mProgTree->topLevelItem(i); mProgTree->setRowHidden(i,mProgTree->indexFromItem(topItem->parent()),false); } } else { QList resultList = mProgTree->findItems(strtemp, Qt::MatchContains,ENUM_PROGRAMLISTHEADERITEM_NAME); //搜索结果 if (resultList.size() > 0) { for (int i = 0; i< mProgTree->topLevelItemCount(); ++i) { QTreeWidgetItem* topItem = mProgTree->topLevelItem(i); if (resultList.contains(topItem)) mProgTree->setRowHidden(i,mProgTree->indexFromItem(topItem->parent()),false); //显示匹配的结果 else mProgTree->setRowHidden(i,mProgTree->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果 } } else { QList resultList1 = mProgTree->findItems(strtemp, Qt::MatchContains,ENUM_PROGRAMLISTHEADERITEM_RESOLUTION); //搜索结果 if (resultList1.size() > 0){ for (int i = 0; i< mProgTree->topLevelItemCount(); ++i){ QTreeWidgetItem* topItem = mProgTree->topLevelItem(i); if (resultList1.contains(topItem)) mProgTree->setRowHidden(i,mProgTree->indexFromItem(topItem->parent()),false); //显示匹配的结果 else mProgTree->setRowHidden(i,mProgTree->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果 } } else { for (int i = 0; i< mProgTree->topLevelItemCount(); ++i){ QTreeWidgetItem* topItem = mProgTree->topLevelItem(i); mProgTree->setRowHidden(i,mProgTree->indexFromItem(topItem->parent()),true); //隐藏不匹配的结果 } } } } }