ctkTransferFunctionWidget.cpp

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00021 #include <QGraphicsScene>
00022 #include <QResizeEvent>
00023 
00025 #include "ctkTransferFunction.h"
00026 #include "ctkTransferFunctionWidget.h"
00027 #include "ctkTransferFunctionItems.h"
00028 
00029 //-----------------------------------------------------------------------------
00030 class ctkTransferFunctionWidgetPrivate: public ctkPrivate<ctkTransferFunctionWidget>
00031 {
00032   CTK_DECLARE_PUBLIC(ctkTransferFunctionWidget);
00033 public:
00034   void init();
00035   ctkTransferFunction* TransferFunction;
00036 };
00037 
00038 //-----------------------------------------------------------------------------
00039 void ctkTransferFunctionWidgetPrivate::init()
00040 {
00041   CTK_P(ctkTransferFunctionWidget);
00042   p->setScene(new QGraphicsScene(p));
00043   p->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00044   p->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00045 }
00046 
00047 //-----------------------------------------------------------------------------
00048 ctkTransferFunctionWidget::ctkTransferFunctionWidget(QWidget* parentWidget)
00049   :QGraphicsView(parentWidget)
00050 {
00051   CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
00052   ctk_d()->init();
00053 }
00054 
00055 //-----------------------------------------------------------------------------
00056 ctkTransferFunctionWidget::ctkTransferFunctionWidget(
00057   ctkTransferFunction* transferFunction, QWidget* parentWidget)
00058   :QGraphicsView(parentWidget)
00059 {
00060   CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
00061   ctk_d()->init();
00062   this->setTransferFunction(transferFunction);
00063 }
00064 
00065 //-----------------------------------------------------------------------------
00066 ctkTransferFunctionWidget::~ctkTransferFunctionWidget()
00067 {
00068 }
00069 
00070 //-----------------------------------------------------------------------------
00071 void ctkTransferFunctionWidget::setTransferFunction(ctkTransferFunction* transferFunction)
00072 {
00073   CTK_D(ctkTransferFunctionWidget);
00074   d->TransferFunction = transferFunction;
00075   Q_ASSERT(this->scene());
00076   this->scene()->clear();
00077   ctkTransferFunctionGradientItem* gradient = 
00078     new ctkTransferFunctionGradientItem(transferFunction);
00079   gradient->setRect(0, 0, this->width(), this->height());
00080   this->scene()->addItem(gradient);
00081   ctkTransferFunctionControlPointsItem* controlPoints = 
00082     new ctkTransferFunctionControlPointsItem(transferFunction);
00083   controlPoints->setRect(0, 0, this->width(), this->height());
00084   this->scene()->addItem(controlPoints);
00085 }
00086 
00087 //-----------------------------------------------------------------------------
00088 ctkTransferFunction* ctkTransferFunctionWidget::transferFunction()const
00089 {
00090   return ctk_d()->TransferFunction;
00091 }
00092 
00093 //-----------------------------------------------------------------------------
00094 void ctkTransferFunctionWidget::resizeEvent(QResizeEvent * event)
00095 {
00096   QRectF sceneRect(QPointF(0,0),event->size());
00097   foreach(QGraphicsItem * item, this->scene()->items())
00098     {
00099     ctkTransferFunctionItem* rectItem = 
00100       qgraphicsitem_cast<ctkTransferFunctionItem*>(item);
00101     if (rectItem)
00102       {
00103       rectItem->setRect(sceneRect);
00104       }
00105     }
00106   this->scene()->setSceneRect(sceneRect);
00107   
00108   this->QGraphicsView::resizeEvent(event);
00109   // Control points are resized by the view transform, we want
00110   // fixed size control points, lines...
00111   //this->fitInView(this->scene()->sceneRect());
00112 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines