/**
- * \file qtTimeout.cpp
+ * \file Timeout.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* This class executes the callback when the timeout expires
* using Qt mechanisms
*/
-class qtTimeout : QObject, public Timeout::Impl {
+class Timeout::Impl : QObject {
public:
///
- qtTimeout(Timeout & owner_);
+ Impl(Timeout & owner) : owner_(owner), timeout_id(-1) {}
///
- virtual bool running() const;
+ bool running() const { return timeout_id != -1; }
/// start the timer
- virtual void start();
+ void start();
/// stop the timer
- virtual void stop();
+ void stop();
/// reset
- virtual void reset();
+ void reset();
+ ///
+ unsigned int timeout_ms() const { return owner_.timeout_ms; }
protected:
- /// slot
- virtual void timerEvent(QTimerEvent *);
+ ///
+ void timerEvent(QTimerEvent *) { owner_.emit(); }
private:
+ ///
+ Timeout & owner_;
/// timout id
int timeout_id;
};
-Timeout::Timeout(unsigned int msec, Type t)
- : pimpl_(new qtTimeout(*this)), type(t), timeout_ms(msec)
-{}
-
-
-qtTimeout::qtTimeout(Timeout & owner)
- : Timeout::Impl(owner), timeout_id(-1)
-{}
-
-
-void qtTimeout::timerEvent(QTimerEvent *)
-{
- emit();
-}
-
-
-void qtTimeout::reset()
+void Timeout::Impl::reset()
{
if (timeout_id != -1)
killTimer(timeout_id);
}
-bool qtTimeout::running() const
-{
- return timeout_id != -1;
-}
-
-
-void qtTimeout::start()
+void Timeout::Impl::start()
{
if (running())
lyxerr << "Timeout::start: already running!" << std::endl;
}
-void qtTimeout::stop()
+void Timeout::Impl::stop()
{
if (running())
reset();
//
-// Timeoute
+// Timeout
//
+Timeout::Timeout(unsigned int msec, Type t)
+ : pimpl_(new Impl(*this)), type(t), timeout_ms(msec)
+{}
+
+
Timeout::~Timeout()
{
pimpl_->stop();
+ delete pimpl_;
}
Timeout & Timeout::setType(Type t)
{
type = t;
- return * this;
+ return *this;
}
BOOST_ASSERT(msec);
timeout_ms = msec;
- return * this;
+ return *this;
}
// -*- C++ -*-
/**
- * \file qtTimeout.h
+ * \file Timeout.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
/// set the timeout value
Timeout & setTimeout(unsigned int msec);
- /** Base class for the GUI implementation.
- It must be public so that C callback functions can access its
- daughter classes.
- */
- class Impl
- {
- public:
- ///
- Impl(Timeout & owner) : owner_(owner) {}
- ///
- virtual ~Impl() {}
- /// Is the timer running?
- virtual bool running() const = 0;
- /// start the timer
- virtual void start() = 0;
- /// stop the timer
- virtual void stop() = 0;
- /// reset
- virtual void reset() = 0;
-
- protected:
- ///
- void emit() { owner_.emit(); }
- ///
- unsigned int timeout_ms() const { return owner_.timeout_ms; }
-
- private:
- ///
- Timeout & owner_;
- };
-
private:
+ /// noncopyable
+ Timeout(Timeout const &);
+ void operator=(Timeout const &);
+ ///
+ class Impl;
///
friend class Impl;
///
- boost::scoped_ptr<Impl> const pimpl_;
+ Impl * const pimpl_;
/// one-shot or repeating
Type type;
/// timeout value in milliseconds