-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
114 lines (95 loc) · 3.78 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "custom/global.h"
#include "device/devicelamp.h"
#include "device/devicefan.h"
#include "device/deviceac.h"
#include "device/devicecurtain.h"
#include <QPalette>
#include <QTime>
#include <QPixmap>
#include <QPainter>
#include <QImageReader>
QPixmap MainWindow::pixmapToRound(const QPixmap &src, int radius)
{
if (src.isNull()) {
return QPixmap();
}
QSize size(2*radius, 2*radius);
QBitmap mask(size);
QPainter painter(&mask);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.fillRect(0, 0, size.width(), size.height(), Qt::white);
painter.setBrush(QColor(0, 0, 0));
painter.drawRoundedRect(0, 0, size.width(), size.height(), 99, 99);
QPixmap image = src.scaled(size);
image.setMask(mask);
return image;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
tcpServer=new TcpServer(this);
tcpServer->listen(QHostAddress::Any,6666);//开始监听
timer =new QTimer(this);
connect(timer,&QTimer::timeout,this,&MainWindow::timeout);
timer->start(1000);
deviceAc=new DeviceAC(LIVINGROOM,this);
deviceAc->setStyleSheet("background-color: #f4fcff;"\
"border-radius: 15px");
deviceAc->move(660,220);
connect(deviceAc,&DeviceAC::doSendData,tcpServer,&TcpServer::deviceSendData);
//
deviceFan=new DeviceFan(LIVINGROOM,this);
deviceFan->setStyleSheet("background-color: #f4fcff;"\
"border-radius: 15px");
deviceFan->move(330,530);
connect(deviceFan,&DeviceFan::doSendData,tcpServer,&TcpServer::deviceSendData);
deviceLamp=new DeviceLamp(LIVINGROOM,this);
deviceLamp->setStyleSheet("background-color: #f4fcff;border-radius: 15px");
deviceLamp->move(330,220);
connect(deviceLamp,&DeviceLamp::doSendData,tcpServer,&TcpServer::deviceSendData);
//
deviceCurtain=new DeviceCurtain(LIVINGROOM,this);
deviceCurtain->setStyleSheet("background-color: #f4fcff;border-radius: 15px");
deviceCurtain->move(1050,220);
connect(deviceCurtain,&DeviceCurtain::doSendData,tcpServer,&TcpServer::deviceSendData);
QPalette pal=this->palette();
pal.setBrush(QPalette::Window,QBrush(QPixmap(":/icons/png/background")));
setPalette(pal);
//ui->label_headpic->setStyleSheet("border-image:url(:/icons/png/header.png)");;
ui->label_headpic->setText("");
ui->frame_left->setStyleSheet("#frame_left{background-color:rgba(0,0,0,70%);}");
ui->label_keting->setStyleSheet("color:#ffffff");
ui->label_time_1->setStyleSheet("color:#ffffff");
ui->label_time_2->setStyleSheet("color:#ffffff");
ui->label_status->setStyleSheet("color:#ffffff");
ui->label_fenge->setFixedWidth(3);
ui->label_fenge->setText("");
ui->label_fenge->setStyleSheet("background-color:#ffffff");
//ui->label_info->setStyleSheet("color:rgba(225,225,225,200)");
ui->label_time_1->setText(QTime::currentTime().toString("hh:mm"));
ui->label_time_2->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd"));
QPixmap header(":/icons/png/header2.png");
QPixmap pixMap= header.scaled(ui->label_headpic->width(),ui->label_headpic->height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
//50为圆形的半径
pixMap = pixmapToRound(pixMap, 50);
ui->label_headpic->setPixmap(pixMap);
}
void MainWindow::timeout()
{
ui->label_time_1->setText(QTime::currentTime().toString("hh:mm"));
ui->label_time_2->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd"));
if(livingRoomStatus==CONNECT){
ui->label_status->setText("状态:在线");
}else{
ui->label_status->setText("状态:离线");
}
}
MainWindow::~MainWindow()
{
delete ui;
}