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

sort the friendlist by contact Status

This commit is contained in:
apprb 2014-08-22 22:19:16 +07:00
parent 24b61d00dd
commit 11c6dd7bec
8 changed files with 132 additions and 13 deletions

View File

@ -58,7 +58,6 @@ int main(int argc, char *argv[])
* Most cameras use YUYV, implement YUYV -> YUV240
* Sending large files (~380MB) "restarts" after ~10MB. Goes back to 0%, consumes twice as much ram (reloads the file?)
* => Don't load the whole file at once, load small chunks (25MB?) when needed, then free them and load the next
* Sort the friend list by status, online first then busy then offline
* Don't do anything if a friend is disconnected, don't print to the chat
* Changing online/away/busy/offline by clicking the bubble
* /me action messages

View File

@ -89,7 +89,8 @@ HEADERS += widget/form/addfriendform.h \
widget/emoticonswidget.h \
style.h \
widget/adjustingscrollarea.h \
widget/croppinglabel.h
widget/croppinglabel.h \
widget/friendlistwidget.h
SOURCES += \
widget/form/addfriendform.cpp \
@ -126,4 +127,5 @@ SOURCES += \
widget/emoticonswidget.cpp \
style.cpp \
widget/adjustingscrollarea.cpp \
widget/croppinglabel.cpp
widget/croppinglabel.cpp \
widget/friendlistwidget.cpp

View File

@ -0,0 +1,66 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
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 "friendlistwidget.h"
FriendListWidget::FriendListWidget(QWidget *parent) :
QWidget(parent)
{
mainLayout = new QGridLayout();
setLayout(mainLayout);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
layout()->setSpacing(0);
layout()->setMargin(0);
groupLayout = new QVBoxLayout();
groupLayout->setSpacing(0);
groupLayout->setMargin(0);
for (Status s : {Status::Online, Status::Away, Status::Busy, Status::Offline})
{
QLayout *l = new QVBoxLayout();
l->setSpacing(0);
l->setMargin(0);
layouts[static_cast<int>(s)] = l;
}
mainLayout->addLayout(layouts[static_cast<int>(Status::Online)], 0, 0);
mainLayout->addLayout(groupLayout, 1, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Away)], 2, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Busy)], 3, 0);
mainLayout->addLayout(layouts[static_cast<int>(Status::Offline)], 4, 0);
}
QLayout* FriendListWidget::getGroupLayout()
{
return groupLayout;
}
QLayout* FriendListWidget::getFriendLayout(Status s)
{
auto res = layouts.find(static_cast<int>(s));
if (res != layouts.end())
return res.value();
qDebug() << "Friend Status: " << static_cast<int>(s) << " not found!";
return layouts[static_cast<int>(Status::Online)];
}
void FriendListWidget::moveWidget(QWidget *w, Status s)
{
mainLayout->removeWidget(w);
getFriendLayout(s)->addWidget(w);
}

44
widget/friendlistwidget.h Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright (C) 2014 by Project Tox <https://tox.im>
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.
*/
#ifndef FRIENDLISTWIDGET_H
#define FRIENDLISTWIDGET_H
#include <QWidget>
#include <QGridLayout>
#include "core.h"
class FriendListWidget : public QWidget
{
Q_OBJECT
public:
explicit FriendListWidget(QWidget *parent = 0);
QLayout* getGroupLayout();
QLayout* getFriendLayout(Status s);
void moveWidget(QWidget *w, Status s);
signals:
public slots:
private:
QHash<int, QLayout*> layouts;
QLayout *groupLayout;
QGridLayout *mainLayout;
};
#endif // FRIENDLISTWIDGET_H

View File

@ -198,3 +198,8 @@ void FriendWidget::setAsInactiveChatroom()
this->setPalette(pal3);
avatar.setPixmap(QPixmap(":img/contact.png"));
}
int FriendWidget::isActive()
{
return isActiveWidget;
}

View File

@ -36,6 +36,7 @@ public:
void leaveEvent(QEvent* event);
void setAsActiveChatroom();
void setAsInactiveChatroom();
int isActive();
signals:
void friendWidgetClicked(FriendWidget* widget);

View File

@ -112,12 +112,8 @@ Widget::Widget(QWidget *parent)
ui->mainHead->layout()->setMargin(0);
ui->mainHead->layout()->setSpacing(0);
QWidget* friendListWidget = new QWidget();
friendListWidget->setLayout(new QVBoxLayout());
friendListWidget->layout()->setSpacing(0);
friendListWidget->layout()->setMargin(0);
friendListWidget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
ui->friendList->setWidget(friendListWidget);
contactListWidget = new FriendListWidget();
ui->friendList->setWidget(contactListWidget);
ui->friendList->setLayoutDirection(Qt::RightToLeft);
// delay setting username and message until Core inits
@ -414,8 +410,7 @@ void Widget::addFriend(int friendId, const QString &userId)
{
qDebug() << "Adding friend with id "+userId;
Friend* newfriend = FriendList::addFriend(friendId, userId);
QWidget* widget = ui->friendList->widget();
QLayout* layout = widget->layout();
QLayout* layout = contactListWidget->getFriendLayout(Status::Offline);
layout->addWidget(newfriend->widget);
connect(newfriend->widget, SIGNAL(friendWidgetClicked(FriendWidget*)), this, SLOT(onFriendWidgetClicked(FriendWidget*)));
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
@ -451,8 +446,14 @@ void Widget::onFriendStatusChanged(int friendId, Status status)
if (!f)
return;
contactListWidget->moveWidget(f->widget, status);
f->friendStatus = status;
updateFriendStatusLights(friendId);
// Workaround widget style after returning to list
if (f->widget->isActive())
f->widget->setAsActiveChatroom();
}
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
@ -716,8 +717,7 @@ Group *Widget::createGroup(int groupId)
QString groupName = QString("Groupchat #%1").arg(groupId);
Group* newgroup = GroupList::addGroup(groupId, groupName);
QWidget* widget = ui->friendList->widget();
QLayout* layout = widget->layout();
QLayout* layout = contactListWidget->getGroupLayout();
layout->addWidget(newgroup->widget);
if (!Settings::getInstance().getUseNativeDecoration())
newgroup->widget->statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));

View File

@ -27,6 +27,7 @@
#include "widget/form/settingsform.h"
#include "widget/form/filesform.h"
#include "camera.h"
#include "friendlistwidget.h"
#define PIXELS_TO_ACT 7
@ -143,6 +144,7 @@ private:
static Widget* instance;
FriendWidget* activeFriendWidget;
GroupWidget* activeGroupWidget;
FriendListWidget* contactListWidget;
int isFriendWidgetActive, isGroupWidgetActive;
SelfCamView* camview;
Camera* camera;