qwt_abstract_scale_draw.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_ABSTRACT_SCALE_DRAW_H
  10. #define QWT_ABSTRACT_SCALE_DRAW_H
  11. #include "qwt_global.h"
  12. #include "qwt_scale_div.h"
  13. #include "qwt_text.h"
  14. class QPalette;
  15. class QPainter;
  16. class QFont;
  17. class QwtScaleTransformation;
  18. class QwtScaleMap;
  19. /*!
  20. \brief A abstract base class for drawing scales
  21. QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
  22. After a scale division has been specified as a QwtScaleDiv object
  23. using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s),
  24. the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
  25. */
  26. class QWT_EXPORT QwtAbstractScaleDraw
  27. {
  28. public:
  29. /*!
  30. Components of a scale
  31. - Backbone
  32. - Ticks
  33. - Labels
  34. \sa enableComponent(), hasComponent
  35. */
  36. enum ScaleComponent
  37. {
  38. Backbone = 1,
  39. Ticks = 2,
  40. Labels = 4
  41. };
  42. QwtAbstractScaleDraw();
  43. virtual ~QwtAbstractScaleDraw();
  44. void setScaleDiv( const QwtScaleDiv &s );
  45. const QwtScaleDiv& scaleDiv() const;
  46. void setTransformation( QwtScaleTransformation * );
  47. const QwtScaleMap &map() const;
  48. void enableComponent( ScaleComponent, bool enable = true );
  49. bool hasComponent( ScaleComponent ) const;
  50. void setTickLength( QwtScaleDiv::TickType, double length );
  51. double tickLength( QwtScaleDiv::TickType ) const;
  52. double majTickLength() const;
  53. void setSpacing( double margin );
  54. double spacing() const;
  55. void setPenWidth( int width );
  56. int penWidth() const;
  57. virtual void draw( QPainter *, const QPalette & ) const;
  58. virtual QwtText label( double ) const;
  59. /*!
  60. Calculate the extent
  61. The extent is the distcance from the baseline to the outermost
  62. pixel of the scale draw in opposite to its orientation.
  63. It is at least minimumExtent() pixels.
  64. \sa setMinimumExtent(), minimumExtent()
  65. */
  66. virtual double extent( const QFont & ) const = 0;
  67. void setMinimumExtent( double );
  68. double minimumExtent() const;
  69. QwtScaleMap &scaleMap();
  70. protected:
  71. /*!
  72. Draw a tick
  73. \param painter Painter
  74. \param value Value of the tick
  75. \param len Lenght of the tick
  76. \sa drawBackbone(), drawLabel()
  77. */
  78. virtual void drawTick( QPainter *painter, double value, double len ) const = 0;
  79. /*!
  80. Draws the baseline of the scale
  81. \param painter Painter
  82. \sa drawTick(), drawLabel()
  83. */
  84. virtual void drawBackbone( QPainter *painter ) const = 0;
  85. /*!
  86. Draws the label for a major scale tick
  87. \param painter Painter
  88. \param value Value
  89. \sa drawTick, drawBackbone
  90. */
  91. virtual void drawLabel( QPainter *painter, double value ) const = 0;
  92. void invalidateCache();
  93. const QwtText &tickLabel( const QFont &, double value ) const;
  94. private:
  95. QwtAbstractScaleDraw( const QwtAbstractScaleDraw & );
  96. QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & );
  97. class PrivateData;
  98. PrivateData *d_data;
  99. };
  100. #endif