Files
gcs-nf/App/ToolsUI/ToolsUI.cpp
T
2022-08-24 11:51:28 +08:00

371 lines
8.8 KiB
C++

#include "ToolsUI.h"
#include "ui_ToolsUI.h"
//消息通过广播和监听处理
ToolsUI::ToolsUI(QWidget *parent) :
QWidget(parent),
ui(new Ui::ToolsUI)
{
ui->setupUi(this);
//load qss
QFile file(":/qss/ToolsUI.qss");
file.open(QFile::ReadOnly);
QTextStream filetext(&file);
QString stylesheet = filetext.readAll();
this->setStyleSheet(stylesheet);
file.close();
//绑定按键和界面
int w = 120;
int h = 50;
ui->scrollArea->setFixedWidth(w);
ui->pushButton_ShowExtern->setFixedSize(w,h);
connect(this, &ToolsUI::recieveData, this, &ToolsUI::recieveDataSlot);
index0 = new Tools_Index0();
index1 = new Tools_Index1();
index2 = new Tools_Index2();
index3 = new Tools_Index3();
index4 = new tools_Index4();
command = new CommandBox();
senser = new Senser();
remotecontrol = new RemoteControl();
ecu = new ECU();
ins = new INS();
gear = new landinggear();
install(index0 ,tr("Inspector"));
install(index1 ,tr("Log"));
install(index2 ,tr("Replay"));
install(index3 ,tr("Terminal"));
install(index4 ,tr("Servos"));
install(command ,tr("CommandBox"));
install(senser ,tr("Senser"));
install(remotecontrol,tr("RC"));
install(ecu ,tr("ECU"));
install(ins ,tr("INS") );
install(gear ,tr("Gear") );
connect(this,SIGNAL(IndexChanged(int)),
this,SLOT(onTabIndexChanged(int)));
CurrentIndex = 0;
emit IndexChanged(CurrentIndex);
foreach (QPushButton *b, btnList) {
if(btnList.key(b) == 0)
{
setPushButtonState(b,state::Selected);
}
else
{
setPushButtonState(b,state::unSelected);
}
}
//测试
/*
connect(&timer, &QTimer::timeout,
this, [this]()
{
QByteArray array;
for(int i = 0; i < 100; ++i)
{
char ch = rand();
array.append(ch);
}
emit recieveData(1, array);
});
timer.start(1000);
*/
}
ToolsUI::~ToolsUI()
{
foreach (QWidget *w, ToolsList) {
if(w)
{
w->deleteLater();
w = nullptr;
}
}
delete ui;
}
void ToolsUI::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event)
foreach (QWidget *w, ToolsList) {
if(w->parent())
{
w->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
}
}
update();
}
void ToolsUI::setPushButtonState(QWidget *w,state s)
{
w->setProperty("state",s);
w->style()->unpolish(w);
w->style()->polish(w);
}
void ToolsUI::install(ToolsWidget *widget, QString name)
{
if(!ToolsList.values().contains(widget))
{
int h = 50;
int w = 120;
QPushButton *btn = new QPushButton();
btn->setText(name);
btn->setFixedSize(w,h);
btnList.insert(ToolsList.size(),btn);
connect(btn,&QPushButton::clicked,
this,&ToolsUI::btnClicked);
ui->gridLayout_Indexs->addWidget(btn,ToolsList.size(),1);
widget->setParent(ui->frame);
widget->setWindowTitle(name);
widget->setIcon(widget->Icon());
widget->hide();
ToolsList.insert(ToolsList.size(),widget);
//接收到信号,每个界面自己解析,获取自己想要的信息
// connect(this,&ToolsUI::recieveData,
// widget,&ToolsWidget::recieveData);
}
else
{
qDebug() << "重复出现" << name;
}
}
void ToolsUI::btnClicked()
{
QObject *obj = sender();
QPushButton *btn = qobject_cast<QPushButton *>(obj);
if(btn)
{
int key = btnList.key(btn);
CurrentIndex = key;
setPushButtonState(btn,state::Selected);
foreach (QPushButton *b, btnList) {
if(b != btn)
{
setPushButtonState(b,state::unSelected);
}
}
emit IndexChanged(CurrentIndex);
}
}
void ToolsUI::recieveDataSlot(const int &id, const QByteArray &data)
{
//qDebug() << "tools thread:" << QThread::currentThreadId();
Parse *parse = new Parse;
connect(this,&ToolsUI::parseData,
parse,&Parse::parseData);
if(id == 0)
{
connect(parse,&Parse::INS_Info,
ins,&INS::INS_Info);
connect(parse,&Parse::NAV_Info,
ins,&INS::NAV_Info);
connect(parse,&Parse::imu_info,
ins,&INS::imu);
connect(parse,&Parse::euler_info,
ins,&INS::euler);
connect(parse,&Parse::gear_Info,
gear,&landinggear::gear_Info);
connect(parse,&Parse::actuator_info,
gear,&landinggear::actuator_info);
connect(parse,&Parse::actuator_info_brake,
gear,&landinggear::actuator_info_brake);
connect(parse,&Parse::actuator1_info,
gear,&landinggear::actuator1_info);
connect(parse,&Parse::actuator2_info,
gear,&landinggear::actuator2_info);
//this
connect(parse,&Parse::INS_Info,
this,&ToolsUI::INS_Info);
connect(parse,&Parse::NAV_Info,
this,&ToolsUI::NAV_Info);
connect(parse,&Parse::imu_info,
this,&ToolsUI::imu_info);
connect(parse,&Parse::euler_info,
this,&ToolsUI::euler_info);
connect(parse,&Parse::gear_Info,
this,&ToolsUI::gear_Info);
connect(parse,&Parse::actuator_info,
this,&ToolsUI::actuator_info);
connect(parse,&Parse::actuator_info_brake,
this,&ToolsUI::actuator_info_brake);
connect(parse,&Parse::actuator1_info,
this,&ToolsUI::actuator1_info);
connect(parse,&Parse::actuator2_info,
this,&ToolsUI::actuator2_info);
}
else if(id == 1)
{
connect(parse,&Parse::EADC_Info,
ecu,&ECU::EADC_Info);
connect(parse,&Parse::ECU_Info,
ecu,&ECU::ECU_Info);
connect(parse,&Parse::SSPC_Info,
ecu,&ECU::SSPC_Info);
connect(parse,&Parse::SSPC_Info_state,
ecu,&ECU::SSPC_Info_state);
connect(parse,&Parse::vel_info,
ins,&INS::vel);
connect(parse,&Parse::pos_info,
ins,&INS::pos);
connect(parse,&Parse::actuator_info,
gear,&landinggear::actuator_info);
connect(parse,&Parse::actuator1_info,
gear,&landinggear::actuator1_info);
connect(parse,&Parse::actuator2_info,
gear,&landinggear::actuator2_info);
//=========================================
connect(parse,&Parse::EADC_Info,
this,&ToolsUI::EADC_Info);
connect(parse,&Parse::ECU_Info,
this,&ToolsUI::ECU_Info);
connect(parse,&Parse::SSPC_Info,
this,&ToolsUI::SSPC_Info);
connect(parse,&Parse::SSPC_Info_state,
this,&ToolsUI::SSPC_Info_state);
connect(parse,&Parse::vel_info,
this,&ToolsUI::vel_info);
connect(parse,&Parse::pos_info,
this,&ToolsUI::pos_info);
connect(parse,&Parse::actuator_info,
this,&ToolsUI::actuator_info);
connect(parse,&Parse::actuator1_info,
this,&ToolsUI::actuator1_info);
connect(parse,&Parse::actuator2_info,
this,&ToolsUI::actuator2_info);
}
QThreadPool::globalInstance()->start(parse);
//emit parseData(id,data);
parse->parseData(id, data);
}
void ToolsUI::onTabIndexChanged(const int &index)//界面选择管理
{
foreach (int key, ToolsList.keys()) {
ToolsWidget *w = ToolsList.value(key);
if(index == key)
{
if(w->parent())
{
w->show();
}
else
{
w->showNormal();
w->activateWindow();
}
}
else {
if(w->parent())
{
w->hide();
}
}
}
}
void ToolsUI::on_pushButton_ShowExtern_clicked()
{
foreach (ToolsWidget *w, ToolsList) {
if(ToolsList.key(w,-1) == CurrentIndex)
{
if(w->parent())
{
w->setFloat();
}
}
}
}