27 #include "QtCore/QMimeData" 
   28 #include "QColorDialog" 
   29 #include "QGraphicsSceneMouseEvent" 
   31 #include "QStyleOption" 
   33 #include "WTransferFunctionWidget.h" 
   35 #include "WTransferFunctionColorPoint.h" 
   40     radius( 8.0 ), left( 0x0 ), right( 0x0 ),
 
   42     color( QColor( 0, 0, 1, 255 ) )
 
   44     this->setFlag( ItemIsMovable );
 
   46     this->setPos( this->pos().x(), 0 );
 
   49     this->setFlag( QGraphicsItem::ItemIsMovable );
 
   50     this->setFlag( QGraphicsItem::ItemSendsGeometryChanges );
 
   51     this->setAcceptDrops( 
true );
 
   84     const double padding( 2 );
 
   85     const double diameter( 
radius * 2 );
 
   86     return QRectF( -
radius - padding, -
radius - padding, diameter + padding, 
radius + padding );
 
   91     QRadialGradient gradient( 0.0, 0.0, 
radius );
 
   93     if( option->state & QStyle::State_Selected )
 
   95         gradient.setColorAt( 0, Qt::yellow );
 
   96         gradient.setColorAt( 1, Qt::red );
 
   97         painter->setPen( QPen( Qt::black, 2 ) );
 
   99     else if( option->state & QStyle::State_Sunken )
 
  101         gradient.setColorAt( 0, 
color ); 
 
  102         gradient.setColorAt( 1, 
color ); 
 
  103         painter->setPen( QPen( Qt::black, 2 ) );
 
  107         gradient.setColorAt( 0, 
color ); 
 
  108         gradient.setColorAt( 1, 
color ); 
 
  109         painter->setPen( QPen( Qt::black, 0 ) );
 
  112     QColor 
color = painter->pen().color();
 
  113     color.setAlpha( 255 * 0.3 );
 
  114     painter->setPen( QPen( 
color, painter->pen().width() ) );
 
  115     painter->setBrush( gradient );
 
  120     triangle << QPoint( 0, 0 );
 
  123     painter->drawPolygon( triangle );
 
  127         if( option->state & QStyle::State_Sunken )
 
  129             painter->setPen(  QPen( Qt::red, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin ) );
 
  133             painter->setPen(  QPen( Qt::black, 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin ) );
 
  136         painter->drawLine( QPoint( 0, 0 ), QPoint( 0, scene()->sceneRect().height() ) );
 
  168     if( change == ItemPositionChange )
 
  170         QPointF newPos = value.toPointF();
 
  171         this->setToolTip( QString( 
"isovalue=" ) + QString::number( newPos.x() ) + 
" color=(" 
  172                 + QString::number( 
color.red() ) +
',' 
  173                 + QString::number( 
color.green() ) +
',' 
  174                 + QString::number( 
color.blue() ) + 
')' );
 
  179     return BaseClass::itemChange( change, value );
 
  184     BaseClass::mouseDoubleClickEvent( event );
 
  192     color.setAlpha( 255 ); 
 
  205         BaseClass::mouseMoveEvent( event );
 
  209         QRectF boundingBox( this->scene()->sceneRect() );
 
  213             this->setPos( 0, this->pos().y() );
 
  218             this->setPos( boundingBox.x() + boundingBox.width(), this->pos().y() );
 
  226         this->setPos( this->pos().x(), 0 );
 
  233     BaseClass::mousePressEvent( event );
 
  240     BaseClass::mouseReleaseEvent( event );
 
  247         if( this->pos().x() <= 
left->pos().x() )
 
  249             this->setPos( 
left->pos().x() + 1, this->pos().y() );
 
  254         if( this->pos().x() >= 
right->pos().x() )
 
  256             this->setPos( 
right->pos().x() - 1, this->pos().y() );
 
  263     qreal x( this->pos().x() );
 
  264     qreal y( this->pos().y() );
 
  266     const qreal xMin( rectangle.x() );
 
  267     const qreal xMax( xMin + rectangle.width() );
 
  268     const qreal yMin( rectangle.y() );
 
  269     const qreal yMax( yMin + rectangle.height() );
 
  277     this->setPos( x, y );
 
  287     if( event->mimeData()->hasColor() )
 
  289         event->setAccepted( 
true );
 
  295     if( event->mimeData()->hasColor() )
 
  297         color = qvariant_cast<QColor>( event->mimeData()->colorData() );
 
  298         color.setAlpha( 255 ); 
 
  312 #ifdef ALLOW_CONTEXT_MENU 
  315     QAction *removeAction = menu.addAction( 
"Remove" );
 
  316     QAction *changeColor  = menu.addAction( 
"Change Color" );
 
  317     QAction *selectedAction = menu.exec( event->screenPos() );
 
  319     if( selectedAction == removeAction )
 
  322     if( selectedAction == changeColor )
 
  327     BaseClass::contextMenuEvent( event );
 
  332     QColorDialog *dialog = 
new QColorDialog( );
 
  333     dialog->setCurrentColor( 
color );
 
  334     dialog->setOption( QColorDialog::NoButtons );
 
  335     connect( dialog, SIGNAL( currentColorChanged( 
const QColor& ) ), 
this, SLOT( 
colorSelected( 
const QColor& ) ) );
 
A control point for the color function.
 
void colorSelected(const QColor &color)
Called by the color dialog every time the user changes the color.
 
QColor color
the color entry
 
WTransferFunctionWidget * _parent
the parent widget
 
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Handles press move events.
 
virtual void dropEvent(QGraphicsSceneDragDropEvent *event)
Drop implementation for items that contain a color.
 
void clampToLeftAndRight()
Helper for item changed.
 
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Handles change notifications.
 
void setLeft(WTransferFunctionColorPoint *left)
Set the item left of us.
 
virtual ~WTransferFunctionColorPoint()
Default destructor.
 
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
Handler for context menu envents.
 
void showColorPicker()
Show the color picker dialog.
 
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0x0)
Paint the handle and additional item hints.
 
WTransferFunctionColorPoint * right
the entry to the right of our entry
 
void clampToRectangle(const QRectF &rectangle)
Helper for item changed.
 
WTransferFunctionColorPoint * getRight() const
Returns the item right of this item.
 
double radius
the radius used for paining of the handle
 
void setRight(WTransferFunctionColorPoint *right)
Set the item right of us.
 
virtual void dragEnterEvent(QGraphicsSceneDragDropEvent *event)
Drag enter implementation for items that contain a color.
 
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
Handles mouse double click events by opening a color selector if the item is clicked.
 
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Handles mouse move events.
 
WTransferFunctionColorPoint * getLeft() const
Returns the item left of the this item.
 
QRectF boundingRect() const
The bounding rectangle used for paint and click events.
 
WTransferFunctionColorPoint * left
the entry left of this entry
 
WTransferFunctionColorPoint(WTransferFunctionWidget *parent=0x0)
Default constructor.
 
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Handles mouse move events.