/*========================================================================= 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. =========================================================================*/ /// Qt includes #include //#include #include #include /// CTK includes #include "ctkTransferFunction.h" #include "ctkTransferFunctionWidget.h" #include "ctkTransferFunctionScene.h" #include "ctkTransferFunctionGradientItem.h" #include "ctkTransferFunctionControlPointsItem.h" //----------------------------------------------------------------------------- class ctkTransferFunctionWidgetPrivate: public ctkPrivate { CTK_DECLARE_PUBLIC(ctkTransferFunctionWidget); public: ctkTransferFunctionWidgetPrivate(); void init(); ctkTransferFunction* TransferFunction; }; //----------------------------------------------------------------------------- ctkTransferFunctionWidgetPrivate::ctkTransferFunctionWidgetPrivate() { this->TransferFunction = 0; } //----------------------------------------------------------------------------- void ctkTransferFunctionWidgetPrivate::init() { CTK_P(ctkTransferFunctionWidget); p->setScene(new ctkTransferFunctionScene(p)); p->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); p->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); //p->setViewport(new QGLWidget); } //----------------------------------------------------------------------------- ctkTransferFunctionWidget::ctkTransferFunctionWidget(QWidget* parentWidget) :QGraphicsView(parentWidget) { CTK_INIT_PRIVATE(ctkTransferFunctionWidget); ctk_d()->init(); } //----------------------------------------------------------------------------- ctkTransferFunctionWidget::ctkTransferFunctionWidget( ctkTransferFunction* transferFunction, QWidget* parentWidget) :QGraphicsView(parentWidget) { CTK_INIT_PRIVATE(ctkTransferFunctionWidget); ctk_d()->init(); this->setTransferFunction(transferFunction); } //----------------------------------------------------------------------------- ctkTransferFunctionWidget::~ctkTransferFunctionWidget() { } //----------------------------------------------------------------------------- void ctkTransferFunctionWidget::setTransferFunction(ctkTransferFunction* transferFunction) { CTK_D(ctkTransferFunctionWidget); d->TransferFunction = transferFunction; ctkTransferFunctionScene* tfScene = dynamic_cast(this->scene()); Q_ASSERT(tfScene); tfScene->clear(); tfScene->setTransferFunction(transferFunction); ctkTransferFunctionGradientItem* gradient = new ctkTransferFunctionGradientItem(transferFunction); //gradient->setRect(tfScene->sceneRect()); this->scene()->addItem(gradient); ctkTransferFunctionControlPointsItem* controlPoints = new ctkTransferFunctionControlPointsItem(transferFunction); //controlPoints->setRect(tfScene->sceneRect()); this->scene()->addItem(controlPoints); } //----------------------------------------------------------------------------- ctkTransferFunction* ctkTransferFunctionWidget::transferFunction()const { return ctk_d()->TransferFunction; } //----------------------------------------------------------------------------- void ctkTransferFunctionWidget::resizeEvent(QResizeEvent * event) { /* QRectF sceneRect(QPointF(0,0),event->size()); this->scene()->setSceneRect(sceneRect); foreach(QGraphicsItem * item, this->scene()->items()) { ctkTransferFunctionItem* rectItem = qgraphicsitem_cast(item); if (rectItem) { rectItem->setRect(sceneRect); } } */ QMatrix zoomMatrix; zoomMatrix.scale(event->size().width(), event->size().height()); bool blocked = this->blockSignals(true); this->setMatrix(zoomMatrix); this->blockSignals(blocked); this->QGraphicsView::resizeEvent(event); // Control points are resized by the view transform, we want // fixed size control points, lines... //this->fitInView(this->scene()->sceneRect()); qDebug() << "resize event caught"; } /* //----------------------------------------------------------------------------- void ctkTransferFunctionWidget::dragEnterEvent ( QDragEnterEvent * event ) { qDebug() << "drag event caught"; this->QGraphicsView::dragEnterEvent(event); } //----------------------------------------------------------------------------- void ctkTransferFunctionWidget::mousePressEvent ( QMouseEvent * event ) { qDebug() << "press event caught"; //One control point is added to the scene // 1 - get position of the mouse qDebug() << "x position " << event->x(); qDebug() << "y position " << event->y(); this->scene()->items()[1]->; // 2nd item are the control points this->QGraphicsView::mousePressEvent(event); } //----------------------------------------------------------------------------- void ctkTransferFunctionWidget::mouseReleaseEvent ( QMouseEvent * event ) { qDebug() << "release event caught"; this->QGraphicsView::mouseReleaseEvent(event); } */