qwt_scale_draw.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_SCALE_DRAW_H
  10. #define QWT_SCALE_DRAW_H
  11. #include "qwt_global.h"
  12. #include "qwt_abstract_scale_draw.h"
  13. #include <qpoint.h>
  14. #include <qrect.h>
  15. #include <qtransform.h>
  16. /*!
  17. \brief A class for drawing scales
  18. QwtScaleDraw can be used to draw linear or logarithmic scales.
  19. A scale has a position, an alignment and a length, which can be specified .
  20. The labels can be rotated and aligned
  21. to the ticks using setLabelRotation() and setLabelAlignment().
  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 QwtScaleDraw: public QwtAbstractScaleDraw
  27. {
  28. public:
  29. /*!
  30. Alignment of the scale draw
  31. \sa setAlignment(), alignment()
  32. */
  33. enum Alignment
  34. {
  35. //! The scale is below
  36. BottomScale,
  37. //! The scale is above
  38. TopScale,
  39. //! The scale is left
  40. LeftScale,
  41. //! The scale is right
  42. RightScale
  43. };
  44. QwtScaleDraw();
  45. virtual ~QwtScaleDraw();
  46. void getBorderDistHint( const QFont &, int &start, int &end ) const;
  47. int minLabelDist( const QFont & ) const;
  48. int minLength( const QFont & ) const;
  49. virtual double extent( const QFont & ) const;
  50. void move( double x, double y );
  51. void move( const QPointF & );
  52. void setLength( double length );
  53. Alignment alignment() const;
  54. void setAlignment( Alignment );
  55. Qt::Orientation orientation() const;
  56. QPointF pos() const;
  57. double length() const;
  58. void setLabelAlignment( Qt::Alignment );
  59. Qt::Alignment labelAlignment() const;
  60. void setLabelRotation( double rotation );
  61. double labelRotation() const;
  62. int maxLabelHeight( const QFont & ) const;
  63. int maxLabelWidth( const QFont & ) const;
  64. QPointF labelPosition( double value ) const;
  65. QRectF labelRect( const QFont &, double value ) const;
  66. QSizeF labelSize( const QFont &, double value ) const;
  67. QRect boundingLabelRect( const QFont &, double value ) const;
  68. protected:
  69. QTransform labelTransformation( const QPointF &, const QSizeF & ) const;
  70. virtual void drawTick( QPainter *, double value, double len ) const;
  71. virtual void drawBackbone( QPainter * ) const;
  72. virtual void drawLabel( QPainter *, double value ) const;
  73. private:
  74. QwtScaleDraw( const QwtScaleDraw & );
  75. QwtScaleDraw &operator=( const QwtScaleDraw &other );
  76. void updateMap();
  77. class PrivateData;
  78. PrivateData *d_data;
  79. };
  80. /*!
  81. Move the position of the scale
  82. \param x X coordinate
  83. \param y Y coordinate
  84. \sa move(const QPointF &)
  85. */
  86. inline void QwtScaleDraw::move( double x, double y )
  87. {
  88. move( QPointF( x, y ) );
  89. }
  90. #endif