YunDaISASImageRecognitionService.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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(sender, &Sender::valueChanged, receiver, &Receiver::updateValue);
  34. connect(this, SIGNAL(valueTxtChanged(QString)), this, SLOT(appendText(QString)));
  35. connect(this, SIGNAL(valueImgChanged(QString)), this, SLOT(changeImgShow(QString)));
  36. QApplication::setQuitOnLastWindowClosed(false);
  37. QSystemTrayIcon* trayIcon = new QSystemTrayIcon(m_self);
  38. QIcon icon = QIcon(QStringLiteral("识别服务.png"));
  39. trayIcon->setIcon(icon);
  40. trayIcon->setToolTip(QStringLiteral("识别服务")); //提示文字
  41. QMenu* menu = new QMenu;
  42. QAction* normal, * min, * max, * quit ,/** center,* confidence,*/* showdectect,* noshowdectect;
  43. normal = new QAction( QStringLiteral("显示主界面"));
  44. connect(normal, &QAction::triggered, [&]() {
  45. showNormal();
  46. });
  47. //confidence = new QAction(QStringLiteral("识别最可识别的"));
  48. //connect(confidence, &QAction::triggered, [&]() {
  49. // //showNormal();
  50. // IsCenter = false;
  51. // });
  52. //center = new QAction(QStringLiteral("识别最中间的"));
  53. //connect(center, &QAction::triggered, [&]() {
  54. // IsCenter = true;
  55. // });
  56. showdectect = new QAction(QStringLiteral("显示识别过程"));
  57. connect(showdectect, &QAction::triggered, [&]() {
  58. IsShowDectect = true;
  59. });
  60. noshowdectect = new QAction(QStringLiteral("隐藏识别过程"));
  61. connect(noshowdectect, &QAction::triggered, [&]() {
  62. IsShowDectect = false;
  63. });
  64. min = new QAction(QStringLiteral("最小化"));
  65. connect(min, &QAction::triggered, [&]() {
  66. showMinimized();
  67. });
  68. max = new QAction(QStringLiteral("最大化"));
  69. connect(max, &QAction::triggered, [&]() {
  70. showMaximized();
  71. });
  72. quit = new QAction(QStringLiteral("退出"));
  73. connect(quit, &QAction::triggered, [&]() {
  74. QCoreApplication::quit();
  75. });
  76. menu->addAction(normal);
  77. /* menu->addAction(confidence);
  78. menu->addAction(center);*/
  79. menu->addAction(showdectect);
  80. menu->addAction(noshowdectect);
  81. menu->addAction(min);
  82. menu->addAction(max);
  83. menu->addSeparator();
  84. menu->addAction(quit);
  85. trayIcon->setContextMenu(menu);
  86. // 设置单击显示主界面
  87. connect(trayIcon, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason r) {
  88. if (r == QSystemTrayIcon::ActivationReason::Trigger) emit normal->triggered();
  89. });
  90. // 显示托盘图标
  91. trayIcon->show();
  92. }
  93. YunDaISASImageRecognitionService::~YunDaISASImageRecognitionService()
  94. {}
  95. QTextBrowser* YunDaISASImageRecognitionService::GetQTextBrowser()
  96. {
  97. return Browser;
  98. }
  99. QImage* YunDaISASImageRecognitionService::GetImage()
  100. {
  101. return image;
  102. }
  103. bool YunDaISASImageRecognitionService::GetReconginzeStratgy() {
  104. return IsCenter;
  105. }
  106. bool YunDaISASImageRecognitionService::GetIsShowDectect()
  107. {
  108. return IsShowDectect;
  109. }
  110. void YunDaISASImageRecognitionService::SetImage(QString path)
  111. {
  112. emit m_self->valueImgChanged(path);
  113. }
  114. void YunDaISASImageRecognitionService::appendText(QString msg) {
  115. WriteLog::SaveLog(msg);
  116. Browser->append(msg);
  117. }
  118. void YunDaISASImageRecognitionService::changeImgShow(QString path) {
  119. image->load(path);
  120. QPixmap pixmap = QPixmap::fromImage(*image);
  121. label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
  122. label->show();
  123. }
  124. void YunDaISASImageRecognitionService::ConsoleLog(QString msg)
  125. {
  126. /* WriteLog::SaveLog(msg);
  127. Browser->append(msg);*/
  128. //WriteLog::SaveLog(msg);
  129. //emit DialogReturn(msg);
  130. //ShowValue(msg);
  131. emit m_self->valueTxtChanged(msg);
  132. }
  133. //void YunDaISASImageRecognitionService::ShowValue(QString msg)
  134. //{
  135. // emit pointer_->valueChanged(msg); // 信号发送形式前面的加类静态指针引用
  136. //}
  137. //void YunDaISASImageRecognitionService::ShowValue(QString msg)
  138. //{
  139. // Browser->append(msg);
  140. //}
  141. void YunDaISASImageRecognitionService::resizeEvent(QResizeEvent* event)
  142. {
  143. Browser->setGeometry(this->width() * 0.7, 0, this->width() * 0.3, this->height());
  144. label->setGeometry(0, 0, this->width() * 0.7, this->height());
  145. }