112 lines
3.2 KiB
C++
112 lines
3.2 KiB
C++
|
#include "homewidget.h"
|
||
|
#include "ui_homewidget.h"
|
||
|
|
||
|
HomeWidget::HomeWidget(QWidget *parent) :
|
||
|
QWidget(parent),
|
||
|
ui(new Ui::HomeWidget)
|
||
|
{
|
||
|
// 计时器
|
||
|
timer = new QTimer(this);
|
||
|
connect(timer,&QTimer::timeout,[&]{
|
||
|
QDateTime cur_datetime = QDateTime::currentDateTime();
|
||
|
QString cur_date = cur_datetime.toString("yyyy.MM.dd");
|
||
|
QString cur_time = cur_datetime.toString("hh:mm:ss");
|
||
|
|
||
|
ui->datetimeLabel->setText(cur_date+"\n"+cur_time);
|
||
|
});
|
||
|
|
||
|
timer->start(1000);
|
||
|
|
||
|
ui->setupUi(this);
|
||
|
change_port_label_show(); // 修改串口连接信息
|
||
|
this->setWindowTitle("不知名系统");
|
||
|
this->setWindowIcon(QIcon(":logo"));
|
||
|
|
||
|
// 启用所有按钮
|
||
|
ui->homeBtn->setEnabled(true);
|
||
|
ui->exitBtn->setEnabled(true);
|
||
|
ui->logsBtn->setEnabled(true);
|
||
|
ui->statusBtn->setEnabled(true);
|
||
|
ui->settingBtn->setEnabled(true);
|
||
|
}
|
||
|
|
||
|
HomeWidget::~HomeWidget()
|
||
|
{
|
||
|
delete ui;
|
||
|
delete timer;
|
||
|
}
|
||
|
|
||
|
void HomeWidget::on_exitBtn_clicked()
|
||
|
{
|
||
|
// emit this->exit_to_shell_window();
|
||
|
// this->close();
|
||
|
QApplication::quit();
|
||
|
}
|
||
|
|
||
|
void HomeWidget::on_homeBtn_clicked()
|
||
|
{
|
||
|
ui->homeStackWidget->setCurrentIndex(0);
|
||
|
ui->homeBtn->setEnabled(false); // 按钮按下后禁用当前,并启用其他按钮,防止多次点击
|
||
|
ui->exitBtn->setEnabled(true);
|
||
|
ui->logsBtn->setEnabled(true);
|
||
|
ui->statusBtn->setEnabled(true);
|
||
|
ui->settingBtn->setEnabled(true);
|
||
|
}
|
||
|
|
||
|
void HomeWidget::on_settingBtn_clicked()
|
||
|
{
|
||
|
ui->homeStackWidget->setCurrentIndex(1);
|
||
|
ui->homeBtn->setEnabled(true);
|
||
|
ui->exitBtn->setEnabled(true);
|
||
|
ui->logsBtn->setEnabled(true);
|
||
|
ui->statusBtn->setEnabled(true);
|
||
|
ui->settingBtn->setEnabled(false);
|
||
|
}
|
||
|
|
||
|
void HomeWidget::change_port_label_show()
|
||
|
{
|
||
|
|
||
|
qDebug() <<"可用串口信息"<<endl;
|
||
|
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
|
||
|
for(int i = 0; i<ports.size();i++){
|
||
|
QSerialPortInfo info = ports.at(i);
|
||
|
qDebug() << info.portName();
|
||
|
}
|
||
|
if(ports.size()!=0){ // 当串口不为空时,至少存在一个串口
|
||
|
QSerialPortInfo portid = ports.at(0); // 获取第一个串口
|
||
|
// emit send_connected_port_id(portid.portName()); // 将串口名广播出去
|
||
|
|
||
|
// 将获取的串口信息显示出来
|
||
|
ui->port_con_msg->setStyleSheet("background-color: rgb(0, 170, 255)");
|
||
|
QFont font("微软雅黑",18);
|
||
|
ui->port_con_msg->setFont(font); // 设置字体
|
||
|
ui->port_con_msg->setAlignment(Qt::AlignCenter); // 居中显示
|
||
|
ui->port_con_msg->setText("串口: "+portid.portName()+" 已连接");
|
||
|
|
||
|
}
|
||
|
|
||
|
// qDebug() <<"可用波特率信息"<<endl;
|
||
|
// QList<qint32> rates = QSerialPortInfo::standardBaudRates();
|
||
|
// for(int i=0;i<rates.size();i++){
|
||
|
// qDebug()<<rates.at(i);
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
void HomeWidget::on_statusBtn_clicked()
|
||
|
{
|
||
|
ui->homeBtn->setEnabled(true);
|
||
|
ui->exitBtn->setEnabled(true);
|
||
|
ui->logsBtn->setEnabled(true);
|
||
|
ui->statusBtn->setEnabled(false);
|
||
|
ui->settingBtn->setEnabled(true);
|
||
|
}
|
||
|
|
||
|
void HomeWidget::on_logsBtn_clicked()
|
||
|
{
|
||
|
ui->homeBtn->setEnabled(true);
|
||
|
ui->exitBtn->setEnabled(true);
|
||
|
ui->logsBtn->setEnabled(false);
|
||
|
ui->statusBtn->setEnabled(true);
|
||
|
ui->settingBtn->setEnabled(true);
|
||
|
}
|