123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #ifndef DIALOG_H
- #define DIALOG_H
- #include "mythread.h"
- #include <QDialog>
- #include "serialport/serailport.h"
- #include "hkcamera/hkcamera.h"
- #include<QMessageBox>
- #include <QCloseEvent>
- #include <QSystemTrayIcon>
- #include <QMenu>
- #include <QAction>
- #include <QVBoxLayout>
- #include <QPushButton>
- #include <QApplication>
- namespace Ui {
- class Dialog;
- }
- class Dialog : public QDialog
- {
- Q_OBJECT
- public:
- explicit Dialog(QWidget *parent = nullptr);
- ~Dialog();
- //这是虚函数,重写这个虚函数,当你按下窗口右上角的"×"时,就会调用你所重写的此函数.
- void closeEvent(QCloseEvent* e);
- //protected:
- // void showEvent(QShowEvent *event) override {
- // QDialog::showEvent(event); // 调用基类的showEvent
- // this->showMinimized(); // 在对话框显示后立即最小化
- // }
- private:
- QSystemTrayIcon *trayIcon; // 在这里声明trayIcon
- public:
- void startInBackground() {
- // 设置对话框的布局和控件(这里只添加一个按钮作为示例)
- // auto *layout = new QVBoxLayout(this);
- // auto *button = new QPushButton("Hello, Tray!", this);
- // layout->addWidget(button);
- // 隐藏对话框
- hide();
- // 创建托盘图标
- trayIcon = new QSystemTrayIcon(this);
- trayIcon->setIcon(QIcon("D:/irdet/cfg/ir.jpg")); // 设置图标
- trayIcon->setToolTip("红外缺陷检测"); // 设置提示信息
- // 创建托盘图标的上下文菜单
- QMenu *menu = new QMenu(this);
- QAction *showAction = menu->addAction("Show Dialog");
- QAction *quitAction = menu->addAction("Quit");
- // 连接信号和槽
- connect(showAction, &QAction::triggered, this, &Dialog::show);
- connect(quitAction, &QAction::triggered, qApp, &QApplication::quit);
- connect(trayIcon, &QSystemTrayIcon::activated, this, &Dialog::onTrayIconActivated);
- // 设置托盘图标的上下文菜单
- trayIcon->setContextMenu(menu);
- // 显示托盘图标
- trayIcon->show();
- // 检查系统托盘是否可用
- if (!trayIcon->isSystemTrayAvailable()) {
- // 如果托盘不可用,则可能需要显示对话框或采取其他措施
- QMessageBox::warning(this, "Tray Icon", "System tray is not available.");
- show(); // 显示对话框作为备选方案
- }
- }
- // 槽函数:处理托盘图标的激活事件
- void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason) {
- if (reason == QSystemTrayIcon::Trigger) {
- // 当用户点击托盘图标时显示对话框
- show();
- activateWindow(); // 激活窗口
- raise(); // 将窗口置于其他窗口之上
- }
- }
- private: void irdetnetproc();
- private:
- QTcpSocket* ptcpSocket = nullptr;
- QTcpSocket* ptcpSocket1 = nullptr;
- private slots:
- void on_OpenPortButton_clicked();
- void on_OpenButton_clicked();
- void on_SavePicButton_clicked();
- void on_CloseButton_clicked();
- void on_minimizeButton_clicked() {
- hide(); // 模拟最小化
- }
- //void on_pushButton_clicked();
- void on_SendCmdButton_clicked();
- void grabPicandRes();
- //重写定时器的事件 虚函数 子类重写父类的虚函数
- virtual void timerEvent(QTimerEvent *);
- public:
- Ui::Dialog *ui;
- int hstopheattimerid; //定时器1的唯一标示
- int hkilltimerid; //
- int htimersampleid; //采样定时器
- QString strnewidr = "";
- QString strposition = "";
- qint64 qiheatms = 0;
- public:
- SerailPort* serailPort;
- hkcamera* phkcamera = nullptr;
- //public slots:
- // void slotNewConnection();
- // void slotReadyRead();
- //private:
- // // 负责监听的套接字
- // QTcpServer* m_server;
- // // 负责通信的套接字
- // QTcpSocket* m_client;
- };
- #endif // DIALOG_H
|