-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatrecord.cpp
More file actions
121 lines (100 loc) · 3.53 KB
/
Copy pathchatrecord.cpp
File metadata and controls
121 lines (100 loc) · 3.53 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
#include "chatrecord.h"
#include "ui_chatrecord.h"
#include"user.h"
#include<QMessageBox>
#include<QListWidgetItem>
#include<QListWidget>
#include<QMap>
#include<QDebug>
#include"user_info.h"
extern QList <record>Record;
extern QMap <QString,QString>corre;
extern QList <USER> list;
extern USER succeed;//单独全局变量已登录的用户
chatRecord::chatRecord(QWidget *parent) :
QDialog(parent),
ui(new Ui::chatRecord)
{
ui->setupUi(this);
this->setWindowTitle("聊天记录");
for(int i=0;i<list.size();i++){
corre[list[i].phone]=list[i].name;
qDebug()<<corre[list[i].phone];
}
ui->accor_friend->setCheckState(Qt::Checked);
}
chatRecord::~chatRecord()
{
delete ui;
}
void chatRecord::on_return_2_clicked()
{
this->close();
User *pic=new User;
pic->show();
}
void chatRecord::on_accor_friend_stateChanged(int arg1)
{
if(arg1==Qt::CheckState::Checked){
ui->accor_content->blockSignals(true);
ui->accor_content->setCheckState(Qt::CheckState::Unchecked);
ui->accor_content->blockSignals(false);
}
}
void chatRecord::on_accor_content_stateChanged(int arg1)
{
if(arg1==Qt::CheckState::Checked){
ui->accor_friend->blockSignals(true);
ui->accor_friend->setCheckState(Qt::CheckState::Unchecked);
ui->accor_friend->blockSignals(false);
}
}
void chatRecord::on_search_clicked()
{
ui->recordList->clear();
if(ui->accor_content->checkState()==Qt::CheckState::Unchecked&&ui->accor_friend->checkState()==Qt::CheckState::Unchecked){
QMessageBox::critical(this,tr("提示"),tr("请选择您的搜索方式"));
}
//根据内容查找
else if(ui->accor_content->checkState()==Qt::CheckState::Checked&&ui->accor_friend->checkState()==Qt::CheckState::Unchecked){
QString cur=ui->recordSearch->text();
int flag=0;
for(int i=0;i<Record.size();i++){
if(Record[i].from==succeed.phone||Record[i].to==succeed.phone){
if(Record[i].content.indexOf(cur)!=-1){
QListWidgetItem *item;
item=new QListWidgetItem;
item->setText(QString(corre[Record[i].from]+"-to-"+corre[Record[i].to]+": \n"+Record[i].content));
item->setTextAlignment(Qt::AlignLeft);
item->setCheckState(Qt::Unchecked);
ui->recordList->addItem(item);
flag=1;
}
}
}
if(flag==0){
QMessageBox::information(this,tr(""),tr("无查询结果"));
}
}
//根据好友查找
else if(ui->accor_content->checkState()==Qt::CheckState::Unchecked&&ui->accor_friend->checkState()==Qt::CheckState::Checked){
QString cur=ui->recordSearch->text();
int flag=0;
for(int i=0;i<Record.size();i++){
if(Record[i].from==succeed.phone||Record[i].to==succeed.phone){
if(corre[Record[i].to].indexOf(cur)!=-1||corre[Record[i].from].indexOf(cur)!=-1){
QListWidgetItem *item;
item=new QListWidgetItem;
item->setText(QString(corre[Record[i].from]+" to "+corre[Record[i].to]+": \n"+Record[i].content));
item->setTextAlignment(Qt::AlignLeft);
item->setCheckState(Qt::Unchecked);
ui->recordList->addItem(item);
flag=1;
}
}
}
if(flag==0){
QMessageBox::information(this,tr(""),tr("无查询结果"));
}
}
}