ctkTransferFunctionGradientItem.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 =========================================================================*/
00020 
00022 #include <QColor>
00023 #include <QDebug>
00024 #include <QLinearGradient>
00025 #include <QGraphicsSceneMouseEvent>
00026 #include <QPainter>
00027 #include <QtGlobal>
00028 #include <QVariant>
00029 
00031 #include "ctkTransferFunction.h"
00032 #include "ctkTransferFunctionGradientItem.h"
00033 #include "ctkTransferFunctionScene.h"
00034 
00035 class ctkTransferFunctionGradientItemPrivate:public ctkPrivate<ctkTransferFunctionGradientItem>
00036 {
00037 public:
00038   ctkTransferFunctionGradientItemPrivate();
00039   bool Mask;
00040 };
00041 
00042 ctkTransferFunctionGradientItemPrivate::ctkTransferFunctionGradientItemPrivate()
00043 {
00044   this->Mask = true;
00045 }
00046 //-----------------------------------------------------------------------------
00047 ctkTransferFunctionGradientItem::ctkTransferFunctionGradientItem(QGraphicsItem* parentGraphicsItem)
00048   :ctkTransferFunctionItem(parentGraphicsItem)
00049 {
00050   CTK_INIT_PRIVATE(ctkTransferFunctionGradientItem);
00051 }
00052 
00053 //-----------------------------------------------------------------------------
00054 ctkTransferFunctionGradientItem::ctkTransferFunctionGradientItem(
00055   ctkTransferFunction* transferFunction, QGraphicsItem* parentItem)
00056   :ctkTransferFunctionItem(transferFunction, parentItem)
00057 {
00058 }
00059 
00060 //-----------------------------------------------------------------------------
00061 ctkTransferFunctionGradientItem::~ctkTransferFunctionGradientItem()
00062 {  
00063 }
00064 
00065 //-----------------------------------------------------------------------------
00066 void ctkTransferFunctionGradientItem::paint(
00067   QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
00068 {
00069   ctkTransferFunctionScene* tfScene = dynamic_cast<ctkTransferFunctionScene*>(this->scene());
00070   Q_ASSERT(tfScene);
00071 
00072   const QGradient& gradient = tfScene->gradient();
00073 
00074   if ( this->mask() )
00075     {
00076     const QPainterPath& curve = tfScene->curve();
00077     QPainterPath closedPath = curve;
00078     QRectF position = this->rect();
00079     // link to last point
00080     closedPath.lineTo(position.x() + position.width(), position.y() + position.height());
00081     // link to first point
00082     closedPath.lineTo(position.x(), position.y() + position.height());
00083     //Don,t need to close because automatic
00084     QPen pen(QColor(255, 255, 255, 191), 1);
00085     pen.setCosmetic(true);
00086     painter->setPen(pen);
00087     painter->setBrush(gradient);
00088     painter->drawPath(closedPath);
00089     }
00090   else
00091     {
00092     painter->fillRect(this->rect(), gradient);
00093     }
00094 }
00095 
00096 //-----------------------------------------------------------------------------
00097 bool ctkTransferFunctionGradientItem::mask() const
00098 {
00099   CTK_D( const ctkTransferFunctionGradientItem );
00100   return d->Mask;
00101 }
00102 
00103 //-----------------------------------------------------------------------------
00104 void ctkTransferFunctionGradientItem::setMask( bool mask )
00105 {
00106   CTK_D( ctkTransferFunctionGradientItem );
00107   d->Mask = mask;
00108 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated on 21 May 2010 for CTK by  doxygen 1.6.1