qwt_column_symbol.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_COLUMN_SYMBOL_H
  10. #define QWT_COLUMN_SYMBOL_H
  11. #include "qwt_global.h"
  12. #include "qwt_interval.h"
  13. #include <qpen.h>
  14. #include <qsize.h>
  15. #include <qrect.h>
  16. class QPainter;
  17. class QPalette;
  18. class QRect;
  19. class QwtText;
  20. /*!
  21. \brief Directed rectangle representing bounding rectangle and orientation
  22. of a column.
  23. */
  24. class QWT_EXPORT QwtColumnRect
  25. {
  26. public:
  27. //! Direction of the column
  28. enum Direction
  29. {
  30. //! From left to right
  31. LeftToRight,
  32. //! From right to left
  33. RightToLeft,
  34. //! From bottom to top
  35. BottomToTop,
  36. //! From top to bottom
  37. TopToBottom
  38. };
  39. //! Build an rectangle with invalid intervals directed BottomToTop.
  40. QwtColumnRect():
  41. direction( BottomToTop )
  42. {
  43. }
  44. //! \return A normalized QRect built from the intervals
  45. QRectF toRect() const
  46. {
  47. QRectF r( hInterval.minValue(), vInterval.minValue(),
  48. hInterval.maxValue() - hInterval.minValue(),
  49. vInterval.maxValue() - vInterval.minValue() );
  50. r = r.normalized();
  51. if ( hInterval.borderFlags() & QwtInterval::ExcludeMinimum )
  52. r.adjust( 1, 0, 0, 0 );
  53. if ( hInterval.borderFlags() & QwtInterval::ExcludeMaximum )
  54. r.adjust( 0, 0, -1, 0 );
  55. if ( vInterval.borderFlags() & QwtInterval::ExcludeMinimum )
  56. r.adjust( 0, 1, 0, 0 );
  57. if ( vInterval.borderFlags() & QwtInterval::ExcludeMaximum )
  58. r.adjust( 0, 0, 0, -1 );
  59. return r;
  60. }
  61. //! \return Orientation
  62. Qt::Orientation orientation() const
  63. {
  64. if ( direction == LeftToRight || direction == RightToLeft )
  65. return Qt::Horizontal;
  66. return Qt::Vertical;
  67. }
  68. //! Interval for the horizontal coordinates
  69. QwtInterval hInterval;
  70. //! Interval for the vertical coordinates
  71. QwtInterval vInterval;
  72. //! Direction
  73. Direction direction;
  74. };
  75. //! A drawing primitive for columns
  76. class QWT_EXPORT QwtColumnSymbol
  77. {
  78. public:
  79. /*!
  80. Style
  81. \sa setStyle(), style()
  82. */
  83. enum Style
  84. {
  85. //! No Style, the symbol draws nothing
  86. NoStyle = -1,
  87. /*!
  88. The column is painted with a frame depending on the frameStyle()
  89. and lineWidth() using the palette().
  90. */
  91. Box,
  92. /*!
  93. Styles >= QwtColumnSymbol::UserStyle are reserved for derived
  94. classes of QwtColumnSymbol that overload draw() with
  95. additional application specific symbol types.
  96. */
  97. UserStyle = 1000
  98. };
  99. /*!
  100. Frame Style used in Box style().
  101. \sa Style, setFrameStyle(), frameStyle(), setStyle(), setPalette()
  102. */
  103. enum FrameStyle
  104. {
  105. //! No frame
  106. NoFrame,
  107. //! A plain frame style
  108. Plain,
  109. //! A raised frame style
  110. Raised
  111. };
  112. public:
  113. QwtColumnSymbol( Style = NoStyle );
  114. virtual ~QwtColumnSymbol();
  115. void setFrameStyle( FrameStyle );
  116. FrameStyle frameStyle() const;
  117. void setLineWidth( int width );
  118. int lineWidth() const;
  119. void setPalette( const QPalette & );
  120. const QPalette &palette() const;
  121. void setStyle( Style );
  122. Style style() const;
  123. virtual void draw( QPainter *, const QwtColumnRect & ) const;
  124. protected:
  125. void drawBox( QPainter *, const QwtColumnRect & ) const;
  126. private:
  127. class PrivateData;
  128. PrivateData* d_data;
  129. };
  130. #endif