Split up in qt.core.
Annotate for file /src/timer.lisp
2010-01-10 tobias 1 (in-package :cl-smoke.qt.core)
2009-04-07 tobias 2
20:07:00 ' 3 (defclass single-shot-timer (qt:object)
2009-04-12 tobias 4 ((function :initarg :function
13:12:20 ' 5 :type function)
' 6 (timer-id :type integer))
2009-04-07 tobias 7 (:metaclass cxx:class))
20:07:00 ' 8
2009-04-12 tobias 9 (defvar *single-shot-timers* nil "Pending timers.")
2009-04-07 tobias 10
20:07:00 ' 11 (defun single-shot (function &optional (timeout 0))
' 12 "Run FUNCTION after TIMEOUT seconds, or as soon as all window events
2009-04-12 tobias 13 have been processed when TIMEOUT is 0. Equivalent to QTimer::singleShot,
13:12:20 ' 14 but calls a function instead of a slot."
2009-04-07 tobias 15 (let ((timer (make-instance 'single-shot-timer
20:07:00 ' 16 :function function)))
' 17 (setf (slot-value timer 'timer-id)
' 18 (cxx:start-timer timer (floor timeout 100)))
' 19 (push timer *single-shot-timers*)))
' 20
2009-06-11 tobias 21 (defmacro qt:do-delayed-initialize (&body body)
2009-04-07 tobias 22 "Run body when the event loop starts.
20:07:00 ' 23
' 24 http://techbase.kde.org/Development/Tutorials/Common_Programming_Mistakes#Delayed_Initialization"
' 25 `(single-shot #'(lambda () ,@body)))
' 26
2009-04-12 tobias 27 (defmethod cxx:timer-event ((timer single-shot-timer) event)
2009-07-01 tobias 28 (declare (ignore event))
2009-04-07 tobias 29 (cxx:kill-timer timer (slot-value timer 'timer-id))
20:07:00 ' 30 (funcall (slot-value timer 'function))
' 31 (remove timer *single-shot-timers*))