mirror of
https://gitlab.com/comunic/comunicmessages
synced 2024-12-04 11:14:09 +00:00
ConversationsListWidget emits a signal to request a conversation to be
opened.
This commit is contained in:
parent
1df359735d
commit
2b5cd7d86b
@ -17,6 +17,8 @@ ConversationItemWidget::~ConversationItemWidget()
|
||||
|
||||
void ConversationItemWidget::setConversation(const Conversation &conv, const UsersList &list)
|
||||
{
|
||||
mCurrentConversation = conv;
|
||||
|
||||
ui->nameLabel->setText(ConversationsListHelper::getConversationDisplayName(conv, list));
|
||||
QFont font = ui->nameLabel->font();
|
||||
font.setBold(!conv.sawLastMessage());
|
||||
@ -28,4 +30,28 @@ void ConversationItemWidget::setConversation(const Conversation &conv, const Use
|
||||
ui->numberMembersLabel->setText(tr("%1 members").arg(conv.members().size()));
|
||||
|
||||
ui->lastActivityLabel->setText(TimeUtils::TimeDiffToString(conv.lastActive()));
|
||||
|
||||
//Conversation not active by default
|
||||
setActive(false);
|
||||
}
|
||||
|
||||
void ConversationItemWidget::mousePressEvent(QMouseEvent *)
|
||||
{
|
||||
emit openConversation();
|
||||
}
|
||||
|
||||
Conversation ConversationItemWidget::currentConversation() const
|
||||
{
|
||||
return mCurrentConversation;
|
||||
}
|
||||
|
||||
void ConversationItemWidget::setActive(bool active)
|
||||
{
|
||||
QString styleContainer = active ? "background: black; color: white" : "";
|
||||
setStyleSheet(styleContainer);
|
||||
|
||||
QString styleLabels = "padding-left: 5px;";
|
||||
ui->numberMembersLabel->setStyleSheet(styleLabels);
|
||||
ui->lastActivityLabel->setStyleSheet(styleLabels);
|
||||
|
||||
}
|
||||
|
@ -10,11 +10,12 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#include "../data/conversation.h"
|
||||
|
||||
namespace Ui {
|
||||
class ConversationItemWidget;
|
||||
}
|
||||
|
||||
class Conversation;
|
||||
class User;
|
||||
class UsersList;
|
||||
|
||||
@ -24,7 +25,7 @@ class ConversationItemWidget : public QWidget
|
||||
|
||||
public:
|
||||
explicit ConversationItemWidget(QWidget *parent = nullptr);
|
||||
~ConversationItemWidget();
|
||||
~ConversationItemWidget() override;
|
||||
|
||||
/**
|
||||
* Apply a conversation to the widget
|
||||
@ -34,8 +35,35 @@ public:
|
||||
*/
|
||||
void setConversation(const Conversation &conv, const UsersList &list);
|
||||
|
||||
/**
|
||||
* Get the current conversation represented by this widget
|
||||
*
|
||||
* @return The current conversation of this widget
|
||||
*/
|
||||
Conversation currentConversation() const;
|
||||
|
||||
/**
|
||||
* Mark the current conversation as active or not
|
||||
*
|
||||
* @param active TRUE to mark the conversation as active /
|
||||
* FALSE else
|
||||
*/
|
||||
void setActive(bool active);
|
||||
|
||||
protected:
|
||||
|
||||
void mousePressEvent(QMouseEvent *) override;
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
* Request the conversation represented by this widget to be opened
|
||||
*/
|
||||
void openConversation();
|
||||
|
||||
private:
|
||||
Ui::ConversationItemWidget *ui;
|
||||
Conversation mCurrentConversation;
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONITEMWIDGET_H
|
||||
|
@ -32,13 +32,13 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>8</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="membersIconLabel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@ -60,6 +60,9 @@
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
@ -78,6 +81,9 @@
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
@ -85,10 +91,10 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="spacing">
|
||||
<number>8</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<widget class="QLabel" name="lastUpdateLabel">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>15</width>
|
||||
|
@ -66,6 +66,29 @@ void ConversationsListWidget::onGotUsersInfo(bool success, const UsersList &user
|
||||
for(Conversation conv : mCurrList){
|
||||
ConversationItemWidget *item = new ConversationItemWidget;
|
||||
item->setConversation(conv, users);
|
||||
connect(item, &ConversationItemWidget::openConversation, this, &ConversationsListWidget::onRequestOpenConversation);
|
||||
layout()->addWidget(item);
|
||||
}
|
||||
}
|
||||
|
||||
void ConversationsListWidget::onRequestOpenConversation()
|
||||
{
|
||||
Conversation conversation = qobject_cast<ConversationItemWidget *>(sender())->currentConversation();
|
||||
|
||||
//Notify ourselves
|
||||
setCurrentConversation(conversation);
|
||||
|
||||
//Notify everybody
|
||||
emit openConversation(conversation, mCurrList.getMembersInformation());
|
||||
}
|
||||
|
||||
void ConversationsListWidget::setCurrentConversation(const Conversation ¤tConversation)
|
||||
{
|
||||
mCurrentConversation = currentConversation;
|
||||
|
||||
//Update UI
|
||||
for(int i = 0; i < layout()->count(); i++){
|
||||
ConversationItemWidget *widget = qobject_cast<ConversationItemWidget *>(layout()->itemAt(i)->widget());
|
||||
widget->setActive(widget->currentConversation().iD() == currentConversation.iD());
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,23 @@ public:
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
/**
|
||||
* This method is used to update the currently active conversation
|
||||
*
|
||||
* @param currentConversation The current conversation
|
||||
*/
|
||||
void setCurrentConversation(const Conversation ¤tConversation);
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
* Signal emitted when a conversation is requested to be opened
|
||||
*
|
||||
* @param conversation The conversation to open
|
||||
* @param list Information about potential required users
|
||||
*/
|
||||
void openConversation(Conversation conversation, UsersList list);
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
@ -41,12 +58,20 @@ private slots:
|
||||
*/
|
||||
void onGotUsersInfo(bool success, const UsersList &users);
|
||||
|
||||
/**
|
||||
* Triggered when a conversation item request a conversation to opened
|
||||
*/
|
||||
void onRequestOpenConversation();
|
||||
|
||||
private:
|
||||
ConversationsListHelper *mConversationsList;
|
||||
UsersHelper *mUsersHelper;
|
||||
|
||||
//Current conversation in cache
|
||||
//Current conversations list in cache
|
||||
ConversationsList mCurrList;
|
||||
|
||||
//Current opened conversation
|
||||
Conversation mCurrentConversation;
|
||||
};
|
||||
|
||||
#endif // CONVERSATIONSLISTWIDGET_H
|
||||
|
Loading…
Reference in New Issue
Block a user