qwt_analog_clock.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
  2. * Qwt Widget Library
  3. * Copyright (C) 1997 Josef Wilgen
  4. * Copyright (C) 2002 Uwe Rathmann
  5. *
  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. *****************************************************************************/
  9. #ifndef QWT_ANALOG_CLOCK_H
  10. #define QWT_ANALOG_CLOCK_H
  11. #include "qwt_global.h"
  12. #include "qwt_dial.h"
  13. #include "qwt_dial_needle.h"
  14. #include <qdatetime.h>
  15. /*!
  16. \brief An analog clock
  17. \image html analogclock.png
  18. \par Example
  19. \code
  20. #include <qwt_analog_clock.h>
  21. QwtAnalogClock *clock = new QwtAnalogClock(...);
  22. clock->scaleDraw()->setPenWidth(3);
  23. clock->setLineWidth(6);
  24. clock->setFrameShadow(QwtDial::Sunken);
  25. clock->setTime();
  26. // update the clock every second
  27. QTimer *timer = new QTimer(clock);
  28. timer->connect(timer, SIGNAL(timeout()), clock, SLOT(setCurrentTime()));
  29. timer->start(1000);
  30. \endcode
  31. \note The examples/dials example shows how to use QwtAnalogClock.
  32. */
  33. class QWT_EXPORT QwtAnalogClock: public QwtDial
  34. {
  35. Q_OBJECT
  36. public:
  37. /*!
  38. Hand type
  39. \sa setHand(), hand()
  40. */
  41. enum Hand
  42. {
  43. //! Needle displaying the seconds
  44. SecondHand,
  45. //! Needle displaying the minutes
  46. MinuteHand,
  47. //! Needle displaying the hours
  48. HourHand,
  49. //! Number of needles
  50. NHands
  51. };
  52. explicit QwtAnalogClock( QWidget* parent = NULL );
  53. virtual ~QwtAnalogClock();
  54. void setHand( Hand, QwtDialNeedle * );
  55. const QwtDialNeedle *hand( Hand ) const;
  56. QwtDialNeedle *hand( Hand );
  57. public Q_SLOTS:
  58. void setCurrentTime();
  59. void setTime( const QTime & );
  60. protected:
  61. virtual void drawNeedle( QPainter *, const QPointF &,
  62. double radius, double direction, QPalette::ColorGroup ) const;
  63. virtual void drawHand( QPainter *, Hand, const QPointF &,
  64. double radius, double direction, QPalette::ColorGroup ) const;
  65. private:
  66. // use setHand instead
  67. void setNeedle( QwtDialNeedle * );
  68. QwtDialNeedle *d_hand[NHands];
  69. };
  70. #endif