qwt_thermo.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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_THERMO_H
  10. #define QWT_THERMO_H
  11. #include "qwt_global.h"
  12. #include "qwt_abstract_scale.h"
  13. #include <qwidget.h>
  14. #include <qcolor.h>
  15. #include <qfont.h>
  16. #include <qrect.h>
  17. class QwtScaleDraw;
  18. /*!
  19. \brief The Thermometer Widget
  20. QwtThermo is a widget which displays a value in an interval. It supports:
  21. - a horizontal or vertical layout;
  22. - a range;
  23. - a scale;
  24. - an alarm level.
  25. \image html sysinfo.png
  26. By default, the scale and range run over the same interval of values.
  27. QwtAbstractScale::setScale() changes the interval of the scale and allows
  28. easy conversion between physical units.
  29. The example shows how to make the scale indicate in degrees Fahrenheit and
  30. to set the value in degrees Kelvin:
  31. \code
  32. #include <qapplication.h>
  33. #include <qwt_thermo.h>
  34. double Kelvin2Fahrenheit(double kelvin)
  35. {
  36. // see http://en.wikipedia.org/wiki/Kelvin
  37. return 1.8*kelvin - 459.67;
  38. }
  39. int main(int argc, char **argv)
  40. {
  41. const double minKelvin = 0.0;
  42. const double maxKelvin = 500.0;
  43. QApplication a(argc, argv);
  44. QwtThermo t;
  45. t.setRange(minKelvin, maxKelvin);
  46. t.setScale(Kelvin2Fahrenheit(minKelvin), Kelvin2Fahrenheit(maxKelvin));
  47. // set the value in Kelvin but the scale displays in Fahrenheit
  48. // 273.15 Kelvin = 0 Celsius = 32 Fahrenheit
  49. t.setValue(273.15);
  50. a.setMainWidget(&t);
  51. t.show();
  52. return a.exec();
  53. }
  54. \endcode
  55. \todo Improve the support for a logarithmic range and/or scale.
  56. */
  57. class QWT_EXPORT QwtThermo: public QWidget, public QwtAbstractScale
  58. {
  59. Q_OBJECT
  60. Q_ENUMS( ScalePos )
  61. Q_PROPERTY( QBrush alarmBrush READ alarmBrush WRITE setAlarmBrush )
  62. Q_PROPERTY( QColor alarmColor READ alarmColor WRITE setAlarmColor )
  63. Q_PROPERTY( bool alarmEnabled READ alarmEnabled WRITE setAlarmEnabled )
  64. Q_PROPERTY( double alarmLevel READ alarmLevel WRITE setAlarmLevel )
  65. Q_PROPERTY( ScalePos scalePosition READ scalePosition
  66. WRITE setScalePosition )
  67. Q_PROPERTY( int borderWidth READ borderWidth WRITE setBorderWidth )
  68. Q_PROPERTY( QBrush fillBrush READ fillBrush WRITE setFillBrush )
  69. Q_PROPERTY( QColor fillColor READ fillColor WRITE setFillColor )
  70. Q_PROPERTY( double maxValue READ maxValue WRITE setMaxValue )
  71. Q_PROPERTY( double minValue READ minValue WRITE setMinValue )
  72. Q_PROPERTY( int pipeWidth READ pipeWidth WRITE setPipeWidth )
  73. Q_PROPERTY( double value READ value WRITE setValue )
  74. public:
  75. /*!
  76. Scale position. QwtThermo tries to enforce valid combinations of its
  77. orientation and scale position:
  78. - Qt::Horizonal combines with NoScale, TopScale and BottomScale
  79. - Qt::Vertical combines with NoScale, LeftScale and RightScale
  80. \sa setOrientation(), setScalePosition()
  81. */
  82. enum ScalePos
  83. {
  84. NoScale,
  85. LeftScale,
  86. RightScale,
  87. TopScale,
  88. BottomScale
  89. };
  90. explicit QwtThermo( QWidget *parent = NULL );
  91. virtual ~QwtThermo();
  92. void setOrientation( Qt::Orientation o, ScalePos s );
  93. void setScalePosition( ScalePos s );
  94. ScalePos scalePosition() const;
  95. void setBorderWidth( int w );
  96. int borderWidth() const;
  97. void setFillBrush( const QBrush &b );
  98. const QBrush &fillBrush() const;
  99. void setFillColor( const QColor &c );
  100. const QColor &fillColor() const;
  101. void setAlarmBrush( const QBrush &b );
  102. const QBrush &alarmBrush() const;
  103. void setAlarmColor( const QColor &c );
  104. const QColor &alarmColor() const;
  105. void setAlarmLevel( double v );
  106. double alarmLevel() const;
  107. void setAlarmEnabled( bool tf );
  108. bool alarmEnabled() const;
  109. void setPipeWidth( int w );
  110. int pipeWidth() const;
  111. void setMaxValue( double v );
  112. double maxValue() const;
  113. void setMinValue( double v );
  114. double minValue() const;
  115. double value() const;
  116. void setRange( double vmin, double vmax, bool lg = false );
  117. void setMargin( int m );
  118. virtual QSize sizeHint() const;
  119. virtual QSize minimumSizeHint() const;
  120. void setScaleDraw( QwtScaleDraw * );
  121. const QwtScaleDraw *scaleDraw() const;
  122. public Q_SLOTS:
  123. virtual void setValue( double val );
  124. protected:
  125. void draw( QPainter *p, const QRect& update_rect );
  126. void drawThermo( QPainter *p );
  127. void layoutThermo( bool update = true );
  128. virtual void scaleChange();
  129. virtual void fontChange( const QFont &oldFont );
  130. virtual void paintEvent( QPaintEvent *e );
  131. virtual void resizeEvent( QResizeEvent *e );
  132. QwtScaleDraw *scaleDraw();
  133. private:
  134. void initThermo();
  135. int transform( double v ) const;
  136. class PrivateData;
  137. PrivateData *d_data;
  138. };
  139. #endif