Commit 758439d4 authored by Tobias Neeb's avatar Tobias Neeb
Browse files

[FIX 761] make triangle move with cursor and map points correctly before...

[FIX 761] make triangle move with cursor and map points correctly before transfering them to transferFunction2D
parent 65845528
......@@ -173,13 +173,16 @@ void WTransferFunction2DGUIWidget::updateTransferFunction()
WTransferFunction2D::PolyPoint points[3] =
{
{
w->getTriangle().left().x(), w->getTriangle().left().y()
static_cast<float>( w->mapToScene( w->getTriangle().left() ).x() ),
static_cast<float>( w->mapToScene( w->getTriangle().left() ).y() )
},
{
w->getTriangle().mid().x(), w->getTriangle().mid().y()
static_cast<float>( w->mapToScene( w->getTriangle().mid() ).x() ),
static_cast<float>( w->mapToScene( w->getTriangle().mid() ).y() )
},
{
w->getTriangle().right().x(), w->getTriangle().right().y()
static_cast<float>( w->mapToScene( w->getTriangle().right() ).x() ),
static_cast<float>( w->mapToScene( w->getTriangle().right() ).y() )
}
};
tf.addTriangleWidget( points, isoX, isoY, width, height, toWColor( col ) );
......@@ -212,12 +215,6 @@ void WTransferFunction2DGUIWidget::insertBoxWidget( const QPointF &pos, const do
void WTransferFunction2DGUIWidget::insertTriangleWidgetNormalized( QPointF points[], const QPointF &pos = QPointF( 0.0, 0.0 ),
const QColor * const color = new QColor( 0.00, 0.0, 255.0, 20.0 ) )
{
points[0].setX( points[0].x() );
points[0].setY( points[0].y() );
points[1].setX( points[1].x() );
points[1].setY( points[1].y() );
points[2].setX( points[2].x() );
points[2].setY( points[2].y() );
insertTriangleWidget( points, QPointF( pos.x() * xMax, pos.y() * yMax ), color );
}
......@@ -225,7 +222,8 @@ void WTransferFunction2DGUIWidget::insertTriangleWidget( QPointF points[], const
{
WTransferFunction2DTriangleWidget *newTriangle( new WTransferFunction2DTriangleWidget( this,
WTransferFunction2DTriangle( points[0], points[1], points[2] ), *color ) );
newTriangle->setPos( pos );
wlog::debug( "insertTriangle" ) << pos.x() << " ," << pos.y();
//newTriangle->setPos(pos);
scene->addItem( newTriangle );
m_triangle_widgets.push_back( newTriangle );
this->update();
......
......@@ -52,7 +52,7 @@ WTransferFunction2DTriangleWidget::WTransferFunction2DTriangleWidget( WTransferF
m_parent = parent;
m_color = color;
m_resizePoints = NONE;
// We always start with top right and go clock wise
m_controlPoints.push_back( new WTransferFunction2DControlPoint( this, m_triangle.left(), LEFT_TRI ) );
m_controlPoints.push_back( new WTransferFunction2DControlPoint( this, m_triangle.mid(), MID_TRI ) );
m_controlPoints.push_back( new WTransferFunction2DControlPoint( this, m_triangle.right(), RIGHT_TRI ) );
......@@ -85,44 +85,32 @@ void WTransferFunction2DTriangleWidget::setControlPointsToCorner()
//m_width = (m_box.right() - m_box.left());
//m_height = (m_box.bottom() - m_box.top());
update();
m_parent->dataChanged();
}
QVariant WTransferFunction2DTriangleWidget::itemChange( GraphicsItemChange change, const QVariant &value )
{
QPointF newPos = value.toPointF();
if( change == ItemPositionChange && scene() )
{
// value is the new position.
QPointF newPos = value.toPointF();
QRectF rect = scene()->sceneRect();
// We create a bounding reactangle with the size of the parent bounds.
// Because this Rect is always moved when moving the widget,
// we have to translate it back into (0,0) of the parent bounds
// by using the inverse of the origin of this widget
rect.translate( -m_triangle.getTriangle().boundingRect().topLeft() );
rect.setRight( rect.right() - ( m_triangle.getTriangle().boundingRect().width() ) - 1 );
rect.setBottom( rect.bottom() - ( m_triangle.getTriangle().boundingRect().height() ) - 1 );
rect.translate( -this->boundingRect().topLeft() );
rect.setRight( rect.right() - ( this->boundingRect().width() ) - 1 );
rect.setBottom( rect.bottom() - ( this->boundingRect().height() ) - 1 );
if( !rect.contains( newPos ) )
{
// Keep the item inside the scene
newPos.setX( qMin( rect.right(), qMax( newPos.x(), rect.left() ) ) );
newPos.setY( qMin( rect.bottom(), qMax( newPos.y(), rect.top() ) ) );
QPointF translationVector = QPointF( newPos.x() - this->pos().x(), newPos.y() - this->pos().y() );
//TODO(T.Neeb): Make Function of code below
m_triangle.setLeft( QPointF( m_triangle.left() + translationVector ) );
m_triangle.setMid( QPointF( m_triangle.mid() + translationVector ) );
m_triangle.setRight( QPointF( m_triangle.right() + translationVector ) );
setControlPointsToCorner();
m_parent->dataChanged();
return newPos;
}
QPointF translationVector = QPointF( newPos.x() - this->pos().x(), newPos.y() - this->pos().y() );
//wlog::debug("TransVec") << "Transvec:" << translationVector.x() << " , " << translationVector.y();
m_triangle.setLeft( QPointF( m_triangle.left() + translationVector ) );
m_triangle.setMid( QPointF( m_triangle.mid() + translationVector ) );
m_triangle.setRight( QPointF( m_triangle.right() + translationVector ) );
setControlPointsToCorner();
m_parent->dataChanged();
}
return QGraphicsItem::itemChange( change, value );
}
......@@ -204,6 +192,7 @@ void WTransferFunction2DTriangleWidget::colorSelected( const QColor &newcolor )
}
}
void WTransferFunction2DTriangleWidget::showColorPicker()
{
// Create a color dialog to create an RGBA quadrupel
......
......@@ -165,6 +165,14 @@ protected:
QVariant itemChange( GraphicsItemChange change, const QVariant &value ) override;
private:
/**
* @brief updates the triangle data
*
* @param newPos
* @param startPos
*/
void updateTriangleData( QPointF newPos, QPointF startPos );
/**
* Show the color picker dialog.
**/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment