You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.7 KiB
C++
79 lines
3.7 KiB
C++
#ifndef WEIGHUI_H
|
|
#define WEIGHUI_H
|
|
|
|
#include <QMainWindow>
|
|
#include <QTimer>
|
|
#include <QLabel>
|
|
#include <QPixmap>
|
|
#include <QSoundEffect>
|
|
#include <memory>
|
|
#include <thread>
|
|
|
|
class DdsSubscriberApp;
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
namespace Ui {
|
|
class WeighUI;
|
|
}
|
|
QT_END_NAMESPACE
|
|
|
|
class WeighUI : public QMainWindow
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit WeighUI(int domainId = 0, QWidget *parent = nullptr);
|
|
~WeighUI();
|
|
|
|
private slots:
|
|
void onCheckWeightInfoOk(); // 定时检查队列,有 WeightInfoOk 数据就弹窗+播放
|
|
void onCheckWeightInfoError(); // 定时检查队列,有 WeightInfoError 数据就弹窗(样式与 WeightInfoOk 完全一致)
|
|
void onShowPopup(const QString& warningText); // 显示弹窗
|
|
void onPopupClosed(); // 弹窗关闭后处理
|
|
void onCheckSummaryUpdate(); // 定时检查 SummaryUpdate 队列,播放 readcardstart 提示音
|
|
void onCheckRealTimeWeight(); // 实时重量轮询: 根据重量显示/隐藏实时弹窗
|
|
void onEnableRealTimePopup(); // 启动5秒后启用实时弹窗
|
|
|
|
private:
|
|
// 实时重量显示: 与 onShowPopup 中 Warning 弹窗使用完全相同的手法
|
|
// 离屏 800x500 横屏 -> 离屏渲染 -> 旋转 90° -> 嵌入主窗口的 500x800 容器内显示
|
|
void startDdsSubscriber(); // 启动 DDS 订阅线程
|
|
void stopDdsSubscriber(); // 停止 DDS 订阅线程
|
|
void buildRealTimeWeightDisplay(); // 构造实时重量显示控件
|
|
void destroyRealTimeWeightDisplay(); // 销毁实时重量显示控件
|
|
QPixmap renderRealTimePopupContent(const QString& weightText); // 渲染并旋转一次实时弹窗内容
|
|
|
|
Ui::WeighUI *ui;
|
|
QTimer *m_closeTimer; // 关闭弹窗定时器
|
|
QTimer *m_pollTimer; // 轮询 WeightInfoOk 队列的定时器
|
|
QTimer *m_errorPollTimer; // 轮询 WeightInfoError 队列的定时器
|
|
QTimer *m_summaryPollTimer; // 轮询 SummaryUpdate 队列的定时器
|
|
QTimer *m_realTimePollTimer; // 轮询 ScaleInfo 队列的定时器(实时重量)
|
|
QTimer *m_enablePopupTimer; // 启动5秒后启用实时弹窗的定时器
|
|
QLabel *m_imageLabel; // 显示图片的Label
|
|
QWidget *m_popupWidget; // 弹窗Widget (Warning 弹窗, 单独顶层窗口, 5秒后自动关闭)
|
|
QSoundEffect *m_soundEffect; // 称重完成提示音 (sound19.wav)
|
|
QSoundEffect *m_soundReadCardStart; // 读卡成功提示音 (readcardstart.wav)
|
|
QSoundEffect *m_soundError; // 称重异常提示音 (sound51.wav)
|
|
|
|
// 实时重量显示控件(嵌入主窗口内的子控件, 不是顶层窗口, 不受 X11/Wayland 窗口管理器干预)
|
|
// 视觉风格与 Warning 弹窗保持一致: 离屏渲染 -> rotate(90) -> 嵌入容器显示
|
|
QWidget *m_realTimeWeightContainer; // 500x800 显示容器(嵌入到 m_imageLabel 之上)
|
|
QLabel *m_realTimeWeightImage; // 容器内的 QLabel, 显示旋转后的 pixmap
|
|
QWidget *m_realTimePopupSource; // 离屏渲染源(800x500 横屏, WA_DontShowOnScreen)
|
|
QLabel *m_realTimeSourceWeight; // 离屏源内的重量 Label
|
|
QString m_realTimeLastWeightText; // 上次渲染的文本, 文本未变时不重新渲染
|
|
QPixmap m_realTimeLastPixmap; // 缓存的上次渲染结果(旋转后的), 文本未变时直接复用
|
|
bool m_realTimePopupEnabled; // 是否已过5秒、可以显示实时弹窗
|
|
bool m_realTimePopupVisible; // 实时重量显示控件当前是否可见
|
|
|
|
std::shared_ptr<DdsSubscriberApp> m_ddsSubscriber;
|
|
std::thread *m_ddsThread; // DDS 订阅线程
|
|
|
|
int m_domainId = 0; // DDS domain id (可由 --domain 覆盖)
|
|
|
|
protected:
|
|
void closeEvent(QCloseEvent *event) override; // 关闭事件
|
|
};
|
|
|
|
#endif // WEIGHUI_H
|