Newer
Older
PhaseMeasure / PhaseWindow.cpp
TAN YUE on 27 Dec 2021 3 KB 20211227 界面修改
#include "PhaseWindow.h"
#include "ui_PhaseWindow.h"

#include <iostream>
#include <QTimer>
#include <QDateTime>
#include <QLabel>
#include <QGroupBox>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QDesktopWidget>
#include <QThread>
#include <ChannelItem.h>

PhaseWindow::PhaseWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PhaseWindow)
{
    ui->setupUi(this);

    // 无边框
    this->setWindowFlags(Qt::FramelessWindowHint);

    // 窗口大小为占满一屏
    QRect screenRect = QApplication::desktop()->screenGeometry();
    resize(screenRect.width(), screenRect.height());

    // 将窗口移动到左上角
    move(0, 0);
    ui->exitButt->move(screenRect.width() - 80, 10);
    ui->minButt->move(screenRect.width() - 140, 10);
    ui->settingButt->move(screenRect.width() - 200, 10);
    ui->line->setGeometry(0, 89, screenRect.width(), 1);
    ui->pointsList->setGeometry(250,30,screenRect.width()-500,40);
    ui->labelsList->setGeometry(250,60,screenRect.width()-500,30);

    // 设置主体区域的大小和位置
    ui->scrollArea->setGeometry(0, 90, screenRect.width(), screenRect.height() - 90);
    ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    ui->tim3->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"));

    this->generateWidgetForDevice();

    device = new PhaseDevice(this);
    device->startWork();
    connect(device, &PhaseDevice::sendDataToDraw,
            this, &PhaseWindow::drawPhaseDataOnPage);
}

PhaseWindow::~PhaseWindow()
{
    delete ui;
}

void PhaseWindow::drawPhaseDataOnPage(PhaseDataDto * phaseData)
{
    ui->tim3->setText(phaseData->timestamp);

    // 更新所有通道BOX的值
//    for (int i = 0; i < phaseData->channelActive.size(); i++)
//    {
//        // 获取对应的通道BOX
//        QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(i + 1);

//        // 赋值,对应的lineEdit/label
//        ((QLineEdit *)channelBox->children().at(2))->setText(phaseData->timestamp);
//        ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(phaseData->channelDataStr.at(i)));
//        ((QLineEdit *)channelBox->children().at(6))->setText(phaseData->frameId);
//        ((QLabel *)channelBox->children().at(7))->setText(phaseData->channelActive.at(i) == "1" ? "有效" : "无效");
//    }
}

void PhaseWindow::generateWidgetForDevice()
{
    // 获取设备数据
    int channelNum = 16;

    QRect screenRect = QApplication::desktop()->screenGeometry();

    ui->scrollContents->setGeometry(0, 90, screenRect.width(), channelNum * 170);

    QVBoxLayout * layout = new QVBoxLayout(ui->scrollContents);
    const QFont labelFont("微软雅黑", 10);

    for (int i = 0; i < channelNum; i++)
    {
        QGroupBox * group = new QGroupBox(ui->scrollContents);
        group->setTitle(QString("通道 - %1").arg(i + 1));
        group->setFont(QFont("微软雅黑", 12));
        group->setGeometry(20, i * 160 + 10, screenRect.width() - 40, 160);

        QHBoxLayout * vbox = new QHBoxLayout(group);
        ChannelItem *widget=new ChannelItem();
        widget->setGeometry(10, 0, screenRect.width() - 60, 160);

        vbox->addWidget(widget);
        group->setLayout(vbox);
        layout->addWidget(group);
    }
}


void PhaseWindow::on_minButt_clicked()
{
    setWindowState(Qt::WindowMinimized | windowState());
}

void PhaseWindow::on_exitButt_clicked()
{
    QApplication::exit(0);
}