qwt_plot_legenditem.h 3.6 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_PLOT_LEGEND_ITEM_H
  10. #define QWT_PLOT_LEGEND_ITEM_H
  11. #include "qwt_global.h"
  12. #include "qwt_plot_item.h"
  13. #include "qwt_legend_data.h"
  14. class QFont;
  15. /*!
  16. \brief A class which draws a legend inside the plot canvas
  17. QwtPlotLegendItem can be used to draw a inside the plot canvas.
  18. It can be used together with a QwtLegend or instead of it
  19. to have more space for the plot canvas.
  20. In opposite to QwtLegend the legend item is not interactive.
  21. To identify mouse clicks on a legend item an event filter
  22. needs to be installed catching mouse events ob the plot canvas.
  23. The geometries of the legend items are available using
  24. legendGeometries().
  25. The legend item is aligned to plot canvas according to
  26. its alignment() flags. It might have a background for the
  27. complete legend ( usually semi transparent ) or for
  28. each legend item.
  29. \note An external QwtLegend with a transparent background
  30. on top the plot canvas might be another option
  31. with a similar effect.
  32. */
  33. class QWT_EXPORT QwtPlotLegendItem: public QwtPlotItem
  34. {
  35. public:
  36. /*!
  37. \brief Background mode
  38. Depending on the mode the complete legend or each item
  39. might have an background.
  40. The default setting is LegendBackground.
  41. \sa setBackgroundMode(), setBackgroundBrush(), drawBackground()
  42. */
  43. enum BackgroundMode
  44. {
  45. //! The legend has a background
  46. LegendBackground,
  47. //! Each item has a background
  48. ItemBackground
  49. };
  50. explicit QwtPlotLegendItem();
  51. virtual ~QwtPlotLegendItem();
  52. virtual int rtti() const;
  53. void setAlignment( Qt::Alignment );
  54. Qt::Alignment alignment() const;
  55. void setMaxColumns( uint );
  56. uint maxColumns() const;
  57. void setMargin( int );
  58. int margin() const;
  59. void setSpacing( int );
  60. int spacing() const;
  61. void setItemMargin( int );
  62. int itemMargin() const;
  63. void setItemSpacing( int );
  64. int itemSpacing() const;
  65. void setFont( const QFont& );
  66. QFont font() const;
  67. void setBorderDistance( int );
  68. int borderDistance() const;
  69. void setBorderRadius( double );
  70. double borderRadius() const;
  71. void setBorderPen( const QPen & );
  72. QPen borderPen() const;
  73. void setBackgroundBrush( const QBrush & );
  74. QBrush backgroundBrush() const;
  75. void setBackgroundMode( BackgroundMode );
  76. BackgroundMode backgroundMode() const;
  77. void setTextPen( const QPen & );
  78. QPen textPen() const;
  79. virtual void draw( QPainter *,
  80. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
  81. const QRectF &canvasRect ) const;
  82. void clearLegend();
  83. virtual void updateLegend( const QwtPlotItem *,
  84. const QList<QwtLegendData> & );
  85. virtual QRect geometry( const QRectF &canvasRect ) const;
  86. virtual QSize minimumSize( const QwtLegendData & ) const;
  87. virtual int heightForWidth( const QwtLegendData &, int width ) const;
  88. QList< const QwtPlotItem * > plotItems() const;
  89. QList< QRect > legendGeometries( const QwtPlotItem * ) const;
  90. protected:
  91. virtual void drawLegendData( QPainter *painter,
  92. const QwtPlotItem *, const QwtLegendData &, const QRectF & ) const;
  93. virtual void drawBackground( QPainter *, const QRectF &rect ) const;
  94. private:
  95. class PrivateData;
  96. PrivateData *d_data;
  97. };
  98. #endif