ctkTransferFunctionItems.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkTransferFunctionItems_h
  15. #define __ctkTransferFunctionItems_h
  16. /// Qt includes
  17. #include <QGraphicsObject>
  18. /// CTK includes
  19. #include "CTKWidgetsExport.h"
  20. #include "ctkPimpl.h"
  21. #include "ctkTransferFunction.h"
  22. class ctkControlPoint;
  23. class ctkTransferFunctionItemPrivate;
  24. //class ctkTransferFunctionGradientItemPrivate;
  25. class ctkTransferFunctionControlPointsItemPrivate;
  26. ///
  27. /// TODO: should probably derive from QGraphicsItem or QAbstractGraphicsShapeItem
  28. class CTK_WIDGETS_EXPORT ctkTransferFunctionItem: public QGraphicsObject
  29. {
  30. Q_OBJECT
  31. public:
  32. ctkTransferFunctionItem(QGraphicsItem* parent = 0);
  33. ctkTransferFunctionItem(ctkTransferFunction* transferFunction,
  34. QGraphicsItem* parent = 0);
  35. virtual ~ctkTransferFunctionItem();
  36. void setTransferFunction(ctkTransferFunction* transferFunction);
  37. ctkTransferFunction* transferFunction()const;
  38. inline void setRect(qreal x, qreal y, qreal width, qreal height);
  39. void setRect(const QRectF& rectangle);
  40. QRectF rect()const;
  41. virtual QRectF boundingRect()const;
  42. protected:
  43. qreal y(const QVariant& value)const;
  44. inline qreal y(const ctkPoint& point)const;
  45. QColor color(const QVariant& value)const;
  46. inline QColor color(const ctkPoint& point)const;
  47. QList<ctkPoint> bezierParams(ctkControlPoint* start, ctkControlPoint* end)const;
  48. QList<ctkPoint> nonLinearPoints(ctkControlPoint* start, ctkControlPoint* end)const;
  49. protected slots:
  50. virtual void onTransferFunctionChanged();
  51. private:
  52. CTK_DECLARE_PRIVATE(ctkTransferFunctionItem);
  53. };
  54. void ctkTransferFunctionItem::setRect(qreal x, qreal y, qreal width, qreal height)
  55. {
  56. this->setRect(QRectF(x,y,width,height));
  57. }
  58. qreal ctkTransferFunctionItem::y(const ctkPoint& p)const
  59. {
  60. return this->y(p.Value);
  61. }
  62. QColor ctkTransferFunctionItem::color(const ctkPoint& p)const
  63. {
  64. return this->color(p.Value);
  65. }
  66. //-----------------------------------------------------------------------------
  67. class CTK_WIDGETS_EXPORT ctkTransferFunctionGradientItem: public ctkTransferFunctionItem
  68. {
  69. Q_OBJECT
  70. public:
  71. ctkTransferFunctionGradientItem(QGraphicsItem* parent = 0);
  72. ctkTransferFunctionGradientItem(ctkTransferFunction* transferFunction,
  73. QGraphicsItem* parent = 0);
  74. virtual ~ctkTransferFunctionGradientItem();
  75. virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
  76. };
  77. //-----------------------------------------------------------------------------
  78. class CTK_WIDGETS_EXPORT ctkTransferFunctionControlPointsItem: public ctkTransferFunctionItem
  79. {
  80. Q_OBJECT
  81. public:
  82. explicit ctkTransferFunctionControlPointsItem(QGraphicsItem* parent = 0);
  83. ctkTransferFunctionControlPointsItem(ctkTransferFunction* transferFunction,
  84. QGraphicsItem* parent = 0);
  85. virtual ~ctkTransferFunctionControlPointsItem();
  86. virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);
  87. protected:
  88. virtual void mousePressEvent(QGraphicsSceneMouseEvent* e);
  89. virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e);
  90. virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* e);
  91. private:
  92. CTK_DECLARE_PRIVATE(ctkTransferFunctionControlPointsItem);
  93. };
  94. #endif