mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Remove using getFriendWidget from FriendWidget
This commit is contained in:
parent
4d806a3661
commit
7d1564e586
|
@ -48,6 +48,14 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
/**
|
||||
* @class FriendWidget
|
||||
*
|
||||
* Widget, which displays brief information about friend.
|
||||
* For example, used on friend list.
|
||||
* When you click should open the chat with friend. Widget has a context menu.
|
||||
*/
|
||||
|
||||
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||
: friendId(FriendId)
|
||||
, isDefaultAvatar{true}
|
||||
|
@ -62,7 +70,25 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
|||
statusMessageLabel->setTextFormat(Qt::PlainText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FriendWidget::contextMenuEvent
|
||||
* @param event Describe a context menu event
|
||||
*
|
||||
* Default context menu event handler.
|
||||
* Redirect all event information to the signal.
|
||||
*/
|
||||
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||
{
|
||||
emit contextMenuCalled(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FriendWidget::onContextMenuCalled
|
||||
* @param event Redirected from native contextMenuEvent
|
||||
*
|
||||
* Context menu handler. Always should be called to FriendWidget from FriendList
|
||||
*/
|
||||
void FriendWidget::onContextMenuCalled(QContextMenuEvent *event)
|
||||
{
|
||||
if (!active)
|
||||
setBackgroundRole(QPalette::Highlight);
|
||||
|
@ -114,7 +140,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
FriendListWidget *friendList;
|
||||
|
||||
if (circleWidget == nullptr)
|
||||
friendList = qobject_cast<FriendListWidget*>(FriendList::findFriend(friendId)->getFriendWidget()->parentWidget());
|
||||
friendList = qobject_cast<FriendListWidget*>(this->parentWidget());
|
||||
else
|
||||
friendList = qobject_cast<FriendListWidget*>(circleWidget->parentWidget());
|
||||
|
||||
|
@ -170,106 +196,105 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
if (!active)
|
||||
setBackgroundRole(QPalette::Window);
|
||||
|
||||
if (selectedItem)
|
||||
if (!selectedItem)
|
||||
return;
|
||||
|
||||
if (selectedItem == setAlias)
|
||||
{
|
||||
if (selectedItem == setAlias)
|
||||
nameLabel->editBegin();
|
||||
}
|
||||
else if (selectedItem == removeFriendAction)
|
||||
{
|
||||
emit removeFriend(friendId);
|
||||
}
|
||||
else if (selectedItem == openChatWindow)
|
||||
{
|
||||
emit chatroomWidgetClicked(this, true);
|
||||
}
|
||||
else if (selectedItem == removeChatWindow)
|
||||
{
|
||||
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
||||
contentDialog->removeFriend(friendId);
|
||||
}
|
||||
else if (selectedItem == autoAccept)
|
||||
{
|
||||
if (!autoAccept->isChecked())
|
||||
{
|
||||
nameLabel->editBegin();
|
||||
qDebug() << "not checked";
|
||||
dir = QDir::homePath();
|
||||
autoAccept->setChecked(false);
|
||||
Settings::getInstance().setAutoAcceptDir(id, "");
|
||||
}
|
||||
else if (selectedItem == removeFriendAction)
|
||||
else if (autoAccept->isChecked())
|
||||
{
|
||||
emit removeFriend(friendId);
|
||||
return;
|
||||
}
|
||||
else if (selectedItem == openChatWindow)
|
||||
{
|
||||
emit chatroomWidgetClicked(this, true);
|
||||
return;
|
||||
}
|
||||
else if (selectedItem == removeChatWindow)
|
||||
{
|
||||
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
||||
contentDialog->removeFriend(friendId);
|
||||
return;
|
||||
}
|
||||
else if (selectedItem == autoAccept)
|
||||
{
|
||||
if (!autoAccept->isChecked())
|
||||
{
|
||||
qDebug() << "not checked";
|
||||
dir = QDir::homePath();
|
||||
autoAccept->setChecked(false);
|
||||
Settings::getInstance().setAutoAcceptDir(id, "");
|
||||
}
|
||||
else if (autoAccept->isChecked())
|
||||
{
|
||||
dir = QFileDialog::getExistingDirectory(0,
|
||||
tr("Choose an auto accept directory","popup title"),
|
||||
dir,
|
||||
QFileDialog::DontUseNativeDialog);
|
||||
autoAccept->setChecked(true);
|
||||
qDebug() << "setting auto accept dir for" << friendId << "to" << dir;
|
||||
Settings::getInstance().setAutoAcceptDir(id, dir);
|
||||
}
|
||||
}
|
||||
else if (selectedItem == aboutWindow)
|
||||
{
|
||||
AboutUser *aboutUser = new AboutUser(id, Widget::getInstance());
|
||||
aboutUser->setFriend(FriendList::findFriend(friendId));
|
||||
aboutUser->show();
|
||||
}
|
||||
else if (selectedItem == newGroupAction)
|
||||
{
|
||||
int groupId = Core::getInstance()->createGroup();
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
}
|
||||
else if (selectedItem == newCircleAction)
|
||||
{
|
||||
if (circleWidget != nullptr)
|
||||
circleWidget->updateStatus();
|
||||
dir = QFileDialog::getExistingDirectory(
|
||||
0, tr("Choose an auto accept directory", "popup title"),
|
||||
dir, QFileDialog::DontUseNativeDialog);
|
||||
|
||||
if (friendList != nullptr)
|
||||
friendList->addCircleWidget(FriendList::findFriend(friendId)->getFriendWidget());
|
||||
else
|
||||
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
||||
autoAccept->setChecked(true);
|
||||
qDebug() << "Setting auto accept dir for" << friendId << "to" << dir;
|
||||
Settings::getInstance().setAutoAcceptDir(id, dir);
|
||||
}
|
||||
else if (groupActions.contains(selectedItem))
|
||||
}
|
||||
else if (selectedItem == aboutWindow)
|
||||
{
|
||||
AboutUser *aboutUser = new AboutUser(id, Widget::getInstance());
|
||||
aboutUser->setFriend(FriendList::findFriend(friendId));
|
||||
aboutUser->show();
|
||||
}
|
||||
else if (selectedItem == newGroupAction)
|
||||
{
|
||||
int groupId = Core::getInstance()->createGroup();
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
}
|
||||
else if (selectedItem == newCircleAction)
|
||||
{
|
||||
if (circleWidget != nullptr)
|
||||
circleWidget->updateStatus();
|
||||
|
||||
if (friendList != nullptr)
|
||||
friendList->addCircleWidget(this);
|
||||
else
|
||||
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
||||
}
|
||||
else if (groupActions.contains(selectedItem))
|
||||
{
|
||||
Group* group = groupActions[selectedItem];
|
||||
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
||||
}
|
||||
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
||||
{
|
||||
if (friendList)
|
||||
friendList->moveWidget(this, FriendList::findFriend(friendId)->getStatus(), true);
|
||||
else
|
||||
Settings::getInstance().setFriendCircleID(id, -1);
|
||||
|
||||
if (circleWidget)
|
||||
{
|
||||
Group* group = groupActions[selectedItem];
|
||||
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
||||
{
|
||||
if (friendList != nullptr)
|
||||
friendList->moveWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus(), true);
|
||||
else
|
||||
Settings::getInstance().setFriendCircleID(id, -1);
|
||||
}
|
||||
else if (circleActions.contains(selectedItem))
|
||||
{
|
||||
CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]);
|
||||
|
||||
if (circleWidget)
|
||||
{
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
if (circle)
|
||||
{
|
||||
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
||||
circle->setExpanded(true);
|
||||
Widget::getInstance()->searchCircle(circle);
|
||||
Settings::getInstance().savePersonal();
|
||||
}
|
||||
else if (circleActions.contains(selectedItem))
|
||||
else
|
||||
{
|
||||
CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]);
|
||||
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
||||
}
|
||||
|
||||
if (circle != nullptr)
|
||||
{
|
||||
circle->addFriendWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus());
|
||||
circle->setExpanded(true);
|
||||
Widget::getInstance()->searchCircle(circle);
|
||||
Settings::getInstance().savePersonal();
|
||||
}
|
||||
else
|
||||
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
||||
|
||||
if (circleWidget != nullptr)
|
||||
{
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
if (circleWidget)
|
||||
{
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,11 +43,13 @@ signals:
|
|||
void friendWidgetClicked(FriendWidget* widget);
|
||||
void removeFriend(int friendId);
|
||||
void copyFriendIdToClipboard(int friendId);
|
||||
void contextMenuCalled(QContextMenuEvent * event);
|
||||
|
||||
public slots:
|
||||
void onAvatarChange(int FriendId, const QPixmap& pic);
|
||||
void onAvatarRemoved(int FriendId);
|
||||
void setAlias(const QString& alias);
|
||||
void onContextMenuCalled(QContextMenuEvent * event);
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent* ev) override;
|
||||
|
|
|
@ -1021,6 +1021,7 @@ void Widget::addFriend(int friendId, const ToxPk& friendPk)
|
|||
connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked);
|
||||
connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput);
|
||||
connect(widget, &FriendWidget::copyFriendIdToClipboard, this, &Widget::copyFriendIdToClipboard);
|
||||
connect(widget, &FriendWidget::contextMenuCalled, widget, &FriendWidget::onContextMenuCalled);
|
||||
connect(widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||
|
||||
// Try to get the avatar from the cache
|
||||
|
@ -1274,6 +1275,12 @@ void Widget::addFriendDialog(Friend *frnd, ContentDialog *dialog)
|
|||
// Signal transmission from the created `friendWidget` (which shown in
|
||||
// ContentDialog) to the `widget` (which shown in main widget)
|
||||
// FIXME: emit should be removed
|
||||
connect(friendWidget, &FriendWidget::contextMenuCalled,
|
||||
widget, [=](QContextMenuEvent * event)
|
||||
{
|
||||
emit widget->contextMenuCalled(event);
|
||||
});
|
||||
|
||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
|
||||
this, [=](GenericChatroomWidget *w, bool group)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user