123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #include "YunDaISASImageRecognitionService.h"
- #include "WriteLog.h"
- #include <QSystemTrayIcon> //托盘使用的头文件
- #include <QMenu>
- //#include <stringapiset.h>
- //#include <debugapi.h>
- //#include "WriteLog.h"
- //#include <stringapiset.h>
- //#include <debugapi.h>
- static QTextBrowser* Browser;
- static QImage* image;
- static QLabel* label;
- static YunDaISASImageRecognitionService* m_self;
- static bool IsCenter = true;
- static bool IsShowDectect = false;
- YunDaISASImageRecognitionService::YunDaISASImageRecognitionService(QWidget *parent)
- : QMainWindow(parent)
- {
- //QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GBK"));
- ui.setupUi(this);
- m_self = this;
- Browser = new QTextBrowser;
- // 添加TextBrowser
- Browser->setParent(this);
- Browser->setGeometry(this->width()*0.7, 0, this->width()*0.3, this->height());
- Browser->document()->setMaximumBlockCount(100);
- label = new QLabel(this); //创建QLabel控件
- label->setGeometry(0, 0, this->width() * 0.7, this->height());
- image = new QImage(QStringLiteral("AI.png"));
- QPixmap pixmap = QPixmap::fromImage(*image);
- label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
- label->show();
-
-
- connect(this, SIGNAL(valueTxtChanged(QString)), this, SLOT(appendText(QString)));
- connect(this, SIGNAL(valueImgChanged(QString)), this, SLOT(changeImgShow(QString)));
-
-
- QApplication::setQuitOnLastWindowClosed(false);
- QSystemTrayIcon* trayIcon = new QSystemTrayIcon(m_self);
- QIcon icon = QIcon(QStringLiteral("识别服务.png"));
- trayIcon->setIcon(icon);
- trayIcon->setToolTip(QStringLiteral("识别服务")); //提示文字
- QMenu* menu = new QMenu;
- QAction* normal, * min, * max, * quit ,/** center,* confidence,*/* showdectect,* noshowdectect;
- normal = new QAction( QStringLiteral("显示主界面"));
- connect(normal, &QAction::triggered, [&]() {
- showNormal();
- });
- //confidence = new QAction(QStringLiteral("识别最可识别的"));
- //connect(confidence, &QAction::triggered, [&]() {
- // //showNormal();
- // IsCenter = false;
- // });
- //center = new QAction(QStringLiteral("识别最中间的"));
- //connect(center, &QAction::triggered, [&]() {
- // IsCenter = true;
- // });
- showdectect = new QAction(QStringLiteral("显示识别过程"));
- connect(showdectect, &QAction::triggered, [&]() {
- IsShowDectect = true;
- });
- noshowdectect = new QAction(QStringLiteral("隐藏识别过程"));
- connect(noshowdectect, &QAction::triggered, [&]() {
- IsShowDectect = false;
- });
- min = new QAction(QStringLiteral("最小化"));
- connect(min, &QAction::triggered, [&]() {
- showMinimized();
- });
- max = new QAction(QStringLiteral("最大化"));
- connect(max, &QAction::triggered, [&]() {
- showMaximized();
- });
- quit = new QAction(QStringLiteral("退出"));
- connect(quit, &QAction::triggered, [&]() {
- QCoreApplication::quit();
- });
- menu->addAction(normal);
- /* menu->addAction(confidence);
- menu->addAction(center);*/
- menu->addAction(showdectect);
- menu->addAction(noshowdectect);
- menu->addAction(min);
- menu->addAction(max);
- menu->addSeparator();
- menu->addAction(quit);
- trayIcon->setContextMenu(menu);
- // 设置单击显示主界面
- connect(trayIcon, &QSystemTrayIcon::activated, [=](QSystemTrayIcon::ActivationReason r) {
- if (r == QSystemTrayIcon::ActivationReason::Trigger) emit normal->triggered();
- });
- // 显示托盘图标
- trayIcon->show();
- }
- YunDaISASImageRecognitionService::~YunDaISASImageRecognitionService()
- {}
- QTextBrowser* YunDaISASImageRecognitionService::GetQTextBrowser()
- {
- return Browser;
- }
- QImage* YunDaISASImageRecognitionService::GetImage()
- {
- return image;
- }
- bool YunDaISASImageRecognitionService::GetReconginzeStratgy() {
- return IsCenter;
- }
- bool YunDaISASImageRecognitionService::GetIsShowDectect()
- {
- return IsShowDectect;
- }
- void YunDaISASImageRecognitionService::SetImage(QString path)
- {
- emit m_self->valueImgChanged(path);
- }
- void YunDaISASImageRecognitionService::appendText(QString msg) {
- WriteLog::SaveLog(msg);
- Browser->append(msg);
- }
- void YunDaISASImageRecognitionService::changeImgShow(QString path) {
- image->load(path);
- QPixmap pixmap = QPixmap::fromImage(*image);
- label->setPixmap(pixmap.scaled(label->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
- label->show();
- }
- void YunDaISASImageRecognitionService::ConsoleLog(QString msg)
- {
- /* WriteLog::SaveLog(msg);
- Browser->append(msg);*/
- //WriteLog::SaveLog(msg);
- //emit DialogReturn(msg);
- //ShowValue(msg);
- emit m_self->valueTxtChanged(msg);
-
- }
- //void YunDaISASImageRecognitionService::ShowValue(QString msg)
- //{
- // emit pointer_->valueChanged(msg); // 信号发送形式前面的加类静态指针引用
- //}
- //void YunDaISASImageRecognitionService::ShowValue(QString msg)
- //{
- // Browser->append(msg);
- //}
- void YunDaISASImageRecognitionService::resizeEvent(QResizeEvent* event)
- {
- Browser->setGeometry(this->width() * 0.7, 0, this->width() * 0.3, this->height());
- label->setGeometry(0, 0, this->width() * 0.7, this->height());
- }
|