1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(ui): code improvement

This commit is contained in:
bodwok 2021-06-17 19:13:32 +03:00
parent 89fa7db90a
commit 1d5dd8063e
No known key found for this signature in database
GPG Key ID: A279D059178DA7BA
2 changed files with 14 additions and 25 deletions

View File

@ -20,8 +20,6 @@
#include "friendlistmanager.h"
#include "src/widget/genericchatroomwidget.h"
#include <QApplication>
bool FriendListManager::groupsOnTop = true;
FriendListManager::FriendListManager(QObject *parent) : QObject(parent)
@ -46,8 +44,7 @@ void FriendListManager::addFriendItem(IFriendListItem *item)
if (item->isGroup()) {
items.push_back(IFriendItemPtr(item, [](IFriendListItem* groupItem){
groupItem->getWidget()->deleteLater();}));
}
else {
} else {
items.push_back(IFriendItemPtr(item));
}
@ -104,8 +101,7 @@ void FriendListManager::applyFilter()
for (IFriendItemPtr itemTmp : items) {
if (searchString.isEmpty()) {
itemTmp->getWidget()->setVisible(true);
}
else {
} else {
QString tmp_name = itemTmp->getNameItem();
itemTmp->getWidget()->setVisible(tmp_name.contains(searchString, Qt::CaseInsensitive));
}
@ -127,8 +123,7 @@ void FriendListManager::applyFilter()
if (filterParams.hideOnline && filterParams.hideOffline) {
hideCircles = true;
}
else {
} else {
hideCircles = false;
}
}
@ -137,8 +132,7 @@ void FriendListManager::updatePositions()
{
if (byName) {
std::sort(items.begin(), items.end(), cmpByName);
}
else {
} else {
std::sort(items.begin(), items.end(), cmpByActivity);
}
}

View File

@ -159,15 +159,13 @@ void FriendListWidget::sortByMode(SortingMode mode)
int posByName = 0; // Needed for scroll contacts
// Linking a friend with a circle and setting scroll position
for (int i = 0; i < itemsTmp.size(); ++i) {
if (itemsTmp[i]->isFriend()) {
if (itemsTmp[i]->getCircleId() >= 0) {
CircleWidget* circleWgt = CircleWidget::getFromID(itemsTmp[i]->getCircleId());
if (circleWgt != nullptr) {
FriendWidget* frndTmp =
qobject_cast<FriendWidget*>((itemsTmp[i].get())->getWidget());
circleWgt->addFriendWidget(frndTmp, frndTmp->getFriend()->getStatus());
continue;
}
if (itemsTmp[i]->isFriend() && itemsTmp[i]->getCircleId() >= 0) {
CircleWidget* circleWgt = CircleWidget::getFromID(itemsTmp[i]->getCircleId());
if (circleWgt != nullptr) {
FriendWidget* frndTmp =
qobject_cast<FriendWidget*>((itemsTmp[i].get())->getWidget());
circleWgt->addFriendWidget(frndTmp, frndTmp->getFriend()->getStatus());
continue;
}
}
itemsTmp[i]->setPosForName(posByName++);
@ -273,8 +271,7 @@ void FriendListWidget::cleanMainLayout()
QWidget* wgt = itemForDel->widget();
if (wgt != nullptr) {
wgt->setParent(nullptr);
}
else if (itemForDel->layout() != nullptr) {
} else if (itemForDel->layout() != nullptr) {
QLayout* layout = itemForDel->layout();
QLayoutItem* itemTmp;
while ((itemTmp = layout->takeAt(0)) != nullptr) {
@ -295,8 +292,7 @@ QWidget* FriendListWidget::getNextWidgetForName(IFriendListItem *currentPos, boo
int nextPos = forward ? pos + 1 : pos - 1;
if (nextPos >= manager->getItems().size()) {
nextPos = 0;
}
else if (nextPos < 0) {
} else if (nextPos < 0) {
nextPos = manager->getItems().size() - 1;
}
@ -483,8 +479,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
if (friendWidget != nullptr) {
wgt = getNextWidgetForName(friendWidget, forward);
}
else {
} else {
GroupWidget* groupWidget = qobject_cast<GroupWidget*>(activeChatroomWidget);
wgt = getNextWidgetForName(groupWidget, forward);
}