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 <QDebug>
00022 //#include <QGLWidget>
00023 #include <QGraphicsScene>
00024 #include <QResizeEvent>
00025 
00027 #include "ctkTransferFunction.h"
00028 #include "ctkTransferFunctionWidget.h"
00029 #include "ctkTransferFunctionScene.h"
00030 #include "ctkTransferFunctionGradientItem.h"
00031 #include "ctkTransferFunctionControlPointsItem.h"
00032 
00033 //-----------------------------------------------------------------------------
00034 class ctkTransferFunctionWidgetPrivate: public ctkPrivate<ctkTransferFunctionWidget>
00035 {
00036   CTK_DECLARE_PUBLIC(ctkTransferFunctionWidget);
00037 public:
00038   ctkTransferFunctionWidgetPrivate();
00039   void init();
00040   ctkTransferFunction* TransferFunction;
00041 };
00042 
00043 //-----------------------------------------------------------------------------
00044 ctkTransferFunctionWidgetPrivate::ctkTransferFunctionWidgetPrivate()
00045 {
00046   this->TransferFunction = 0;
00047 }
00048 
00049 //-----------------------------------------------------------------------------
00050 void ctkTransferFunctionWidgetPrivate::init()
00051 {
00052   CTK_P(ctkTransferFunctionWidget);
00053   p->setScene(new ctkTransferFunctionScene(p));
00054   p->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00055   p->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
00056   //p->setViewport(new QGLWidget);
00057   p->setRenderHint(QPainter::Antialiasing);
00058 }
00059 
00060 //-----------------------------------------------------------------------------
00061 ctkTransferFunctionWidget::ctkTransferFunctionWidget(QWidget* parentWidget)
00062   :QGraphicsView(parentWidget)
00063 {
00064   CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
00065   ctk_d()->init();
00066 }
00067 
00068 //-----------------------------------------------------------------------------
00069 ctkTransferFunctionWidget::ctkTransferFunctionWidget(
00070   ctkTransferFunction* transferFunction, QWidget* parentWidget)
00071   :QGraphicsView(parentWidget)
00072 {
00073   CTK_INIT_PRIVATE(ctkTransferFunctionWidget);
00074   ctk_d()->init();
00075   this->setTransferFunction(transferFunction);
00076 }
00077 //-----------------------------------------------------------------------------
00078 ctkTransferFunctionWidget::~ctkTransferFunctionWidget()
00079 {
00080 }
00081 
00082 //-----------------------------------------------------------------------------
00083 void ctkTransferFunctionWidget::setTransferFunction(ctkTransferFunction* transferFunction)
00084 {
00085   CTK_D(ctkTransferFunctionWidget);
00086   d->TransferFunction = transferFunction;
00087   ctkTransferFunctionScene* tfScene = dynamic_cast<ctkTransferFunctionScene*>(this->scene());
00088   Q_ASSERT(tfScene);
00089   tfScene->clear();
00090   tfScene->setTransferFunction(transferFunction);
00091 
00092   bool useMask = true;
00093   ctkTransferFunctionGradientItem* gradient = 
00094     new ctkTransferFunctionGradientItem(transferFunction);
00095   //gradient->setRect(tfScene->sceneRect());
00096   this->scene()->addItem(gradient);
00097 
00098   ctkTransferFunctionControlPointsItem* controlPoints = 
00099     new ctkTransferFunctionControlPointsItem(transferFunction);
00100   //controlPoints->setRect(tfScene->sceneRect());
00101   this->scene()->addItem(controlPoints);
00102 }
00103 
00104 //-----------------------------------------------------------------------------
00105 ctkTransferFunction* ctkTransferFunctionWidget::transferFunction()const
00106 {
00107   return ctk_d()->TransferFunction;
00108 }
00109 
00110 //-----------------------------------------------------------------------------
00111 void ctkTransferFunctionWidget::resizeEvent(QResizeEvent * event)
00112 {
00113   /*
00114   QRectF sceneRect(QPointF(0,0),event->size());
00115   this->scene()->setSceneRect(sceneRect);
00116   foreach(QGraphicsItem * item, this->scene()->items())
00117     {
00118     ctkTransferFunctionItem* rectItem = 
00119       qgraphicsitem_cast<ctkTransferFunctionItem*>(item);
00120     if (rectItem)
00121       {
00122       rectItem->setRect(sceneRect);
00123       }
00124     }
00125   */
00126   QMatrix zoomMatrix;
00127   zoomMatrix.scale(event->size().width(), event->size().height());
00128   bool blocked = this->blockSignals(true);
00129   this->setMatrix(zoomMatrix);
00130   this->blockSignals(blocked);
00131   this->QGraphicsView::resizeEvent(event);
00132   // Control points are resized by the view transform, we want
00133   // fixed size control points, lines...
00134   //this->fitInView(this->scene()->sceneRect());
00135   qDebug() << "resize event caught";
00136 }
00137 /*
00138 //-----------------------------------------------------------------------------
00139 void ctkTransferFunctionWidget::dragEnterEvent ( QDragEnterEvent * event )
00140 {
00141   qDebug() << "drag event caught";
00142 
00143   this->QGraphicsView::dragEnterEvent(event);
00144 
00145 }
00146 
00147 //-----------------------------------------------------------------------------
00148 void ctkTransferFunctionWidget::mousePressEvent ( QMouseEvent * event )
00149 {
00150   qDebug() << "press event caught";
00151   //One control point is added to the scene
00152   // 1 - get position of the mouse
00153   qDebug() << "x position " << event->x();
00154   qDebug() << "y position " << event->y();
00155 
00156   this->scene()->items()[1]->;
00157 
00158   // 2nd item are the control points
00159 
00160   this->QGraphicsView::mousePressEvent(event);
00161 }
00162 
00163 //-----------------------------------------------------------------------------
00164 void ctkTransferFunctionWidget::mouseReleaseEvent ( QMouseEvent * event )
00165 {
00166   qDebug() << "release event caught";
00167 
00168   this->QGraphicsView::mouseReleaseEvent(event);
00169 }
00170 */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1