1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: Split 'onChatrootWidgetClicked' on 2 methods

onChatrootWidgetClicked was used for 2 different actions.
Now it's splitted on 'activate' and 'openNewDialog'
This commit is contained in:
Diadlo 2017-05-28 12:39:11 +03:00
parent 4d15aed53f
commit 331a8f1006
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
8 changed files with 106 additions and 74 deletions

View File

@ -30,11 +30,12 @@
void CategoryWidget::emitChatroomWidget(QLayout* layout, int index) void CategoryWidget::emitChatroomWidget(QLayout* layout, int index)
{ {
GenericChatroomWidget* chatWidget = QWidget* widget = layout->itemAt(index)->widget();
qobject_cast<GenericChatroomWidget*>(layout->itemAt(index)->widget()); GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
if (chatWidget != nullptr) if (chatWidget != nullptr) {
emit chatWidget->chatroomWidgetClicked(chatWidget); emit chatWidget->chatroomWidgetClicked(chatWidget);
} }
}
CategoryWidget::CategoryWidget(bool compact, QWidget* parent) CategoryWidget::CategoryWidget(bool compact, QWidget* parent)
: GenericChatItemWidget(compact, parent) : GenericChatItemWidget(compact, parent)

View File

@ -168,11 +168,11 @@ FriendWidget* ContentDialog::addFriend(int friendId, QString id)
Friend* frnd = friendWidget->getFriend(); Friend* frnd = friendWidget->getFriend();
friendLayout->addFriendWidget(friendWidget, frnd->getStatus()); friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
ChatForm* form = frnd->getChatForm();
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget); connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
&ContentDialog::onChatroomWidgetClicked); connect(friendWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
connect(friendWidget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), connect(friendWidget, &FriendWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
frnd->getChatForm(), SLOT(focusInput()));
ContentDialog* lastDialog = getFriendDialog(friendId); ContentDialog* lastDialog = getFriendDialog(friendId);
if (lastDialog) { if (lastDialog) {
@ -181,7 +181,7 @@ FriendWidget* ContentDialog::addFriend(int friendId, QString id)
friendList.insert(friendId, std::make_tuple(this, friendWidget)); friendList.insert(friendId, std::make_tuple(this, friendWidget));
// FIXME: emit should be removed // FIXME: emit should be removed
emit friendWidget->chatroomWidgetClicked(friendWidget, false); emit friendWidget->chatroomWidgetClicked(friendWidget);
return friendWidget; return friendWidget;
} }
@ -195,8 +195,8 @@ GroupWidget* ContentDialog::addGroup(int groupId, const QString& name)
Group* group = groupWidget->getGroup(); Group* group = groupWidget->getGroup();
connect(group, &Group::titleChanged, this, &ContentDialog::updateGroupWidget); connect(group, &Group::titleChanged, this, &ContentDialog::updateGroupWidget);
connect(group, &Group::userListChanged, this, &ContentDialog::updateGroupWidget); connect(group, &Group::userListChanged, this, &ContentDialog::updateGroupWidget);
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
&ContentDialog::onChatroomWidgetClicked); connect(groupWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
ContentDialog* lastDialog = getGroupDialog(groupId); ContentDialog* lastDialog = getGroupDialog(groupId);
@ -206,7 +206,7 @@ GroupWidget* ContentDialog::addGroup(int groupId, const QString& name)
groupList.insert(groupId, std::make_tuple(this, groupWidget)); groupList.insert(groupId, std::make_tuple(this, groupWidget));
// FIXME: emit should be removed // FIXME: emit should be removed
emit groupWidget->chatroomWidgetClicked(groupWidget, false); emit groupWidget->chatroomWidgetClicked(groupWidget);
return groupWidget; return groupWidget;
} }
@ -379,7 +379,7 @@ void ContentDialog::cycleContacts(bool forward, bool inverse)
GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget); GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
if (chatWidget && chatWidget != activeChatroomWidget) { if (chatWidget && chatWidget != activeChatroomWidget) {
// FIXME: emit should be removed // FIXME: emit should be removed
emit chatWidget->chatroomWidgetClicked(chatWidget, false); emit chatWidget->chatroomWidgetClicked(chatWidget);
} }
} }
@ -691,13 +691,11 @@ void ContentDialog::keyPressEvent(QKeyEvent* event)
} }
/** /**
* @brief Show ContentDialog, activate chatroom widget. * @brief Open a new dialog window associated with widget
* @param widget Widget which was clicked. * @param widget Widget associated with contact.
* @param group Seems always `false`. TODO: Remove
*/ */
void ContentDialog::onChatroomWidgetClicked(GenericChatroomWidget* widget, bool group) void ContentDialog::openNewDialog(GenericChatroomWidget* widget)
{ {
if (group) {
ContentDialog* contentDialog = new ContentDialog(settingsWidget); ContentDialog* contentDialog = new ContentDialog(settingsWidget);
contentDialog->show(); contentDialog->show();
@ -711,10 +709,14 @@ void ContentDialog::onChatroomWidgetClicked(GenericChatroomWidget* widget, bool
contentDialog->raise(); contentDialog->raise();
contentDialog->activateWindow(); contentDialog->activateWindow();
return;
} }
/**
* @brief Show ContentDialog, activate chatroom widget.
* @param widget Widget which should be activated.
*/
void ContentDialog::activate(GenericChatroomWidget* widget)
{
// If we clicked on the currently active widget, don't reload and relayout everything // If we clicked on the currently active widget, don't reload and relayout everything
if (activeChatroomWidget == widget) { if (activeChatroomWidget == widget) {
return; return;
@ -839,7 +841,7 @@ void ContentDialog::focusDialog(int id, const QHash<int, ContactInfo>& list)
dialog->raise(); dialog->raise();
dialog->activateWindow(); dialog->activateWindow();
dialog->onChatroomWidgetClicked(std::get<1>(iter.value()), false); dialog->activate(std::get<1>(iter.value()));
} }
/** /**

View File

@ -100,7 +100,8 @@ protected:
void keyPressEvent(QKeyEvent* event) override; void keyPressEvent(QKeyEvent* event) override;
private slots: private slots:
void onChatroomWidgetClicked(GenericChatroomWidget* widget, bool group); void activate(GenericChatroomWidget* widget);
void openNewDialog(GenericChatroomWidget* widget);
void updateFriendWidget(uint32_t friendId, QString alias); void updateFriendWidget(uint32_t friendId, QString alias);
void updateGroupWidget(GroupWidget* w); void updateGroupWidget(GroupWidget* w);
void onGroupchatPositionChanged(bool top); void onGroupchatPositionChanged(bool top);

View File

@ -199,18 +199,20 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
removeEventFilter(this); removeEventFilter(this);
if (!active) if (!active) {
setBackgroundRole(QPalette::Window); setBackgroundRole(QPalette::Window);
}
if (!selectedItem) if (!selectedItem) {
return; return;
}
if (selectedItem == setAlias) { if (selectedItem == setAlias) {
nameLabel->editBegin(); nameLabel->editBegin();
} else if (selectedItem == removeFriendAction) { } else if (selectedItem == removeFriendAction) {
emit removeFriend(friendId); emit removeFriend(friendId);
} else if (selectedItem == openChatWindow) { } else if (selectedItem == openChatWindow) {
emit chatroomWidgetClicked(this, true); emit newWindowOpened(this);
} else if (selectedItem == removeChatWindow) { } else if (selectedItem == removeChatWindow) {
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId); ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
contentDialog->removeFriend(friendId); contentDialog->removeFriend(friendId);

View File

@ -68,7 +68,8 @@ public slots:
void compactChange(bool compact); void compactChange(bool compact);
signals: signals:
void chatroomWidgetClicked(GenericChatroomWidget* widget, bool group = false); void chatroomWidgetClicked(GenericChatroomWidget* widget);
void newWindowOpened(GenericChatroomWidget* widget);
protected: protected:
virtual void mouseReleaseEvent(QMouseEvent* event) override; virtual void mouseReleaseEvent(QMouseEvent* event) override;

View File

@ -101,21 +101,21 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent* event)
if (!active) if (!active)
setBackgroundRole(QPalette::Window); setBackgroundRole(QPalette::Window);
if (selectedItem) { if (!selectedItem) {
return;
}
if (selectedItem == quitGroup) { if (selectedItem == quitGroup) {
emit removeGroup(groupId); emit removeGroup(groupId);
} else if (selectedItem == openChatWindow) { } else if (selectedItem == openChatWindow) {
emit chatroomWidgetClicked(this, true); emit newWindowOpened(this);
return;
} else if (selectedItem == removeChatWindow) { } else if (selectedItem == removeChatWindow) {
ContentDialog* contentDialog = ContentDialog::getGroupDialog(groupId); ContentDialog* contentDialog = ContentDialog::getGroupDialog(groupId);
contentDialog->removeGroup(groupId); contentDialog->removeGroup(groupId);
return;
} else if (selectedItem == setTitle) { } else if (selectedItem == setTitle) {
editName(); editName();
} }
} }
}
void GroupWidget::mousePressEvent(QMouseEvent* ev) void GroupWidget::mousePressEvent(QMouseEvent* ev)
{ {

View File

@ -980,6 +980,7 @@ void Widget::addFriend(int friendId, const ToxPk& friendPk)
connect(friendForm, &ChatForm::rejectCall, this, &Widget::onRejectCall); connect(friendForm, &ChatForm::rejectCall, this, &Widget::onRejectCall);
connect(friendForm, &ChatForm::acceptCall, this, &Widget::onAcceptCall); connect(friendForm, &ChatForm::acceptCall, this, &Widget::onAcceptCall);
connect(widget, &FriendWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked); connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput); connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput);
connect(widget, &FriendWidget::copyFriendIdToClipboard, this, &Widget::copyFriendIdToClipboard); connect(widget, &FriendWidget::copyFriendIdToClipboard, this, &Widget::copyFriendIdToClipboard);
@ -1093,19 +1094,29 @@ void Widget::onFriendAliasChanged(uint32_t friendId, const QString& alias)
} }
} }
void Widget::onChatroomWidgetClicked(GenericChatroomWidget* widget, bool group) void Widget::onChatroomWidgetClicked(GenericChatroomWidget* widget)
{
openDialog(widget, false);
}
void Widget::openNewDialog(GenericChatroomWidget* widget)
{
openDialog(widget, true);
}
void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
{ {
widget->resetEventFlags(); widget->resetEventFlags();
widget->updateStatusLight(); widget->updateStatusLight();
if (widget->chatFormIsSet(true) && !group) { if (widget->chatFormIsSet(true) && !newWindow) {
return; return;
} }
if (Settings::getInstance().getSeparateWindow() || group) { if (Settings::getInstance().getSeparateWindow() || newWindow) {
ContentDialog* dialog = nullptr; ContentDialog* dialog = nullptr;
if (!Settings::getInstance().getDontGroupWindows() && !group) { if (!Settings::getInstance().getDontGroupWindows() && !newWindow) {
dialog = ContentDialog::current(); dialog = ContentDialog::current();
} }
@ -1189,13 +1200,18 @@ void Widget::addFriendDialog(Friend* frnd, ContentDialog* dialog)
connect(friendWidget, &FriendWidget::contextMenuCalled, widget, connect(friendWidget, &FriendWidget::contextMenuCalled, widget,
[=](QContextMenuEvent* event) { emit widget->contextMenuCalled(event); }); [=](QContextMenuEvent* event) { emit widget->contextMenuCalled(event); });
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
[=](GenericChatroomWidget* w, bool group) { [=](GenericChatroomWidget* w) {
Q_UNUSED(w); Q_UNUSED(w);
emit widget->chatroomWidgetClicked(widget, group); emit widget->chatroomWidgetClicked(widget);
});
connect(friendWidget, &FriendWidget::newWindowOpened,
[=](GenericChatroomWidget* w) {
Q_UNUSED(w);
emit widget->newWindowOpened(widget);
}); });
// FIXME: emit should be removed // FIXME: emit should be removed
emit widget->chatroomWidgetClicked(widget, false); emit widget->chatroomWidgetClicked(widget);
Core* core = Core::getInstance(); Core* core = Core::getInstance();
connect(core, &Core::friendAvatarChanged, friendWidget, &FriendWidget::onAvatarChange); connect(core, &Core::friendAvatarChanged, friendWidget, &FriendWidget::onAvatarChange);
@ -1226,14 +1242,20 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
// Signal transmission from the created `groupWidget` (which shown in // Signal transmission from the created `groupWidget` (which shown in
// ContentDialog) to the `widget` (which shown in main widget) // ContentDialog) to the `widget` (which shown in main widget)
// FIXME: emit should be removed // FIXME: emit should be removed
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, connect(groupWidget, &GroupWidget::chatroomWidgetClicked,
[=](GenericChatroomWidget* w, bool group) { [=](GenericChatroomWidget* w) {
Q_UNUSED(w); Q_UNUSED(w);
emit widget->chatroomWidgetClicked(widget, group); emit widget->chatroomWidgetClicked(widget);
});
connect(groupWidget, &GroupWidget::newWindowOpened,
[=](GenericChatroomWidget* w) {
Q_UNUSED(w);
emit widget->newWindowOpened(widget);
}); });
// FIXME: emit should be removed // FIXME: emit should be removed
emit widget->chatroomWidgetClicked(widget, false); emit widget->chatroomWidgetClicked(widget);
} }
bool Widget::newFriendMessageAlert(int friendId, bool sound) bool Widget::newFriendMessageAlert(int friendId, bool sound)
@ -1764,22 +1786,23 @@ Group* Widget::createGroup(int groupId)
bool enabled = coreAv->isGroupAvEnabled(groupId); bool enabled = coreAv->isGroupAvEnabled(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName, enabled); Group* newgroup = GroupList::addGroup(groupId, groupName, enabled);
GroupWidget* widget = newgroup->getGroupWidget();
contactListWidget->addGroupWidget(newgroup->getGroupWidget()); contactListWidget->addGroupWidget(widget);
newgroup->getGroupWidget()->updateStatusLight(); widget->updateStatusLight();
contactListWidget->activateWindow(); contactListWidget->activateWindow();
connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*, bool)), GroupChatForm* form = newgroup->getChatForm();
this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*, bool))); connect(widget, &GroupWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
connect(newgroup->getGroupWidget(), SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int))); connect(widget, &GroupWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), connect(widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
newgroup->getChatForm(), SLOT(focusInput())); connect(widget, &GroupWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
connect(newgroup->getChatForm(), &GroupChatForm::sendMessage, core, &Core::sendGroupMessage); connect(form, &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
connect(newgroup->getChatForm(), &GroupChatForm::sendAction, core, &Core::sendGroupAction); connect(form, &GroupChatForm::sendAction, core, &Core::sendGroupAction);
connect(newgroup->getChatForm(), &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle); connect(form, &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle);
FilterCriteria filter = getFilterCriteria(); FilterCriteria filter = getFilterCriteria();
newgroup->getGroupWidget()->searchName(ui->searchContactText->text(), filterGroups(filter)); widget->searchName(ui->searchContactText->text(), filterGroups(filter));
return newgroup; return newgroup;
} }

View File

@ -196,7 +196,8 @@ private slots:
void onGroupClicked(); void onGroupClicked();
void onTransferClicked(); void onTransferClicked();
void showProfile(); void showProfile();
void onChatroomWidgetClicked(GenericChatroomWidget*, bool group); void openNewDialog(GenericChatroomWidget* widget);
void onChatroomWidgetClicked(GenericChatroomWidget* widget);
void onStatusMessageChanged(const QString& newStatusMessage); void onStatusMessageChanged(const QString& newStatusMessage);
void removeFriend(int friendId); void removeFriend(int friendId);
void copyFriendIdToClipboard(int friendId); void copyFriendIdToClipboard(int friendId);
@ -240,6 +241,7 @@ private:
static bool filterOffline(FilterCriteria index); static bool filterOffline(FilterCriteria index);
void retranslateUi(); void retranslateUi();
void focusChatInput(); void focusChatInput();
void openDialog(GenericChatroomWidget* widget, bool newWindow);
private: private:
SystemTrayIcon* icon = nullptr; SystemTrayIcon* icon = nullptr;