1 ;;; Copyright (c) 2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
2 ;;; Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
3 ;;; Contact: Qt Software Information (qt-info@nokia.com)
5 ;;; This file is part of the examples of the Qt Toolkit.
7 ;;; $QT_BEGIN_LICENSE:LGPL$
9 ;;; Licensees holding valid Qt Commercial licenses may use this file in
10 ;;; accordance with the Qt Commercial License Agreement provided with the
11 ;;; Software or, alternatively, in accordance with the terms contained in
12 ;;; a written agreement between you and Nokia.
14 ;;; GNU Lesser General Public License Usage
15 ;;; Alternatively, this file may be used under the terms of the GNU Lesser
16 ;;; General Public License version 2.1 as published by the Free Software
17 ;;; Foundation and appearing in the file LICENSE.LGPL included in the
18 ;;; packaging of this file. Please review the following information to
19 ;;; ensure the GNU Lesser General Public License version 2.1 requirements
20 ;;; will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22 ;;; In addition, as a special exception, Nokia gives you certain
23 ;;; additional rights. These rights are described in the Nokia Qt LGPL
24 ;;; Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
27 ;;; GNU General Public License Usage
28 ;;; Alternatively, this file may be used under the terms of the GNU
29 ;;; General Public License version 3.0 as published by the Free Software
30 ;;; Foundation and appearing in the file LICENSE.GPL included in the
31 ;;; packaging of this file. Please review the following information to
32 ;;; ensure the GNU General Public License version 3.0 requirements will be
33 ;;; met: http://www.gnu.org/copyleft/gpl.html.
35 ;;; If you are unsure which license is appropriate for your use, please
36 ;;; contact the sales department at qt-sales@nokia.com.
39 (in-package :qt.examples)
41 (defclass analog-clock (qt:widget)
43 (:metaclass cxx:class))
45 (defmethod initialize-instance :after ((clock analog-clock) &rest initargs)
46 (declare (ignore initargs))
47 (let ((timer (make-instance 'qt:timer :arg0 clock)))
48 (qt:connect (qt:get-signal timer "timeout()")
49 (qt:get-slot clock "update()"))
50 (cxx:start timer 1000))
51 (setf (cxx:window-title clock) "Analog Clock")
52 (cxx:resize clock 200 200))
54 (defun make-polygon (points)
55 (make-instance 'qt:polygon :arg0
56 (map 'vector #'(lambda (coords)
57 (make-instance 'qt:point
62 (let ((hour-hand (make-polygon '((7 . 8) (-7 . 8) (0 . -40))))
63 (minute-hand (make-polygon '((7 . 8) (-7 . 8) (0 . -70)))))
64 (defmethod cxx:paint-event ((clock analog-clock) paint-event)
65 (let ((hour-color (make-instance 'qt:color :args '(127 0 127)))
66 (minute-color (make-instance 'qt:color :args '(0 127 127 191)))
67 (side (min (cxx:width clock) (cxx:height clock)))
68 (time (qt:time.current-time)))
69 (qt:with-painter (painter clock)
70 (cxx:set-render-hint painter qt:painter.+antialiasing+)
71 (cxx:translate painter
72 (/ (cxx:width clock) 2) (/ (cxx:height clock) 2))
73 (cxx:scale painter (/ side 200.0) (/ side 200.0))
74 (cxx:set-pen painter qt:+no-pen+)
75 (cxx:set-brush painter hour-color)
77 (qt:with-painter (painter)
78 (cxx:rotate painter (* 30.0 (+ (cxx:hour time)
79 (/ (cxx:minute time) 60.0))))
80 (cxx:draw-convex-polygon painter hour-hand))
82 (cxx:set-pen painter hour-color)
85 (cxx:draw-line painter 88 0 96 0)
86 (cxx:rotate painter 30.0))
88 (cxx:set-pen painter qt:+no-pen+)
89 (cxx:set-brush painter minute-color)
91 (qt:with-painter (painter)
92 (cxx:rotate painter (* 6.0 (+ (cxx:minute time)
93 (/ (cxx:second time) 60.0))))
94 (cxx:draw-convex-polygon painter minute-hand))
96 (cxx:set-pen painter minute-color)
99 (unless (zerop (mod i 5))
100 (cxx:draw-line painter 92 0 96 0))
101 (cxx:rotate painter 6.0))))))
103 (defun analog-clock ()
106 (let ((clock (make-instance 'analog-clock)))