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->setProperty("active", false);
|
||||
mainLayout = new QVBoxLayout(this);
|
||||
listLayout = new FriendListLayout(this);
|
||||
listLayout = new FriendListLayout();
|
||||
QHBoxLayout *layout = new QHBoxLayout();
|
||||
QVBoxLayout *midLayout = new QVBoxLayout;
|
||||
QHBoxLayout *topLayout = new QHBoxLayout;
|
||||
|
@ -64,10 +64,11 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
QFrame *lineFrame = new QFrame(container);
|
||||
lineFrame->setObjectName("line");
|
||||
lineFrame->setFrameShape(QFrame::HLine);
|
||||
topLayout->addSpacing(5);
|
||||
topLayout->addWidget(lineFrame, 1);
|
||||
//topLayout->addSpacing(5);
|
||||
//topLayout->addWidget(lineFrame, 1);
|
||||
|
||||
midLayout->addLayout(topLayout);
|
||||
midLayout->addWidget(lineFrame);
|
||||
|
||||
midLayout->addStretch();
|
||||
|
||||
|
@ -76,35 +77,37 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
QLabel *onlineIconLabel = new QLabel(container);
|
||||
onlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||
onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
||||
QLabel *onlineLabel = new QLabel("0", container);
|
||||
onlineLabel = new QLabel("0", container);
|
||||
onlineLabel->setObjectName("status");
|
||||
|
||||
QLabel *awayIconLabel = new QLabel(container);
|
||||
/*QLabel *awayIconLabel = new QLabel(container);
|
||||
awayIconLabel->setAlignment(Qt::AlignCenter);
|
||||
awayIconLabel->setPixmap(QPixmap(":img/status/dot_away.svg"));
|
||||
QLabel *awayLabel = new QLabel("0", container);
|
||||
awayLabel->setObjectName("status");
|
||||
awayLabel->setObjectName("status");*/
|
||||
|
||||
QLabel *offlineIconLabel = new QLabel(container);
|
||||
offlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||
offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
||||
QLabel *offlineLabel = new QLabel("0", container);
|
||||
offlineLabel = new QLabel("0", container);
|
||||
offlineLabel->setObjectName("status");
|
||||
|
||||
statusLayout->addWidget(onlineIconLabel);
|
||||
statusLayout->addSpacing(5);
|
||||
statusLayout->addWidget(onlineLabel);
|
||||
statusLayout->addSpacing(10);
|
||||
statusLayout->addWidget(awayIconLabel);
|
||||
statusLayout->addSpacing(5);
|
||||
statusLayout->addWidget(awayLabel);
|
||||
statusLayout->addSpacing(10);
|
||||
//statusLayout->addWidget(awayIconLabel);
|
||||
//statusLayout->addSpacing(5);
|
||||
//statusLayout->addWidget(awayLabel);
|
||||
//statusLayout->addSpacing(10);
|
||||
statusLayout->addWidget(offlineIconLabel);
|
||||
statusLayout->addSpacing(5);
|
||||
statusLayout->addWidget(offlineLabel);
|
||||
statusLayout->addStretch();
|
||||
//statusLayout->addStretch();
|
||||
|
||||
midLayout->addLayout(statusLayout);
|
||||
//midLayout->addLayout(statusLayout);
|
||||
topLayout->addStretch();
|
||||
topLayout->addLayout(statusLayout);
|
||||
|
||||
midLayout->addStretch();
|
||||
|
||||
|
@ -120,13 +123,18 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
|
||||
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
||||
{
|
||||
qDebug() << "YOLO COMBO";
|
||||
listLayout->addFriendWidget(w, s);
|
||||
//if (s == Status::Offline)
|
||||
updateOffline();
|
||||
//else
|
||||
updateOnline();
|
||||
}
|
||||
|
||||
void CircleWidget::toggle()
|
||||
{
|
||||
visible = !visible;
|
||||
if (visible)
|
||||
expanded = !expanded;
|
||||
if (expanded)
|
||||
{
|
||||
mainLayout->addLayout(listLayout);
|
||||
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarDownArrow.svg"));
|
||||
|
@ -167,7 +175,7 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
|||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
if (!visible)
|
||||
if (!expanded)
|
||||
toggle();
|
||||
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
|
@ -177,9 +185,29 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
|||
FriendWidget *widget = f->getFriendWidget();
|
||||
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);
|
||||
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 updateOnline();
|
||||
void updateOffline();
|
||||
|
||||
protected:
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
@ -50,10 +53,12 @@ private:
|
|||
Online = 0,
|
||||
Offline = 1
|
||||
};
|
||||
bool visible = false;
|
||||
bool expanded = false;
|
||||
FriendListLayout *listLayout;
|
||||
QVBoxLayout *mainLayout;
|
||||
QLabel *arrowLabel;
|
||||
QLabel *onlineLabel;
|
||||
QLabel *offlineLabel;
|
||||
QWidget *container;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,10 +23,8 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
FriendListLayout::FriendListLayout(QWidget *parent, bool groupsOnTop)
|
||||
: QVBoxLayout(parent)
|
||||
FriendListLayout::FriendListLayout(bool groupsOnTop)
|
||||
{
|
||||
setObjectName("FriendListLayout");
|
||||
setSpacing(0);
|
||||
setMargin(0);
|
||||
|
||||
|
@ -85,6 +83,16 @@ void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
|
|||
l->insertWidget(min, w);
|
||||
}
|
||||
|
||||
int FriendListLayout::friendOnlineCount() const
|
||||
{
|
||||
return friendLayouts[Online]->count();
|
||||
}
|
||||
|
||||
int FriendListLayout::friendOfflineCount() const
|
||||
{
|
||||
return friendLayouts[Offline]->count();
|
||||
}
|
||||
|
||||
template <typename WidgetType>
|
||||
void searchHelper(const QString &searchString, QBoxLayout *boxLayout, bool hideAll)
|
||||
{
|
||||
|
|
|
@ -26,10 +26,12 @@ class FriendListLayout : public QVBoxLayout
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FriendListLayout(QWidget *parent, bool groupsOnTop = true);
|
||||
explicit FriendListLayout(bool groupsOnTop = true);
|
||||
|
||||
void addGroupWidget(GroupWidget *widget);
|
||||
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);
|
||||
bool hasChatrooms() const;
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
#include "friendlistwidget.h"
|
||||
#include <QDebug>
|
||||
#include <QGridLayout>
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragLeaveEvent>
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/widget/friendwidget.h"
|
||||
|
@ -30,7 +33,8 @@
|
|||
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop) :
|
||||
QWidget(parent)
|
||||
{
|
||||
listLayout = new FriendListLayout(this, groupsOnTop);
|
||||
listLayout = new FriendListLayout(groupsOnTop);
|
||||
setLayout(listLayout);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
|
||||
circleLayout = new QVBoxLayout();
|
||||
|
@ -38,6 +42,8 @@ FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop) :
|
|||
circleLayout->setMargin(0);
|
||||
|
||||
listLayout->addLayout(circleLayout);
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void FriendListWidget::addGroupWidget(GroupWidget *widget)
|
||||
|
@ -45,20 +51,6 @@ void FriendListWidget::addGroupWidget(GroupWidget *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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
return s == Status::Offline ? listLayout->friendLayouts[Offline] : listLayout->friendLayouts[Online];
|
||||
|
@ -137,6 +115,37 @@ QList<GenericChatroomWidget*> FriendListWidget::getAllFriends()
|
|||
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)
|
||||
{
|
||||
CircleWidget *circleWidget = dynamic_cast<CircleWidget*>(w->parent());
|
||||
|
|
|
@ -42,13 +42,11 @@ public:
|
|||
explicit FriendListWidget(QWidget *parent = 0, bool groupsOnTop = true);
|
||||
|
||||
void addGroupWidget(GroupWidget *widget);
|
||||
void hideGroups(QString searchString, bool hideAll = false);
|
||||
|
||||
void addCircleWidget(CircleWidget *widget);
|
||||
|
||||
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();
|
||||
|
||||
void reDraw();
|
||||
|
@ -57,6 +55,10 @@ public slots:
|
|||
void onGroupchatPositionChanged(bool top);
|
||||
void moveWidget(FriendWidget *w, Status s, bool add = false);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private:
|
||||
QVBoxLayout* getFriendLayout(Status s);
|
||||
enum FriendLayoutType
|
||||
|
|
Loading…
Reference in New Issue
Block a user