Files
gcs-nf/App/ToolsUI/ToolsUI.cpp
T
2020-12-06 23:06:17 +08:00

755 lines
18 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->pushButton_Inspector->setFixedSize(w,h);
ui->pushButton_Log->setFixedSize(w,h);
ui->pushButton_Replay->setFixedSize(w,h);
ui->pushButton_Console->setFixedSize(w,h);
ui->pushButton_Servos->setFixedSize(w,h);
ui->PowerSystem->setFixedSize(w,h);
ui->ServoSystem->setFixedSize(w,h);
ui->pushButton_ShowExtern->setFixedSize(w,h);
ui->pushButton_CommandBox->setFixedSize(w,h);
ui->pushButton_Diagram->setFixedSize(w,h);
ui->pushButton_Senser->setFixedSize(w,h);
index0 = new Tools_Index0(ui->frame);
index1 = new Tools_Index1(ui->frame);
index1->hide();
index2 = new Tools_Index2(ui->frame);
index2->hide();
index3 = new Tools_Index3(ui->frame);
index3->hide();
index4 = new tools_Index4(ui->frame);
index4->hide();
powersystem = new PowerSystem(ui->frame);
powersystem->hide();
servosystem = new ServoSystem(ui->frame);
servosystem->hide();
command = new CommandBox(ui->frame);
command->hide();
diagram = new Diagram(ui->frame);
diagram->hide();
senser = new Senser(ui->frame);
senser->hide();
//connect(index4,SIGNAL(destroyed(QObject*)))
connect(this,SIGNAL(IndexChanged(int)),
this,SLOT(onTabIndexChanged(int)));
CurrentIndex = 0;
emit IndexChanged(CurrentIndex);
setPushButtonState(ui->pushButton_Inspector,
state::Selected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
}
ToolsUI::~ToolsUI()
{
if(index0)
{
delete index0;
}
if(index1)
{
delete index1;
}
if(index2)
{
delete index2;
}
if(index3)
{
delete index3;
}
if(index4)
{
delete index4;
}
delete ui;
}
void ToolsUI::resizeEvent(QResizeEvent *event)
{
Q_UNUSED(event)
qDebug() << this->x() << this->y();
index0->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
index1->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
index2->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
index3->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
index4->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
powersystem->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
servosystem->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
diagram->setGeometry(0,0,ui->frame->geometry().width(),ui->frame->geometry().height());
senser->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::onTabIndexChanged(const int &index)//界面选择管理
{
if(index == 0)
{
if(index0->parent())
{
index0->show();
}
else
{
index0->showNormal();
index0->activateWindow();
}
}
else {
if(index0->parent())
{
index0->hide();
}
}
if(index == 1)
{
if(index1->parent())
{
index1->show();
}
else
{
index1->showNormal();
index1->activateWindow();
}
}
else {
if(index1->parent())
index1->hide();
}
if(index == 2)
{
if(index2->parent())
{
index2->show();
}
else
{
index2->showNormal();
index2->activateWindow();
}
}
else {
if(index2->parent())
index2->hide();
}
if(index == 3)
{
if(index3->parent())
{
index3->show();
}
else
{
index3->showNormal();
index3->activateWindow();
}
}
else {
if(index3->parent())
index3->hide();
}
if(index == 4)
{
if(index4->parent())
{
index4->show();
}
else
{
index4->showNormal();
index4->activateWindow();
}
}
else {
if(index4->parent())
index4->hide();
}
if(index == 5)
{
if(powersystem->parent())
{
powersystem->show();
}
else
{
powersystem->showNormal();
powersystem->activateWindow();
}
}
else {
if(powersystem->parent())
powersystem->hide();
}
if(index == 6)
{
if(servosystem->parent())
{
servosystem->show();
}
else
{
servosystem->showNormal();
servosystem->activateWindow();
}
}
else {
if(servosystem->parent())
servosystem->hide();
}
if(index == 7)
{
if(command->parent())
{
command->show();
}
else
{
command->showNormal();
command->activateWindow();
}
}
else {
if(command->parent())
command->hide();
}
if(index == 8)
{
if(diagram->parent())
{
diagram->show();
}
else
{
diagram->showNormal();
diagram->activateWindow();
}
}
else {
if(diagram->parent())
diagram->hide();
}
if(index == 9)
{
if(senser->parent())
{
senser->show();
}
else
{
senser->showNormal();
senser->activateWindow();
}
}
else {
if(senser->parent())
senser->hide();
}
}
void ToolsUI::on_pushButton_Inspector_clicked()
{
CurrentIndex = 0;
setPushButtonState(ui->pushButton_Inspector,
state::Selected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_Log_clicked()
{
CurrentIndex = 1;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::Selected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_Replay_clicked()
{
CurrentIndex = 2;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::Selected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_Console_clicked()
{
CurrentIndex = 3;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::Selected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_Servos_clicked()
{
CurrentIndex = 4;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::Selected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_PowerSystem_clicked()
{
CurrentIndex = 5;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::Selected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_ServoSystem_clicked()
{
CurrentIndex = 6;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::Selected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_CommandBox_clicked()
{
CurrentIndex = 7;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::Selected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_Diagram_clicked()
{
CurrentIndex = 8;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::Selected);
setPushButtonState(ui->pushButton_Senser,
state::unSelected);
emit IndexChanged(CurrentIndex);
}
void ToolsUI::on_pushButton_ShowExtern_clicked()
{
switch (CurrentIndex) {
case 0:
index0->setFloat();
break;
case 1:
index1->setFloat();
break;
case 2:
index2->setFloat();
break;
case 3:
index3->setFloat();
break;
case 4:
index4->setFloat();
break;
case 5:
powersystem->setFloat();
break;
case 6:
servosystem->setFloat();
break;
case 7:
command->setFloat();
break;
case 8:
diagram->setFloat();
break;
case 9:
senser->setFloat();
break;
}
}
void ToolsUI::on_pushButton_Senser_clicked()
{
CurrentIndex = 9;
setPushButtonState(ui->pushButton_Inspector,
state::unSelected);
setPushButtonState(ui->pushButton_Log,
state::unSelected);
setPushButtonState(ui->pushButton_Replay,
state::unSelected);
setPushButtonState(ui->pushButton_Console,
state::unSelected);
setPushButtonState(ui->pushButton_Servos,
state::unSelected);
setPushButtonState(ui->PowerSystem,
state::unSelected);
setPushButtonState(ui->ServoSystem,
state::unSelected);
setPushButtonState(ui->pushButton_CommandBox,
state::unSelected);
setPushButtonState(ui->pushButton_Diagram,
state::unSelected);
setPushButtonState(ui->pushButton_Senser,
state::Selected);
emit IndexChanged(CurrentIndex);
}