1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 12:00:49 +00:00
serenity/Ladybird/TimerQt.cpp
Andreas Kling 37d844fd66 Ladybird: Use only the Qt event loop to speed everything up :^)
This patch removes the dual-event-loop setup, leaving only the Qt event
loop. We teach LibWeb how to drive Qt by installing an EventLoopPlugin.

This removes the 50ms latency on all UI interactions (and network
requests, etc.)
2022-12-25 07:58:58 -07:00

95 lines
1.3 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* 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);
}
}