Files
CalibratorLauncher/widgets/channelstatuswidget.h
2026-01-02 19:20:35 +09:00

99 lines
2.6 KiB
C++

#ifndef CHANNELSTATUSWIDGET_H
#define CHANNELSTATUSWIDGET_H
#include "../hardware/channelmanager.h"
#include <QWidget>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPainter>
/**
* @brief 通道状态显示组件
*
* 用于显示单个通道的状态,包括:
* - 通道连接器图形(显示接线端子和线色)
* - 通道名称
* - 当前操作状态
* - 接线信息(详细模式下)
*/
class ChannelStatusWidget : public QWidget
{
Q_OBJECT
public:
/**
* @brief 显示模式
*/
enum DisplayMode
{
OVERVIEW_MODE, // 概览模式 - 只显示通道名称和连接器图形
DETAILED_MODE // 详细模式 - 显示状态文本和接线信息
};
explicit ChannelStatusWidget(ChannelManager::ChannelId channelId,
const QString &channelName,
QWidget *parent = nullptr,
DisplayMode mode = OVERVIEW_MODE);
void updateStatus(ChannelManager::OperationType operation,
const QString &description);
void setDisplayMode(DisplayMode mode);
DisplayMode displayMode() const { return m_displayMode; }
ChannelManager::ChannelId channelId() const { return m_channelId; }
ChannelManager::OperationType currentOperation() const { return m_currentOperation; }
protected:
void paintEvent(QPaintEvent *event) override;
private:
ChannelManager::ChannelId m_channelId;
QString m_channelName;
ChannelManager::OperationType m_currentOperation;
QString m_description;
ChannelManager *m_channelManager;
DisplayMode m_displayMode;
void drawChannelConnector(QPainter &painter, const QRect &rect);
QColor getStatusColor() const;
};
/**
* @brief 通道状态面板
*
* 显示所有通道的状态,支持水平和垂直布局
*/
class ChannelStatusPanel : public QWidget
{
Q_OBJECT
public:
enum LayoutOrientation
{
HORIZONTAL,
VERTICAL
};
explicit ChannelStatusPanel(QWidget *parent = nullptr,
LayoutOrientation orientation = HORIZONTAL);
void setDisplayMode(ChannelStatusWidget::DisplayMode mode);
void refresh();
public slots:
void onChannelStatusChanged(ChannelManager::ChannelId channel,
ChannelManager::OperationType operation,
const QString &description);
private:
QMap<ChannelManager::ChannelId, ChannelStatusWidget *> m_channelWidgets;
ChannelManager *m_channelManager;
ChannelStatusWidget::DisplayMode m_displayMode;
void setupUI(LayoutOrientation orientation);
};
#endif // CHANNELSTATUSWIDGET_H