-
Notifications
You must be signed in to change notification settings - Fork 0
/
friendlistform.cpp
182 lines (148 loc) · 4.96 KB
/
friendlistform.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
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
#include "friendlistform.h"
#include "ui_friendlistform.h"
#include "clientadapter.h"
#include <QDebug>
#include <QMessageBox>
#include <QPainter>
#include <QGraphicsDropShadowEffect>
FriendListForm::FriendListForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::FriendListForm)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
ui->friendsPool->setResizeMode(QListView::Adjust);
setWindowFlag(Qt::FramelessWindowHint);
setAttribute(Qt::WA_TranslucentBackground);
auto shadow_effect = new QGraphicsDropShadowEffect(this);
shadow_effect->setOffset(0, 0);
shadow_effect->setColor(Qt::gray);
shadow_effect->setBlurRadius(8);
setGraphicsEffect(shadow_effect);
// ui->friendsPool->setViewMode(QListView::IconMode);
}
FriendListForm::~FriendListForm()
{
delete ui;
}
//Debug 访问ui控件
int FriendListForm::getSize() {
return ui -> friendsPool -> count();
}
//设置Qtid
void FriendListForm::set_qtid(QtId id) {
//ui ->qtIdLabel ->setText(QString("%1").arg(id));
}
//设置昵称和头像
void FriendListForm::set_nickandicon(QString nick) {
ui -> MyNicknameLabel -> setText(nick.mid(1,nick.size()-1));
int iconId = nick.mid(0,1).toInt();
QString imgPath = ":/Icons/icon/img" +QString::number(iconId + 1) + ".jpg";
int myWidth = ui ->iconLabel ->width() - 6;
int myHeight = ui ->iconLabel ->height();
QPixmap originPath(imgPath);
QPixmap roundCircle(myWidth,myHeight);
roundCircle.fill(Qt::transparent);
QPainter painter(&roundCircle);
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
QPainterPath path;
path.addEllipse(0,0,myWidth,myHeight); //绘制椭圆
painter.setClipPath(path);
painter.drawPixmap(0,0,myWidth,myHeight,originPath);
ui->iconLabel->setPixmap(roundCircle);
}
//更新UI界面 将传输的好友数据显示到UI上
void FriendListForm::set_friend_list(QList<std::tuple<QtId, QString> > dataList) {
//TODO
ui ->friendsPool -> clear();
for(int i = 0;i < dataList.size();++i) {
add_Item_toUI(std::get<1>(dataList.at(i)),std::get<0>(dataList.at(i)));
}
}
//将tarQtid的好友标红 有未读消息 双击后取消
void FriendListForm::emphasis_friend_item(QtId tarQtid) {
qDebug() << tarQtid;
MyItemWidget* selected = nullptr;
for(int i = 0;i < ui ->friendsPool->count();++i) {
int curQtid = (dynamic_cast<MyItemWidget*>
(ui ->friendsPool->itemWidget(ui->friendsPool->item(i)))->getQid());
if(tarQtid == curQtid) {
selected = dynamic_cast<MyItemWidget*>
(ui ->friendsPool->itemWidget(ui->friendsPool->item(i)));
selected ->setHasMsg();
return;
}
}
show_error("未找到的好友");
}
void FriendListForm::on_friendListWidget_itemDoubleClicked(MyItemWidget *item) {
//qDebug() << item << adapter;
//除去未读消息标志
item ->clearMsgIcon();
//打开聊天窗口
adapter ->open_chatform(item->getQid());
}
void FriendListForm::show_error(QString warningMsg) {
int ret = QMessageBox::warning(this,"警告",warningMsg,QMessageBox::Yes);
if(ret == QMessageBox::Yes) {
//do nothing
}
}
//增加一个好友
void FriendListForm::add_Item_toUI(QString nickName,int qtID) {
MyItemWidget* pItemWidget = new MyItemWidget(this);
//连接信号槽
connect(pItemWidget,SIGNAL(double_cliceked_to_friendsform(MyItemWidget*)),
this,SLOT(on_friendListWidget_itemDoubleClicked(MyItemWidget*)));
//好友位置中要记录id是多少
pItemWidget->SetNickAndIcon(nickName);
pItemWidget->setQtId(qtID);
QListWidgetItem* pItem = new QListWidgetItem();
//手动调整自定义Item大小
pItem->setSizeHint(QSize(320, 122));
//连接自定义控件
ui->friendsPool->addItem(pItem);
ui->friendsPool->setItemWidget(pItem, pItemWidget);
}
//添加一个好友
void FriendListForm::add_friend(std::tuple<QtId, QString> mFriend) {
add_Item_toUI(std::get<1>(mFriend),std::get<0>(mFriend));
}
void FriendListForm::set_adapter(ClientAdapter *cli) {
adapter = cli;
}
void FriendListForm::on_pushButton_clicked()
{
if(!(ui ->friendListEdit->toPlainText().isEmpty())) {
adapter ->add_friend(ui -> friendListEdit ->toPlainText().toInt());
}
}
void FriendListForm::on_closebutton_clicked()
{
close();
}
void FriendListForm::on_minimizebutton_clicked()
{
setWindowState(Qt::WindowMinimized);
}
void FriendListForm::mousePressEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
isDrag = true;
mouse_start_point = e->globalPos();
window_topleft_point = frameGeometry().topLeft();
}
}
void FriendListForm::mouseReleaseEvent(QMouseEvent *e)
{
if (e->button() == Qt::LeftButton) {
isDrag = false;
}
}
void FriendListForm::mouseMoveEvent(QMouseEvent *e)
{
if (isDrag) {
QPoint dist = e->globalPos() - mouse_start_point;
this->move(window_topleft_point + dist);
}
}