summaryrefslogtreecommitdiff
path: root/noncore/tools/clock/analogclock.cpp
Unidiff
Diffstat (limited to 'noncore/tools/clock/analogclock.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/analogclock.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/tools/clock/analogclock.cpp b/noncore/tools/clock/analogclock.cpp
index bf358e2..c5f0155 100644
--- a/noncore/tools/clock/analogclock.cpp
+++ b/noncore/tools/clock/analogclock.cpp
@@ -1,95 +1,95 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21#include "analogclock.h" 21#include "analogclock.h"
22 22
23#include <qlayout.h> 23#include <qlayout.h>
24#include <qpainter.h> 24#include <qpainter.h>
25#include <qtopia/global.h> 25#include <qtopia/global.h>
26 26
27#include <math.h> 27#include <math.h>
28 28
29 const double deg2rad = 0.017453292519943295769;// pi/180 29 const double deg2rad = 0.017453292519943295769;// pi/180
30 30
31AnalogClock::AnalogClock( QWidget *parent, const char *name ) 31AnalogClock::AnalogClock( QWidget *parent, const char *name )
32 : QFrame( parent, name ), clear(false) 32 : QFrame( parent, name ), clear(false)
33{ 33{
34 setMinimumSize(50,50); 34 setMinimumSize(50,50);
35} 35}
36 36
37QSizePolicy AnalogClock::sizePolicy() const 37QSizePolicy AnalogClock::sizePolicy() const
38{ 38{
39 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 39 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
40} 40}
41 41
42void AnalogClock::drawContents( QPainter *p ) 42void AnalogClock::drawContents( QPainter *p )
43{ 43{
44#if !defined(NO_DEBUG) 44#if !defined(NO_DEBUG)
45 static bool first = true; 45 static bool first = true;
46 if ( first ) { 46 if ( first ) {
47 QTOPIA_PROFILE("first paint event"); 47 //QTOPIA_PROFILE("first paint event");
48 first = false; 48 first = false;
49 } 49 }
50#endif 50#endif
51 51
52 QRect r = contentsRect(); 52 QRect r = contentsRect();
53 53
54 if ( r.width() < r.height() ) { 54 if ( r.width() < r.height() ) {
55 r.setY( (r.height() - r.width())/2 ); 55 r.setY( (r.height() - r.width())/2 );
56 r.setHeight( r.width() ); 56 r.setHeight( r.width() );
57 } 57 }
58 58
59 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 59 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
60 60
61 const int w_tick = r.width()/300+1; 61 const int w_tick = r.width()/300+1;
62 const int w_sec = r.width()/400+1; 62 const int w_sec = r.width()/400+1;
63 const int w_hour = r.width()/80+1; 63 const int w_hour = r.width()/80+1;
64 64
65 QPoint l1( r.x() + r.width() / 2, r.y() + 2 ); 65 QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
66 QPoint l2( r.x() + r.width() / 2, r.y() + 8 ); 66 QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
67 67
68 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 ); 68 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 );
69 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 69 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
70 70
71 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 9 ); 71 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 9 );
72 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 72 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
73 73
74 QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); 74 QPoint s1( r.x() + r.width() / 2, r.y() + 8 );
75 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 75 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
76 76
77 QColor color( clear ? backgroundColor() : black ); 77 QColor color( clear ? backgroundColor() : black );
78 QTime time = clear ? prevTime : currTime; 78 QTime time = clear ? prevTime : currTime;
79 79
80 if ( clear && prevTime.secsTo(currTime) > 1 ) { 80 if ( clear && prevTime.secsTo(currTime) > 1 ) {
81 p->eraseRect( rect() ); 81 p->eraseRect( rect() );
82 return; 82 return;
83 } 83 }
84 84
85 if ( !clear ) { 85 if ( !clear ) {
86 // draw ticks 86 // draw ticks
87 p->setPen( QPen( color, w_tick ) ); 87 p->setPen( QPen( color, w_tick ) );
88 for ( int i = 0; i < 12; i++ ) 88 for ( int i = 0; i < 12; i++ )
89 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 89 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
90 } 90 }
91 91
92 if ( !clear || prevTime.minute() != currTime.minute() || 92 if ( !clear || prevTime.minute() != currTime.minute() ||
93 prevTime.hour() != currTime.hour() ) { 93 prevTime.hour() != currTime.hour() ) {
94 // draw hour pointer 94 // draw hour pointer
95 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 95 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );