// if preformance would be critical, replace with QHash<int friendId, ChatPageWidget*> ChatPageWidget* PagesWidget::widget(int friendId) const { for (int i = 0; i < count(); i++) { ChatPageWidget* chatPage = dynamic_cast<ChatPageWidget*>(QStackedWidget::widget(i)); if (chatPage != nullptr && chatPage->getFriendId() == friendId) { return chatPage; } } return nullptr; }
void PagesWidget::onActionToSend(const QString &action) { ChatPageWidget* chatPage = static_cast<ChatPageWidget*>(sender()); emit sendAction(chatPage->getFriendId(), action); }
void PagesWidget::onMessageSent(const QString& message) { ChatPageWidget* chatPage = static_cast<ChatPageWidget*>(sender()); emit sendMessage(chatPage->getFriendId(), message); }