qwt_analog_clock.h 2.12 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 * Qwt Widget Library
 * Copyright (C) 1997   Josef Wilgen
 * Copyright (C) 2002   Uwe Rathmann
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the Qwt License, Version 1.0
 *****************************************************************************/

#ifndef QWT_ANALOG_CLOCK_H
#define QWT_ANALOG_CLOCK_H

#include "qwt_global.h"
#include "qwt_dial.h"
#include "qwt_dial_needle.h"
Bryant's avatar
Bryant committed
16
#include <qdatetime.h>
pixhawk's avatar
pixhawk committed
17 18 19 20 21 22 23

/*!
  \brief An analog clock

  \image html analogclock.png

  \par Example
Bryant's avatar
Bryant committed
24 25
  \code 
  #include <qwt_analog_clock.h>
pixhawk's avatar
pixhawk committed
26 27 28 29 30 31 32 33 34 35 36 37

  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);

Bryant's avatar
Bryant committed
38
  \endcode
pixhawk's avatar
pixhawk committed
39 40 41 42 43 44 45 46 47

  \note The examples/dials example shows how to use QwtAnalogClock.
*/

class QWT_EXPORT QwtAnalogClock: public QwtDial
{
    Q_OBJECT

public:
48
    /*!
pixhawk's avatar
pixhawk committed
49 50 51
        Hand type
        \sa setHand(), hand()
    */
Bryant's avatar
Bryant committed
52 53 54
    enum Hand
    {
        //! Needle displaying the seconds
pixhawk's avatar
pixhawk committed
55
        SecondHand,
Bryant's avatar
Bryant committed
56 57

        //! Needle displaying the minutes
pixhawk's avatar
pixhawk committed
58
        MinuteHand,
Bryant's avatar
Bryant committed
59 60

        //! Needle displaying the hours
pixhawk's avatar
pixhawk committed
61 62
        HourHand,

Bryant's avatar
Bryant committed
63
        //! Number of needles
pixhawk's avatar
pixhawk committed
64 65 66
        NHands
    };

Bryant's avatar
Bryant committed
67
    explicit QwtAnalogClock( QWidget* parent = NULL );
pixhawk's avatar
pixhawk committed
68 69
    virtual ~QwtAnalogClock();

Bryant's avatar
Bryant committed
70
    void setHand( Hand, QwtDialNeedle * );
pixhawk's avatar
pixhawk committed
71

Bryant's avatar
Bryant committed
72 73 74 75
    const QwtDialNeedle *hand( Hand ) const;
    QwtDialNeedle *hand( Hand );

public Q_SLOTS:
pixhawk's avatar
pixhawk committed
76
    void setCurrentTime();
Bryant's avatar
Bryant committed
77
    void setTime( const QTime & );
pixhawk's avatar
pixhawk committed
78 79

protected:
Bryant's avatar
Bryant committed
80 81
    virtual void drawNeedle( QPainter *, const QPointF &,
        double radius, double direction, QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed
82

Bryant's avatar
Bryant committed
83 84
    virtual void drawHand( QPainter *, Hand, const QPointF &,
        double radius, double direction, QPalette::ColorGroup ) const;
pixhawk's avatar
pixhawk committed
85 86

private:
Bryant's avatar
Bryant committed
87 88
    // use setHand instead
    void setNeedle( QwtDialNeedle * );
pixhawk's avatar
pixhawk committed
89 90 91 92 93

    QwtDialNeedle *d_hand[NHands];
};

#endif