An analog clock. More...
#include <qwt_analog_clock.h>
Public Types | |
enum | Hand { SecondHand, MinuteHand, HourHand, NHands } |
Public Slots | |
void | setCurrentTime () |
Set the current time. | |
void | setTime (const QTime &=QTime::currentTime()) |
Public Member Functions | |
QwtAnalogClock (QWidget *parent=NULL) | |
QwtAnalogClock (QWidget *parent, const char *name) | |
virtual | ~QwtAnalogClock () |
Destructor. | |
virtual void | setHand (Hand, QwtDialNeedle *) |
const QwtDialNeedle * | hand (Hand) const |
QwtDialNeedle * | hand (Hand) |
Protected Member Functions | |
virtual QwtText | scaleLabel (double) const |
virtual void | drawNeedle (QPainter *, const QPoint &, int radius, double direction, QPalette::ColorGroup) const |
Draw the needle. | |
virtual void | drawHand (QPainter *, Hand, const QPoint &, int radius, double direction, QPalette::ColorGroup) const |
An analog clock.
#include <qwt_analog_clock.h> QwtAnalogClock *clock = new QwtAnalogClock(...); clock->scaleDraw()->setPenWidth(3); clock->setLineWidth(6); clock->setFrameShadow(QwtDial::Sunken); clock->setTime(); // update the clock every second QTimer *timer = new QTimer(clock); timer->connect(timer, SIGNAL(timeout()), clock, SLOT(setCurrentTime())); timer->start(1000);
Qwt is missing a set of good looking hands. Contributions are very welcome.
Definition at line 45 of file qwt_analog_clock.h.
enum QwtAnalogClock::Hand |
QwtAnalogClock::QwtAnalogClock | ( | QWidget * | parent = NULL ) |
[explicit] |
Constructor
parent | Parent widget |
Definition at line 16 of file qwt_analog_clock.cpp.
: QwtDial(parent) { initClock(); }
QwtAnalogClock::QwtAnalogClock | ( | QWidget * | parent, |
const char * | name | ||
) | [explicit] |
Constructor
parent | Parent widget |
name | Object name |
Definition at line 28 of file qwt_analog_clock.cpp.
: QwtDial(parent, name) { initClock(); }
QwtAnalogClock::~QwtAnalogClock | ( | ) | [virtual] |
Destructor.
Definition at line 82 of file qwt_analog_clock.cpp.
References NHands.
{ for ( int i = 0; i < NHands; i++ ) delete d_hand[i]; }
void QwtAnalogClock::drawHand | ( | QPainter * | painter, |
Hand | hd, | ||
const QPoint & | center, | ||
int | radius, | ||
double | direction, | ||
QPalette::ColorGroup | cg | ||
) | const [protected, virtual] |
Draw a clock hand
painter | Painter |
hd | Specify the type of hand |
center | Center of the clock |
radius | Maximum length for the hands |
direction | Direction of the hand in degrees, counter clockwise |
cg | ColorGroup |
Definition at line 229 of file qwt_analog_clock.cpp.
References QwtDialNeedle::draw(), hand(), HourHand, and QwtDial::needle().
Referenced by drawNeedle().
void QwtAnalogClock::drawNeedle | ( | QPainter * | painter, |
const QPoint & | center, | ||
int | radius, | ||
double | direction, | ||
QPalette::ColorGroup | cg | ||
) | const [protected, virtual] |
Draw the needle.
A clock has no single needle but three hands instead. drawNeedle translates value() into directions for the hands and calls drawHand().
painter | Painter |
center | Center of the clock |
radius | Maximum length for the hands |
direction | Dummy, not used. |
cg | ColorGroup |
Reimplemented from QwtDial.
Definition at line 191 of file qwt_analog_clock.cpp.
References QwtDial::Clockwise, QwtDial::direction(), drawHand(), hand(), HourHand, int(), QwtAbstractSlider::isValid(), MinuteHand, NHands, QwtDial::origin(), SecondHand, and QwtDoubleRange::value().
{ if ( isValid() ) { const double hours = value() / (60.0 * 60.0); const double minutes = (value() - (int)hours * 60.0 * 60.0) / 60.0; const double seconds = value() - (int)hours * 60.0 * 60.0 - (int)minutes * 60.0; double angle[NHands]; angle[HourHand] = 360.0 * hours / 12.0; angle[MinuteHand] = 360.0 * minutes / 60.0; angle[SecondHand] = 360.0 * seconds / 60.0; for ( int hand = 0; hand < NHands; hand++ ) { double d = angle[hand]; if ( direction() == Clockwise ) d = 360.0 - d; d -= origin(); drawHand(painter, (Hand)hand, center, radius, d, cg); } } }
QwtDialNeedle * QwtAnalogClock::hand | ( | Hand | hd ) |
hd | Specifies the type of hand |
Definition at line 118 of file qwt_analog_clock.cpp.
{ if ( hd < 0 || hd >= NHands ) return NULL; return d_hand[hd]; }
const QwtDialNeedle * QwtAnalogClock::hand | ( | Hand | hd ) | const |
hd | Specifies the type of hand |
Definition at line 131 of file qwt_analog_clock.cpp.
Referenced by drawHand(), drawNeedle(), and setHand().
{ return ((QwtAnalogClock *)this)->hand(hd); }
QwtText QwtAnalogClock::scaleLabel | ( | double | value ) | const [protected, virtual] |
void QwtAnalogClock::setCurrentTime | ( | ) | [slot] |
Set the current time.
This is the same as QwtAnalogClock::setTime(), but Qt < 3.0 can't handle default parameters for slots.
Definition at line 142 of file qwt_analog_clock.cpp.
References setTime().
{ setTime(QTime::currentTime()); }
void QwtAnalogClock::setHand | ( | Hand | hand, |
QwtDialNeedle * | needle | ||
) | [virtual] |
void QwtAnalogClock::setTime | ( | const QTime & | time = QTime::currentTime() ) |
[slot] |
Set a time
time | Time to display |
Definition at line 151 of file qwt_analog_clock.cpp.
References QwtAbstractSlider::setValid(), and QwtAbstractSlider::setValue().
Referenced by setCurrentTime().