From 0d4ca979bc42d631cabbb1396e5123344ace9f48 Mon Sep 17 00:00:00 2001 From: TheSpiritXIII Date: Fri, 5 Jun 2015 13:38:07 -0400 Subject: [PATCH] Fix right click friend in circle --- src/persistence/settings.cpp | 9 ++++++ src/widget/circlewidget.cpp | 7 ++--- src/widget/friendlistwidget.cpp | 54 +++++++++++++++++---------------- src/widget/friendwidget.cpp | 2 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 0dd804b59..359fd4762 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -1301,6 +1301,15 @@ void Settings::setFriendCircleIndex(const ToxId &id, int index) auto it = friendLst.find(key); if (it != friendLst.end()) it->circleIndex = index; + else + { + friendProp fp; + fp.addr = key; + fp.alias = ""; + fp.autoAcceptDir = ""; + fp.circleIndex = index; + friendLst[key] = fp; + } } void Settings::removeFriendSettings(const ToxId &id) diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index f0e99b32f..0b07801c5 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -119,8 +119,6 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_) renameCircle(); listWidget->setVisible(Settings::getInstance().getCircleExpanded(id)); - //expand(); - //Settings::getInstance().setCircleExpanded(id, isExpanded); } void CircleWidget::addFriendWidget(FriendWidget *w, Status s) @@ -128,6 +126,7 @@ void CircleWidget::addFriendWidget(FriendWidget *w, Status s) listLayout->addFriendWidget(w, s); updateStatus(); Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId(), id); + qDebug() << Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(w->friendId)->getToxId()) << " WITH " << id; } void CircleWidget::expand() @@ -401,7 +400,7 @@ void CircleWidget::dropEvent(QDropEvent *event) assert(widget != nullptr); // Update old circle after moved. - CircleWidget *circleWidget = dynamic_cast(widget->parent()); + CircleWidget *circleWidget = getFromID(Settings::getInstance().getFriendCircleIndex(f->getToxId())); addFriendWidget(widget, f->getStatus()); @@ -433,7 +432,6 @@ void CircleWidget::updateID(int index) FriendWidget* friendWidget = dynamic_cast(listLayout->getLayoutOnline()->itemAt(i)); if (friendWidget != nullptr) { - qDebug() << "My yolo slow"; Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(friendWidget->friendId)->getToxId(), id); } } @@ -442,7 +440,6 @@ void CircleWidget::updateID(int index) FriendWidget* friendWidget = dynamic_cast(listLayout->getLayoutOffline()->itemAt(i)); if (friendWidget != nullptr) { - qDebug() << "My yolo slow"; Settings::getInstance().setFriendCircleIndex(FriendList::findFriend(friendWidget->friendId)->getToxId(), id); } } diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index ad53a93f9..67459de9b 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -156,27 +156,29 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget if (activeChatroomWidget == nullptr) return; - CircleWidget* circleWidget = dynamic_cast(activeChatroomWidget->parentWidget()); int index = -1; QLayout* currentLayout = nullptr; + CircleWidget* circleWidget = nullptr; FriendWidget* friendWidget = dynamic_cast(activeChatroomWidget); - if (circleWidget != nullptr) - { - if (friendWidget == nullptr) - { - return; - } - if (circleWidget->cycleContacts(friendWidget, forward)) - return; - index = circleLayout.indexOfSortedWidget(circleWidget); - currentLayout = circleLayout.getLayout(); - } - else + if (friendWidget != nullptr) { - if (friendWidget != nullptr) + circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(friendWidget->friendId)->getToxId())); + if (circleWidget != nullptr) + { + if (friendWidget == nullptr) + { + return; + } + if (circleWidget->cycleContacts(friendWidget, forward)) + return; + + index = circleLayout.indexOfSortedWidget(circleWidget); + currentLayout = circleLayout.getLayout(); + } + else { currentLayout = listLayout->getLayoutOnline(); index = listLayout->indexOfFriendWidget(friendWidget, true); @@ -186,19 +188,19 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget index = listLayout->indexOfFriendWidget(friendWidget, false); } } + } + else + { + GroupWidget* groupWidget = dynamic_cast(activeChatroomWidget); + if (groupWidget != nullptr) + { + currentLayout = groupLayout.getLayout(); + index = groupLayout.indexOfSortedWidget(groupWidget); + } else { - GroupWidget* groupWidget = dynamic_cast(activeChatroomWidget); - if (groupWidget != nullptr) - { - currentLayout = groupLayout.getLayout(); - index = groupLayout.indexOfSortedWidget(groupWidget); - } - else - { - return; - }; - } + return; + }; } index += forward ? 1 : -1; @@ -277,7 +279,7 @@ void FriendListWidget::dropEvent(QDropEvent *event) assert(widget != nullptr); // Update old circle after moved. - CircleWidget *circleWidget = dynamic_cast(widget->parent()); + CircleWidget *circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(f->getToxId())); listLayout->addFriendWidget(widget, f->getStatus()); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 19592e015..59f7afe4f 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -215,7 +215,7 @@ void FriendWidget::updateStatusLight() if (f->getEventFlag()) { - CircleWidget* circleWidget = dynamic_cast(parentWidget()); + CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleIndex(FriendList::findFriend(friendId)->getToxId())); if (circleWidget != nullptr) circleWidget->expand(); }