mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Update status on contact groupings
This commit is contained in:
parent
682feb7a58
commit
1e2bad8611
|
@ -41,7 +41,7 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
container->setObjectName("circleWidgetContainer");
|
container->setObjectName("circleWidgetContainer");
|
||||||
container->setProperty("active", false);
|
container->setProperty("active", false);
|
||||||
mainLayout = new QVBoxLayout(this);
|
mainLayout = new QVBoxLayout(this);
|
||||||
listLayout = new FriendListLayout(this);
|
listLayout = new FriendListLayout();
|
||||||
QHBoxLayout *layout = new QHBoxLayout();
|
QHBoxLayout *layout = new QHBoxLayout();
|
||||||
QVBoxLayout *midLayout = new QVBoxLayout;
|
QVBoxLayout *midLayout = new QVBoxLayout;
|
||||||
QHBoxLayout *topLayout = new QHBoxLayout;
|
QHBoxLayout *topLayout = new QHBoxLayout;
|
||||||
|
@ -64,10 +64,11 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
QFrame *lineFrame = new QFrame(container);
|
QFrame *lineFrame = new QFrame(container);
|
||||||
lineFrame->setObjectName("line");
|
lineFrame->setObjectName("line");
|
||||||
lineFrame->setFrameShape(QFrame::HLine);
|
lineFrame->setFrameShape(QFrame::HLine);
|
||||||
topLayout->addSpacing(5);
|
//topLayout->addSpacing(5);
|
||||||
topLayout->addWidget(lineFrame, 1);
|
//topLayout->addWidget(lineFrame, 1);
|
||||||
|
|
||||||
midLayout->addLayout(topLayout);
|
midLayout->addLayout(topLayout);
|
||||||
|
midLayout->addWidget(lineFrame);
|
||||||
|
|
||||||
midLayout->addStretch();
|
midLayout->addStretch();
|
||||||
|
|
||||||
|
@ -76,35 +77,37 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
QLabel *onlineIconLabel = new QLabel(container);
|
QLabel *onlineIconLabel = new QLabel(container);
|
||||||
onlineIconLabel->setAlignment(Qt::AlignCenter);
|
onlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||||
onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
||||||
QLabel *onlineLabel = new QLabel("0", container);
|
onlineLabel = new QLabel("0", container);
|
||||||
onlineLabel->setObjectName("status");
|
onlineLabel->setObjectName("status");
|
||||||
|
|
||||||
QLabel *awayIconLabel = new QLabel(container);
|
/*QLabel *awayIconLabel = new QLabel(container);
|
||||||
awayIconLabel->setAlignment(Qt::AlignCenter);
|
awayIconLabel->setAlignment(Qt::AlignCenter);
|
||||||
awayIconLabel->setPixmap(QPixmap(":img/status/dot_away.svg"));
|
awayIconLabel->setPixmap(QPixmap(":img/status/dot_away.svg"));
|
||||||
QLabel *awayLabel = new QLabel("0", container);
|
QLabel *awayLabel = new QLabel("0", container);
|
||||||
awayLabel->setObjectName("status");
|
awayLabel->setObjectName("status");*/
|
||||||
|
|
||||||
QLabel *offlineIconLabel = new QLabel(container);
|
QLabel *offlineIconLabel = new QLabel(container);
|
||||||
offlineIconLabel->setAlignment(Qt::AlignCenter);
|
offlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||||
offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
||||||
QLabel *offlineLabel = new QLabel("0", container);
|
offlineLabel = new QLabel("0", container);
|
||||||
offlineLabel->setObjectName("status");
|
offlineLabel->setObjectName("status");
|
||||||
|
|
||||||
statusLayout->addWidget(onlineIconLabel);
|
statusLayout->addWidget(onlineIconLabel);
|
||||||
statusLayout->addSpacing(5);
|
statusLayout->addSpacing(5);
|
||||||
statusLayout->addWidget(onlineLabel);
|
statusLayout->addWidget(onlineLabel);
|
||||||
statusLayout->addSpacing(10);
|
statusLayout->addSpacing(10);
|
||||||
statusLayout->addWidget(awayIconLabel);
|
//statusLayout->addWidget(awayIconLabel);
|
||||||
statusLayout->addSpacing(5);
|
//statusLayout->addSpacing(5);
|
||||||
statusLayout->addWidget(awayLabel);
|
//statusLayout->addWidget(awayLabel);
|
||||||
statusLayout->addSpacing(10);
|
//statusLayout->addSpacing(10);
|
||||||
statusLayout->addWidget(offlineIconLabel);
|
statusLayout->addWidget(offlineIconLabel);
|
||||||
statusLayout->addSpacing(5);
|
statusLayout->addSpacing(5);
|
||||||
statusLayout->addWidget(offlineLabel);
|
statusLayout->addWidget(offlineLabel);
|
||||||
statusLayout->addStretch();
|
//statusLayout->addStretch();
|
||||||
|
|
||||||
midLayout->addLayout(statusLayout);
|
//midLayout->addLayout(statusLayout);
|
||||||
|
topLayout->addStretch();
|
||||||
|
topLayout->addLayout(statusLayout);
|
||||||
|
|
||||||
midLayout->addStretch();
|
midLayout->addStretch();
|
||||||
|
|
||||||
|
@ -120,13 +123,18 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
|
|
||||||
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
||||||
{
|
{
|
||||||
|
qDebug() << "YOLO COMBO";
|
||||||
listLayout->addFriendWidget(w, s);
|
listLayout->addFriendWidget(w, s);
|
||||||
|
//if (s == Status::Offline)
|
||||||
|
updateOffline();
|
||||||
|
//else
|
||||||
|
updateOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleWidget::toggle()
|
void CircleWidget::toggle()
|
||||||
{
|
{
|
||||||
visible = !visible;
|
expanded = !expanded;
|
||||||
if (visible)
|
if (expanded)
|
||||||
{
|
{
|
||||||
mainLayout->addLayout(listLayout);
|
mainLayout->addLayout(listLayout);
|
||||||
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
||||||
|
@ -167,7 +175,7 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
||||||
{
|
{
|
||||||
if (event->mimeData()->hasFormat("friend"))
|
if (event->mimeData()->hasFormat("friend"))
|
||||||
{
|
{
|
||||||
if (!visible)
|
if (!expanded)
|
||||||
toggle();
|
toggle();
|
||||||
|
|
||||||
int friendId = event->mimeData()->data("friend").toInt();
|
int friendId = event->mimeData()->data("friend").toInt();
|
||||||
|
@ -177,9 +185,29 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
||||||
FriendWidget *widget = f->getFriendWidget();
|
FriendWidget *widget = f->getFriendWidget();
|
||||||
assert(widget != nullptr);
|
assert(widget != nullptr);
|
||||||
|
|
||||||
listLayout->addFriendWidget(widget, f->getStatus());
|
// Update old circle after moved.
|
||||||
|
CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(widget->parent());
|
||||||
|
|
||||||
|
addFriendWidget(widget, f->getStatus());
|
||||||
|
|
||||||
|
if (circleWidget != nullptr)
|
||||||
|
{
|
||||||
|
// In case the status was changed while moving, update both.
|
||||||
|
circleWidget->updateOffline();
|
||||||
|
circleWidget->updateOnline();
|
||||||
|
}
|
||||||
|
|
||||||
container->setAttribute(Qt::WA_UnderMouse, false);
|
container->setAttribute(Qt::WA_UnderMouse, false);
|
||||||
Style::repolish(container);
|
Style::repolish(container);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CircleWidget::updateOnline()
|
||||||
|
{
|
||||||
|
onlineLabel->setText(QString::number(listLayout->friendOnlineCount()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CircleWidget::updateOffline()
|
||||||
|
{
|
||||||
|
offlineLabel->setText(QString::number(listLayout->friendOfflineCount()));
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,9 @@ public:
|
||||||
|
|
||||||
void toggle();
|
void toggle();
|
||||||
|
|
||||||
|
void updateOnline();
|
||||||
|
void updateOffline();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
@ -50,10 +53,12 @@ private:
|
||||||
Online = 0,
|
Online = 0,
|
||||||
Offline = 1
|
Offline = 1
|
||||||
};
|
};
|
||||||
bool visible = false;
|
bool expanded = false;
|
||||||
FriendListLayout *listLayout;
|
FriendListLayout *listLayout;
|
||||||
QVBoxLayout *mainLayout;
|
QVBoxLayout *mainLayout;
|
||||||
QLabel *arrowLabel;
|
QLabel *arrowLabel;
|
||||||
|
QLabel *onlineLabel;
|
||||||
|
QLabel *offlineLabel;
|
||||||
QWidget *container;
|
QWidget *container;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,8 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
FriendListLayout::FriendListLayout(QWidget *parent, bool groupsOnTop)
|
FriendListLayout::FriendListLayout(bool groupsOnTop)
|
||||||
: QVBoxLayout(parent)
|
|
||||||
{
|
{
|
||||||
setObjectName("FriendListLayout");
|
|
||||||
setSpacing(0);
|
setSpacing(0);
|
||||||
setMargin(0);
|
setMargin(0);
|
||||||
|
|
||||||
|
@ -85,6 +83,16 @@ void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
|
||||||
l->insertWidget(min, w);
|
l->insertWidget(min, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int FriendListLayout::friendOnlineCount() const
|
||||||
|
{
|
||||||
|
return friendLayouts[Online]->count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int FriendListLayout::friendOfflineCount() const
|
||||||
|
{
|
||||||
|
return friendLayouts[Offline]->count();
|
||||||
|
}
|
||||||
|
|
||||||
template <typename WidgetType>
|
template <typename WidgetType>
|
||||||
void searchHelper(const QString &searchString, QBoxLayout *boxLayout, bool hideAll)
|
void searchHelper(const QString &searchString, QBoxLayout *boxLayout, bool hideAll)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,10 +26,12 @@ class FriendListLayout : public QVBoxLayout
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit FriendListLayout(QWidget *parent, bool groupsOnTop = true);
|
explicit FriendListLayout(bool groupsOnTop = true);
|
||||||
|
|
||||||
void addGroupWidget(GroupWidget *widget);
|
void addGroupWidget(GroupWidget *widget);
|
||||||
void addFriendWidget(FriendWidget *widget, Status s);
|
void addFriendWidget(FriendWidget *widget, Status s);
|
||||||
|
int friendOnlineCount() const;
|
||||||
|
int friendOfflineCount() const;
|
||||||
|
|
||||||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
|
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
|
||||||
bool hasChatrooms() const;
|
bool hasChatrooms() const;
|
||||||
|
|
|
@ -19,6 +19,9 @@
|
||||||
#include "friendlistwidget.h"
|
#include "friendlistwidget.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QDragEnterEvent>
|
||||||
|
#include <QDragLeaveEvent>
|
||||||
#include "src/friend.h"
|
#include "src/friend.h"
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
#include "src/widget/friendwidget.h"
|
#include "src/widget/friendwidget.h"
|
||||||
|
@ -30,7 +33,8 @@
|
||||||
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop) :
|
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop) :
|
||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
{
|
{
|
||||||
listLayout = new FriendListLayout(this, groupsOnTop);
|
listLayout = new FriendListLayout(groupsOnTop);
|
||||||
|
setLayout(listLayout);
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||||
|
|
||||||
circleLayout = new QVBoxLayout();
|
circleLayout = new QVBoxLayout();
|
||||||
|
@ -38,6 +42,8 @@ FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop) :
|
||||||
circleLayout->setMargin(0);
|
circleLayout->setMargin(0);
|
||||||
|
|
||||||
listLayout->addLayout(circleLayout);
|
listLayout->addLayout(circleLayout);
|
||||||
|
|
||||||
|
setAcceptDrops(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::addGroupWidget(GroupWidget *widget)
|
void FriendListWidget::addGroupWidget(GroupWidget *widget)
|
||||||
|
@ -45,20 +51,6 @@ void FriendListWidget::addGroupWidget(GroupWidget *widget)
|
||||||
listLayout->groupLayout->addWidget(widget);
|
listLayout->groupLayout->addWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::hideGroups(QString searchString, bool hideAll)
|
|
||||||
{
|
|
||||||
QVBoxLayout* groups = listLayout->groupLayout;
|
|
||||||
int groupCount = groups->count(), index;
|
|
||||||
|
|
||||||
for (index = 0; index<groupCount; index++)
|
|
||||||
{
|
|
||||||
GroupWidget* groupWidget = static_cast<GroupWidget*>(groups->itemAt(index)->widget());
|
|
||||||
QString groupName = groupWidget->getName();
|
|
||||||
|
|
||||||
groupWidget->setVisible(groupName.contains(searchString, Qt::CaseInsensitive) && !hideAll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FriendListWidget::addCircleWidget(CircleWidget *widget)
|
void FriendListWidget::addCircleWidget(CircleWidget *widget)
|
||||||
{
|
{
|
||||||
circleLayout->addWidget(widget);
|
circleLayout->addWidget(widget);
|
||||||
|
@ -74,20 +66,6 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::hideFriends(QString searchString, Status status, bool hideAll)
|
|
||||||
{
|
|
||||||
QVBoxLayout* friends = getFriendLayout(status);
|
|
||||||
int friendCount = friends->count(), index;
|
|
||||||
|
|
||||||
for (index = 0; index<friendCount; index++)
|
|
||||||
{
|
|
||||||
FriendWidget* friendWidget = static_cast<FriendWidget*>(friends->itemAt(index)->widget());
|
|
||||||
QString friendName = friendWidget->getName();
|
|
||||||
|
|
||||||
friendWidget->setVisible(friendName.contains(searchString, Qt::CaseInsensitive) && !hideAll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QVBoxLayout* FriendListWidget::getFriendLayout(Status s)
|
QVBoxLayout* FriendListWidget::getFriendLayout(Status s)
|
||||||
{
|
{
|
||||||
return s == Status::Offline ? listLayout->friendLayouts[Offline] : listLayout->friendLayouts[Online];
|
return s == Status::Offline ? listLayout->friendLayouts[Offline] : listLayout->friendLayouts[Online];
|
||||||
|
@ -137,6 +115,37 @@ QList<GenericChatroomWidget*> FriendListWidget::getAllFriends()
|
||||||
return friends;
|
return friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FriendListWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasFormat("friend"))
|
||||||
|
event->acceptProposedAction();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendListWidget::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
if (event->mimeData()->hasFormat("friend"))
|
||||||
|
{
|
||||||
|
int friendId = event->mimeData()->data("friend").toInt();
|
||||||
|
Friend *f = FriendList::findFriend(friendId);
|
||||||
|
assert(f != nullptr);
|
||||||
|
|
||||||
|
FriendWidget *widget = f->getFriendWidget();
|
||||||
|
assert(widget != nullptr);
|
||||||
|
|
||||||
|
// Update old circle after moved.
|
||||||
|
CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(widget->parent());
|
||||||
|
|
||||||
|
listLayout->addFriendWidget(widget, f->getStatus());
|
||||||
|
|
||||||
|
if (circleWidget != nullptr)
|
||||||
|
{
|
||||||
|
// In case the status was changed while moving, update both.
|
||||||
|
circleWidget->updateOffline();
|
||||||
|
circleWidget->updateOnline();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FriendListWidget::moveWidget(FriendWidget *w, Status s, bool add)
|
void FriendListWidget::moveWidget(FriendWidget *w, Status s, bool add)
|
||||||
{
|
{
|
||||||
CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(w->parent());
|
CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(w->parent());
|
||||||
|
|
|
@ -42,13 +42,11 @@ public:
|
||||||
explicit FriendListWidget(QWidget *parent = 0, bool groupsOnTop = true);
|
explicit FriendListWidget(QWidget *parent = 0, bool groupsOnTop = true);
|
||||||
|
|
||||||
void addGroupWidget(GroupWidget *widget);
|
void addGroupWidget(GroupWidget *widget);
|
||||||
void hideGroups(QString searchString, bool hideAll = false);
|
|
||||||
|
|
||||||
void addCircleWidget(CircleWidget *widget);
|
void addCircleWidget(CircleWidget *widget);
|
||||||
|
|
||||||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
|
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
|
||||||
|
|
||||||
void hideFriends(QString searchString, Status status, bool hideAll = false);
|
|
||||||
QList<GenericChatroomWidget*> getAllFriends();
|
QList<GenericChatroomWidget*> getAllFriends();
|
||||||
|
|
||||||
void reDraw();
|
void reDraw();
|
||||||
|
@ -57,6 +55,10 @@ public slots:
|
||||||
void onGroupchatPositionChanged(bool top);
|
void onGroupchatPositionChanged(bool top);
|
||||||
void moveWidget(FriendWidget *w, Status s, bool add = false);
|
void moveWidget(FriendWidget *w, Status s, bool add = false);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* getFriendLayout(Status s);
|
QVBoxLayout* getFriendLayout(Status s);
|
||||||
enum FriendLayoutType
|
enum FriendLayoutType
|
||||||
|
|
Loading…
Reference in New Issue
Block a user