mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix friend list when day changes
This commit is contained in:
parent
74b771373d
commit
e574af7a5e
|
@ -31,6 +31,7 @@
|
|||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragLeaveEvent>
|
||||
#include <QTimer>
|
||||
#include <cassert>
|
||||
|
||||
enum Time : int
|
||||
|
@ -114,6 +115,14 @@ QDate getDateFriend(Friend* contact)
|
|||
return Settings::getInstance().getFriendActivity(contact->getToxId());
|
||||
}
|
||||
|
||||
qint64 timeUntilTomorrow()
|
||||
{
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
QDateTime tomorrow = now.addDays(1); // Tomorrow.
|
||||
tomorrow.setTime(QTime()); // Midnight.
|
||||
return now.msecsTo(tomorrow);
|
||||
}
|
||||
|
||||
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
||||
: QWidget(parent)
|
||||
// Prevent Valgrind from complaining. We're changing this to Name here.
|
||||
|
@ -135,6 +144,10 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
|||
setMode(Name);
|
||||
|
||||
onGroupchatPositionChanged(groupsOnTop);
|
||||
dayTimer = new QTimer(this);
|
||||
dayTimer->setTimerType(Qt::VeryCoarseTimer);
|
||||
connect(dayTimer, &QTimer::timeout, this, &FriendListWidget::dayTimeout);
|
||||
dayTimer->start(timeUntilTomorrow());
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
@ -621,6 +634,17 @@ void FriendListWidget::dropEvent(QDropEvent* event)
|
|||
}
|
||||
}
|
||||
|
||||
void FriendListWidget::dayTimeout()
|
||||
{
|
||||
if (mode == Activity)
|
||||
{
|
||||
setMode(Name);
|
||||
setMode(Activity); // Refresh all.
|
||||
}
|
||||
|
||||
dayTimer->start(timeUntilTomorrow());
|
||||
}
|
||||
|
||||
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
|
||||
{
|
||||
if (mode == Name)
|
||||
|
|
|
@ -76,6 +76,9 @@ protected:
|
|||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private slots:
|
||||
void dayTimeout();
|
||||
|
||||
private:
|
||||
CircleWidget* createCircleWidget(int id = -1);
|
||||
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
||||
|
@ -86,6 +89,7 @@ private:
|
|||
GenericChatItemLayout* circleLayout = nullptr;
|
||||
GenericChatItemLayout groupLayout;
|
||||
QVBoxLayout* activityLayout = nullptr;
|
||||
QTimer* dayTimer;
|
||||
};
|
||||
|
||||
#endif // FRIENDLISTWIDGET_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user