void GroupWidget::contextMenuEvent(QContextMenuEvent* event) { if (!active) { setBackgroundRole(QPalette::Highlight); } installEventFilter(this); // Disable leave event. QMenu menu(this); QAction* openChatWindow = nullptr; QAction* removeChatWindow = nullptr; // TODO: Move to model ContentDialog* contentDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId); const bool notAlone = contentDialog != nullptr && contentDialog->chatroomWidgetCount() > 1; if (contentDialog == nullptr || notAlone) { openChatWindow = menu.addAction(tr("Open chat in new window")); } if (contentDialog && contentDialog->hasContactWidget(groupId)) { removeChatWindow = menu.addAction(tr("Remove chat from this window")); } menu.addSeparator(); QAction* setTitle = menu.addAction(tr("Set title...")); QAction* quitGroup = menu.addAction(tr("Quit group", "Menu to quit a groupchat")); QAction* selectedItem = menu.exec(event->globalPos()); removeEventFilter(this); if (!active) { setBackgroundRole(QPalette::Window); } if (!selectedItem) { return; } if (selectedItem == quitGroup) { emit removeGroup(groupId); } else if (selectedItem == openChatWindow) { emit newWindowOpened(this); } else if (selectedItem == removeChatWindow) { // TODO: move to model ContentDialog* contentDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId); contentDialog->removeGroup(groupId); } else if (selectedItem == setTitle) { editName(); } }
GroupWidget* ContentDialogManager::addGroupToDialog(ContentDialog* dialog, std::shared_ptr<GroupChatroom> chatroom, GenericChatForm* form) { auto groupWidget = dialog->addGroup(chatroom, form); const auto& groupId = groupWidget->getGroup()->getPersistentId(); ContentDialog* lastDialog = getGroupDialog(groupId); if (lastDialog) { lastDialog->removeGroup(groupId); } contactDialogs[groupId] = dialog; return groupWidget; }
GroupWidget* ContentDialog::addGroup(int groupId, const QString& name) { GroupWidget* groupWidget = new GroupWidget(groupId, name); groupLayout.addSortedWidget(groupWidget); Group* group = groupWidget->getGroup(); connect(group, &Group::titleChanged, this, &ContentDialog::updateGroupWidget); connect(group, &Group::userListChanged, this, &ContentDialog::updateGroupWidget); connect(settingsWidget, &SettingsWidget::compactToggled, groupWidget, &GroupWidget::compactChange); connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, &ContentDialog::onChatroomWidgetClicked); ContentDialog* lastDialog = getGroupDialog(groupId); if (lastDialog != nullptr) lastDialog->removeGroup(groupId); groupList.insert(groupId, std::make_tuple(this, groupWidget)); onChatroomWidgetClicked(groupWidget, false); return groupWidget; }