Skip to content

Commit

Permalink
[MOD] 增加了搜索页面点击时的跳转逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
qin11152 committed Feb 11, 2023
1 parent 438ea31 commit 24a6e72
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 19 deletions.
50 changes: 49 additions & 1 deletion ui/ChatWidget/ChatWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,9 @@ void ChatWidget::initConnect()
SLOT(onSignalUpdateChatMessage(QString)));
//聊天界面中点击了头像
connect(m_ptrChatMessageWid->getRootObj(), SIGNAL(signalProfileImageClicked(QString)), this, SLOT(onSignalChatWidProfileImageClicked(QString)));

//搜索好友界面点击了头像
connect(reinterpret_cast<QObject*>(m_ptrSearchFriendList->rootObject()), SIGNAL(signalSearchFriendListClicked(QString,QString)), this, SLOT(onSignalSearchFriendProfileImageClicked(QString,QString)));

//自己的头像换了
connect(m_ptrProfileImagePreviewWid, &ProfileImagePreview::signalProfileImageChanged, this, &ChatWidget::onSignalProfileImageChanged);
//好友头像更换后的处理
Expand Down Expand Up @@ -835,6 +837,52 @@ void ChatWidget::onSignalChatWidProfileImageClicked(const QString id)
onSignalChatWidOpenProfileImagePreview(id.toInt());
}

//搜索好友界面中点击了头像
void ChatWidget::onSignalSearchFriendProfileImageClicked(const QString id, const QString& name)
{
//左侧列表界面设为lastchat
ui->friendStackedWidget->setCurrentIndex(LastChatWidget);

//如果不存在才添加,如果不是这个界面,还要切换
auto friendVec = PublicDataManager::get_mutable_instance().getMyFriendInfoWithCVec();
auto friendInfo = friendVec[PublicDataManager::get_mutable_instance().getMyUsetInfoMap()[id]];
//获取上次聊天内容
QString imagePath = "";
if ("" == friendInfo.m_strImagePath)
{
imagePath = kDefaultProfileImage;
}
else
{
imagePath = QString::fromStdString(friendInfo.m_strImagePath);
}
QMetaObject::invokeMethod(m_ptrLastChatQMLRoot, "judgeAndInsertToModel", Q_ARG(QVariant, name.mid(0, 1)),
Q_ARG(QVariant, name), Q_ARG(QVariant, id));

QMetaObject::invokeMethod(m_ptrLastChatQMLRoot, "switchToItemAndChangeColor", Q_ARG(QVariant, id));

//插入到上次聊天的数据库中
//DataBaseDelegate::Instance()->insertLastChat(strId);
if (!PublicDataManager::get_mutable_instance().isIdExistInLastChatList(id))
{
DataBaseDelegate::Instance()->insertLastChat(id);
PublicDataManager::get_mutable_instance().insertLastChatList({ name, id });
}

//如果当前聊天页面不是这个人
if (id != PublicDataManager::get_mutable_instance().getCurrentChatWidgetUserInfo().userId.c_str())
{
//现在的聊天页面换成这个id
PublicDataManager::get_mutable_instance().setCurrentChatWidgetUserInfo(CurrentChatWidgetUserInfo(10, name.toStdString()));
initChatMessageWidAcordId(MyLastChatFriendInfo(name, id));
ui->chatStackedWidget->SwitchToChatPage(ChatWid);
}

//去除掉红点
onSignalHideRedRectangleInLastChat(id);
ui->nickNameLabel->setText(name);
}

//底部栏闪烁槽函数
//parm[IN] bNeed true:闪烁,false:不闪烁
void ChatWidget::onSignalTrayIconTwinkle(const bool bNeed)
Expand Down
2 changes: 2 additions & 0 deletions ui/ChatWidget/ChatWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ private slots:
void onSignalFriendListItemClicked(QString strId,QString name);
//底部托盘被点击后
void onSignalTrayTriggered(QSystemTrayIcon::ActivationReason reason);
//搜索好友页面头像点击
void onSignalSearchFriendProfileImageClicked(const QString id, const QString& name);

