#include "mainwidget.h" #include "qmovewindowmanager.h" #include "QMouseEvent" #include #include "../SmartEvaluationLogic/ScanDll.h" #include "../Util/Util.h" #include "../Util/typedef_struct.h" #include #include "../ZLibWrapLib/ZLibWrapLib.h" #include #include #include #include #include #include #include "updatedlg.h" #include //调用WIN API需要用到的头文件与库 [实现缩放] #ifdef Q_OS_WIN #include #include #include #endif wstring g_strConfigPath; MainWidget::MainWidget(QWidget *parent) : QWidget(parent) { ui.setupUi(this); this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint); ui.widget1_head->installEventFilter(new QMoveWindowManager(this)); ui.widget_sys_btn->setControlWidget(this); ui.stackedWidget_init->setCurrentWidget(ui.page_bindschool); ui.stackedWidget_exception->setCurrentWidget(ui.page_wellcome); ui.label_top_school_static->hide(); ui.label_top_school->hide(); ui.widget_index_page->hide(); m_nBorderWidth = 3; wstring strModuleDir; GetModuleDir(strModuleDir); g_strConfigPath = strModuleDir; g_strConfigPath.append(L"config.ini"); InitScanDll((HWND)this->winId()); showMaximized(); bind_signlslot(); load_schoolinfo(); WCHAR version[MAX_PATH] = { 0 }; GetPrivateProfileString(L"GLOBAL", L"local_version", L"1.0.0", version, MAX_PATH, g_strConfigPath.c_str()); m_localVersion = QString::fromStdWString(wstring(version)); ui.label_version->setText(QString::fromLocal8Bit("当前版本为:%1").arg(m_localVersion)); CheckUpdate(); } MainWidget::~MainWidget() { } void MainWidget::CheckUpdate() // 检查更新 { WCHAR server_url[MAX_PATH] = { 0 }; GetPrivateProfileString(L"USER", L"server_url", L"", server_url, MAX_PATH, g_strConfigPath.c_str()); QString url(QString::fromStdWString(server_url)); url.append("/teacher/third/get/latestVersion?appType=0"); QNetworkRequest request; request.setUrl(url); request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json;charset=utf-8")); request.setRawHeader("Authorization", "Basic ZnhiLXNoOmVDbGo0TlRoSHlMY05USE0wZWl3ZWpVUExCcGFlZQ==");//Authorization身份验证 QNetworkAccessManager manager; manager.setNetworkAccessible(QNetworkAccessManager::Accessible); QNetworkReply* reply = manager.get(request); QEventLoop eventLoop; QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit())); eventLoop.exec(); QByteArray bytes = reply->readAll(); // bytes QString response = QString::fromUtf8(bytes); QJsonParseError json_error; QJsonDocument jsonDoc = QJsonDocument::fromJson(bytes, &json_error); QString message; if (jsonDoc.isObject()) { QJsonObject json_obj = jsonDoc.object(); if (json_obj.contains("code") && json_obj.value("code").toInt() == 200) { if (json_obj.contains("data")) { QJsonObject json_data = json_obj.value("data").toObject(); QString version = json_data.value("versionNumber").toString(); QString changeLog = json_data.value("changeLog").toString(); QString fileUrl = json_data.value("fileUrl").toString(); if (m_localVersion != version) { ui.label_new->setText("new"); QMessageBox box(QMessageBox::Warning, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("发现新版本:%1").arg(version)); box.setStandardButtons(QMessageBox::Yes | QMessageBox::No); box.setButtonText(QMessageBox::Yes, QString::fromLocal8Bit("查看更新")); box.setButtonText(QMessageBox::No, QString::fromLocal8Bit("以后再说")); int res=box.exec(); if (res == QMessageBox::Yes) { vector vct = m_dataBaseService.GetFailedBatch(); UpdateDlg *updateDlg = new UpdateDlg(changeLog, version, fileUrl, vct.size() > 0 ? true : false); updateDlg->setAttribute(Qt::WA_ShowModal, true); updateDlg->show(); int ret = updateDlg->exec(); } } else { ui.label_new->setText(""); } } } } } bool MainWidget::nativeEvent(const QByteArray &eventType, void *message, long *result) { Q_UNUSED(eventType) MSG *param = static_cast(message); switch (param->message) { case WM_NCHITTEST: { int nX = GET_X_LPARAM(param->lParam) - this->geometry().x(); int nY = GET_Y_LPARAM(param->lParam) - this->geometry().y(); // 如果鼠标位于子控件上,则不进行处理 if (childAt(nX, nY) != nullptr) return QWidget::nativeEvent(eventType, message, result); *result = HTCAPTION; // 鼠标区域位于窗体边框,进行缩放 if ((nX > 0) && (nX < m_nBorderWidth)) *result = HTLEFT; if ((nX > this->width() - m_nBorderWidth) && (nX < this->width())) *result = HTRIGHT; if ((nY > 0) && (nY < m_nBorderWidth)) *result = HTTOP; if ((nY > this->height() - m_nBorderWidth) && (nY < this->height())) *result = HTBOTTOM; if ((nX > 0) && (nX < m_nBorderWidth) && (nY > 0) && (nY < m_nBorderWidth)) *result = HTTOPLEFT; if ((nX > this->width() - m_nBorderWidth) && (nX < this->width()) && (nY > 0) && (nY < m_nBorderWidth)) *result = HTTOPRIGHT; if ((nX > 0) && (nX < m_nBorderWidth) && (nY > this->height() - m_nBorderWidth) && (nY < this->height())) *result = HTBOTTOMLEFT; if ((nX > this->width() - m_nBorderWidth) && (nX < this->width()) && (nY > this->height() - m_nBorderWidth) && (nY < this->height())) *result = HTBOTTOMRIGHT; return true; } case UM_ULOAD_SUCCESS: { slots_bindUnHandle(); } break; } return QWidget::nativeEvent(eventType, message, result); }