YunDaISASImageRecognitionService.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "YunDaISASImageRecognitionService.h"
  2. #include "WriteLog.h"
  3. #include <QSystemTrayIcon> //托盘使用的头文件
  4. #include <QMenu>
  5. //#include <stringapiset.h>
  6. //#include <debugapi.h>
  7. //#include "WriteLog.h"
  8. //#include <stringapiset.h>
  9. //#include <debugapi.h>
  10. static QTextBrowser* Browser;
  11. static QImage* image;
  12. static QLabel* label;
  13. static YunDaISASImageRecognitionService* m_self;
  14. static bool IsCenter = true;
  15. static bool IsShowDectect = false;
  16. YunDaISASImageRecognitionService::YunDaISASImageRecognitionService(QWidget *parent)
  17. : QMainWindow(parent)
  18. {
  19. //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
  20. ui.setupUi(this);
  21. m_self = this;
  22. Browser = new QTextBrowser;
  23. // 添加TextBrowser
  24. Browser->setParent(this);
  25. Browser->setGeometry(this->width()*0.7, 0, this->width()*0.3, this->height());
  26. Browser->document()->setMaximumBlockCount(100);
  27. label = new QLabel(this); //创建QLabel控件
  28. label->setGeometry(0, 0, this->width() * 0.7, this->height());
  29. image = new QImage(QStringLiteral("AI.png"));
  30. QPixmap pixmap = QPixmap::fromImage(*image);
  31. label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
  32. label->show();
  33. connect(this, SIGNAL(valueTxtChanged(QString)), this, SLOT(appendText(QString)));
  34. connect(this, SIGNAL(valueImgChanged(QString)), this, SLOT(changeImgShow(QString)));
  35. QApplication::setQuitOnLastWindowClosed(false);
  36. QSystemTrayIcon* trayIcon = new QSystemTrayIcon(m_self);
  37. QIcon icon = QIcon(QStringLiteral("识别服务.png"));
  38. trayIcon->setIcon(icon);
  39. trayIcon->setToolTip(QStringLiteral("识别服务")); //提示文字
  40. QMenu* menu = new QMenu;
  41. QAction* normal, * min, * max, * quit ,/** center,* confidence,*/* showdectect,* noshowdectect;
  42. normal = new QAction( QStringLiteral("显示主界面"));
  43. connect(normal, &QAction::triggered, [&]() {
  44. showNormal();
  45. });
  46. //confidence = new QAction(QStringLiteral("识别最可识别的"));
  47. //connect(confidence, &QAction::triggered, [&]() {
  48. // //showNormal();
  49. // IsCenter = false;
  50. // });
  51. //center = new QAction(QStringLiteral("识别最中间的"));
  52. //connect(center, &QAction::triggered, [&]() {
  53. // IsCenter = true;
  54. // });
  55. showdectect = new QAction(QStringLiteral("显示识别过程"));
  56. connect(showdectect, &QAction::triggered, [&]() {
  57. IsShowDectect = true;
  58. });
  59. noshowdectect = new QAction(QStringLiteral("隐藏识别过程"));
  60. connect(noshowdectect, &QAction::triggered, [&]() {
  61. IsShowDectect = false;
  62. });
  63. min = new QAction(QStringLiteral("最小化"));
  64. connect(min, &QAction::triggered, [&]() {
  65. showMinimized();
  66. });
  67. max = new QAction(QStringLiteral("最大化"));
  68. connect(max, &QAction::triggered, [&]() {
  69. showMaximized();
  70. });
  71. quit = new QAction(QStringLiteral("退出"));
  72. connect(quit, &QAction::triggered, [&]() {
  73. QCoreApplication::quit();
  74. });
  75. menu->addAction(normal);
  76. /* menu->addAction(confidence);
  77. menu->addAction(center);*/
  78. menu->addAction(showdectect);
  79. menu->addAction(noshowdectect);
  80. menu->addAction(min);
  81. menu->addAction(max);
  82. menu->addSeparator();
  83. menu->addAction(quit);
  84. trayIcon->setContextMenu(menu);
  85. // 设置单击显示主界面
  86. connect(trayIcon, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason r) {
  87. if (r == QSystemTrayIcon::ActivationReason::Trigger) emit normal->triggered();
  88. });
  89. // 显示托盘图标
  90. trayIcon->show();
  91. }
  92. YunDaISASImageRecognitionService::~YunDaISASImageRecognitionService()
  93. {}
  94. QTextBrowser* YunDaISASImageRecognitionService::GetQTextBrowser()
  95. {
  96. return Browser;
  97. }
  98. QImage* YunDaISASImageRecognitionService::GetImage()
  99. {
  100. return image;
  101. }
  102. bool YunDaISASImageRecognitionService::GetReconginzeStratgy() {
  103. return IsCenter;
  104. }
  105. bool YunDaISASImageRecognitionService::GetIsShowDectect()
  106. {
  107. return IsShowDectect;
  108. }
  109. void YunDaISASImageRecognitionService::SetImage(QString path)
  110. {
  111. emit m_self->valueImgChanged(path);
  112. }
  113. void YunDaISASImageRecognitionService::appendText(QString msg) {
  114. WriteLog::SaveLog(msg);
  115. Browser->append(msg);
  116. }
  117. void YunDaISASImageRecognitionService::changeImgShow(QString path) {
  118. image->load(path);
  119. QPixmap pixmap = QPixmap::fromImage(*image);
  120. label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
  121. label->show();
  122. }
  123. void YunDaISASImageRecognitionService::ConsoleLog(QString msg)
  124. {
  125. /* WriteLog::SaveLog(msg);
  126. Browser->append(msg);*/
  127. //WriteLog::SaveLog(msg);
  128. //emit DialogReturn(msg);
  129. //ShowValue(msg);
  130. emit m_self->valueTxtChanged(msg);
  131. }
  132. //void YunDaISASImageRecognitionService::ShowValue(QString msg)
  133. //{
  134. // emit pointer_->valueChanged(msg); // 信号发送形式前面的加类静态指针引用
  135. //}
  136. //void YunDaISASImageRecognitionService::ShowValue(QString msg)
  137. //{
  138. // Browser->append(msg);
  139. //}
  140. void YunDaISASImageRecognitionService::resizeEvent(QResizeEvent* event)
  141. {
  142. Browser->setGeometry(this->width() * 0.7, 0, this->width() * 0.3, this->height());
  143. label->setGeometry(0, 0, this->width() * 0.7, this->height());
  144. }