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>
|
#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)
|
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
: friendId(FriendId)
|
: friendId(FriendId)
|
||||||
, isDefaultAvatar{true}
|
, isDefaultAvatar{true}
|
||||||
|
@ -62,7 +70,25 @@ FriendWidget::FriendWidget(int FriendId, QString id)
|
||||||
statusMessageLabel->setTextFormat(Qt::PlainText);
|
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)
|
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)
|
if (!active)
|
||||||
setBackgroundRole(QPalette::Highlight);
|
setBackgroundRole(QPalette::Highlight);
|
||||||
|
@ -114,7 +140,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
FriendListWidget *friendList;
|
FriendListWidget *friendList;
|
||||||
|
|
||||||
if (circleWidget == nullptr)
|
if (circleWidget == nullptr)
|
||||||
friendList = qobject_cast<FriendListWidget*>(FriendList::findFriend(friendId)->getFriendWidget()->parentWidget());
|
friendList = qobject_cast<FriendListWidget*>(this->parentWidget());
|
||||||
else
|
else
|
||||||
friendList = qobject_cast<FriendListWidget*>(circleWidget->parentWidget());
|
friendList = qobject_cast<FriendListWidget*>(circleWidget->parentWidget());
|
||||||
|
|
||||||
|
@ -170,8 +196,9 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
if (!active)
|
if (!active)
|
||||||
setBackgroundRole(QPalette::Window);
|
setBackgroundRole(QPalette::Window);
|
||||||
|
|
||||||
if (selectedItem)
|
if (!selectedItem)
|
||||||
{
|
return;
|
||||||
|
|
||||||
if (selectedItem == setAlias)
|
if (selectedItem == setAlias)
|
||||||
{
|
{
|
||||||
nameLabel->editBegin();
|
nameLabel->editBegin();
|
||||||
|
@ -179,18 +206,15 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
else if (selectedItem == removeFriendAction)
|
else if (selectedItem == removeFriendAction)
|
||||||
{
|
{
|
||||||
emit removeFriend(friendId);
|
emit removeFriend(friendId);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (selectedItem == openChatWindow)
|
else if (selectedItem == openChatWindow)
|
||||||
{
|
{
|
||||||
emit chatroomWidgetClicked(this, true);
|
emit chatroomWidgetClicked(this, true);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (selectedItem == removeChatWindow)
|
else if (selectedItem == removeChatWindow)
|
||||||
{
|
{
|
||||||
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
||||||
contentDialog->removeFriend(friendId);
|
contentDialog->removeFriend(friendId);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (selectedItem == autoAccept)
|
else if (selectedItem == autoAccept)
|
||||||
{
|
{
|
||||||
|
@ -203,12 +227,12 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
}
|
}
|
||||||
else if (autoAccept->isChecked())
|
else if (autoAccept->isChecked())
|
||||||
{
|
{
|
||||||
dir = QFileDialog::getExistingDirectory(0,
|
dir = QFileDialog::getExistingDirectory(
|
||||||
tr("Choose an auto accept directory","popup title"),
|
0, tr("Choose an auto accept directory", "popup title"),
|
||||||
dir,
|
dir, QFileDialog::DontUseNativeDialog);
|
||||||
QFileDialog::DontUseNativeDialog);
|
|
||||||
autoAccept->setChecked(true);
|
autoAccept->setChecked(true);
|
||||||
qDebug() << "setting auto accept dir for" << friendId << "to" << dir;
|
qDebug() << "Setting auto accept dir for" << friendId << "to" << dir;
|
||||||
Settings::getInstance().setAutoAcceptDir(id, dir);
|
Settings::getInstance().setAutoAcceptDir(id, dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,7 +253,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
circleWidget->updateStatus();
|
circleWidget->updateStatus();
|
||||||
|
|
||||||
if (friendList != nullptr)
|
if (friendList != nullptr)
|
||||||
friendList->addCircleWidget(FriendList::findFriend(friendId)->getFriendWidget());
|
friendList->addCircleWidget(this);
|
||||||
else
|
else
|
||||||
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
||||||
}
|
}
|
||||||
|
@ -240,8 +264,8 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
}
|
}
|
||||||
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
||||||
{
|
{
|
||||||
if (friendList != nullptr)
|
if (friendList)
|
||||||
friendList->moveWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus(), true);
|
friendList->moveWidget(this, FriendList::findFriend(friendId)->getStatus(), true);
|
||||||
else
|
else
|
||||||
Settings::getInstance().setFriendCircleID(id, -1);
|
Settings::getInstance().setFriendCircleID(id, -1);
|
||||||
|
|
||||||
|
@ -255,23 +279,24 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
{
|
{
|
||||||
CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]);
|
CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]);
|
||||||
|
|
||||||
if (circle != nullptr)
|
if (circle)
|
||||||
{
|
{
|
||||||
circle->addFriendWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus());
|
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
||||||
circle->setExpanded(true);
|
circle->setExpanded(true);
|
||||||
Widget::getInstance()->searchCircle(circle);
|
Widget::getInstance()->searchCircle(circle);
|
||||||
Settings::getInstance().savePersonal();
|
Settings::getInstance().savePersonal();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
||||||
|
}
|
||||||
|
|
||||||
if (circleWidget != nullptr)
|
if (circleWidget)
|
||||||
{
|
{
|
||||||
circleWidget->updateStatus();
|
circleWidget->updateStatus();
|
||||||
Widget::getInstance()->searchCircle(circleWidget);
|
Widget::getInstance()->searchCircle(circleWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendWidget::setAsActiveChatroom()
|
void FriendWidget::setAsActiveChatroom()
|
||||||
|
|
|
@ -43,11 +43,13 @@ signals:
|
||||||
void friendWidgetClicked(FriendWidget* widget);
|
void friendWidgetClicked(FriendWidget* widget);
|
||||||
void removeFriend(int friendId);
|
void removeFriend(int friendId);
|
||||||
void copyFriendIdToClipboard(int friendId);
|
void copyFriendIdToClipboard(int friendId);
|
||||||
|
void contextMenuCalled(QContextMenuEvent * event);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onAvatarChange(int FriendId, const QPixmap& pic);
|
void onAvatarChange(int FriendId, const QPixmap& pic);
|
||||||
void onAvatarRemoved(int FriendId);
|
void onAvatarRemoved(int FriendId);
|
||||||
void setAlias(const QString& alias);
|
void setAlias(const QString& alias);
|
||||||
|
void onContextMenuCalled(QContextMenuEvent * event);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QMouseEvent* ev) override;
|
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, 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);
|
||||||
|
connect(widget, &FriendWidget::contextMenuCalled, widget, &FriendWidget::onContextMenuCalled);
|
||||||
connect(widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
connect(widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||||
|
|
||||||
// Try to get the avatar from the cache
|
// 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
|
// Signal transmission from the created `friendWidget` (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(friendWidget, &FriendWidget::contextMenuCalled,
|
||||||
|
widget, [=](QContextMenuEvent * event)
|
||||||
|
{
|
||||||
|
emit widget->contextMenuCalled(event);
|
||||||
|
});
|
||||||
|
|
||||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
|
connect(friendWidget, &FriendWidget::chatroomWidgetClicked,
|
||||||
this, [=](GenericChatroomWidget *w, bool group)
|
this, [=](GenericChatroomWidget *w, bool group)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user