mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
Add a taxonomy
This commit is contained in:
@ -71,7 +71,7 @@ SessionFriendArea::SessionFriendArea(QWidget *parent)
|
||||
#if TEST_UI
|
||||
QIcon icon(":/resource/image/defaultAv.png");
|
||||
for(int i = 0; i < 30; i++) {
|
||||
this->addItem(icon, "张三" + QString::number(i), "test: last message..." + QString::number(i));
|
||||
this->addItem(SessionItemType, QString::number(i), icon, "张三" + QString::number(i), "test: last message..." + QString::number(i));
|
||||
}
|
||||
// LOG() << "hello world!";
|
||||
#endif
|
||||
@ -195,12 +195,78 @@ void SessionFriendArea::clear()
|
||||
}
|
||||
}
|
||||
|
||||
void SessionFriendArea::addItem(const QIcon &avatar, const QString &name, const QString &text)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//此时这个函数添加的就不是SessionFriendItem了,而是其子类
|
||||
//SessionItem FriendItem ApplyItem
|
||||
void SessionFriendArea::addItem(ItemType itemType, const QString& id, const QIcon &avatar, const QString &name, const QString &text)
|
||||
{
|
||||
//构造一个Item
|
||||
SessionFriendItem* Item = new SessionFriendItem(this, avatar, name, text);
|
||||
//将Item添加到container中
|
||||
container->layout()->addWidget(Item);
|
||||
// //构造一个Item
|
||||
// SessionFriendItem* Item = new SessionFriendItem(this, avatar, name, text);
|
||||
// //将Item添加到container中
|
||||
// container->layout()->addWidget(Item);
|
||||
|
||||
SessionFriendItem* item = nullptr;
|
||||
switch (itemType) {
|
||||
case SessionItemType:
|
||||
item = new SessionItem(this, id, avatar, name, text);
|
||||
break;
|
||||
case FriendItemType:
|
||||
item = new FriendItem(this, id, avatar, name, text);
|
||||
break;
|
||||
case ApplyItemType:
|
||||
item = new ApplyItem(this, id, avatar, name);
|
||||
break;
|
||||
default:
|
||||
LOG() << "Error ItemType: " << itemType;
|
||||
return;
|
||||
}
|
||||
|
||||
container->layout()->addWidget(item);
|
||||
}
|
||||
|
||||
void SessionFriendArea::clickItem(int index)
|
||||
{
|
||||
if(index < 0 || index > container->layout()->count()) {
|
||||
LOG() << "The subscript of the clicked element is out of range... index:" << index;
|
||||
return;
|
||||
}
|
||||
QLayoutItem* layoutItem = container->layout()->itemAt(index);
|
||||
if(layoutItem == nullptr || layoutItem->widget() == nullptr) {
|
||||
LOG() << "The specified element does not exist... index: " << index;
|
||||
return;
|
||||
}
|
||||
SessionFriendItem* item = dynamic_cast<SessionFriendItem*>(layoutItem->widget());
|
||||
item->select();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 会话Item的实现
|
||||
////////////////////////////////////////
|
||||
SessionItem::SessionItem(QWidget *owner, const QString &chatSessionId, const QIcon &avatar,
|
||||
const QString &name, const QString &lastmessage)
|
||||
:SessionFriendItem(owner, avatar, name, lastmessage), chatSessionId(chatSessionId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 好友Item的实现
|
||||
////////////////////////////////////////
|
||||
FriendItem::FriendItem(QWidget *owner, const QString &userId, const QIcon &avatar,
|
||||
const QString &name, const QString &description)
|
||||
:SessionFriendItem(owner, avatar, name, description), userId(userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////
|
||||
/// 好友申请Item的实现
|
||||
////////////////////////////////////////
|
||||
ApplyItem::ApplyItem(QWidget *owner, const QString &userId, const QIcon &avatar,
|
||||
const QString &name)
|
||||
:SessionFriendItem(owner, avatar, name, ""), userId(userId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user