GTimer.cpp 503 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <LibGUI/GTimer.h>
  2. GTimer::GTimer(GObject* parent)
  3. : GObject(parent)
  4. {
  5. }
  6. GTimer::~GTimer()
  7. {
  8. }
  9. void GTimer::start()
  10. {
  11. start(m_interval);
  12. }
  13. void GTimer::start(int interval)
  14. {
  15. if (m_active)
  16. return;
  17. start_timer(interval);
  18. m_active = true;
  19. }
  20. void GTimer::stop()
  21. {
  22. if (!m_active)
  23. return;
  24. stop_timer();
  25. m_active = false;
  26. }
  27. void GTimer::timer_event(GTimerEvent&)
  28. {
  29. if (m_single_shot)
  30. stop();
  31. if (on_timeout)
  32. on_timeout();
  33. }