mainwidget.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include "mainwidget.h"
  2. #include "qmovewindowmanager.h"
  3. #include "QMouseEvent"
  4. #include <qdebug.h>
  5. #include "../SmartEvaluationLogic/ScanDll.h"
  6. #include "../Util/Util.h"
  7. #include "../Util/typedef_struct.h"
  8. #include <QTimer>
  9. #include "../ZLibWrapLib/ZLibWrapLib.h"
  10. #include <QNetworkRequest>
  11. #include <QNetworkReply>
  12. #include <QJsonObject>
  13. #include <QJsonParseError>
  14. #include <QJsonArray>
  15. #include <QSettings>
  16. #include "updatedlg.h"
  17. #include <QProcess>
  18. //调用WIN API需要用到的头文件与库 [实现缩放]
  19. #ifdef Q_OS_WIN
  20. #include <qt_windows.h>
  21. #include <Windowsx.h>
  22. #include <QMessageBox>
  23. #endif
  24. wstring g_strConfigPath;
  25. MainWidget::MainWidget(QWidget *parent)
  26. : QWidget(parent)
  27. {
  28. ui.setupUi(this);
  29. this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
  30. ui.widget1_head->installEventFilter(new QMoveWindowManager(this));
  31. ui.widget_sys_btn->setControlWidget(this);
  32. ui.stackedWidget_init->setCurrentWidget(ui.page_bindschool);
  33. ui.stackedWidget_exception->setCurrentWidget(ui.page_wellcome);
  34. ui.label_top_school_static->hide();
  35. ui.label_top_school->hide();
  36. ui.widget_index_page->hide();
  37. m_nBorderWidth = 3;
  38. wstring strModuleDir;
  39. GetModuleDir(strModuleDir);
  40. g_strConfigPath = strModuleDir;
  41. g_strConfigPath.append(L"config.ini");
  42. InitScanDll((HWND)this->winId());
  43. showMaximized();
  44. bind_signlslot();
  45. load_schoolinfo();
  46. WCHAR version[MAX_PATH] = { 0 };
  47. GetPrivateProfileString(L"GLOBAL", L"local_version", L"1.0.0", version, MAX_PATH, g_strConfigPath.c_str());
  48. m_localVersion = QString::fromStdWString(wstring(version));
  49. ui.label_version->setText(QString::fromLocal8Bit("当前版本为:%1").arg(m_localVersion));
  50. CheckUpdate();
  51. }
  52. MainWidget::~MainWidget()
  53. {
  54. }
  55. void MainWidget::CheckUpdate() // 检查更新
  56. {
  57. WCHAR server_url[MAX_PATH] = { 0 };
  58. GetPrivateProfileString(L"USER", L"server_url", L"", server_url, MAX_PATH, g_strConfigPath.c_str());
  59. QString url(QString::fromStdWString(server_url));
  60. url.append("/teacher/third/get/latestVersion?appType=0");
  61. QNetworkRequest request;
  62. request.setUrl(url);
  63. request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json;charset=utf-8"));
  64. request.setRawHeader("Authorization", "Basic ZnhiLXNoOmVDbGo0TlRoSHlMY05USE0wZWl3ZWpVUExCcGFlZQ==");//Authorization身份验证
  65. QNetworkAccessManager manager;
  66. manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
  67. QNetworkReply* reply = manager.get(request);
  68. QEventLoop eventLoop;
  69. QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  70. eventLoop.exec();
  71. QByteArray bytes = reply->readAll(); // bytes
  72. QString response = QString::fromUtf8(bytes);
  73. QJsonParseError json_error;
  74. QJsonDocument jsonDoc = QJsonDocument::fromJson(bytes, &json_error);
  75. QString message;
  76. if (jsonDoc.isObject())
  77. {
  78. QJsonObject json_obj = jsonDoc.object();
  79. if (json_obj.contains("code") && json_obj.value("code").toInt() == 200)
  80. {
  81. if (json_obj.contains("data"))
  82. {
  83. QJsonObject json_data = json_obj.value("data").toObject();
  84. QString version = json_data.value("versionNumber").toString();
  85. QString changeLog = json_data.value("changeLog").toString();
  86. QString fileUrl = json_data.value("fileUrl").toString();
  87. if (m_localVersion != version)
  88. {
  89. ui.label_new->setText("new");
  90. QMessageBox box(QMessageBox::Warning, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("发现新版本:%1").arg(version));
  91. box.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  92. box.setButtonText(QMessageBox::Yes, QString::fromLocal8Bit("查看更新"));
  93. box.setButtonText(QMessageBox::No, QString::fromLocal8Bit("以后再说"));
  94. int res=box.exec();
  95. if (res == QMessageBox::Yes)
  96. {
  97. vector<batch_info> vct = m_dataBaseService.GetFailedBatch();
  98. UpdateDlg *updateDlg = new UpdateDlg(changeLog, version, fileUrl, vct.size() > 0 ? true : false);
  99. updateDlg->setAttribute(Qt::WA_ShowModal, true);
  100. updateDlg->show();
  101. int ret = updateDlg->exec();
  102. }
  103. }
  104. else
  105. {
  106. ui.label_new->setText("");
  107. }
  108. }
  109. }
  110. }
  111. }
  112. bool MainWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
  113. {
  114. Q_UNUSED(eventType)
  115. MSG *param = static_cast<MSG *>(message);
  116. switch (param->message)
  117. {
  118. case WM_NCHITTEST:
  119. {
  120. int nX = GET_X_LPARAM(param->lParam) - this->geometry().x();
  121. int nY = GET_Y_LPARAM(param->lParam) - this->geometry().y();
  122. // 如果鼠标位于子控件上,则不进行处理
  123. if (childAt(nX, nY) != nullptr)
  124. return QWidget::nativeEvent(eventType, message, result);
  125. *result = HTCAPTION;
  126. // 鼠标区域位于窗体边框,进行缩放
  127. if ((nX > 0) && (nX < m_nBorderWidth))
  128. *result = HTLEFT;
  129. if ((nX > this->width() - m_nBorderWidth) && (nX < this->width()))
  130. *result = HTRIGHT;
  131. if ((nY > 0) && (nY < m_nBorderWidth))
  132. *result = HTTOP;
  133. if ((nY > this->height() - m_nBorderWidth) && (nY < this->height()))
  134. *result = HTBOTTOM;
  135. if ((nX > 0) && (nX < m_nBorderWidth) && (nY > 0)
  136. && (nY < m_nBorderWidth))
  137. *result = HTTOPLEFT;
  138. if ((nX > this->width() - m_nBorderWidth) && (nX < this->width())
  139. && (nY > 0) && (nY < m_nBorderWidth))
  140. *result = HTTOPRIGHT;
  141. if ((nX > 0) && (nX < m_nBorderWidth)
  142. && (nY > this->height() - m_nBorderWidth) && (nY < this->height()))
  143. *result = HTBOTTOMLEFT;
  144. if ((nX > this->width() - m_nBorderWidth) && (nX < this->width())
  145. && (nY > this->height() - m_nBorderWidth) && (nY < this->height()))
  146. *result = HTBOTTOMRIGHT;
  147. return true;
  148. }
  149. case UM_ULOAD_SUCCESS:
  150. {
  151. slots_bindUnHandle();
  152. }
  153. break;
  154. }
  155. return QWidget::nativeEvent(eventType, message, result);
  156. }