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/lassert.h"
14 #include "support/Timeout.h"
15 #include "support/debug.h"
18 #include <QTimerEvent>
25 * This class executes the callback when the timeout expires
28 class Timeout::Impl : QObject {
31 Impl(Timeout & owner) : owner_(owner), timeout_id(-1) {}
33 bool running() const { return timeout_id != -1; }
41 unsigned int timeout_ms() const { return owner_.timeout_ms; }
45 void timerEvent(QTimerEvent *) { owner_.emit(); }
55 void Timeout::Impl::reset()
58 killTimer(timeout_id);
63 void Timeout::Impl::start()
66 lyxerr << "Timeout::start: already running!" << endl;
67 timeout_id = startTimer(timeout_ms());
71 void Timeout::Impl::stop()
82 Timeout::Timeout(unsigned int msec, Type t)
83 : pimpl_(new Impl(*this)), type(t), timeout_ms(msec)
94 bool Timeout::running() const
96 return pimpl_->running();
100 void Timeout::start()
112 void Timeout::restart()
123 if (type == CONTINUOUS)
128 Timeout & Timeout::setType(Type t)
135 Timeout & Timeout::setTimeout(unsigned int msec)
137 // Can't have a timeout of zero!