QT 蓝牙通信.zip
#include "control.h"
#include <qdebug.h>
#include <QMessageBox>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QTime>
/* 外部变量,定义在BLE.cpp里 蓝牙连接成功后的socket */
Control::Control(int w, int h, QTabWidget *parent) :
QTabWidget(parent)
{
// BTE = new BlueTooth(w,h);
this->setFixedSize(w,h);
QFont titleFont;//标题文字字体
titleFont.setPointSize(25);
//titleFont.setBold(true);
setFont(titleFont);
for(int i = 0;i<30;i++){
classroom.sit[i] = 0;
}
QWidget *wnd1 = new QWidget;
QWidget *wnd2 = new QWidget;
QWidget *wnd3 = new QWidget;
wnd1->setFont(titleFont);
wnd2->setFont(titleFont);
this->addTab(wnd1,"教室设置");
this->addTab(wnd2,"参数输入");
this->addTab(wnd3,"聊天窗口");
//-----------------------------------------------------wnd1
floorCob = new QComboBox;
floorCob->addItems( QStringList()<<tr("1层")
<<tr("2层")<<tr("3层")<<tr("4层")<<tr("5层") );
floorCob->setCurrentIndex(0);
floorCob->setFixedSize(0.35*w,0.07*h);
classroomCob = new QComboBox;
classroomCob->addItems( QStringList()<<tr("101")
<<tr("102")<<tr("103")<<tr("104")<<tr("105") );
classroomCob->setCurrentIndex(0);
classroomCob->setFixedSize(0.35 *w,0.07*h);
QPushButton *backbtn = new QPushButton;
backbtn->setText("返回");
backbtn->setFixedSize(0.2 *w,0.07*h);
connect(floorCob, SIGNAL(currentIndexChanged(int)), this, SLOT(changeFloor(int)));
connect(classroomCob, SIGNAL(currentIndexChanged(int)), this, SLOT(changeClassroom(int)));
connect(backbtn, SIGNAL(clicked( )), this, SLOT(on_pushButton_back_clicked( )));
QHBoxLayout *comlay = new QHBoxLayout;
comlay->addWidget(floorCob);
comlay->addWidget(classroomCob);
comlay->addWidget(backbtn);
QVBoxLayout *sitlay_v = new QVBoxLayout;
for(int i = 0;i<6;i++){
QHBoxLayout *sitlay_h = new QHBoxLayout;
for(int j = 0;j<5;j++){
sit[i][j] = new topmenubtn;
sitlay_h->addWidget(sit[i][j]);
sit[i][j]->setFixedSize(0.98*w*0.18,0.88*h/7);
sit[i][j]->setFont(titleFont);
sit[i][j]->setText(QString("%1").arg(i*5+j+1));
sit[i][j]->setAlignment( Qt::AlignCenter|Qt::AlignVCenter );//
sit[i][j]->setStyleSheet("background-color:rgb(252,227,239);");
connect(sit[i][j], SIGNAL(Clicked( )), this, SLOT(chooseSit( )));
}
sitlay_v->addLayout(sitlay_h);
sitlay_v->setMargin(0);
}
QVBoxLayout *ALL1 = new QVBoxLayout;
ALL1->addLayout(comlay);
ALL1->addLayout(sitlay_v);
ALL1->addStretch();
ALL1->setMargin(0);
wnd1->setLayout(ALL1);
//-----------------------------------------------------wnd2
QLabel *na1 = new QLabel;
na1->setText("设置温度:");
na1->setFixedSize(0.4 *w,0.1*h);
QLabel *na11 = new QLabel;
na11->setText("℃");
na11->setFixedSize(0.1 *w,0.1*h);
TEM_led = new QLineEdit;
TEM_led->setFixedSize(0.4 *w,0.1*h);
connect(TEM_led, SIGNAL(textEdited(QString)), this, SLOT(changetemp(QString)));
QHBoxLayout *set1_h = new QHBoxLayout;
set1_h->addWidget(na1);
set1_h->addWidget(TEM_led);
set1_h->addWidget(na11);
QLabel *na2 = new QLabel;
na2->setText("设置风速:");
na2->setFixedSize(0.4 *w,0.1*h);
QLabel *na21 = new QLabel;
na21->setText("米/秒");
na21->setFixedSize(0.1 *w,0.1*h);
windspd_led = new QLineEdit;
connect(windspd_led, SIGNAL(textEdited(QString)), this, SLOT(changewindspd(QString)));
windspd_led->setFixedSize(0.4 *w,0.1*h);
QHBoxLayout *set2_h = new QHBoxLayout;
set2_h->addWidget(na2);
set2_h->addWidget(windspd_led);
set2_h->addWidget(na21);
QLabel *na3 = new QLabel;
na3->setText("设置时间:");
na3->setFixedSize(0.4 *w,0.1*h);
timeCob_h = new QComboBox;
timeCob_h->addItems( QStringList()<<tr("00:00")<<tr("01:00")<<tr("02:00")<<tr("03:00")<<tr("04:00")<<tr("05:00")<<tr("06:00")<<tr("07:00")<<tr("08:00")<<tr("09:00")<<tr("10:00")<<tr("11:00")<<tr("12:00") <<tr("13:00") <<tr("14:00")<<tr("15:00")<<tr("16:00")<<tr("17:00")<<tr("18:00")<<tr("19:00")<<tr("20:00")<<tr("21:00")<<tr("22:00")<<tr("23:00") );
timeCob_h->setCurrentIndex(0);
timeCob_h->setFixedSize(0.5 *w,0.1*h);
connect(timeCob_h, SIGNAL(currentIndexChanged(int)), this, SLOT(changeclock(int)));
QHBoxLayout *set3_h = new QHBoxLayout;
set3_h->addWidget(na3);
set3_h->addWidget(timeCob_h);
QLabel *na4 = new QLabel;
na4->setText("设置月份:");
na4->setFixedSize(0.4 *w,0.1*h);
monthCob = new QComboBox;
monthCob->addItems( QStringList()<<tr("1月")<<tr("2月")<<tr("3月")<<tr("4月")<<tr("5月")<<tr("6月")<<tr("7月")<<tr("8月")<<tr("9月")<<tr("10月")<<tr("11月") <<tr("12月") );
monthCob->setCurrentIndex(0);
connect(monthCob, SIGNAL(currentIndexChanged(int)), this, SLOT(changemonth(int)));
monthCob->setFixedSize(0.5 *w,0.1*h);
QHBoxLayout *set4_h = new QHBoxLayout;
set4_h->addWidget(na4);
set4_h->addWidget(monthCob);
QLabel *na5 = new QLabel;
na5->setText("设置天气:");
na5->setFixedSize(0.4 *w,0.1*h);
weatherCob = new QComboBox;
weatherCob->addItems( QStringList()<<tr("晴天")
<<tr("阴天") );
connect(weatherCob, SIGNAL(currentIndexChanged(int)), this, SLOT(changeweather(int)));
weatherCob->setCurrentIndex(0);
weatherCob->setFixedSize(0.5 *w,0.1*h);
QHBoxLayout *set5_h = new QHBoxLayout;
set5_h->addWidget(na5);
set5_h->addWidget(weatherCob);
QPushButton *backbtn1 = new QPushButton;
backbtn1->setText("返回");
backbtn1->setFixedSize(0.8 *w,0.1*h);
connect(backbtn1, SIGNAL(clicked( )), this, SLOT(on_pushButton_back_clicked( )));
QHBoxLayout *set6_h = new QHBoxLayout;
set6_h->addStretch(1);
set6_h->addWidget(backbtn1);
set6_h->addStretch(1);
QVBoxLayout *ALL2 = new QVBoxLayout;
ALL2->addLayout(set1_h);
ALL2->addLayout(set2_h);
ALL2->addLayout(set3_h);
ALL2->addLayout(set4_h);
ALL2->addLayout(set5_h);
ALL2->addLayout(set6_h);
wnd2->setLayout(ALL2);
//-----------------------------------------------------wnd3
MsgLed = new QPlainTextEdit;
MsgLed->setFixedSize(0.98*w,0.4*h);
SendLed = new QLineEdit;
SendLed->setFixedSize(0.98*w,0.2*h);
QPushButton *sendBtn = new QPushButton;
sendBtn->setFixedSize(0.35*w,0.1*h);
sendBtn->setText("发送");
connect(sendBtn, SIGNAL(clicked( )), this, SLOT(on_sendbtn_click( )));
QPushButton *clearBtn = new QPushButton;
clearBtn->setFixedSize(0.35*w,0.1*h);
clearBtn->setText("清除");
connect(clearBtn, SIGNAL(clicked( )), this, SLOT(on_clearbtn_click( )));
QHBoxLayout *hh_h = new QHBoxLayout;
hh_h->addStretch(1);
hh_h->addWidget(sendBtn);
hh_h->addWidget(clearBtn);
hh_h->addStretch(1);
QVBoxLayout *ALL3 = new QVBoxLayout;
ALL3->addWidget(MsgLed);
ALL3->addWidget(SendLed);
ALL3->addLayout(hh_h);
wnd3->setLayout(ALL3);
}
Control::~Control()
{
}
bool Control::blueStates()
{
// if( socket == NULL)
// {
// QMessageBox::information(this, "错误", "蓝牙未连接");
// return false;
// }
// else
return true;
}
void Control::receiveMsg(QString msg)
{
QTime current_time =QTime::currentTime();
int hour = current_time.hour();//当前的小时
int minute = current_time.minute();//当前的分
int second = current_time.second();//当前的秒QString
QString h