qwt_scale_widget.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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_WIDGET_H
  10. #define QWT_SCALE_WIDGET_H
  11. #include "qwt_global.h"
  12. #include "qwt_text.h"
  13. #include "qwt_scale_draw.h"
  14. #include <qwidget.h>
  15. #include <qfont.h>
  16. #include <qcolor.h>
  17. #include <qstring.h>
  18. class QPainter;
  19. class QwtTransform;
  20. class QwtScaleDiv;
  21. class QwtColorMap;
  22. /*!
  23. \brief A Widget which contains a scale
  24. This Widget can be used to decorate composite widgets with
  25. a scale.
  26. */
  27. class QWT_EXPORT QwtScaleWidget : public QWidget
  28. {
  29. Q_OBJECT
  30. public:
  31. //! Layout flags of the title
  32. enum LayoutFlag
  33. {
  34. /*!
  35. The title of vertical scales is painted from top to bottom.
  36. Otherwise it is painted from bottom to top.
  37. */
  38. TitleInverted = 1
  39. };
  40. //! Layout flags of the title
  41. typedef QFlags<LayoutFlag> LayoutFlags;
  42. explicit QwtScaleWidget( QWidget *parent = NULL );
  43. explicit QwtScaleWidget( QwtScaleDraw::Alignment, QWidget *parent = NULL );
  44. virtual ~QwtScaleWidget();
  45. Q_SIGNALS:
  46. //! Signal emitted, whenever the scale division changes
  47. void scaleDivChanged();
  48. public:
  49. void setTitle( const QString &title );
  50. void setTitle( const QwtText &title );
  51. QwtText title() const;
  52. void setLayoutFlag( LayoutFlag, bool on );
  53. bool testLayoutFlag( LayoutFlag ) const;
  54. void setBorderDist( int dist1, int dist2 );
  55. int startBorderDist() const;
  56. int endBorderDist() const;
  57. void getBorderDistHint( int &start, int &end ) const;
  58. void getMinBorderDist( int &start, int &end ) const;
  59. void setMinBorderDist( int start, int end );
  60. void setMargin( int );
  61. int margin() const;
  62. void setSpacing( int );
  63. int spacing() const;
  64. void setScaleDiv( const QwtScaleDiv & );
  65. void setTransformation( QwtTransform * );
  66. void setScaleDraw( QwtScaleDraw * );
  67. const QwtScaleDraw *scaleDraw() const;
  68. QwtScaleDraw *scaleDraw();
  69. void setLabelAlignment( Qt::Alignment );
  70. void setLabelRotation( double rotation );
  71. void setColorBarEnabled( bool );
  72. bool isColorBarEnabled() const;
  73. void setColorBarWidth( int );
  74. int colorBarWidth() const;
  75. void setColorMap( const QwtInterval &, QwtColorMap * );
  76. QwtInterval colorBarInterval() const;
  77. const QwtColorMap *colorMap() const;
  78. virtual QSize sizeHint() const;
  79. virtual QSize minimumSizeHint() const;
  80. int titleHeightForWidth( int width ) const;
  81. int dimForLength( int length, const QFont &scaleFont ) const;
  82. void drawColorBar( QPainter *painter, const QRectF & ) const;
  83. void drawTitle( QPainter *painter, QwtScaleDraw::Alignment,
  84. const QRectF &rect ) const;
  85. void setAlignment( QwtScaleDraw::Alignment );
  86. QwtScaleDraw::Alignment alignment() const;
  87. QRectF colorBarRect( const QRectF& ) const;
  88. protected:
  89. virtual void paintEvent( QPaintEvent * );
  90. virtual void resizeEvent( QResizeEvent * );
  91. void draw( QPainter * ) const;
  92. void scaleChange();
  93. void layoutScale( bool update_geometry = true );
  94. private:
  95. void initScale( QwtScaleDraw::Alignment );
  96. class PrivateData;
  97. PrivateData *d_data;
  98. };
  99. Q_DECLARE_OPERATORS_FOR_FLAGS( QwtScaleWidget::LayoutFlags )
  100. #endif