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)
{
GenericChatroomWidget* chatWidget =
qobject_cast<GenericChatroomWidget*>(layout->itemAt(index)->widget());
if (chatWidget != nullptr)
QWidget* widget = layout->itemAt(index)->widget();
GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
if (chatWidget != nullptr) {
emit chatWidget->chatroomWidgetClicked(chatWidget);
}
}
CategoryWidget::CategoryWidget(bool compact, QWidget* parent)
: GenericChatItemWidget(compact, parent)

View File

@ -168,11 +168,11 @@ FriendWidget* ContentDialog::addFriend(int friendId, QString id)
Friend* frnd = friendWidget->getFriend();
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
ChatForm* form = frnd->getChatForm();
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this,
&ContentDialog::onChatroomWidgetClicked);
connect(friendWidget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)),
frnd->getChatForm(), SLOT(focusInput()));
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
connect(friendWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
ContentDialog* lastDialog = getFriendDialog(friendId);
if (lastDialog) {
@ -181,7 +181,7 @@ FriendWidget* ContentDialog::addFriend(int friendId, QString id)
friendList.insert(friendId, std::make_tuple(this, friendWidget));
// FIXME: emit should be removed
emit friendWidget->chatroomWidgetClicked(friendWidget, false);
emit friendWidget->chatroomWidgetClicked(friendWidget);
return friendWidget;
}
@ -195,8 +195,8 @@ GroupWidget* ContentDialog::addGroup(int groupId, const QString& name)
Group* group = groupWidget->getGroup();
connect(group, &Group::titleChanged, this, &ContentDialog::updateGroupWidget);
connect(group, &Group::userListChanged, this, &ContentDialog::updateGroupWidget);
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this,
&ContentDialog::onChatroomWidgetClicked);
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
connect(groupWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
ContentDialog* lastDialog = getGroupDialog(groupId);
@ -206,7 +206,7 @@ GroupWidget* ContentDialog::addGroup(int groupId, const QString& name)
groupList.insert(groupId, std::make_tuple(this, groupWidget));
// FIXME: emit should be removed
emit groupWidget->chatroomWidgetClicked(groupWidget, false);
emit groupWidget->chatroomWidgetClicked(groupWidget);
return groupWidget;
}
@ -379,7 +379,7 @@ void ContentDialog::cycleContacts(bool forward, bool inverse)
GenericChatroomWidget* chatWidget = qobject_cast<GenericChatroomWidget*>(widget);
if (chatWidget && chatWidget != activeChatroomWidget) {
// 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.
* @param widget Widget which was clicked.
* @param group Seems always `false`. TODO: Remove
* @brief Open a new dialog window associated with widget
* @param widget Widget associated with contact.
*/
void ContentDialog::onChatroomWidgetClicked(GenericChatroomWidget* widget, bool group)
void ContentDialog::openNewDialog(GenericChatroomWidget* widget)
{
if (group) {
ContentDialog* contentDialog = new ContentDialog(settingsWidget);
contentDialog->show();
@ -711,10 +709,14 @@ void ContentDialog::onChatroomWidgetClicked(GenericChatroomWidget* widget, bool
contentDialog->raise();
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 (activeChatroomWidget == widget) {
return;
@ -839,7 +841,7 @@ void ContentDialog::focusDialog(int id, const QHash<int, ContactInfo>& list)
dialog->raise();
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;
private slots:
void onChatroomWidgetClicked(GenericChatroomWidget* widget, bool group);
void activate(GenericChatroomWidget* widget);
void openNewDialog(GenericChatroomWidget* widget);
void updateFriendWidget(uint32_t friendId, QString alias);
void updateGroupWidget(GroupWidget* w);
void onGroupchatPositionChanged(bool top);

View File

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

View File

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

View File

@ -101,21 +101,21 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent* event)
if (!active)
setBackgroundRole(QPalette::Window);
if (selectedItem) {
if (!selectedItem) {
return;
}
if (selectedItem == quitGroup) {
emit removeGroup(groupId);
} else if (selectedItem == openChatWindow) {
emit chatroomWidgetClicked(this, true);
return;
emit newWindowOpened(this);
} else if (selectedItem == removeChatWindow) {
ContentDialog* contentDialog = ContentDialog::getGroupDialog(groupId);
contentDialog->removeGroup(groupId);
return;
} else if (selectedItem == setTitle) {
editName();
}
}
}
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::acceptCall, this, &Widget::onAcceptCall);
connect(widget, &FriendWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput);
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->updateStatusLight();
if (widget->chatFormIsSet(true) && !group) {
if (widget->chatFormIsSet(true) && !newWindow) {
return;
}
if (Settings::getInstance().getSeparateWindow() || group) {
if (Settings::getInstance().getSeparateWindow() || newWindow) {
ContentDialog* dialog = nullptr;
if (!Settings::getInstance().getDontGroupWindows() && !group) {
if (!Settings::getInstance().getDontGroupWindows() && !newWindow) {
dialog = ContentDialog::current();
}
@ -1189,13 +1200,18 @@ void Widget::addFriendDialog(Friend* frnd, ContentDialog* dialog)
connect(friendWidget, &FriendWidget::contextMenuCalled, widget,
[=](QContextMenuEvent* event) { emit widget->contextMenuCalled(event); });
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this,
[=](GenericChatroomWidget* w, bool group) {
connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
[=](GenericChatroomWidget* 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
emit widget->chatroomWidgetClicked(widget, false);
emit widget->chatroomWidgetClicked(widget);
Core* core = Core::getInstance();
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
// ContentDialog) to the `widget` (which shown in main widget)
// FIXME: emit should be removed
connect(groupWidget, &GroupWidget::chatroomWidgetClicked, this,
[=](GenericChatroomWidget* w, bool group) {
connect(groupWidget, &GroupWidget::chatroomWidgetClicked,
[=](GenericChatroomWidget* 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
emit widget->chatroomWidgetClicked(widget, false);
emit widget->chatroomWidgetClicked(widget);
}
bool Widget::newFriendMessageAlert(int friendId, bool sound)
@ -1764,22 +1786,23 @@ Group* Widget::createGroup(int groupId)
bool enabled = coreAv->isGroupAvEnabled(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName, enabled);
GroupWidget* widget = newgroup->getGroupWidget();
contactListWidget->addGroupWidget(newgroup->getGroupWidget());
newgroup->getGroupWidget()->updateStatusLight();
contactListWidget->addGroupWidget(widget);
widget->updateStatusLight();
contactListWidget->activateWindow();
connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*, bool)),
this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*, bool)));
connect(newgroup->getGroupWidget(), SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
connect(newgroup->getGroupWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)),
newgroup->getChatForm(), SLOT(focusInput()));
connect(newgroup->getChatForm(), &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
connect(newgroup->getChatForm(), &GroupChatForm::sendAction, core, &Core::sendGroupAction);
connect(newgroup->getChatForm(), &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle);
GroupChatForm* form = newgroup->getChatForm();
connect(widget, &GroupWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
connect(widget, &GroupWidget::newWindowOpened, this, &Widget::openNewDialog);
connect(widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
connect(widget, &GroupWidget::chatroomWidgetClicked, form, &ChatForm::focusInput);
connect(form, &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
connect(form, &GroupChatForm::sendAction, core, &Core::sendGroupAction);
connect(form, &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle);
FilterCriteria filter = getFilterCriteria();
newgroup->getGroupWidget()->searchName(ui->searchContactText->text(), filterGroups(filter));
widget->searchName(ui->searchContactText->text(), filterGroups(filter));
return newgroup;
}

View File

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