#include "mainwindow.h" #include "gutil/qgui.h" #include "cfg.h" #include "globaldefine.h" #include "deviceitem.h" #include "devicepanel.h" #include "gutil/qnetwork.h" #include "device/upgradeapkdialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include extern QPoint gPlayPos; class ImgBtn : public QToolButton { public: ImgBtn() { auto policy = sizePolicy(); policy.setHorizontalPolicy(QSizePolicy::Preferred); setSizePolicy(policy); connect(this, &QToolButton::toggled, this, [this](bool checked) { setIcon(icons[checked ? 1 : 0]); }); } void setIcons(const QIcon &unchecked, const QIcon &checked) { setIcon(unchecked); icons[0] = unchecked; icons[1] = checked; } protected: #if(QT_VERSION_MAJOR > 5) void enterEvent(QEnterEvent *) override { #else void enterEvent(QEvent *) override { #endif if(this->isChecked()) return; setIcon(icons[1]); } void leaveEvent(QEvent *) override { if(this->isChecked()) return; setIcon(icons[0]); } QIcon icons[2]; }; MainWindow::MainWindow(QWidget *parent) : BaseWin(parent) { setAttribute(Qt::WA_AlwaysShowToolTips); auto ft = font(); ft.setPixelSize(14); setFont(ft); auto menuLang = new QMenu; auto actCN = new QAction("中文"); actCN->setCheckable(true); actCN->setObjectName("zh_CN"); menuLang->addAction(actCN); auto actTW = new QAction("中文繁体"); actTW->setCheckable(true); actTW->setObjectName("zh_TW"); menuLang->addAction(actTW); auto actEn = new QAction("English"); actEn->setCheckable(true); actEn->setObjectName("en"); menuLang->addAction(actEn); auto actJa = new QAction("日本語"); actJa->setCheckable(true); actJa->setObjectName("ja"); menuLang->addAction(actJa); langGrp = new QActionGroup(menuLang); langGrp->addAction(actCN); langGrp->addAction(actTW); langGrp->addAction(actEn); langGrp->addAction(actJa); connect(menuLang, &QMenu::triggered, this, [this](QAction* action) { auto lanName = action->objectName(); translator.load("app_"+lanName, ":/i18n"); transQt.load("qt_"+lanName, ":/i18n"); }); QSettings settings; QString langName = settings.value("Language").toString(); QAction *actLan = 0; if(! langName.isEmpty()) { if(langName.endsWith("CN")) actLan = actCN; else if(langName.endsWith("TW")) actLan = actTW; else if(langName.startsWith("en")) actLan = actEn; else if(langName.startsWith("ja")) actLan = actJa; } if(actLan==0) { langName = QLocale().name(); if(langName.endsWith("TW")) actLan = actTW; else if(langName.startsWith("en")) actLan = actEn; else if(langName.startsWith("ja")) actLan = actJa; else actLan = actCN; } actLan->setChecked(true); auto lanName = actLan->objectName(); translator.load("app_"+lanName, ":/i18n"); transQt.load("qt_"+lanName, ":/i18n"); QApplication::installTranslator(&translator); QApplication::installTranslator(&transQt); auto geo = settings.value("MainGeo").toRect(); if(geo.width()>=800 && geo.height()>=500 && geo.x()>=-600 && geo.x()<=1280 && geo.y()>=-200 && geo.y()<=800) setGeometry(geo); else resize(1280, 800); if(settings.value("MainIsMax", false).toBool()) setWindowState(Qt::WindowMaximized); gPlayPos = settings.value("PlayPos").toPoint(); setWindowTitle("LedOK Express"); icon.load(":/res/Logo.png"); titlePos = QPointF(26, 80); iconPos = QPointF(38, 20); auto plt = palette(); plt.setBrush(QPalette::Window, QColor(0xdddddd)); setPalette(plt); //项目保存的文档路径 QString doc_path = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); if(!doc_path.isEmpty()) { QDir app_dir = QDir(doc_path + "/" + QApplication::applicationName()); if(!app_dir.exists()) { QDir doc_dir(doc_path); doc_dir.mkdir(QApplication::applicationName()); } } //创建一个垂直布局 auto vBox = new VBox(center); vBox->setContentsMargins(0, 0, 0, 0); vBox->setSpacing(0); //自定义的标题上的工具栏创建(语言和设置选项) m_wTitle = new LoQTitleBar(this); installEventFilter(m_wTitle); //水平布局,放置配置按钮,最小化,最大化,关闭按钮 QHBoxLayout *pLayout = new QHBoxLayout(m_wTitle); pLayout->setContentsMargins(0, 0, 0, 0); pLayout->addStretch(); bn_Setting = new QPushButton; bn_Setting->setIcon(QIcon(":/res/AppSetting.png")); bn_Setting->setToolTip(tr("Setting")); pLayout->addWidget(bn_Setting); pLayout->addWidget(m_wTitle->bn_Minimize); pLayout->addWidget(m_wTitle->bn_Maximize); pLayout->addWidget(m_wTitle->bn_Close); auto menu_setting = new QMenu; act_lang = new QAction; act_lang->setMenu(menuLang); menu_setting->addAction(act_lang); actFirmware = new QAction(tr("firmware manager")); connect(actFirmware, &QAction::triggered, this, [this] { UpgradeApkDialog dlg(this); dlg.exec(); }); menu_setting->addAction(actFirmware); actPreferences = new QAction(tr("Preferences")); connect(actPreferences, &QAction::triggered, this, [this] { QDialog dlg(this); dlg.setWindowFlag(Qt::WindowContextHelpButtonHint, 0); dlg.resize(400, 300); dlg.setWindowTitle(tr("Preferences")); auto vBox = new VBox(&dlg); auto fdPress = new QCheckBox(tr("Video compress to")+" 720p"); fdPress->setChecked(gVideoCompress); vBox->addWidget(fdPress); auto fdTrans = new QCheckBox(tr("Video transcoding to")+" h264"); fdTrans->setChecked(gVideoTranscoding); vBox->addWidget(fdTrans); auto hbox = new HBox(vBox); hbox->setContentsMargins(-1, 0, -1, -1); auto fdAnti = new QCheckBox(tr("Text antialiasing")); fdAnti->setChecked(gTextAntialiasing); hbox->addWidget(fdAnti, 0, Qt::AlignTop); auto fdAntiTip = new QLabel(tr("TextAntilaTip")); fdAntiTip->setStyleSheet("QLabel{color: #f00;}"); fdAntiTip->setWordWrap(true); hbox->addWidget(fdAntiTip, 1); auto fdWidthSplit = new QCheckBox(tr("Width Split")); fdWidthSplit->setChecked(gWidthSplit); vBox->addWidget(fdWidthSplit); auto fdHideDetect = new QCheckBox(tr("Hide Detect Button")); fdHideDetect->setChecked(gHideDetect); vBox->addWidget(fdHideDetect); auto fdShowLora = new QCheckBox(tr("Show Lora Screen")); fdShowLora->setChecked(gShowLora); vBox->addWidget(fdShowLora); vBox->addStretch(); auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok); connect(btnBox, &QDialogButtonBox::accepted, &dlg, [=, &dlg] { QSettings settings; settings.setValue("VideoCompress", gVideoCompress = fdPress->isChecked()); settings.setValue("VideoTranscoding", gVideoTranscoding = fdTrans->isChecked()); settings.setValue("TextAntialiasing", gTextAntialiasing = fdAnti->isChecked()); settings.setValue("WidthSplit", gWidthSplit = fdWidthSplit->isChecked()); settings.setValue("HideDetect", gHideDetect = fdHideDetect->isChecked()); settings.setValue("GuangYingPin", gShowLora = fdShowLora->isChecked()); dlg.accept(); }); vBox->addWidget(btnBox); dlg.exec(); fdDetectCard->setVisible(! gHideDetect); mBtnGrp->button(MainPage_LoraScreen)->setVisible(gShowLora); }); menu_setting->addAction(actPreferences); act_update = new QAction(tr("Check for updates")); connect(act_update, &QAction::triggered, this, [this] { { QDialog dlg(this); #ifdef Q_OS_WIN dlg.setWindowFlag(Qt::WindowContextHelpButtonHint, false); #endif dlg.setWindowTitle(tr("Software Update")); dlg.resize(500, 400); auto vBox = new VBox(&dlg); auto label = new QLabel(tr("CurVersion")+": "+APP_VERSION); auto font = label->font(); font.setPixelSize(18); label->setFont(font); vBox->addWidget(label); label = new QLabel(hasNewVer ? tr("Latest Version")+": "+updates["ver"].toString() : tr("The current version is already the latest version")); vBox->addWidget(label); label = new QLabel(tr("Update Log")+":"); vBox->addWidget(label); auto fdUpdLog = new QTextEdit; fdUpdLog->setReadOnly(true); vBox->addWidget(fdUpdLog); auto reply = NetReq(updates["changelog_zh_CN"].toString()).timeout(60000).get(); connect(reply, &QNetworkReply::finished, this, [=] { auto err = errStr(reply); if(! err.isEmpty()) { qCritical()<<"Check Updates"<setPlainText(reply->readAll()); }); auto btnBox = new QDialogButtonBox; if(hasNewVer) { btnBox->addButton(tr("Download"), QDialogButtonBox::AcceptRole); connect(btnBox, &QDialogButtonBox::accepted, &dlg, &QDialog::accept); } btnBox->addButton(QDialogButtonBox::Cancel); connect(btnBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject); vBox->addWidget(btnBox); if(dlg.exec() != QDialog::Accepted) return; } auto filePath = QStandardPaths::writableLocation(QStandardPaths::TempLocation) + "/ledok-express-updater"; auto url = updates["url"].toString(); auto idx = url.lastIndexOf('.'); if(idx!=-1) filePath += url.midRef(idx); qDebug()<<"filePath"<readAll()); }); connect(reply, &QNetworkReply::finished, &msgBox, [&, reply] { auto err = errStr(reply); if(! err.isEmpty()) { msgBox.setIcon(QMessageBox::Critical); msgBox.setText(tr("Error")+": "+err); return; } msgBox.accept(); }); auto res = msgBox.exec(); qFile.close(); if(res != QDialog::Accepted) return; QApplication::quit(); QDesktopServices::openUrl(QUrl::fromLocalFile(filePath)); }); menu_setting->addAction(act_update); auto reply = NetReq(UpdVerUrl).timeout(60000).get(); connect(reply, &QNetworkReply::finished, this, [=] { auto err = errStr(reply); if(! err.isEmpty()) { qCritical()<<"Check Updates"<readAll(); QJsonParseError jsonErr; auto json = QJsonDocument::fromJson(data, &jsonErr); if(jsonErr.error != QJsonParseError::NoError) { qCritical()<<"Check Updates JsonError"< 0) { hasNewVer = true; bn_Setting->setIcon(QIcon(":/res/AppSettingTip.png")); act_update->setIcon(QIcon(":/res/reddot.png")); } }); act_help = new QAction(); connect(act_help, &QAction::triggered, this, [this] { auto act = langGrp->checkedAction(); if(act==0) return; QDesktopServices::openUrl(QUrl::fromLocalFile(QCoreApplication::applicationDirPath()+"/help/"+act->objectName()+".pdf")); }); menu_setting->addAction(act_help); actInfo = new QAction; connect(actInfo, &QAction::triggered, this, [this] { QMessageBox::information(this, tr("Info"), QFileInfo("aaa.file").absoluteFilePath() .append("\nSupportsSsl: ").append(QSslSocket::supportsSsl()?"true":"false") .append("\nSslLibraryBuildVersion: ").append(QSslSocket::sslLibraryBuildVersionString().append(" (").append(QString::number(QSslSocket::sslLibraryBuildVersionNumber())).append(")")) .append("\nSslLibraryVersion: ").append(QSslSocket::sslLibraryVersionString()).append(" (").append(QString::number(QSslSocket::sslLibraryVersionNumber())).append(")")); }); menu_setting->addAction(actInfo); act_about = new QAction(tr("About")); connect(act_about, &QAction::triggered, this, [this] { QDialog dlg(this); dlg.setWindowFlag(Qt::WindowContextHelpButtonHint, false); dlg.setWindowTitle(tr("About")); auto hBox = new HBox(&dlg); hBox->setContentsMargins(24, 24, 24, 24); hBox->setSpacing(24); auto label = new QLabel; label->setPixmap(QPixmap(":/res/Logo.png")); hBox->addWidget(label); auto vBox = new VBox(hBox); label = new QLabel("LedOK Express"); label->setAlignment(Qt::AlignCenter); auto font = label->font(); font.setPixelSize(30); label->setFont(font); vBox->addWidget(label); label = new QLabel("V" APP_VERSION" - " __DATE__); font = label->font(); font.setPixelSize(18); label->setFont(font); label->setAlignment(Qt::AlignCenter); vBox->addWidget(label); label = new QLabel("www.ledok.cn"); font = label->font(); font.setPixelSize(20); label->setFont(font); label->setAlignment(Qt::AlignCenter); label->setOpenExternalLinks(true); vBox->addWidget(label); dlg.exec(); }); menu_setting->addAction(act_about); bn_Setting->setMenu(menu_setting);//按钮上添加下拉菜单 vBox->addWidget(m_wTitle); //设备管理,节目管理,高级节目管理页创建 mDevicePanel = new DevicePanel(settings); auto hBox = new HBox(vBox); hBox->setSpacing(2); hBox->addSpacing(144); mBtnGrp = new QButtonGroup(this); for(int i=0; isetToolButtonStyle(Qt::ToolButtonTextUnderIcon); btn->setCheckable(true); btn->setIconSize(QSize(40,40)); btn->setProperty("ss", "MainTab"); if(i==MainPage_DeviceManager) btn->setIcons(QIcon{":/res/DeviceManager_u.png"}, QIcon{":/res/DeviceManager_s.png"}); else if(i==MainPage_ProgManager) btn->setIcons(QIcon{":/res/ProgramManager_u.png"}, QIcon{":/res/ProgramManager_s.png"}); else if(i==MainPage_Setting) btn->setIcons(QIcon{":/res/DeviceSetting_u.png"}, QIcon{":/res/DeviceSetting_s.png"}); else if(i==MainPage_LoraScreen) btn->setIcons(QIcon{":/res/GuangYingPin_u.png"}, QIcon{":/res/GuangYingPin_s.png"}); hBox->addWidget(btn); mBtnGrp->addButton(btn, i); } wgts[MainPage_DeviceManager] = mDevicePanel; wgts[MainPage_Setting] = mDevicePanel; vBox->addWidget(wgts[mDevicePanel->mainPanelIdx]);//初始化响应页面为终端管理页面 mBtnGrp->button(mDevicePanel->mainPanelIdx)->setChecked(true); connect(mBtnGrp, &QButtonGroup::idToggled, this, [this, vBox](int id, bool checked) { if(!checked || id==mDevicePanel->mainPanelIdx) return; if((id!=MainPage_DeviceManager || mDevicePanel->mainPanelIdx!=MainPage_Setting) && (id!=MainPage_Setting || mDevicePanel->mainPanelIdx!=MainPage_DeviceManager)){ if(wgts[id]==0) { if(id==MainPage_ProgManager) wgts[id] = mProgPanel = new ProgPanel(center); else if(id==MainPage_LoraScreen) wgts[id] = m_wGuangYingPinWidget = new mGuangYingPinWidget; } vBox->replaceWidget(wgts[mDevicePanel->mainPanelIdx], wgts[id]); wgts[mDevicePanel->mainPanelIdx]->setParent(0); } mDevicePanel->mainPanelIdx = id; if(id==MainPage_DeviceManager) { //设备信息列表页面 mDevicePanel->mDeviceTable->hideColumn(0); mDevicePanel->mDeviceTable->fdIsSelAll->hide(); if(mDevicePanel->mDeviceCtrlPanel) { for(int j=DeviceTable_ScreenSize;jmDeviceTable->showColumn(j); mDevicePanel->mDeviceTable->setMaximumWidth(0xffffff); mDevicePanel->mDeviceTable->setSelectionMode(QAbstractItemView::NoSelection); mDevicePanel->mDeviceCtrlPanel->hide(); mDevicePanel->fdCardNumInfo->hide(); } } else if(id==MainPage_Setting) { //终端控制页面 mDevicePanel->mDeviceTable->showColumn(0); mDevicePanel->mDeviceTable->fdIsSelAll->show(); for(int j=DeviceTable_ScreenSize; jmDeviceTable->hideColumn(j); if(mDevicePanel->mDeviceCtrlPanel) mDevicePanel->mDeviceCtrlPanel->show(); else mDevicePanel->newCtrl(); mDevicePanel->mDeviceTable->setMaximumWidth(340); mDevicePanel->mDeviceTable->setSelectionMode(QAbstractItemView::SingleSelection); mDevicePanel->fdCardNumInfo->show(); } }); hBox = new HBox(vBox); fdDetectCard = new QPushButton; fdDetectCard->setCursor(Qt::PointingHandCursor); fdDetectCard->setProperty("ssType", "progManageTool"); connect(fdDetectCard, &QPushButton::clicked, this, [this] { auto res = QMessageBox::warning(this, tr("Tip Info"), tr("RestoreLedCardIpByUdpTip"), QMessageBox::Ok, QMessageBox::Cancel); if(res != QMessageBox::Ok) return; QList networkinterfaces = QNetworkInterface::allInterfaces(); foreach(QNetworkInterface interfaces, networkinterfaces) {//networkinterfaces负责提供主机的IP地址和网络接口的列表 foreach(QNetworkAddressEntry entry, interfaces.addressEntries()) {//QNetworkAddressEntry存储了一个IP地址,子网掩码和广播地址 entry.setBroadcast(QHostAddress::Broadcast); QHostAddress broadcastAddress("255.255.255.255"); entry.setBroadcast(QHostAddress::Broadcast); RESTORE_IP stTempIp; memset(&stTempIp,0x00,sizeof(RESTORE_IP)); QString strNew=entry.ip().toString(); int itempOffset = strNew.lastIndexOf("."); QString sstrNew=strNew.left(itempOffset)+".254"; if(sstrNew.length()<=20) memcpy(stTempIp.cNewIp,sstrNew.toLatin1().data(),sstrNew.length()); QString strMask=entry.netmask().toString(); if(strMask.length()<=20) memcpy(stTempIp.cMask,strMask.toLatin1().data(),strMask.length()); QString strGateway=entry.ip().toString(); if(strGateway.length()<=20) memcpy(stTempIp.cGateway,strGateway.toLatin1().data(),strGateway.length()); if(strGateway.length()<=20) memcpy(stTempIp.cDns,strGateway.toLatin1().data(),strGateway.length()); STREAM_PACKET packet; memset(&packet, 0, sizeof(STREAM_PACKET)); memset(packet.SyncHead, 0x7e, 3); memset(packet.ucSerialCode, 0x00, 20); QByteArray ba("Broadcast!"); memcpy(packet.ucSerialCode, ba.data(), ba.size()); packet.iLength = 80; packet.ucCommType = 0X43; memcpy(packet.pDataBuffer, &stTempIp, 80); packet.pDataBuffer[packet.iLength] = GetCheckCodeIn8(&packet.ucCommType,packet.iLength+sizeof(packet.ucCommType)+sizeof(char)*20+sizeof(packet.iLength)); int iLenPacket = packet.iLength+sizeof(int)+3*sizeof(unsigned char)+sizeof(char)+20*sizeof(char)+sizeof(char);/////除正文外的协议结构大小; QUdpSocket *tempUdpSocket = new QUdpSocket(this); if(!tempUdpSocket->bind(entry.ip())) break; tempUdpSocket->writeDatagram((char *)&packet,iLenPacket,broadcastAddress, 31296); } } }); hBox->addWidget(fdDetectCard); hBox->addStretch(); hBox->addWidget(new QLabel("V" APP_VERSION" - " __DATE__)); gVideoCompress = settings.value("VideoCompress", true).toBool(); gVideoTranscoding = settings.value("VideoTranscoding", true).toBool(); gTextAntialiasing = settings.value("TextAntialiasing", false).toBool(); gWidthSplit = settings.value("WidthSplit", false).toBool(); gHideDetect = settings.value("HideDetect", false).toBool(); gShowLora = settings.value("GuangYingPin", false).toBool(); if(gHideDetect) fdDetectCard->hide(); if(! gShowLora) mBtnGrp->button(MainPage_LoraScreen)->hide(); if(settings.value("AddFirewallFlag").toString() !="1") { //添加exe到win防火墙例外 auto appFile = QCoreApplication::applicationFilePath(); appFile.replace('/','\\'); QProcess cmd; connect(&cmd, &QProcess::readyReadStandardOutput, this, [&cmd] { qDebug()<<"out"<checkedAction(); if(act) settings.setValue("Language", act->objectName()); settings.setValue("MainGeo", normalGeometry()); settings.setValue("MainIsMax", isMaximized()); settings.setValue("PlayPos", gPlayPos); if(mDevicePanel->fdIP) { auto ipstr = mDevicePanel->fdIP->toPlainText(); if(! ipstr.isEmpty()) settings.setValue("SpecifyIP", ipstr); else settings.remove("SpecifyIP"); } if(m_pTimerSendResoreIpOneKey) { if(m_pTimerSendResoreIpOneKey->isActive()) m_pTimerSendResoreIpOneKey->stop(); delete m_pTimerSendResoreIpOneKey; } if(mProgPanel) { settings.setValue("ProgramListSortColumn", mProgPanel->mProgTree->sortColumn()); settings.setValue("ProgramListSortOrder", mProgPanel->mProgTree->header()->sortIndicatorOrder()); } } void MainWindow::changeEvent(QEvent *event) { BaseWin::changeEvent(event); if(event->type() == QEvent::LanguageChange) transUi(); } void MainWindow::transUi() { m_wTitle->refreshLable(); mBtnGrp->button(MainPage_DeviceManager)->setText(tr("Device")); mBtnGrp->button(MainPage_ProgManager)->setText(tr("Program")); mBtnGrp->button(MainPage_Setting)->setText(tr("Control")); mBtnGrp->button(MainPage_LoraScreen)->setText(tr("Lora Screen")); fdDetectCard->setText(tr("Check card")); act_lang->setText(tr("Language")); act_help->setText(tr("Help")); actInfo->setText(tr("Info")); act_about->setText(tr("About")); act_update->setText(tr("Check for updates")); actFirmware->setText(tr("firmware manager")); actPreferences->setText(tr("Preferences")); bn_Setting->setToolTip(tr("Setting")); }