2020-10-24 11:21:24 +08:00
|
|
|
#include "ToolsUI.h"
|
2020-03-28 21:27:22 +08:00
|
|
|
#include "ui_ToolsUI.h"
|
|
|
|
|
|
2020-05-29 19:30:33 +08:00
|
|
|
|
2021-05-29 11:56:43 +08:00
|
|
|
//消息通过广播和监听处理
|
|
|
|
|
|
|
|
|
|
|
2020-03-28 21:27:22 +08:00
|
|
|
ToolsUI::ToolsUI(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
|
|
|
|
ui(new Ui::ToolsUI)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2020-05-28 18:11:23 +08:00
|
|
|
|
|
|
|
|
//load qss
|
2020-10-15 22:21:38 +08:00
|
|
|
QFile file(":/qss/ToolsUI.qss");
|
2020-05-28 18:11:23 +08:00
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
|
QTextStream filetext(&file);
|
|
|
|
|
QString stylesheet = filetext.readAll();
|
|
|
|
|
this->setStyleSheet(stylesheet);
|
|
|
|
|
file.close();
|
|
|
|
|
|
2021-01-06 16:54:28 +08:00
|
|
|
|
|
|
|
|
//绑定按键和界面
|
|
|
|
|
|
2020-10-07 19:50:45 +08:00
|
|
|
int w = 120;
|
|
|
|
|
int h = 50;
|
2020-10-10 12:12:30 +08:00
|
|
|
|
2021-01-09 18:08:45 +08:00
|
|
|
ui->scrollArea->setFixedWidth(w);
|
|
|
|
|
ui->pushButton_ShowExtern->setFixedSize(w,h);
|
2020-10-10 12:12:30 +08:00
|
|
|
|
2021-01-11 14:23:12 +08:00
|
|
|
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();
|
2021-01-13 17:56:47 +08:00
|
|
|
remotecontrol = new RemoteControl();
|
2020-10-15 22:21:38 +08:00
|
|
|
|
2022-06-15 18:52:14 +08:00
|
|
|
ecu = new ECU();
|
2022-07-16 23:54:47 +08:00
|
|
|
ins = new INS();
|
|
|
|
|
gear = new landinggear();
|
2022-06-15 18:52:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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"));
|
2022-07-16 23:54:47 +08:00
|
|
|
install(ins ,tr("INS") );
|
|
|
|
|
install(gear ,tr("Gear") );
|
2021-06-03 23:01:25 +08:00
|
|
|
|
|
|
|
|
|
2021-03-05 10:22:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-15 22:21:38 +08:00
|
|
|
|
2021-01-07 00:27:32 +08:00
|
|
|
connect(this,SIGNAL(IndexChanged(int)),
|
|
|
|
|
this,SLOT(onTabIndexChanged(int)));
|
2020-10-15 22:21:38 +08:00
|
|
|
|
2021-01-07 00:27:32 +08:00
|
|
|
CurrentIndex = 0;
|
|
|
|
|
emit IndexChanged(CurrentIndex);
|
2020-10-26 21:42:04 +08:00
|
|
|
|
2021-01-07 00:27:32 +08:00
|
|
|
foreach (QPushButton *b, btnList) {
|
2021-01-07 10:55:02 +08:00
|
|
|
if(btnList.key(b) == 0)
|
|
|
|
|
{
|
|
|
|
|
setPushButtonState(b,state::Selected);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setPushButtonState(b,state::unSelected);
|
|
|
|
|
}
|
2021-01-07 00:27:32 +08:00
|
|
|
}
|
2020-03-28 21:27:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ToolsUI::~ToolsUI()
|
|
|
|
|
{
|
2021-01-08 10:39:28 +08:00
|
|
|
foreach (QWidget *w, ToolsList) {
|
|
|
|
|
if(w)
|
|
|
|
|
{
|
|
|
|
|
w->deleteLater();
|
|
|
|
|
w = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 21:27:22 +08:00
|
|
|
delete ui;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-28 18:11:23 +08:00
|
|
|
void ToolsUI::resizeEvent(QResizeEvent *event)
|
2020-03-28 21:27:22 +08:00
|
|
|
{
|
2020-05-28 18:11:23 +08:00
|
|
|
Q_UNUSED(event)
|
2020-03-28 21:27:22 +08:00
|
|
|
|
2021-01-07 00:27:32 +08:00
|
|
|
foreach (QWidget *w, ToolsList) {
|
|
|
|
|
if(w->parent())
|
|
|
|
|
{
|
|
|
|
|
w->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
|
|
|
|
|
}
|
2021-01-06 14:03:02 +08:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 18:11:23 +08:00
|
|
|
update();
|
2020-03-28 21:27:22 +08:00
|
|
|
}
|
|
|
|
|
|
2020-10-15 22:21:38 +08:00
|
|
|
void ToolsUI::setPushButtonState(QWidget *w,state s)
|
|
|
|
|
{
|
|
|
|
|
w->setProperty("state",s);
|
|
|
|
|
w->style()->unpolish(w);
|
|
|
|
|
w->style()->polish(w);
|
|
|
|
|
}
|
2020-05-28 18:11:23 +08:00
|
|
|
|
|
|
|
|
|
2022-06-15 18:52:14 +08:00
|
|
|
void ToolsUI::install(ToolsWidget *widget, QString name)
|
2021-01-06 16:54:28 +08:00
|
|
|
{
|
2021-05-15 15:01:24 +08:00
|
|
|
if(!ToolsList.values().contains(widget))
|
2021-01-06 16:54:28 +08:00
|
|
|
{
|
|
|
|
|
int h = 50;
|
|
|
|
|
int w = 120;
|
|
|
|
|
|
2021-01-09 18:08:45 +08:00
|
|
|
QPushButton *btn = new QPushButton();
|
|
|
|
|
btn->setText(name);
|
2021-01-06 16:54:28 +08:00
|
|
|
btn->setFixedSize(w,h);
|
|
|
|
|
|
2021-05-15 15:01:24 +08:00
|
|
|
btnList.insert(ToolsList.size(),btn);
|
2021-01-06 16:54:28 +08:00
|
|
|
|
2021-01-09 18:08:45 +08:00
|
|
|
connect(btn,&QPushButton::clicked,
|
2021-01-06 16:54:28 +08:00
|
|
|
this,&ToolsUI::btnClicked);
|
|
|
|
|
|
2022-06-15 18:52:14 +08:00
|
|
|
ui->gridLayout_Indexs->addWidget(btn,ToolsList.size(),1);
|
2021-01-11 14:23:12 +08:00
|
|
|
|
|
|
|
|
widget->setParent(ui->frame);
|
2021-01-06 16:54:28 +08:00
|
|
|
widget->setWindowTitle(name);
|
2021-05-15 15:01:24 +08:00
|
|
|
widget->setIcon(widget->Icon());
|
2021-01-11 14:23:12 +08:00
|
|
|
widget->hide();
|
2021-05-15 15:01:24 +08:00
|
|
|
ToolsList.insert(ToolsList.size(),widget);
|
2022-06-15 18:52:14 +08:00
|
|
|
|
|
|
|
|
//接收到信号,每个界面自己解析,获取自己想要的信息
|
|
|
|
|
connect(this,&ToolsUI::recieveData,
|
|
|
|
|
widget,&ToolsWidget::recieveData);
|
2021-01-06 16:54:28 +08:00
|
|
|
}
|
2021-05-15 15:01:24 +08:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
qDebug() << "重复出现" << name;
|
|
|
|
|
}
|
2021-01-06 16:54:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolsUI::btnClicked()
|
|
|
|
|
{
|
|
|
|
|
QObject *obj = sender();
|
2021-01-07 10:55:02 +08:00
|
|
|
|
|
|
|
|
|
2021-01-06 16:54:28 +08:00
|
|
|
QPushButton *btn = qobject_cast<QPushButton *>(obj);
|
|
|
|
|
if(btn)
|
|
|
|
|
{
|
|
|
|
|
int key = btnList.key(btn);
|
2021-01-07 00:27:32 +08:00
|
|
|
CurrentIndex = key;
|
2021-01-06 16:54:28 +08:00
|
|
|
|
2021-01-07 10:55:02 +08:00
|
|
|
setPushButtonState(btn,state::Selected);
|
2021-01-07 00:27:32 +08:00
|
|
|
|
|
|
|
|
foreach (QPushButton *b, btnList) {
|
|
|
|
|
if(b != btn)
|
|
|
|
|
{
|
2021-01-07 10:55:02 +08:00
|
|
|
setPushButtonState(b,state::unSelected);
|
2021-01-07 00:27:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
emit IndexChanged(CurrentIndex);
|
2021-01-06 16:54:28 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-05-28 18:11:23 +08:00
|
|
|
void ToolsUI::onTabIndexChanged(const int &index)//界面选择管理
|
2020-03-28 21:27:22 +08:00
|
|
|
{
|
2021-01-07 00:27:32 +08:00
|
|
|
foreach (int key, ToolsList.keys()) {
|
2021-01-07 10:55:02 +08:00
|
|
|
ToolsWidget *w = ToolsList.value(key);
|
2020-06-04 18:20:13 +08:00
|
|
|
|
2021-01-07 00:27:32 +08:00
|
|
|
if(index == key)
|
2020-10-07 19:50:45 +08:00
|
|
|
{
|
2021-01-07 00:27:32 +08:00
|
|
|
if(w->parent())
|
|
|
|
|
{
|
|
|
|
|
w->show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
w->showNormal();
|
|
|
|
|
w->activateWindow();
|
|
|
|
|
}
|
2020-10-07 19:50:45 +08:00
|
|
|
}
|
2021-01-07 00:27:32 +08:00
|
|
|
else {
|
|
|
|
|
if(w->parent())
|
|
|
|
|
{
|
|
|
|
|
w->hide();
|
|
|
|
|
}
|
2020-10-07 19:50:45 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-05-29 19:30:33 +08:00
|
|
|
}
|
|
|
|
|
|
2021-01-07 00:27:32 +08:00
|
|
|
void ToolsUI::on_pushButton_ShowExtern_clicked()
|
2020-10-26 21:42:04 +08:00
|
|
|
{
|
2021-01-07 10:55:02 +08:00
|
|
|
foreach (ToolsWidget *w, ToolsList) {
|
|
|
|
|
if(ToolsList.key(w,-1) == CurrentIndex)
|
|
|
|
|
{
|
|
|
|
|
if(w->parent())
|
|
|
|
|
{
|
|
|
|
|
w->setFloat();
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 16:07:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-26 21:42:04 +08:00
|
|
|
|