parent
71b42aa414
commit
ba8847d7b4
@ -0,0 +1,43 @@
|
|||||||
|
#include "weighui.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
#include <QCommandLineOption>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
// 使用 linuxfb 平台
|
||||||
|
qputenv("QT_QPA_PLATFORM", "linuxfb");
|
||||||
|
qputenv("QT_PLUGIN_PATH", "/userdata/lib/qt/plugins");
|
||||||
|
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
// ── 解析命令行参数 ──
|
||||||
|
QCommandLineParser parser;
|
||||||
|
parser.setApplicationDescription("WeighUI - 称重系统 UI");
|
||||||
|
parser.addHelpOption();
|
||||||
|
parser.addVersionOption();
|
||||||
|
|
||||||
|
QCommandLineOption domainOpt(QStringList() << "d" << "domain",
|
||||||
|
"DDS domain id (default 0).",
|
||||||
|
"id", "0");
|
||||||
|
parser.addOption(domainOpt);
|
||||||
|
|
||||||
|
parser.process(a);
|
||||||
|
|
||||||
|
bool ok = false;
|
||||||
|
int domainId = parser.value(domainOpt).toInt(&ok);
|
||||||
|
if (!ok || domainId < 0) {
|
||||||
|
qWarning() << "Invalid --domain value:" << parser.value(domainOpt)
|
||||||
|
<< ", fallback to 0";
|
||||||
|
domainId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << "WeighUI 启动, DDS domain =" << domainId;
|
||||||
|
|
||||||
|
WeighUI w(domainId);
|
||||||
|
w.show();
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
import QtQuick 2.15
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: root
|
||||||
|
width: 800
|
||||||
|
height: 1280
|
||||||
|
color: "white"
|
||||||
|
|
||||||
|
Image {
|
||||||
|
id: backgroundImage
|
||||||
|
anchors.fill: parent
|
||||||
|
source: "qrc:/123.png"
|
||||||
|
fillMode: Image.PreserveAspectFit
|
||||||
|
smooth: true
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
console.log("QML: 图片加载中...")
|
||||||
|
}
|
||||||
|
|
||||||
|
onStatusChanged: {
|
||||||
|
if (status === Image.Error) {
|
||||||
|
console.log("QML: 图片加载失败")
|
||||||
|
placeholderText.visible = true
|
||||||
|
} else if (status === Image.Ready) {
|
||||||
|
console.log("QML: 图片加载成功")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
id: placeholderText
|
||||||
|
anchors.centerIn: parent
|
||||||
|
text: "背景图片加载失败"
|
||||||
|
color: "red"
|
||||||
|
font.pixelSize: 24
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
anchors.centerIn: parent
|
||||||
|
text: "QML 界面已显示"
|
||||||
|
font.pixelSize: 40
|
||||||
|
color: "blue"
|
||||||
|
visible: false
|
||||||
|
}
|
||||||
|
|
||||||
|
Component.onCompleted: {
|
||||||
|
console.log("QML: 界面初始化完成")
|
||||||
|
placeholderText.visible = true
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
#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
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>WeighUI</class>
|
||||||
|
<widget class="QMainWindow" name="WeighUI">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>600</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>WeighUI</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="centralwidget"/>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>27</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
Loading…
Reference in New Issue