qwt_abstract_scale_draw.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 QwtTransform;
  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 setScaleDiv(), the scale can be drawn with the draw() member.
  24. */
  25. class QWT_EXPORT QwtAbstractScaleDraw
  26. {
  27. public:
  28. /*!
  29. Components of a scale
  30. \sa enableComponent(), hasComponent
  31. */
  32. enum ScaleComponent
  33. {
  34. //! Backbone = the line where the ticks are located
  35. Backbone = 0x01,
  36. //! Ticks
  37. Ticks = 0x02,
  38. //! Labels
  39. Labels = 0x04
  40. };
  41. //! Scale components
  42. typedef QFlags<ScaleComponent> ScaleComponents;
  43. QwtAbstractScaleDraw();
  44. virtual ~QwtAbstractScaleDraw();
  45. void setScaleDiv( const QwtScaleDiv & );
  46. const QwtScaleDiv& scaleDiv() const;
  47. void setTransformation( QwtTransform * );
  48. const QwtScaleMap &scaleMap() const;
  49. QwtScaleMap &scaleMap();
  50. void enableComponent( ScaleComponent, bool enable = true );
  51. bool hasComponent( ScaleComponent ) const;
  52. void setTickLength( QwtScaleDiv::TickType, double length );
  53. double tickLength( QwtScaleDiv::TickType ) const;
  54. double maxTickLength() const;
  55. void setSpacing( double );
  56. double spacing() const;
  57. void setPenWidth( int width );
  58. int penWidth() const;
  59. virtual void draw( QPainter *, const QPalette & ) const;
  60. virtual QwtText label( double ) const;
  61. /*!
  62. Calculate the extent
  63. The extent is the distance from the baseline to the outermost
  64. pixel of the scale draw in opposite to its orientation.
  65. It is at least minimumExtent() pixels.
  66. \param font Font used for drawing the tick labels
  67. \return Number of pixels
  68. \sa setMinimumExtent(), minimumExtent()
  69. */
  70. virtual double extent( const QFont &font ) const = 0;
  71. void setMinimumExtent( double );
  72. double minimumExtent() const;
  73. protected:
  74. /*!
  75. Draw a tick
  76. \param painter Painter
  77. \param value Value of the tick
  78. \param len Length of the tick
  79. \sa drawBackbone(), drawLabel()
  80. */
  81. virtual void drawTick( QPainter *painter, double value, double len ) const = 0;
  82. /*!
  83. Draws the baseline of the scale
  84. \param painter Painter
  85. \sa drawTick(), drawLabel()
  86. */
  87. virtual void drawBackbone( QPainter *painter ) const = 0;
  88. /*!
  89. Draws the label for a major scale tick
  90. \param painter Painter
  91. \param value Value
  92. \sa drawTick(), drawBackbone()
  93. */
  94. virtual void drawLabel( QPainter *painter, double value ) const = 0;
  95. void invalidateCache();
  96. const QwtText &tickLabel( const QFont &, double value ) const;
  97. private:
  98. QwtAbstractScaleDraw( const QwtAbstractScaleDraw & );
  99. QwtAbstractScaleDraw &operator=( const QwtAbstractScaleDraw & );
  100. class PrivateData;
  101. PrivateData *d_data;
  102. };
  103. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtAbstractScaleDraw::ScaleComponents )
  104. #endif