forked from Blackmamba-xuan/QtQQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.cpp
116 lines (105 loc) · 3.86 KB
/
chat.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
114
115
116
#include "chat.h"
#include "ui_chat.h"
#include<QDesktopWidget>
Chat::Chat(QWidget *parent) :
QWidget(parent),
ui(new Ui::Chat)
{
ui->setupUi(this);
setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
ui->label_4->installEventFilter(this);
ui->label_5->installEventFilter(this);
QFile file(":/myqss/scrollbar.qss");
file.open(QFile::ReadOnly);
ui->textBrowser->verticalScrollBar()->setStyleSheet(file.readAll());
ui->label_8->installEventFilter(this);
move((QApplication::desktop()->width() - width())/2,(QApplication::desktop()->height() - height()-20)/2);
emotion=new Emotion();
connect(emotion,SIGNAL(imgurl(QString)),this,SLOT(sendemotion(QString)));
}
Chat::~Chat()
{
delete ui;
}
void Chat::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
this->setMouseTracking(true);
mouse_press = true;
//鼠标相对于窗体的位置(或者使用event->globalPos() - this->pos())
move_point = event->pos();
qDebug()<<"移动1";
qDebug()<<event->source();
}
}
void Chat::mouseReleaseEvent(QMouseEvent *event)
{
//设置鼠标为未被按下
mouse_press = false;
}
void Chat::mouseMoveEvent(QMouseEvent *event)
{
//若鼠标左键被按下
// qDebug()<<"mouse_press="<<event->globalPos();
if(mouse_press)
{
//鼠标相对于屏幕的位置
QPoint move_pos = event->globalPos();
//移动主窗体位置
this->move(move_pos - move_point);
}
}
bool Chat::eventFilter(QObject *object, QEvent *e)
{
if(e->type()==QEvent::MouseButtonPress&&object==ui->label_5)
{
close();
}
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_4){
showMinimized();
qDebug()<<"最小化";
qDebug()<<mouse_press;
}
//表情发送
else if(e->type()==QEvent::MouseButtonPress&&object==ui->label_8){
qDebug()<<ui->label_8->x();
qDebug()<<x();
emotion->move(x()-10,ui->label_8->y()-100);
emotion->show();
}
return false;
}
void Chat::showEvent(QShowEvent *event)
{
qDebug()<<"出现了";
mouse_press=false;
qDebug()<<mouse_press;
}
void Chat::on_pushButton_2_clicked()
{
QString content=ui->textEdit->toPlainText();
qDebug()<<content.length();
if(content.length()>=23){
qDebug()<<"进入了这个";
QString s1="<img width='30' height='30' src='qrc:/10.jpeg' style='float:right;margin-left:15px;margin-right:15px;'><div style='background:rgb(205,215,226);padding-top:8px;float:right;margin-top:10px;margin-right:45px;padding:10px;margin-left:60px;'><span style='font-size:15px;font-family:'Microsoft YaHei';margin-top:2px;'>"+content+"</span></div><br><br><br>";
ui->textBrowser->insertHtml(s1);
}
else{
int flag=60+(24-content.length())*15;
QString myflag=QString::number(flag, 10);;
qDebug()<<myflag;
QString s1="<img width='30' height='30' src='qrc:/10.jpeg' style='float:right;margin-left:15px;margin-right:15px;'><div style='background:rgb(205,215,226);padding-top:8px;float:right;margin-top:10px;margin-right:45px;padding:10px;margin-left:"+myflag+"px;'>";
s1+="<span style='font-size:15px;font-family:'Microsoft YaHei';margin-top:2px;'>"+content+"</span></div><br><br><br>";
qDebug()<<s1;
ui->textBrowser->insertHtml(s1);
}
//ui->textEdit->clear();
}
void Chat::sendemotion(QString s)
{
qDebug()<<"选择了发送表情";
QString s1="<img width='30' height='30' src='qrc:/10.jpeg' style='float:right;margin-left:15px;margin-right:15px;'><div style='background:rgb(205,215,226);padding-top:8px;float:right;margin-top:10px;margin-right:45px;padding:10px;margin-left:387px;'><img src='"+s+"'></div><br><br><br>";
ui->textBrowser->insertHtml(s1);
}