コード例 #1
0
void PagesWidget::addPage(const QString& userId, const QString& username)
{
    ChatPageWidget* chatPage = new ChatPageWidget(userId, this);
    chatPage->setUsername(username);
    connect(chatPage, &ChatPageWidget::messageSent, this, &PagesWidget::onMessageSent);
    addWidget(chatPage);
    qDebug() << "page" << userId << "added" << count();
}
コード例 #2
0
void PagesWidget::addPage(int friendId, const QString& username)
{
    ChatPageWidget* chatPage = new ChatPageWidget(friendId, this);
    chatPage->setUsername(username);
    connect(chatPage, &ChatPageWidget::sendMessage, this, &PagesWidget::onMessageSent);
    connect(chatPage, &ChatPageWidget::sendAction,  this, &PagesWidget::onActionToSend);
    addWidget(chatPage);
    qDebug() << "page" << friendId << "added" << count();
}
コード例 #3
0
// if preformance would be critical, replace with QHash<QString userId, ChatPageWidget*>
ChatPageWidget* PagesWidget::widget(const QString& userId) const
{
    for (int i = 0; i < count(); i ++) {
        ChatPageWidget* chatPage = dynamic_cast<ChatPageWidget*>(QStackedWidget::widget(i));
        if (chatPage != nullptr && chatPage->getUserId() == userId) {
            return chatPage;
        }
    }
    return nullptr;
}
コード例 #4
0
void PagesWidget::onMessageSent(const QString &message)
{
    ChatPageWidget* chatPage = static_cast<ChatPageWidget*>(sender());
    emit messageSent(chatPage->getUserId(), message);
}
コード例 #5
0
void PagesWidget::onActionToSend(const QString &action)
{
    ChatPageWidget* chatPage = static_cast<ChatPageWidget*>(sender());
    emit sendAction(chatPage->getFriendId(), action);
}