2015-05-28 01:17:12 +08:00
|
|
|
/*
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
2015-05-28 08:45:23 +08:00
|
|
|
#include "circlewidget.h"
|
2015-05-28 01:17:12 +08:00
|
|
|
#include "src/misc/style.h"
|
|
|
|
#include "src/misc/settings.h"
|
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "src/friend.h"
|
2015-06-07 11:20:06 +08:00
|
|
|
#include "friendwidget.h"
|
|
|
|
#include "friendlistlayout.h"
|
|
|
|
#include "friendlistwidget.h"
|
|
|
|
#include "croppinglabel.h"
|
|
|
|
#include "widget.h"
|
2015-05-28 01:17:12 +08:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QBoxLayout>
|
2015-05-28 22:28:11 +08:00
|
|
|
#include <QMouseEvent>
|
2015-05-28 01:17:12 +08:00
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QMimeData>
|
2015-05-29 06:36:21 +08:00
|
|
|
#include <QMenu>
|
2015-05-28 01:17:12 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2015-06-02 02:39:40 +08:00
|
|
|
void maxCropLabel(CroppingLabel* label)
|
|
|
|
{
|
|
|
|
QFontMetrics metrics = label->fontMetrics();
|
|
|
|
// Text width + padding. Without padding, we'll have elipses.
|
|
|
|
label->setMaximumWidth(metrics.width(label->fullText()) + metrics.width("..."));
|
|
|
|
}
|
|
|
|
|
2015-06-04 04:18:40 +08:00
|
|
|
QHash<int, CircleWidget*> CircleWidget::circleList;
|
|
|
|
|
|
|
|
CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
|
2015-05-28 08:45:23 +08:00
|
|
|
: GenericChatItemWidget(parent)
|
2015-06-04 04:18:40 +08:00
|
|
|
, id(id_)
|
2015-05-28 01:17:12 +08:00
|
|
|
{
|
|
|
|
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/circleWidget.css"));
|
|
|
|
|
2015-05-28 22:28:11 +08:00
|
|
|
container = new QWidget(this);
|
2015-05-28 01:17:12 +08:00
|
|
|
container->setObjectName("circleWidgetContainer");
|
2015-05-31 03:10:43 +08:00
|
|
|
container->setLayoutDirection(Qt::LeftToRight);
|
2015-05-28 01:17:12 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
// status text
|
2015-06-10 01:40:45 +08:00
|
|
|
statusLabel = new QLabel(this);
|
2015-05-31 03:10:43 +08:00
|
|
|
statusLabel->setObjectName("status");
|
|
|
|
statusLabel->setTextFormat(Qt::PlainText);
|
2015-05-28 01:17:12 +08:00
|
|
|
|
2015-06-10 01:40:45 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
|
2015-05-28 01:17:12 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
fullLayout = new QVBoxLayout(this);
|
|
|
|
fullLayout->setSpacing(0);
|
|
|
|
fullLayout->setMargin(0);
|
|
|
|
fullLayout->addWidget(container);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
lineFrame = new QFrame(container);
|
|
|
|
lineFrame->setObjectName("line");
|
|
|
|
lineFrame->setFrameShape(QFrame::HLine);
|
2015-06-02 02:39:40 +08:00
|
|
|
lineFrame->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
|
|
|
|
lineFrame->resize(0, 0);
|
2015-05-28 01:17:12 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
listLayout = new FriendListLayout();
|
2015-06-04 04:18:40 +08:00
|
|
|
listWidget = new QWidget(this);
|
|
|
|
listWidget->setLayout(listLayout);
|
2015-06-05 00:30:24 +08:00
|
|
|
fullLayout->addWidget(listWidget);
|
|
|
|
|
|
|
|
setAcceptDrops(true);
|
2015-06-04 04:18:40 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
onCompactChanged(isCompact());
|
2015-05-28 01:17:12 +08:00
|
|
|
|
2015-06-04 04:18:40 +08:00
|
|
|
if (id != -1)
|
|
|
|
{
|
|
|
|
setName(Settings::getInstance().getCircleName(id));
|
|
|
|
}
|
|
|
|
|
2015-06-08 02:25:05 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::editFinished, [this](const QString &newName)
|
2015-06-02 02:39:40 +08:00
|
|
|
{
|
2015-06-08 02:25:05 +08:00
|
|
|
if (!newName.isEmpty())
|
|
|
|
{
|
|
|
|
emit renameRequested(newName);
|
|
|
|
}
|
2015-06-02 02:39:40 +08:00
|
|
|
});
|
|
|
|
|
2015-06-04 04:18:40 +08:00
|
|
|
bool isNew = false;
|
|
|
|
auto circleIt = circleList.find(id);
|
|
|
|
if (circleIt == circleList.end())
|
|
|
|
{
|
|
|
|
if (id == -1)
|
|
|
|
{
|
|
|
|
isNew = true;
|
2015-06-07 11:20:06 +08:00
|
|
|
id = Settings::getInstance().addCircle();
|
|
|
|
nameLabel->setText(tr("Circle #%1").arg(id + 1));
|
|
|
|
Settings::getInstance().setCircleName(id, nameLabel->fullText());
|
2015-06-04 04:18:40 +08:00
|
|
|
}
|
|
|
|
}
|
2015-06-07 11:20:06 +08:00
|
|
|
circleList[id] = this;
|
2015-06-04 04:18:40 +08:00
|
|
|
|
|
|
|
if (isNew)
|
|
|
|
renameCircle();
|
|
|
|
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(Settings::getInstance().getCircleExpanded(id));
|
2015-06-10 01:40:45 +08:00
|
|
|
|
|
|
|
updateStatus();
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
|
2015-05-28 08:45:23 +08:00
|
|
|
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
2015-05-28 01:17:12 +08:00
|
|
|
{
|
2015-05-28 08:45:23 +08:00
|
|
|
listLayout->addFriendWidget(w, s);
|
2015-05-31 03:10:43 +08:00
|
|
|
updateStatus();
|
2015-06-06 03:34:32 +08:00
|
|
|
Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), id);
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
|
2015-06-06 03:34:32 +08:00
|
|
|
void CircleWidget::setExpanded(bool isExpanded)
|
2015-05-29 21:26:43 +08:00
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
expanded = isExpanded;
|
|
|
|
listWidget->setVisible(isExpanded);
|
|
|
|
if (isExpanded)
|
2015-05-28 01:17:12 +08:00
|
|
|
{
|
2015-06-10 01:40:45 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-10 01:40:45 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
2015-06-05 00:30:24 +08:00
|
|
|
|
2015-06-06 03:34:32 +08:00
|
|
|
Settings::getInstance().setCircleExpanded(id, isExpanded);
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
|
2015-06-07 11:20:06 +08:00
|
|
|
void CircleWidget::search(const QString &searchString, bool updateAll, bool hideOnline, bool hideOffline)
|
2015-05-28 01:17:12 +08:00
|
|
|
{
|
2015-06-07 11:20:06 +08:00
|
|
|
if (updateAll)
|
|
|
|
{
|
|
|
|
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
|
|
|
}
|
|
|
|
bool inCategory = searchString.isEmpty() && !(hideOnline && hideOffline);
|
|
|
|
setVisible(inCategory || listLayout->hasChatrooms());
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
void CircleWidget::setName(const QString &name)
|
|
|
|
{
|
|
|
|
nameLabel->setText(name);
|
2015-06-08 02:25:05 +08:00
|
|
|
Settings::getInstance().setCircleName(id, name);
|
|
|
|
if (isCompact())
|
|
|
|
maxCropLabel(nameLabel);
|
2015-05-31 03:10:43 +08:00
|
|
|
}
|
|
|
|
|
2015-05-29 06:36:21 +08:00
|
|
|
void CircleWidget::renameCircle()
|
|
|
|
{
|
2015-06-02 02:39:40 +08:00
|
|
|
nameLabel->editStart();
|
|
|
|
nameLabel->setMaximumWidth(QWIDGETSIZE_MAX);
|
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
void emitChatroomWidget(QLayout* layout, int index)
|
|
|
|
{
|
|
|
|
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(layout->itemAt(index)->widget());
|
|
|
|
if (chatWidget != nullptr)
|
|
|
|
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CircleWidget::cycleContacts(bool forward)
|
|
|
|
{
|
|
|
|
if (listLayout->friendTotalCount() == 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (forward)
|
|
|
|
{
|
|
|
|
if (listLayout->getLayoutOnline()->count() != 0)
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(true);
|
2015-06-03 21:51:23 +08:00
|
|
|
emitChatroomWidget(listLayout->getLayoutOnline(), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (listLayout->getLayoutOffline()->count() != 0)
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(true);
|
2015-06-03 21:51:23 +08:00
|
|
|
emitChatroomWidget(listLayout->getLayoutOffline(), 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (listLayout->getLayoutOffline()->count() != 0)
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(true);
|
2015-06-03 21:51:23 +08:00
|
|
|
emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (listLayout->getLayoutOnline()->count() != 0)
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(true);
|
2015-06-03 21:51:23 +08:00
|
|
|
emitChatroomWidget(listLayout->getLayoutOnline(), listLayout->getLayoutOnline()->count() - 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CircleWidget::cycleContacts(FriendWidget *activeChatroomWidget, bool forward)
|
|
|
|
{
|
|
|
|
int index = -1;
|
|
|
|
QLayout* currentLayout = nullptr;
|
|
|
|
|
|
|
|
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(activeChatroomWidget);
|
|
|
|
if (friendWidget != nullptr)
|
|
|
|
{
|
|
|
|
currentLayout = listLayout->getLayoutOnline();
|
|
|
|
index = listLayout->indexOfFriendWidget(friendWidget, true);
|
|
|
|
if (index == -1)
|
|
|
|
{
|
|
|
|
currentLayout = listLayout->getLayoutOffline();
|
|
|
|
index = listLayout->indexOfFriendWidget(friendWidget, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
index += forward ? 1 : -1;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
// Bounds checking.
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
if (currentLayout == listLayout->getLayoutOffline())
|
|
|
|
currentLayout = listLayout->getLayoutOnline();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
index = currentLayout->count() - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (index >= currentLayout->count())
|
|
|
|
{
|
|
|
|
if (currentLayout == listLayout->getLayoutOnline())
|
|
|
|
currentLayout = listLayout->getLayoutOffline();
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());
|
|
|
|
if (chatWidget != nullptr)
|
|
|
|
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-04 04:18:40 +08:00
|
|
|
CircleWidget* CircleWidget::getFromID(int id)
|
2015-06-02 02:39:40 +08:00
|
|
|
{
|
2015-06-04 04:18:40 +08:00
|
|
|
auto circleIt = circleList.find(id);
|
|
|
|
if (circleIt != circleList.end())
|
|
|
|
return circleIt.value();
|
|
|
|
return nullptr;
|
2015-05-29 06:36:21 +08:00
|
|
|
}
|
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
void CircleWidget::onCompactChanged(bool _compact)
|
2015-05-29 21:26:43 +08:00
|
|
|
{
|
2015-05-31 03:10:43 +08:00
|
|
|
delete topLayout;
|
|
|
|
delete mainLayout;
|
|
|
|
|
|
|
|
topLayout = new QHBoxLayout;
|
|
|
|
topLayout->setSpacing(0);
|
|
|
|
topLayout->setMargin(0);
|
|
|
|
|
|
|
|
setProperty("compact", _compact);
|
|
|
|
|
|
|
|
if (property("compact").toBool())
|
|
|
|
{
|
2015-06-02 02:39:40 +08:00
|
|
|
maxCropLabel(nameLabel);
|
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
mainLayout = nullptr;
|
|
|
|
|
|
|
|
container->setFixedHeight(25);
|
|
|
|
container->setLayout(topLayout);
|
|
|
|
|
|
|
|
topLayout->addSpacing(18);
|
2015-06-10 01:40:45 +08:00
|
|
|
topLayout->addWidget(&statusPic);
|
2015-05-31 03:10:43 +08:00
|
|
|
topLayout->addSpacing(5);
|
2015-06-02 02:39:40 +08:00
|
|
|
topLayout->addWidget(nameLabel, 100);
|
2015-05-31 03:10:43 +08:00
|
|
|
topLayout->addWidget(lineFrame, 1);
|
|
|
|
topLayout->addSpacing(5);
|
|
|
|
topLayout->addWidget(statusLabel);
|
|
|
|
topLayout->addSpacing(5);
|
|
|
|
topLayout->activate();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-02 02:39:40 +08:00
|
|
|
nameLabel->setMaximumWidth(QWIDGETSIZE_MAX);
|
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
mainLayout = new QVBoxLayout();
|
|
|
|
mainLayout->setSpacing(0);
|
|
|
|
mainLayout->setContentsMargins(20, 0, 20, 0);
|
|
|
|
|
|
|
|
container->setFixedHeight(55);
|
|
|
|
container->setLayout(mainLayout);
|
|
|
|
|
2015-06-10 01:40:45 +08:00
|
|
|
topLayout->addWidget(&statusPic);
|
2015-05-31 03:10:43 +08:00
|
|
|
topLayout->addSpacing(10);
|
2015-06-02 02:39:40 +08:00
|
|
|
topLayout->addWidget(nameLabel, 1);
|
|
|
|
topLayout->addSpacing(5);
|
2015-05-31 03:10:43 +08:00
|
|
|
topLayout->addWidget(statusLabel);
|
|
|
|
topLayout->activate();
|
|
|
|
|
|
|
|
mainLayout->addStretch();
|
|
|
|
mainLayout->addLayout(topLayout);
|
|
|
|
mainLayout->addWidget(lineFrame);
|
|
|
|
mainLayout->addStretch();
|
|
|
|
mainLayout->activate();
|
|
|
|
}
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
Style::repolish(this);
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
|
|
|
|
2015-05-29 06:36:21 +08:00
|
|
|
void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
{
|
|
|
|
QMenu menu;
|
|
|
|
QAction *renameAction = menu.addAction(tr("Rename circle", "Menu for renaming a circle"));
|
|
|
|
QAction *removeAction = menu.addAction(tr("Remove circle", "Menu for removing a circle"));
|
|
|
|
|
|
|
|
QAction *selectedItem = menu.exec(mapToGlobal(event->pos()));
|
|
|
|
if (selectedItem == renameAction)
|
|
|
|
renameCircle();
|
|
|
|
else if (selectedItem == removeAction)
|
|
|
|
{
|
|
|
|
FriendListWidget *friendList = static_cast<FriendListWidget*>(parentWidget());
|
2015-06-03 21:51:23 +08:00
|
|
|
listLayout->moveFriendWidgets(friendList);
|
2015-05-29 06:36:21 +08:00
|
|
|
|
|
|
|
friendList->removeCircleWidget(this);
|
2015-06-04 04:18:40 +08:00
|
|
|
|
|
|
|
circleList.remove(id);
|
|
|
|
int replacedCircle = Settings::getInstance().removeCircle(id);
|
|
|
|
|
|
|
|
auto circleReplace = circleList.find(replacedCircle);
|
|
|
|
if (circleReplace != circleList.end())
|
|
|
|
circleReplace.value()->updateID(id);
|
2015-05-29 06:36:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-28 22:28:11 +08:00
|
|
|
void CircleWidget::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if (event->button() == Qt::LeftButton)
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(!expanded);
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CircleWidget::dragEnterEvent(QDragEnterEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat("friend"))
|
|
|
|
event->acceptProposedAction();
|
2015-05-28 22:28:11 +08:00
|
|
|
container->setAttribute(Qt::WA_UnderMouse, true); // Simulate hover.
|
|
|
|
Style::repolish(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CircleWidget::dragLeaveEvent(QDragLeaveEvent *)
|
|
|
|
{
|
|
|
|
container->setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
Style::repolish(container);
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CircleWidget::dropEvent(QDropEvent *event)
|
|
|
|
{
|
|
|
|
if (event->mimeData()->hasFormat("friend"))
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
setExpanded(true);
|
2015-05-28 08:45:23 +08:00
|
|
|
|
2015-05-28 01:17:12 +08:00
|
|
|
int friendId = event->mimeData()->data("friend").toInt();
|
|
|
|
Friend *f = FriendList::findFriend(friendId);
|
|
|
|
assert(f != nullptr);
|
|
|
|
|
|
|
|
FriendWidget *widget = f->getFriendWidget();
|
|
|
|
assert(widget != nullptr);
|
|
|
|
|
2015-05-29 00:58:44 +08:00
|
|
|
// Update old circle after moved.
|
2015-06-06 03:34:32 +08:00
|
|
|
CircleWidget *circleWidget = getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
2015-05-29 00:58:44 +08:00
|
|
|
|
|
|
|
addFriendWidget(widget, f->getStatus());
|
|
|
|
|
|
|
|
if (circleWidget != nullptr)
|
|
|
|
{
|
2015-05-31 03:10:43 +08:00
|
|
|
circleWidget->updateStatus();
|
2015-06-07 11:20:06 +08:00
|
|
|
Widget::getInstance()->searchCircle(circleWidget);
|
2015-05-29 00:58:44 +08:00
|
|
|
}
|
2015-05-28 22:28:11 +08:00
|
|
|
|
|
|
|
container->setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
Style::repolish(container);
|
2015-05-28 01:17:12 +08:00
|
|
|
}
|
|
|
|
}
|
2015-05-29 00:58:44 +08:00
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
void CircleWidget::updateStatus()
|
2015-05-29 00:58:44 +08:00
|
|
|
{
|
2015-05-31 03:10:43 +08:00
|
|
|
statusLabel->setText(QString::number(listLayout->friendOnlineCount()) + QStringLiteral(" / ") + QString::number(listLayout->friendTotalCount()));
|
2015-05-29 00:58:44 +08:00
|
|
|
}
|
2015-06-04 04:18:40 +08:00
|
|
|
|
|
|
|
void CircleWidget::updateID(int index)
|
|
|
|
{
|
|
|
|
// For when a circle gets destroyed, another takes its id.
|
2015-06-10 01:40:45 +08:00
|
|
|
// This function updates all friends widgets for this new id.
|
2015-06-04 04:18:40 +08:00
|
|
|
id = index;
|
|
|
|
circleList[id] = this;
|
|
|
|
|
|
|
|
for (int i = 0; i < listLayout->getLayoutOnline()->count(); ++i)
|
|
|
|
{
|
|
|
|
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(listLayout->getLayoutOnline()->itemAt(i));
|
|
|
|
if (friendWidget != nullptr)
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);
|
2015-06-04 04:18:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < listLayout->getLayoutOffline()->count(); ++i)
|
|
|
|
{
|
|
|
|
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(listLayout->getLayoutOffline()->itemAt(i));
|
|
|
|
if (friendWidget != nullptr)
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
Settings::getInstance().setFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId(), id);
|
2015-06-04 04:18:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|