forked from LadybirdBrowser/ancient-history
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimerQt.cpp
94 lines (76 loc) · 1.34 KB
/
TimerQt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2022, Andreas Kling <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#define AK_DONT_REPLACE_STD
#include "TimerQt.h"
#include <AK/NonnullRefPtr.h>
#include <QTimer>
namespace Ladybird {
NonnullRefPtr<TimerQt> TimerQt::create()
{
return adopt_ref(*new TimerQt);
}
TimerQt::TimerQt()
{
m_timer = new QTimer;
QObject::connect(m_timer, &QTimer::timeout, [this] {
if (on_timeout)
on_timeout();
});
}
TimerQt::~TimerQt()
{
delete m_timer;
}
void TimerQt::start()
{
m_timer->start();
}
void TimerQt::start(int interval_ms)
{
m_timer->start(interval_ms);
}
void TimerQt::restart()
{
restart(interval());
}
void TimerQt::restart(int interval_ms)
{
if (is_active())
stop();
start(interval_ms);
}
void TimerQt::stop()
{
m_timer->stop();
}
void TimerQt::set_active(bool active)
{
if (active)
m_timer->start();
else
m_timer->stop();
}
bool TimerQt::is_active() const
{
return m_timer->isActive();
}
int TimerQt::interval() const
{
return m_timer->interval();
}
void TimerQt::set_interval(int interval_ms)
{
m_timer->setInterval(interval_ms);
}
bool TimerQt::is_single_shot() const
{
return m_timer->isSingleShot();
}
void TimerQt::set_single_shot(bool single_shot)
{
m_timer->setSingleShot(single_shot);
}
}