| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 | /*=========================================================================  Library:   CTK   Copyright (c) 2010  Kitware Inc.  Licensed under the Apache License, Version 2.0 (the "License");  you may not use this file except in compliance with the License.  You may obtain a copy of the License at      http://www.commontk.org/LICENSE  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License. =========================================================================*/#ifndef __ctkTransferFunctionItems_h#define __ctkTransferFunctionItems_h/// Qt includes#include <QGraphicsObject>/// CTK includes#include "CTKWidgetsExport.h"#include "ctkPimpl.h"#include "ctkTransferFunction.h"class ctkControlPoint;class ctkTransferFunctionItemPrivate;//class ctkTransferFunctionGradientItemPrivate;class ctkTransferFunctionControlPointsItemPrivate;/// /// TODO: should probably derive from QGraphicsItem or QAbstractGraphicsShapeItemclass CTK_WIDGETS_EXPORT ctkTransferFunctionItem: public QGraphicsObject{  Q_OBJECTpublic:  ctkTransferFunctionItem(QGraphicsItem* parent = 0);  ctkTransferFunctionItem(ctkTransferFunction* transferFunction,                                   QGraphicsItem* parent = 0);  virtual ~ctkTransferFunctionItem();  void setTransferFunction(ctkTransferFunction* transferFunction);  ctkTransferFunction* transferFunction()const;  inline void setRect(qreal x, qreal y, qreal width, qreal height);  void setRect(const QRectF& rectangle);  QRectF rect()const;  virtual QRectF boundingRect()const;protected:  qreal y(const QVariant& value)const;  inline qreal y(const ctkPoint& point)const;  QColor color(const QVariant& value)const;  inline QColor color(const ctkPoint& point)const;  QList<ctkPoint> bezierParams(ctkControlPoint* start, ctkControlPoint* end)const;  QList<ctkPoint> nonLinearPoints(ctkControlPoint* start, ctkControlPoint* end)const;protected slots:  virtual void onTransferFunctionChanged();private:  CTK_DECLARE_PRIVATE(ctkTransferFunctionItem);};void ctkTransferFunctionItem::setRect(qreal x, qreal y, qreal width, qreal height){  this->setRect(QRectF(x,y,width,height));}qreal ctkTransferFunctionItem::y(const ctkPoint& p)const{  return this->y(p.Value);}QColor ctkTransferFunctionItem::color(const ctkPoint& p)const{  return this->color(p.Value);}//-----------------------------------------------------------------------------class CTK_WIDGETS_EXPORT ctkTransferFunctionGradientItem: public ctkTransferFunctionItem{  Q_OBJECTpublic:  ctkTransferFunctionGradientItem(QGraphicsItem* parent = 0);  ctkTransferFunctionGradientItem(ctkTransferFunction* transferFunction,                                   QGraphicsItem* parent = 0);  virtual ~ctkTransferFunctionGradientItem();  virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);};//-----------------------------------------------------------------------------class CTK_WIDGETS_EXPORT ctkTransferFunctionControlPointsItem: public ctkTransferFunctionItem{  Q_OBJECTpublic:  explicit ctkTransferFunctionControlPointsItem(QGraphicsItem* parent = 0);  ctkTransferFunctionControlPointsItem(ctkTransferFunction* transferFunction,                                        QGraphicsItem* parent = 0);  virtual ~ctkTransferFunctionControlPointsItem();  virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0);protected:  virtual void mousePressEvent(QGraphicsSceneMouseEvent* e);  virtual void mouseMoveEvent(QGraphicsSceneMouseEvent* e);  virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent* e);private:  CTK_DECLARE_PRIVATE(ctkTransferFunctionControlPointsItem);};#endif
 |