diff --git a/main.cpp b/main.cpp index f61cbadf4..d2d34b138 100644 --- a/main.cpp +++ b/main.cpp @@ -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 diff --git a/qtox.pro b/qtox.pro index c975ceea5..84ec1e54e 100644 --- a/qtox.pro +++ b/qtox.pro @@ -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 diff --git a/widget/friendlistwidget.cpp b/widget/friendlistwidget.cpp new file mode 100644 index 000000000..1792e00c5 --- /dev/null +++ b/widget/friendlistwidget.cpp @@ -0,0 +1,66 @@ +/* + Copyright (C) 2014 by Project Tox + + 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(s)] = l; + } + + mainLayout->addLayout(layouts[static_cast(Status::Online)], 0, 0); + mainLayout->addLayout(groupLayout, 1, 0); + mainLayout->addLayout(layouts[static_cast(Status::Away)], 2, 0); + mainLayout->addLayout(layouts[static_cast(Status::Busy)], 3, 0); + mainLayout->addLayout(layouts[static_cast(Status::Offline)], 4, 0); +} + +QLayout* FriendListWidget::getGroupLayout() +{ + return groupLayout; +} + +QLayout* FriendListWidget::getFriendLayout(Status s) +{ + auto res = layouts.find(static_cast(s)); + if (res != layouts.end()) + return res.value(); + + qDebug() << "Friend Status: " << static_cast(s) << " not found!"; + return layouts[static_cast(Status::Online)]; +} + +void FriendListWidget::moveWidget(QWidget *w, Status s) +{ + mainLayout->removeWidget(w); + getFriendLayout(s)->addWidget(w); +} diff --git a/widget/friendlistwidget.h b/widget/friendlistwidget.h new file mode 100644 index 000000000..02baa3f94 --- /dev/null +++ b/widget/friendlistwidget.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2014 by Project Tox + + 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 +#include +#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 layouts; + QLayout *groupLayout; + QGridLayout *mainLayout; +}; + +#endif // FRIENDLISTWIDGET_H diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index 84866e755..4840ed4a7 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -198,3 +198,8 @@ void FriendWidget::setAsInactiveChatroom() this->setPalette(pal3); avatar.setPixmap(QPixmap(":img/contact.png")); } + +int FriendWidget::isActive() +{ + return isActiveWidget; +} diff --git a/widget/friendwidget.h b/widget/friendwidget.h index 3fa37649a..71050d985 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -36,6 +36,7 @@ public: void leaveEvent(QEvent* event); void setAsActiveChatroom(); void setAsInactiveChatroom(); + int isActive(); signals: void friendWidgetClicked(FriendWidget* widget); diff --git a/widget/widget.cpp b/widget/widget.cpp index 1b102ef9b..2feb16d99 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -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")); diff --git a/widget/widget.h b/widget/widget.h index a31e8e6f2..4b95fd800 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -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;