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

Merge pull request #2045 from TheSpiritXIII/recent

Fix friend list when day changes
This commit is contained in:
agilob 2015-08-20 21:59:19 +01:00
commit eea7fd1c63
2 changed files with 28 additions and 0 deletions

View File

@ -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)

View File

@ -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