//收到好友聊天消息后
void onSignalSingleChatMessage(const QString& chatMessage);
Expand Down
26 changes: 13 additions & 13 deletions ui/MyChatMessageQuickWid/MyChatMessageQuickWid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#include "../DataBaseDelegate/DataBaseDelegate.h"

MyChatMessageQuickWid::MyChatMessageQuickWid(QWidget *parent)
: QQuickWidget(parent)
: QQuickWidget(parent)
{
ui.setupUi(this);
ui.setupUi(this);
}

MyChatMessageQuickWid::~MyChatMessageQuickWid()
Expand All @@ -14,50 +14,50 @@ MyChatMessageQuickWid::~MyChatMessageQuickWid()
//设置和当前用户的聊天记录数量
void MyChatMessageQuickWid::addTotalAndCurrentRecordCount(int cnt)
{
m_iChatRecordCount += cnt;
m_iTotalRecordCount += cnt;
m_iChatRecordCount += cnt;
m_iTotalRecordCount += cnt;
}

void MyChatMessageQuickWid::addCurrentRecordCount(int cnt)
{
m_iChatRecordCount += cnt;
m_iChatRecordCount += cnt;
}

void MyChatMessageQuickWid::setRecordCount(int cnt)
{
m_iChatRecordCount = cnt;
m_iChatRecordCount = cnt;
}

//获得当前用户聊天记录数量
int MyChatMessageQuickWid::getRecordCount() const
{
return m_iChatRecordCount;
return m_iChatRecordCount;
}

void MyChatMessageQuickWid::setTotalRecordCount(int cnt)
{
m_iTotalRecordCount = cnt;
m_iTotalRecordCount = cnt;
}

int MyChatMessageQuickWid::getTotalRecordCount() const
{
return m_iTotalRecordCount;
return m_iTotalRecordCount;
}

void MyChatMessageQuickWid::setRootObj()
{
m_ptrRootObj = reinterpret_cast<QObject*>(rootObject());
m_ptrRootObj = reinterpret_cast<QObject*>(rootObject());
}

QObject* MyChatMessageQuickWid::getRootObj() const
{
return m_ptrRootObj;
return m_ptrRootObj;
}

void MyChatMessageQuickWid::SetUserId(QString id)
{
m_strId = id;
//DataBaseDelegate::Instance()->queryInitialAcordIdFromDB(id, m_strInitial);
m_strId = id;
//DataBaseDelegate::Instance()->queryInitialAcordIdFromDB(id, m_strInitial);
}

void MyChatMessageQuickWid::focusInEvent(QFocusEvent* event)
Expand Down
10 changes: 5 additions & 5 deletions ui/res/QML/searchFriend.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ Rectangle {
searchFriendView.lastItem.color="transparent";
}
color="grey";
searchFriendView.currentIndex=index;
searchFriendView.lastIndex=index;
searchFriendView.currentIndex=idx;
searchFriendView.lastIndex=idx;
searchFriendView.lastItem=searchFriendView.currentItem;
searchFriend.signalFriendListClicked(strIdx,name);
searchFriend.signalSearchFriendListClicked(idx,name);
}
hoverEnabled: true;
//鼠标移动到上方时变为银色,如果移动到上次点击的item则不做处理
onEntered:
{
scrollBar.visible=true;
if(searchFriendView.currentIndex===index)
if(searchFriendView.currentIndex===idx)
{
return;
}
Expand All @@ -74,7 +74,7 @@ Rectangle {
onExited:
{
scrollBar.visible=false;
if(searchFriendView.currentIndex===index)
if(searchFriendView.currentIndex===idx)
{
return;
}
Expand Down

0 comments on commit 24a6e72

Please sign in to comment.