1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
10
#include "qwt_analog_clock.h"
14
\param parent Parent widget
16
QwtAnalogClock::QwtAnalogClock(QWidget *parent):
22
#if QT_VERSION < 0x040000
25
\param parent Parent widget
26
\param name Object name
28
QwtAnalogClock::QwtAnalogClock(QWidget* parent, const char *name):
35
void QwtAnalogClock::initClock()
41
setRange(0.0, 60.0 * 60.0 * 12.0); // seconds
42
setScale(-1, 5, 60.0 * 60.0);
44
setScaleOptions(ScaleTicks | ScaleLabel);
45
setScaleTicks(1, 0, 8);
46
scaleDraw()->setSpacing(8);
49
#if QT_VERSION < 0x040000
50
palette().color(QPalette::Active, QColorGroup::Text);
52
palette().color(QPalette::Active, QPalette::Text);
54
knobColor = knobColor.dark(120);
59
for ( int i = 0; i < NHands; i++ )
61
if ( i == SecondHand )
64
handColor = knobColor.dark(120);
69
handColor = knobColor;
72
QwtDialSimpleNeedle *hand = new QwtDialSimpleNeedle(
73
QwtDialSimpleNeedle::Arrow, true, handColor, knobColor);
74
hand->setWidth(width);
77
setHand((Hand)i, hand);
82
QwtAnalogClock::~QwtAnalogClock()
84
for ( int i = 0; i < NHands; i++ )
89
Nop method, use setHand instead
90
\sa QwtAnalogClock::setHand
92
void QwtAnalogClock::setNeedle(QwtDialNeedle *)
100
\param hand Specifies the type of hand
102
\sa QwtAnalogClock::hand()
104
void QwtAnalogClock::setHand(Hand hand, QwtDialNeedle *needle)
106
if ( hand >= 0 || hand < NHands )
109
d_hand[hand] = needle;
115
\param hd Specifies the type of hand
116
\sa QwtAnalogClock::setHand
118
QwtDialNeedle *QwtAnalogClock::hand(Hand hd)
120
if ( hd < 0 || hd >= NHands )
128
\param hd Specifies the type of hand
129
\sa QwtAnalogClock::setHand
131
const QwtDialNeedle *QwtAnalogClock::hand(Hand hd) const
133
return ((QwtAnalogClock *)this)->hand(hd);
137
\brief Set the current time
139
This is the same as QwtAnalogClock::setTime(), but Qt < 3.0
140
can't handle default parameters for slots.
142
void QwtAnalogClock::setCurrentTime()
144
setTime(QTime::currentTime());
149
\param time Time to display
151
void QwtAnalogClock::setTime(const QTime &time)
153
if ( time.isValid() )
155
setValue((time.hour() % 12) * 60.0 * 60.0
156
+ time.minute() * 60.0 + time.second());
163
Find the scale label for a given value
168
QwtText QwtAnalogClock::scaleLabel(double value) const
171
value = 60.0 * 60.0 * 12.0;
173
return QString::number(int(value / (60.0 * 60.0)));
177
\brief Draw the needle
179
A clock has no single needle but three hands instead. drawNeedle
180
translates value() into directions for the hands and calls
183
\param painter Painter
184
\param center Center of the clock
185
\param radius Maximum length for the hands
186
\param direction Dummy, not used.
189
\sa QwtAnalogClock::drawHand()
191
void QwtAnalogClock::drawNeedle(QPainter *painter, const QPoint ¢er,
192
int radius, double, QPalette::ColorGroup cg) const
196
const double hours = value() / (60.0 * 60.0);
197
const double minutes = (value() - (int)hours * 60.0 * 60.0) / 60.0;
198
const double seconds = value() - (int)hours * 60.0 * 60.0
199
- (int)minutes * 60.0;
201
drawHand(painter, HourHand, center, radius,
202
360.0 - (origin() + 360.0 * hours / 12.0), cg);
203
drawHand(painter, MinuteHand, center, radius,
204
360.0 - (origin() + 360.0 * minutes / 60.0), cg);
205
drawHand(painter, SecondHand, center, radius,
206
360.0 - (origin() + 360.0 * seconds / 60.0), cg);
213
\param painter Painter
214
\param hd Specify the type of hand
215
\param center Center of the clock
216
\param radius Maximum length for the hands
217
\param direction Direction of the hand in degrees, counter clockwise
220
void QwtAnalogClock::drawHand(QPainter *painter, Hand hd,
221
const QPoint ¢er, int radius, double direction,
222
QPalette::ColorGroup cg) const
224
const QwtDialNeedle *needle = hand(hd);
227
if ( hd == HourHand )
228
radius = qRound(0.8 * radius);
230
needle->draw(painter, center, radius, direction, cg);