mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Adds functionality for sorting FriendWidgets alphabetically in the
friends list. Widgets are sorted upon being added to the friends list in the first place, and re-sorted if a user changes their name, or if a user is given an alias. -Friend now inherits from QObject -Friend objects now emit a signal when their display name is changed -FriendListWidget::moveWidget() is now a slot
This commit is contained in:
parent
4f0798bde7
commit
fdb4fef374
|
@ -53,6 +53,8 @@ void Friend::setName(QString name)
|
||||||
|
|
||||||
if (widget->isActive())
|
if (widget->isActive())
|
||||||
GUI::setWindowTitle(name);
|
GUI::setWindowTitle(name);
|
||||||
|
|
||||||
|
emit displayedNameChanged(getFriendWidget(), getStatus(), hasNewEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,6 +68,8 @@ void Friend::setAlias(QString name)
|
||||||
|
|
||||||
if (widget->isActive())
|
if (widget->isActive())
|
||||||
GUI::setWindowTitle(dispName);
|
GUI::setWindowTitle(dispName);
|
||||||
|
|
||||||
|
emit displayedNameChanged(getFriendWidget(), getStatus(), hasNewEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Friend::setStatusMessage(QString message)
|
void Friend::setStatusMessage(QString message)
|
||||||
|
|
|
@ -17,14 +17,16 @@
|
||||||
#ifndef FRIEND_H
|
#ifndef FRIEND_H
|
||||||
#define FRIEND_H
|
#define FRIEND_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "corestructs.h"
|
#include "corestructs.h"
|
||||||
|
|
||||||
struct FriendWidget;
|
struct FriendWidget;
|
||||||
class ChatForm;
|
class ChatForm;
|
||||||
|
|
||||||
struct Friend
|
struct Friend : QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Friend(int FriendId, const ToxID &UserId);
|
Friend(int FriendId, const ToxID &UserId);
|
||||||
Friend(const Friend& other)=delete;
|
Friend(const Friend& other)=delete;
|
||||||
|
@ -49,6 +51,9 @@ public:
|
||||||
ChatForm *getChatForm();
|
ChatForm *getChatForm();
|
||||||
FriendWidget *getFriendWidget();
|
FriendWidget *getFriendWidget();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void displayedNameChanged(FriendWidget* widget, Status s, int hasNewEvents);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString userAlias, userName;
|
QString userAlias, userName;
|
||||||
ToxID userID;
|
ToxID userID;
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
#include "friendlistwidget.h"
|
#include "friendlistwidget.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
#include "src/friend.h"
|
||||||
|
#include "src/friendlist.h"
|
||||||
|
#include "src/widget/friendwidget.h"
|
||||||
|
|
||||||
FriendListWidget::FriendListWidget(QWidget *parent) :
|
FriendListWidget::FriendListWidget(QWidget *parent) :
|
||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
|
@ -63,9 +66,18 @@ QVBoxLayout* FriendListWidget::getFriendLayout(Status s)
|
||||||
|
|
||||||
void FriendListWidget::moveWidget(QWidget *w, Status s, int hasNewEvents)
|
void FriendListWidget::moveWidget(QWidget *w, Status s, int hasNewEvents)
|
||||||
{
|
{
|
||||||
mainLayout->removeWidget(w);
|
getFriendLayout(s)->removeWidget(w);
|
||||||
if (hasNewEvents == 0)
|
QVBoxLayout* l = getFriendLayout(s);
|
||||||
getFriendLayout(s)->addWidget(w);
|
Friend* g = FriendList::findFriend(dynamic_cast<FriendWidget*>(w)->friendId);
|
||||||
else
|
for(int i = 0; i < l->count(); i++){
|
||||||
getFriendLayout(s)->insertWidget(0, w);
|
FriendWidget* w1 = dynamic_cast<FriendWidget*>(l->itemAt(i)->widget());
|
||||||
|
if(w1 != NULL){
|
||||||
|
Friend* f = FriendList::findFriend(w1->friendId);
|
||||||
|
if(f->getDisplayedName().localeAwareCompare(g->getDisplayedName()) > 0){
|
||||||
|
l->insertWidget(i,w);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l->addWidget(w);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,11 +33,11 @@ public:
|
||||||
|
|
||||||
QVBoxLayout* getGroupLayout();
|
QVBoxLayout* getGroupLayout();
|
||||||
QVBoxLayout* getFriendLayout(Status s);
|
QVBoxLayout* getFriendLayout(Status s);
|
||||||
void moveWidget(QWidget *w, Status s, int hasNewEvents);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void moveWidget(QWidget *w, Status s, int hasNewEvents);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<int, QVBoxLayout*> layouts;
|
QHash<int, QVBoxLayout*> layouts;
|
||||||
|
|
|
@ -559,10 +559,10 @@ void Widget::addFriend(int friendId, const QString &userId)
|
||||||
//qDebug() << "Widget: Adding friend with id" << userId;
|
//qDebug() << "Widget: Adding friend with id" << userId;
|
||||||
ToxID userToxId = ToxID::fromString(userId);
|
ToxID userToxId = ToxID::fromString(userId);
|
||||||
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
|
Friend* newfriend = FriendList::addFriend(friendId, userToxId);
|
||||||
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
|
contactListWidget->moveWidget(newfriend->getFriendWidget(),Status::Offline,0);
|
||||||
layout->addWidget(newfriend->getFriendWidget());
|
|
||||||
|
|
||||||
Core* core = Nexus::getCore();
|
Core* core = Nexus::getCore();
|
||||||
|
connect(newfriend, &Friend::displayedNameChanged, contactListWidget, &FriendListWidget::moveWidget);
|
||||||
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::onCompactChanged);
|
connect(settingsWidget, &SettingsWidget::compactToggled, newfriend->getFriendWidget(), &GenericChatroomWidget::onCompactChanged);
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
connect(newfriend->getFriendWidget(), SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
|
||||||
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
connect(newfriend->getFriendWidget(), SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user