2015-05-28 08:45:23 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "friendlistlayout.h"
|
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "friendwidget.h"
|
|
|
|
#include <cassert>
|
|
|
|
|
2015-05-28 22:28:11 +08:00
|
|
|
#include "groupwidget.h"
|
|
|
|
#include "friendwidget.h"
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
#include "friendlistwidget.h"
|
|
|
|
|
2015-05-28 22:28:11 +08:00
|
|
|
#include <QDebug>
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
FriendListLayout::FriendListLayout()
|
2015-05-28 08:45:23 +08:00
|
|
|
{
|
|
|
|
setSpacing(0);
|
|
|
|
setMargin(0);
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
friendOnlineLayout.getLayout()->setSpacing(0);
|
|
|
|
friendOnlineLayout.getLayout()->setMargin(0);
|
2015-05-28 08:45:23 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
friendOfflineLayout.getLayout()->setSpacing(0);
|
|
|
|
friendOfflineLayout.getLayout()->setMargin(0);
|
2015-05-28 08:45:23 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
addLayout(friendOnlineLayout.getLayout());
|
|
|
|
addLayout(friendOfflineLayout.getLayout());
|
|
|
|
}
|
2015-05-28 08:45:23 +08:00
|
|
|
|
2015-06-05 00:30:24 +08:00
|
|
|
FriendListLayout::FriendListLayout(QWidget *parent)
|
|
|
|
: QVBoxLayout(parent)
|
|
|
|
{
|
|
|
|
FriendListLayout();
|
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
|
|
|
|
{
|
|
|
|
// bug somewhere here.
|
2015-06-04 04:18:40 +08:00
|
|
|
friendOfflineLayout.getLayout()->removeWidget(w);
|
|
|
|
friendOnlineLayout.getLayout()->removeWidget(w);
|
2015-06-03 21:51:23 +08:00
|
|
|
if (s == Status::Offline)
|
2015-05-28 08:45:23 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
friendOfflineLayout.addSortedWidget(w);
|
|
|
|
return;
|
2015-05-28 08:45:23 +08:00
|
|
|
}
|
2015-06-03 21:51:23 +08:00
|
|
|
friendOnlineLayout.addSortedWidget(w);
|
2015-05-28 08:45:23 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
int FriendListLayout::indexOfFriendWidget(FriendWidget *widget, bool online) const
|
2015-05-28 08:45:23 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
if (online)
|
|
|
|
return friendOnlineLayout.indexOfSortedWidget(widget);
|
|
|
|
return friendOfflineLayout.indexOfSortedWidget(widget);
|
|
|
|
}
|
2015-05-28 08:45:23 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
|
|
|
|
{
|
|
|
|
while (friendOnlineLayout.getLayout()->count() != 0)
|
2015-05-28 08:45:23 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
QWidget *getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
|
|
|
|
assert(getWidget != nullptr);
|
|
|
|
|
|
|
|
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
|
|
|
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
2015-05-28 08:45:23 +08:00
|
|
|
}
|
2015-06-03 21:51:23 +08:00
|
|
|
while (friendOfflineLayout.getLayout()->count() != 0)
|
|
|
|
{
|
|
|
|
QWidget *getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
|
|
|
|
assert(getWidget != nullptr);
|
2015-05-28 08:45:23 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
|
|
|
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
|
|
|
}
|
2015-05-28 08:45:23 +08:00
|
|
|
}
|
|
|
|
|
2015-05-29 00:58:44 +08:00
|
|
|
int FriendListLayout::friendOnlineCount() const
|
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
return friendOnlineLayout.getLayout()->count();
|
2015-05-29 00:58:44 +08:00
|
|
|
}
|
|
|
|
|
2015-05-31 03:10:43 +08:00
|
|
|
int FriendListLayout::friendTotalCount() const
|
2015-05-29 00:58:44 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
return friendOfflineLayout.getLayout()->count() + friendOnlineCount();
|
2015-05-29 00:58:44 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
bool FriendListLayout::hasChatrooms() const
|
2015-05-28 22:28:11 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-05-28 22:28:11 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
void FriendListLayout::searchChatrooms(const QString& searchString, bool hideOnline, bool hideOffline)
|
|
|
|
{
|
|
|
|
searchLayout<FriendWidget>(searchString, friendOnlineLayout.getLayout(), hideOnline);
|
|
|
|
searchLayout<FriendWidget>(searchString, friendOfflineLayout.getLayout(), hideOffline);
|
2015-05-28 22:28:11 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
QLayout* FriendListLayout::getLayoutOnline() const
|
2015-05-28 22:28:11 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
return friendOnlineLayout.getLayout();
|
2015-05-28 22:28:11 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
QLayout* FriendListLayout::getLayoutOffline() const
|
2015-05-28 08:45:23 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
return friendOfflineLayout.getLayout();
|
2015-05-28 08:45:23 +08:00
|
|
|
}
|
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
QLayout* FriendListLayout::getFriendLayout(Status s)
|
2015-05-28 08:45:23 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
return s == Status::Offline ? friendOfflineLayout.getLayout() : friendOnlineLayout.getLayout();
|
2015-05-28 08:45:23 +08:00
|
|
|
}
|