Commit 541cc871 authored by Tobias Neeb's avatar Tobias Neeb
Browse files

[ADD #736] extend existing methods to update the position of the...

[ADD #736] extend existing methods to update the position of the triangle-points after they have been moved
parent 3b99cd77
......@@ -42,6 +42,56 @@ WTransferFunction2DTriangle::WTransferFunction2DTriangle( QPointF left, QPointF
m_triangle = QPolygonF( points );
}
/* void WTransferFunction2DTriangle::reassignPoints()
{
QPointF low, mid, high;
if (m_left.x() <= m_mid.x() && m_left.x() <= m_right.x())
{
low = m_left;
if (m_mid.x() <= m_right.x())
{
mid = m_mid;
high = m_right;
}
else
{
mid = m_right;
high = m_mid;
}
}
else if (m_mid.x() <= m_left.x() && m_mid.x() <= m_right.x())
{
low = m_mid;
if (m_left.x() <= m_right.x())
{
mid = m_left;
high = m_right;
}
else
{
mid = m_right;
high = m_left;
}
}
else
{
low = m_right;
if (m_left.x() <= m_mid.x())
{
mid = m_left;
high = m_mid;
}
else
{
mid = m_mid;
high = m_left;
}
}
m_left = low;
m_mid = mid;
m_right = high;
}*/
WTransferFunction2DTriangle::~WTransferFunction2DTriangle()
{
}
......@@ -41,7 +41,7 @@ class WTransferFunction2DTriangle
* \param mid the point of the triangle titled "mid"
* \param right the point of the triangle titled "right"
*/
WTransferFunction2DTriangle( QPointF left = QPointF( 1.0, 1.0 ), QPointF mid = QPointF( 1.5, 1.5 ), QPointF right = QPointF( 2.0, 1.0 ) );
WTransferFunction2DTriangle( QPointF left = QPointF( 1.0, 1.0 ), QPointF mid = QPointF( 1.50, 1.5 ), QPointF right = QPointF( 2.0, 1.0 ) );
/**
* Destroy the WTransferFunction2DTriangle object
......@@ -136,6 +136,14 @@ class WTransferFunction2DTriangle
m_right = m_triangle[2];
}
/**
* @brief reassigns the points based on their x-coordinate
* left -> point with lowest x-coordinate
* right -> point with highest x-coordinate
*
*/
void reassignPoints();
private:
/** QPoint which presents the "left" triangle point*/
QPointF m_left;
......
......@@ -89,16 +89,16 @@ void WTransferFunction2DTriangleWidget::setControlPointsToCorner()
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.left() );
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 );
......@@ -107,9 +107,21 @@ QVariant WTransferFunction2DTriangleWidget::itemChange( GraphicsItemChange chang
// 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() );
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;
}
//TODO(T. Neeb): Add keeping in bounds for triangle/other widgets
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 );
}
......
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