Public Types | Public Slots | Public Member Functions | Protected Member Functions

QwtAnalogClock Class Reference

An analog clock. More...

#include <qwt_analog_clock.h>

Inheritance diagram for QwtAnalogClock:
Inheritance graph
[legend]
Collaboration diagram for QwtAnalogClock:
Collaboration graph
[legend]

List of all members.

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 QwtDialNeedlehand (Hand) const
QwtDialNeedlehand (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

Detailed Description

An analog clock.

analogclock.png
Example
#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.

Note:
The examples/dials example shows how to use QwtAnalogClock.

Definition at line 45 of file qwt_analog_clock.h.


Member Enumeration Documentation

Hand type

See also:
setHand(), hand()
Enumerator:
SecondHand 
MinuteHand 
HourHand 
NHands 

Definition at line 26 of file qwt_analog_clock.h.

                               : public QwtDial

Constructor & Destructor Documentation

QwtAnalogClock::QwtAnalogClock ( QWidget *  parent = NULL ) [explicit]

Constructor

Parameters:
parentParent widget

Definition at line 16 of file qwt_analog_clock.cpp.

                                             :
    QwtDial(parent)
{
    initClock();
}
QwtAnalogClock::QwtAnalogClock ( QWidget *  parent,
const char *  name 
) [explicit]

Constructor

Parameters:
parentParent widget
nameObject 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];
}

Member Function Documentation

void QwtAnalogClock::drawHand ( QPainter *  painter,
Hand  hd,
const QPoint &  center,
int  radius,
double  direction,
QPalette::ColorGroup  cg 
) const [protected, virtual]

Draw a clock hand

Parameters:
painterPainter
hdSpecify the type of hand
centerCenter of the clock
radiusMaximum length for the hands
directionDirection of the hand in degrees, counter clockwise
cgColorGroup

Definition at line 229 of file qwt_analog_clock.cpp.

References QwtDialNeedle::draw(), hand(), HourHand, and QwtDial::needle().

Referenced by drawNeedle().

{
    const QwtDialNeedle *needle = hand(hd);
    if ( needle )
    {
        if ( hd == HourHand )
            radius = qRound(0.8 * radius);

        needle->draw(painter, center, radius, direction, cg);
    }
}
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().

Parameters:
painterPainter
centerCenter of the clock
radiusMaximum length for the hands
directionDummy, not used.
cgColorGroup
See also:
drawHand()

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 )
Returns:
Clock hand
Parameters:
hdSpecifies the type of hand
See also:
setHand()

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
Returns:
Clock hand
Parameters:
hdSpecifies the type of hand
See also:
setHand()

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]

Find the scale label for a given value

Parameters:
valueValue
Returns:
Label

Reimplemented from QwtDial.

Definition at line 168 of file qwt_analog_clock.cpp.

{
    if ( value == 0.0 )
        value = 60.0 * 60.0 * 12.0;

    return QString::number(int(value / (60.0 * 60.0)));
}
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]

Set a clockhand

Parameters:
handSpecifies the type of hand
needleHand
See also:
hand()

Definition at line 104 of file qwt_analog_clock.cpp.

References hand(), and QwtDial::needle().

{
    if ( hand >= 0 || hand < NHands )
    {
        delete d_hand[hand];
        d_hand[hand] = needle;
    }
}
void QwtAnalogClock::setTime ( const QTime &  time = QTime::currentTime() ) [slot]

Set a time

Parameters:
timeTime to display

Definition at line 151 of file qwt_analog_clock.cpp.

References QwtAbstractSlider::setValid(), and QwtAbstractSlider::setValue().

Referenced by setCurrentTime().

{
    if ( time.isValid() )
    {
        setValue((time.hour() % 12) * 60.0 * 60.0 
            + time.minute() * 60.0 + time.second());
    }
    else
        setValid(false);
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines