-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprivatechat.cpp
More file actions
577 lines (500 loc) · 20.8 KB
/
Copy pathprivatechat.cpp
File metadata and controls
577 lines (500 loc) · 20.8 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
#include "privatechat.h"
#include <QPalette>
#include <QBitmap>
#include <QPainter>
#include <QBrush>
#include <QPixmap>
#include <QMouseEvent>
#include <QByteArray>
#include <QDataStream>
#include <QWebFrame>
#include <QFileDialog>
#include <QMessageBox>
#include <QMimeData>
#include "sharedefine.h"
#include <QFile>
#include "ui_privatechat.h"
#include "screenshotwidget.h"
#include <QPropertyAnimation>
#include <QFontDatabase>
privatechat::privatechat(QString targetAcc,QHostAddress targetIp,QString targetImgPath,QWidget *parent) :
QWidget(parent),
ui(new Ui::privatechat)
{
ui->setupUi(this);
beautifyMainWidget();
addTooBtns();
this->targetAcc=targetAcc;
this->targetIp=targetIp;
this->targetImgPath=targetImgPath;
iniPrivateChatSetting();
ui->msgTextEdit->setAcceptDrops(false);
this->setAcceptDrops(true);
//实现消息通信
msgReceiveUdpSocket=new QUdpSocket();
msgSendUdpSocket=new QUdpSocket();
bool udpBindResult=msgReceiveUdpSocket->bind(QHostAddress::LocalHost,PrivateChatPort);
if(!udpBindResult){
}
connect(msgReceiveUdpSocket,SIGNAL(readyRead()),this,SLOT(receiveMsg()));//处理接收消息
//得到当前聊天对方的IP地址
this->targetIp=targetIp;
connect(ui->sendPushBtn,SIGNAL(clicked()),this,SLOT(btnSendClick()));
ui->msgTextEdit->installEventFilter(this);
//设置WebView样式
QFile webviewFile("://img/WebviewStyle/MsgShowStyle.html");
webviewFile.open(QIODevice::ReadOnly);
ui->msgShowWebView->setHtml(QString::fromUtf8(webviewFile.readAll().constData()));
webviewFile.close();
//实现文件发送功能
loadSize=4*1024;
totalBytes=0;
bytesWritten=0;
bytesToWrite=0;
ui->sendFileProgressBar->setValue(0);
this->setWindowTitle("好友聊天");
changePrivateChatStyle();
IniVoiceChatSetting();
//设置发送文件的进度条和状态信息隐藏
ui->sendFileStateLabel->setHidden(true);
ui->sendFileProgressBar->setHidden(true);
}
privatechat::~privatechat()
{
delete ui;
}
void privatechat::beautifyMainWidget(){
QPalette mainWidgetPalette;
mainWidgetPalette.setBrush(QPalette::Background,QBrush(QPixmap(":/img/privatechat.jpg")));
this->setPalette(mainWidgetPalette);
this->setAutoFillBackground(true);
this->setWindowFlags(Qt::FramelessWindowHint);
QBitmap mainWidgetBitmap(this->size());
mainWidgetBitmap.fill();
QPainter mainWidgetPainter(&mainWidgetBitmap);
mainWidgetPainter.setRenderHint(QPainter::Antialiasing);
int arcR = 10; //弧度
QRect rect = this->rect();
QPainterPath path;
//逆时针
path.moveTo(arcR, 0);
path.arcTo(0, 0, arcR * 2, arcR * 2, 90.0f, 90.0f);
path.lineTo(0, rect.height());
path.lineTo(rect.width(), rect.height());
path.lineTo(rect.width(), arcR);
path.arcTo(rect.width() - arcR * 2, 0, arcR * 2, arcR * 2, 0.0f, 90.0f);
path.lineTo(arcR, 0);
mainWidgetPainter.drawPath(path);
mainWidgetPainter.fillPath(path, QBrush(Qt::red));
setMask(mainWidgetBitmap);
}
void privatechat::mousePressEvent(QMouseEvent * e){
windowPos=this->pos();
mousePos=e->globalPos();
moveDisPos=mousePos-windowPos;
}
void privatechat::mouseMoveEvent(QMouseEvent * e){
this->move(e->globalPos() - this->moveDisPos);
}
void privatechat::addTooBtns(){
btnClose=new sysButton("sys_button_close.png","关闭");
btnMin=new sysButton("sys_button_min.png","最小化");
ui->mainToolLayout->addStretch();
//
connect(btnClose,SIGNAL(clicked()),this,SLOT(closeMainWidget()));
connect(btnMin,SIGNAL(clicked()),this,SLOT(minMainWidget()));
ui->mainToolLayout->addWidget(btnMin);
ui->mainToolLayout->addWidget(btnClose);
ui->mainToolLayout->setSpacing(0);
ui->mainToolLayout->setContentsMargins(0,0,0,0);
}
void privatechat::closeMainWidget(){
//this->close();
// fadeInOutWidget=new fadeinout(this);
// fadeInOutWidget->startFadeInOut(FADEOUT_EXIT);
//以渐隐方式退出聊天窗口
//界面动画,改变透明度的方式消失1 - 0渐变
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();
connect(animation, SIGNAL(finished()), this, SLOT(close()));
}
void privatechat::minMainWidget(){
this->showMinimized();
}
//实现消息接收函数
void privatechat::receiveMsg(){
//以循环方式接收消息
while(msgReceiveUdpSocket->hasPendingDatagrams()){
QByteArray bufferData;
bufferData.resize(msgReceiveUdpSocket->pendingDatagramSize());
msgReceiveUdpSocket->readDatagram(bufferData.data(),bufferData.size());
QByteArray aesKey=aesCrypto.HexStringToByte(keyString);
QByteArray decryptedData=aesCrypto.Decrypt(bufferData,aesKey);
QDataStream inData(&decryptedData,QIODevice::ReadOnly);
QString senderAcc;
int msgType;
inData>>msgType;
QString msgContent;
switch(msgType){
case Message:{
inData>>senderAcc;
inData>>msgContent;
QString html = QString("document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;'><p class='triangle-left left'>%1</p></div>\")").arg(msgContent);
ui->msgShowWebView->page()->mainFrame()->evaluateJavaScript(html);
}
break;
case SENDFILE:{
inData>>senderAcc;
inData>>msgContent;
if(msgContent=="AccFile"){
if(!fileName.isEmpty()){
fileSendSocket=new QTcpSocket(this);
connect(fileSendSocket,SIGNAL(connected()),this,SLOT(startSendFile()));
connect(fileSendSocket,SIGNAL(bytesWritten(qint64)),this,SLOT(updateFileSendProgress(qint64)));
connect(fileSendSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(displayError(QAbstractSocket::SocketError)));
fileSendSocket->connectToHost(QHostAddress::LocalHost,SendFileDataPort);
//在界面上展现状态信息
ui->sendFileProgressBar->setHidden(false);
ui->sendFileStateLabel->setHidden(false);
ui->sendFileStateLabel->setText(QString("开始发送%1文件").arg(fileName));
}
}
else if(msgContent=="DenyFile"){
//QMessageBox::critical(this,"拒绝接收文件","你的好友拒绝了你发送的文件");
//在界面上展现状态信息
// ui->sendFileProgressBar->setHidden(false);
ui->sendFileStateLabel->setHidden(false);
ui->sendFileStateLabel->setText(QString("对方拒绝接收%1文件").arg(fileName));
}
}
break;
case Shake:{
//接收到窗口抖动,抖动自己的窗口
shake=new shakewindow(this);
shake->startShake();
// QMessageBox::about(this,"Shake","Shake");
}
break;
}
}
}
//实现消息发送
void privatechat::sendMsg(MessageType msgType){
switch(msgType){
case Message:
{
if(ui->msgTextEdit->toPlainText()==""){
QMessageBox::warning(this,"消息为空","发送消息不能为空");
}
//保存自己的当前账号
//QString curAccount="ShadowWalker";
QString plainMsg=ui->msgTextEdit->toPlainText();
plainMsg=formateSendMsgToShow(plainMsg);
QString htmlMSG="";
htmlMSG.append(QString("document.getElementById(\"content\").insertAdjacentHTML(\"beforeEnd\",\"<div style='overflow:hidden;'><p class='triangle-right right'>%1</p></div>\")").arg(plainMsg));
ui->msgShowWebView->page()->mainFrame()->evaluateJavaScript(htmlMSG);
QByteArray data;
QDataStream out(&data, QIODevice::WriteOnly);
out<<Message<<curLoginAcc<<plainMsg;
//测试先发送数据到本机端口
QByteArray aesKey=aesCrypto.HexStringToByte(keyString);
QByteArray encryptData=aesCrypto.Encrypt(data,aesKey);
msgSendUdpSocket->writeDatagram(encryptData,targetIp,BroadcastPort);
msgSendUdpSocket->writeDatagram(encryptData,targetIp,PrivateChatPort);
}
break;
case Shake:
{
//发送窗口抖动
QByteArray data;
QString curAccount="ShadowWalker";
QDataStream out(&data, QIODevice::WriteOnly);
QString shakeContent="ShakeRequest";
out<<Shake<<curAccount<<shakeContent;
//测试先发送数据到本机端口
QByteArray aesKey=aesCrypto.HexStringToByte(keyString);
QByteArray encryptData=aesCrypto.Encrypt(data,aesKey);
msgSendUdpSocket->writeDatagram(encryptData,targetIp,PrivateChatPort);
}
break;
case SENDFILE:
{
//发送文件请求代码 在这里我自己定义三个特征码分别为SendFile AccFile DenyFile
QByteArray data;
QDataStream out(&data, QIODevice::WriteOnly);
QString msgSendContenet="SendFile";
out<<SENDFILE<<curLoginAcc<<msgSendContenet;
//测试先发送数据到本机端口
QByteArray aesKey=aesCrypto.HexStringToByte(keyString);
QByteArray encryptData=aesCrypto.Encrypt(data,aesKey);
msgSendUdpSocket->writeDatagram(encryptData,targetIp,BroadcastPort);//一个是广播端口,一个是私聊端口
msgSendUdpSocket->writeDatagram(encryptData,targetIp,PrivateChatPort);
}
break;
}
}
void privatechat::btnSendClick(){
sendMsg(Message);
}
//实现Ctrl +Enter 键发送消息
bool privatechat::eventFilter(QObject * targetObj, QEvent * e){
Q_ASSERT(targetObj==ui->msgTextEdit);
if(e->type()==QEvent::KeyPress){
QKeyEvent* event=static_cast<QKeyEvent*>(e);
if(event->key()==Qt::Key_Return&&(event->modifiers()==Qt::ControlModifier)){
sendMsg(Message);
return true;
}
}
return QWidget::eventFilter(targetObj,e);
}
//实现聊天窗口的抖动
void privatechat::on_shakeToolBtn_clicked()
{
shake=new shakewindow(this);
shake->startShake();
//发送窗口抖动
sendMsg(Shake);
}
void privatechat::on_fontComboBox_currentFontChanged(const QFont &f)
{
currentFont=f;
ui->msgTextEdit->setFont(f);
}
void privatechat::on_blackToolBtn_clicked()
{
isBlack=!isBlack;
if(isBlack){
ui->msgTextEdit->setFontWeight(QFont::Black);
}
}
void privatechat::on_inclineToolBtn_clicked()
{
isIncline=!isIncline;
ui->msgTextEdit->setFontItalic(isIncline);
}
void privatechat::on_snapScreenToolBtn_clicked()
{
ScreenShotWidget * screenShotWidget=new ScreenShotWidget();
screenShotWidget->show();
}
//表情框响应函数
void privatechat::insertEmotion(QString emotionImgPath){
// ui->msgTextEdit->textCursor().insertImage(emotionImgPath.left(emotionImgPath.size()-1));//图片路径多了个换行符
QString trueEmotionImgPath=emotionImgPath.left(emotionImgPath.size()-1);
int index=trueEmotionImgPath.lastIndexOf("/");
QString EmotionID=trueEmotionImgPath.right(trueEmotionImgPath.size()-index-1);
QString EmotionText="["+EmotionID+"]";
//ui->msgTextEdit->append(EmotionText);
ui->msgTextEdit->textCursor().insertText(EmotionText);
}
void privatechat::on_emotionToolBtn_clicked()
{
emotionWidget=new EmotionWidget;
//设置emotionWidget的位置
QPoint emotionBtnGP=ui->emotionToolBtn->mapToGlobal(QPoint(0,0));
int emotionBtnGPX=emotionBtnGP.x();
int emotionBtnGPY=emotionBtnGP.y();
int trueX=emotionBtnGPX-120;
int trueY=emotionBtnGPY-200;
emotionWidget->setGeometry(trueX,trueY,400,120);
emotionWidget->show();
connect(emotionWidget,SIGNAL(emotionTrigger(QString)),this,SLOT(insertEmotion(QString)));
connect(emotionWidget,SIGNAL(emotionClick()),this,SLOT(closeEmotionWidget()));
}
void privatechat::closeEmotionWidget(){
emotionWidget->close();
delete emotionWidget;
}
//实现文件发送按钮响应
void privatechat::on_sendFileBtn_clicked()
{
fileName=QFileDialog::getOpenFileName(this);
if(!fileName.isEmpty()){
sendMsg(SENDFILE);
}
//如果打开的文件名不为空就执行发送,在这里文件名应该包含路径信息
// if(!fileName.isEmpty()){
// fileSendSocket=new QTcpSocket(this);
// connect(fileSendSocket,SIGNAL(connected()),this,SLOT(startSendFile()));
// connect(fileSendSocket,SIGNAL(bytesWritten(qint64)),this,SLOT(updateFileSendProgress(qint64)));
// connect(fileSendSocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(displayError(QAbstractSocket::SocketError)));
// fileSendSocket->connectToHost(QHostAddress::LocalHost,6666);
// }
}
//实现文件大小等信息的发送
void privatechat::startSendFile(){
localFile=new QFile(fileName);
if(!localFile->open(QFile::ReadOnly)){
//QDebug("open send file error");
return ;
}
totalBytes=localFile->size();
QDataStream sendout(&outBlock,QIODevice::WriteOnly);
sendout.setVersion(QDataStream::Qt_5_2);
QString currentFileName=fileName.right(fileName.size() - fileName.lastIndexOf('/')-1);
sendout << qint64(0) << qint64(0) << currentFileName;
totalBytes+=outBlock.size();
sendout.device()->seek(0);
sendout<<totalBytes<<(qint64)(outBlock.size()-sizeof(qint64)*2);
bytesToWrite=totalBytes-fileSendSocket->write(outBlock);
outBlock.resize(0);
}
//更新进度条数据
void privatechat::updateFileSendProgress(qint64 numBytes){
bytesWritten+=(int)numBytes;
//已经发送数据的大小
if(bytesToWrite > 0)
{
//每次发送loadSize大小的数据,这里设置为4KB,如果剩余的数据不足4KB,
//就发送剩余数据的大小
outBlock = localFile->read(qMin(bytesToWrite,loadSize));
//发送完一次数据后还剩余数据的大小
bytesToWrite -= (int)fileSendSocket->write(outBlock);
//清空发送缓冲区
outBlock.resize(0);
}
else
{
localFile->close(); //如果没有发送任何数据,则关闭文件
}
ui->sendFileProgressBar->setMaximum(totalBytes);
ui->sendFileProgressBar->setValue(bytesWritten);
//如果数据已经发送完成更改状态信息
if(bytesWritten==totalBytes){
ui->sendFileStateLabel->setText("文件已经发送成功");
}
}
void privatechat::displayError(QAbstractSocket::SocketError){
qDebug()<<fileSendSocket->errorString();
}
QString privatechat::formateSendMsgToShow(QString plainMsg){
plainMsg.replace("[act-up.png]","<img src=qrc:/img/Emotion/act-up.png />");
plainMsg.replace("[admonish.png]","<img src=qrc:/img/Emotion/admonish.png />");
plainMsg.replace("[amorous.png]","<img src=qrc:/img/Emotion/amorous.png />");
plainMsg.replace("[angry.png]","<<img src=qrc:/img/Emotion/angry.png />");
plainMsg.replace("[ass.png]","<img src=qrc:/img/Emotion/ass.png />");
plainMsg.replace("[bad.png]","<img src=qrc:/img/Emotion/bad.png />");
plainMsg.replace("[beat-up.png]","<img src=qrc:/img/Emotion/beat-up.png />");
plainMsg.replace("[bloomer.png]","<img src=qrc:/img/Emotion/bloomer.png />");
plainMsg.replace("[bulgy-eyes.png]","<img src=qrc:/img/Emotion/bulgy-eyes.png />");
plainMsg.replace("[bye.png]","<img src=qrc:/img/Emotion/bye.png />");
plainMsg.replace("[calmly.png]","<<img src=qrc:/img/Emotion/calmly.png />");
plainMsg.replace("[clap.png]","<img src=qrc:/img/Emotion/clap.png />");
plainMsg.replace("[cute.png]","<img src=qrc:/img/Emotion/cute.png />");
plainMsg.replace("[dance.png]","<img src=qrc:/img/Emotion/dance.png />");
plainMsg.replace("[daydreamer.png]","<img src=qrc:/img/Emotion/daydreamer.png />");
plainMsg.replace("[devil.png]","<img src=qrc:/img/Emotion/devil.png />");
plainMsg.replace("[disappointed.png]","<img src=qrc:/img/Emotion/disappointed.png />");
plainMsg.replace("[dog.png]","<img src=qrc:/img/Emotion/dog.png />");
plainMsg.replace("[dont-know.png]","<img src=qrc:/img/Emotion/dont-know.png />");
plainMsg.replace("[eat.png]","<img src=qrc:/img/Emotion/eat.png />");
plainMsg.replace("[embarrassed.png]","<img src=qrc:/img/Emotion/embarrassed.png />");
plainMsg.replace("[freaked-out.png]","<img src=qrc:/img/Emotion/freaked-out.png />");
plainMsg.replace("[go-away.png]","<img src=qrc:/img/Emotion/go-away.png />");
plainMsg.replace("[dont-know.png]","<img src=qrc:/img/Emotion/dont-know.png />");
plainMsg.replace("[good.png]","<img src=qrc:/img/Emotion/good.png />");
plainMsg.replace("[handshake.png]","<img src=qrc:/img/Emotion/handshake.png />");
plainMsg.replace("[laugh.png]","<img src=qrc:/img/Emotion/laugh.png />");
plainMsg.replace("[love.png]","<img src=qrc:/img/Emotion/love.png />");
plainMsg.replace("[music.png]","<img src=qrc:/img/Emotion/music.png />");
plainMsg.replace("[poop.png]","<img src=qrc:/img/Emotion/poop.png />");
plainMsg.replace("[smile.png]","<img src=qrc:/img/Emotion/smile.png />");
return plainMsg;
}
//更改聊天窗口的样式,使其美观
void privatechat::changePrivateChatStyle(){
//初始化字体大小选择框
QFontDatabase fontDB;
foreach(int fontSize,fontDB.standardSizes()){
ui->fontSizeComboBox->addItem(QString::number(fontSize));
}
ui->blackToolBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/Bold.png"));
ui->blackToolBtn->setToolTip("加粗");
ui->emotionToolBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/Emotion.png"));
ui->emotionToolBtn->setToolTip("表情");
ui->inclineToolBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/Italic.png"));
ui->inclineToolBtn->setToolTip("倾斜");
ui->shakeToolBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/Shake.png"));
ui->shakeToolBtn->setToolTip("发送窗口抖动");
ui->sendFileBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/SendFile.ico"));
ui->sendFileBtn->setToolTip("传送文件");
ui->snapScreenToolBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/ScreenShot.png"));
ui->snapScreenToolBtn->setToolTip("截图");
ui->voiceChatToolBtn->setIcon(QIcon(":/PrivateChat/img/PrivateChat/Voice.png"));
ui->voiceChatToolBtn->setToolTip("点击开始语音通话,再次点击关闭语音通话");
}
//初始化语音通信设置
void privatechat::IniVoiceChatSetting(){
isInVoiceTalk=false;
quint16 buffersize = 0;
buf1 = new Buffer(buffersize);
buf2 = new Buffer(buffersize);
vio = new VoiceIO();
vso = new VoiceSocket();
vso->startListen();
connect(vio, SIGNAL(readVoice(QByteArray)), buf1, SLOT(input(QByteArray)));//当数据录入设备有数据录入时
connect(buf1, SIGNAL(output(QByteArray)), vso, SLOT(writeData(QByteArray)));//把数据写入Socket发送出去
connect(vso, SIGNAL(readData(QByteArray)), buf2, SLOT(input(QByteArray)));
connect(buf2, SIGNAL(output(QByteArray)), vio, SLOT(writeVoice(QByteArray)));
}
void privatechat::on_voiceChatToolBtn_clicked()
{
//在这里先用本机地址进行测试是否能够通信
if(!isInVoiceTalk){
QHostAddress adr = QHostAddress::LocalHost;
vso->connectToHost(adr);//我把Ip地址更改为自己看一下效果
//vso->connectToHost(QHostAddress::LocalHost);
vso->setEnabled(true);
vio->setEnabled(true);
}
else{
vso->setEnabled(false);
vio->setEnabled(false);
}
isInVoiceTalk=!isInVoiceTalk;
}
//改变编辑框中的字体大小
void privatechat::on_fontSizeComboBox_currentIndexChanged(int index)
{
QString currentFontSize=ui->fontSizeComboBox->currentText();
ui->msgTextEdit->setFontPointSize(currentFontSize.toFloat()+6);//随意加的一个数字
}
//初始化私聊界面设置
void privatechat::iniPrivateChatSetting(){
ui->headImgToolBtn->setIcon(QIcon(targetImgPath));
ui->headImgToolBtn->setIconSize(QSize(70,70));
ui->targetAccStateLabel->setText(QString("当前正在与好友:%1聊天").arg(targetAcc));
}
//实现文件拖放发送
void privatechat::dragEnterEvent(QDragEnterEvent *event){
//QMessageBox::information(this,"拖放","拖放");
if(event->mimeData()->hasFormat("text/uri-list")){
event->acceptProposedAction();
// QMessageBox::information(this,"拖放","拖放");
}
}
void privatechat::dropEvent(QDropEvent *event){
QList<QUrl> urls=event->mimeData()->urls();
if(urls.isEmpty()){
return ;
}
fileName=urls.first().toLocalFile();
// QMessageBox::information(this,"拖放",fileName);
if(fileName.isEmpty()){
return;
}else{
sendMsg(SENDFILE);
}
}
void privatechat::on_closePushBtn_clicked()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "windowOpacity");
animation->setDuration(1000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();
}