3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "support/Timeout.h"
14 #include "support/debug.h"
17 #include <QTimerEvent>
22 * This class executes the callback when the timeout expires
25 class Timeout::Impl : QObject {
28 Impl(Timeout & owner) : owner_(owner), timeout_id(-1) {}
30 bool running() const { return timeout_id != -1; }
38 unsigned int timeout_ms() const { return owner_.timeout_ms; }
42 void timerEvent(QTimerEvent *) { owner_.emit(); }
52 void Timeout::Impl::reset()
55 killTimer(timeout_id);
60 void Timeout::Impl::start()
63 lyxerr << "Timeout::start: already running!" << std::endl;
64 timeout_id = startTimer(timeout_ms());
68 void Timeout::Impl::stop()
79 Timeout::Timeout(unsigned int msec, Type t)
80 : pimpl_(new Impl(*this)), type(t), timeout_ms(msec)
91 bool Timeout::running() const
93 return pimpl_->running();
109 void Timeout::restart()
120 if (type == CONTINUOUS)
125 Timeout & Timeout::setType(Type t)
132 Timeout & Timeout::setTimeout(unsigned int msec)
134 // Can't have a timeout of zero!