add more spacing
[personal-kdebase.git] / workspace / kdm / kfrontend / kdmclock.cpp
blob4b7d802da73b4126ac82951e84d9d1899b9ed1f0
1 /*
3 clock module for kdm
5 Copyright (C) 2000 Espen Sand, espen@kde.org
6 Based on work by NN(yet to be determined)
7 flicker free code by Remi Guyomarch <rguyom@mail.dotcom.fr>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "kdmclock.h"
27 #include <QPainter>
28 #include <QTime>
29 #include <QTimer>
31 KdmClock::KdmClock( QWidget *parent )
32 : inherited( parent )
34 QTimer *timer = new QTimer( this );
35 connect( timer, SIGNAL(timeout()), SLOT(timeout()) );
36 timer->start( 1000 );
38 #ifdef MORE
39 mDate = false;//config->readEntry( "date", false );
40 mSecond = true;//config->readEntry( "second", true );
41 mDigital = false;//config->readEntry( "digital", false );
42 mBorder = true;//config->readEntry( "border", false );
44 //config->setGroup( "Font" );
45 mFont.setFamily( QString::fromLatin1("Utopia")/*config->readEntry( "Family", "Utopia" )*/ );
46 mFont.setPointSize( 51/*config->readEntry( "Point Size", 51 )*/ );
47 mFont.setWeight( 75/*config->readEntry( "Weight", 75 )*/ );
48 mFont.setItalic( true/*config->readEntry( "Italic", true )*/ );
49 mFont.setBold( true/*config->readEntry( "Bold", false )*/ );
51 if (mBorder)
52 setFrameStyle( WinPanel|Sunken );
53 #endif
55 setFixedSize( 100, 100 );
57 repaint();
61 void KdmClock::showEvent( QShowEvent * )
63 repaint();
67 void KdmClock::timeout()
69 repaint();
72 void KdmClock::paintEvent( QPaintEvent * )
74 QPainter p( this );
75 #ifdef MORE
76 drawFrame( &p );
77 #endif
79 p.setPen( palette().foreground().color() );
80 p.setBrush( palette().foreground() );
82 QTime time = QTime::currentTime();
84 #ifdef MORE
85 if (mDigital) {
86 QString buf;
87 if (mSecond)
88 buf.sprintf( "%02d:%02d:%02d", time.hour(), time.minute(),
89 time.second() );
90 else
91 buf.sprintf( "%02d:%02d", time.hour(), time.minute() );
92 mFont.setPointSize( qMin( (int)(width() / buf.length() * 1.5), height() ) );
93 p.setFont( mFont );
94 p.drawText( contentsRect(), Qt::AlignCenter, buf );
95 } else
96 #endif
98 QTransform matrix;
99 QPoint cp = contentsRect().center();
100 matrix.translate( cp.x(), cp.y() );
101 int d = qMin( contentsRect().width() - 15, contentsRect().height() - 15 );
102 matrix.scale( d/1000.0F, d/1000.0F );
104 QPolygon pts;
106 // Hour
107 float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
108 matrix.rotate( h_angle );
109 p.setWorldTransform( matrix );
110 pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 );
111 p.drawPolygon( pts );
112 matrix.rotate( -h_angle );
114 // Minute
115 float m_angle = (time.minute()-15)*6;
116 matrix.rotate( m_angle );
117 p.setWorldTransform( matrix );
118 pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
119 p.drawPolygon( pts );
120 matrix.rotate( -m_angle );
122 // Second
123 #ifdef MORE
124 if (mSecond)
125 #endif
127 float s_angle = (time.second()-15)*6;
128 matrix.rotate( s_angle );
129 p.setWorldTransform( matrix );
130 pts.setPoints( 4,0,0,0,0,400,0,0,0 );
131 p.drawPolygon( pts );
132 matrix.rotate( -s_angle );
135 // quadrante
136 for (int i = 0; i < 60; i++) {
137 p.setWorldTransform( matrix );
138 if ((i % 5) == 0)
139 p.drawLine( 450,0, 500,0 ); // draw hour lines
140 else
141 p.drawPoint( 480,0 ); // draw second lines
142 matrix.rotate( 6 );
145 } // if (mDigital)
148 #include "kdmclock.moc"