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>
24 * This class executes the callback when the timeout expires
27 class Timeout::Impl : QObject {
30 Impl(Timeout & owner) : owner_(owner), timeout_id(-1) {}
32 bool running() const { return timeout_id != -1; }
40 unsigned int timeout_ms() const { return owner_.timeout_ms; }
44 void timerEvent(QTimerEvent *) { owner_.emit(); }
54 void Timeout::Impl::reset()
57 killTimer(timeout_id);
62 void Timeout::Impl::start()
65 lyxerr << "Timeout::start: already running!" << endl;
66 timeout_id = startTimer(timeout_ms());
70 void Timeout::Impl::stop()
81 Timeout::Timeout(unsigned int msec, Type t)
82 : pimpl_(new Impl(*this)), type(t), timeout_ms(msec)
93 bool Timeout::running() const
95 return pimpl_->running();
111 void Timeout::restart()
122 if (type == CONTINUOUS)
127 Timeout & Timeout::setType(Type t)
134 Timeout & Timeout::setTimeout(unsigned int msec)
136 // Can't have a timeout of zero!