PDA

View Full Version : implementing boxzoom



mammaiap
12-01-2010, 12:42 AM
Hi,

I am implementing the box zoom for my CFD Application....

for that i can able to capture the Rectangle co-ordinates which is defining the are need to be zoom..

but the problem is while doing the box zoom it is not exactly zoom the Rectangle,it shows nothing in the graphics screen..i.e it is not zooming the reqd area...

here i am giving my code ...
can anyone please correct me what i did wrong?...



void GraphicsViewMesh::mousePressEvent ( QMouseEvent * me )
{

if(me->button()==Qt::LeftButton) {

onLButtonDown( ( me->buttons() | me->modifiers() ),me->pos() );

}

}

void GraphicsViewMesh::mouseMoveEvent ( QMouseEvent * me )
{



onMouseMove( me->buttons(), me->pos() );


}

void GraphicsViewMesh::mouseReleaseEvent ( QMouseEvent * me )
{

if(me->button()==Qt::LeftButton) {

onLButtonUp( me->buttons(), me->pos() );
}


}


void GraphicsViewMesh:nLButtonDown( const int/*Qt::MouseButtons*/ nFlags, const QPoint point )
{
// save the current mouse coordinate in min
myXmin = point.x();
myYmin = point.y();
myXmax = point.x();
myYmax = point.y();

}

void GraphicsViewMesh:nLButtonUp( Qt::MouseButtons nFlags, const QPoint point )
{

DrawRectangle( myXmin, myYmin, myXmax, myYmax, false );//,LongDash);
myXmax = point.x();
myYmax = point.y();
fitArea( myXmin, myYmin, myXmax, myYmax );
myCurrentMode = CurAction_Nothing;
updateGL();

}

void GraphicsViewMesh:nMouseMove( Qt::MouseButtons nFlags, const QPoint point )
{

if ( nFlags & Qt::LeftButton )
{
myXmax = point.x();
myYmax = point.y();

DrawRectangle( myXmin, myYmin, myXmax, myYmax, false );
DrawRectangle( myXmin, myYmin, myXmax, myYmax, true );
}


}


void GraphicsViewMesh:rawRectangle(const int MinX, const int MinY,
const int MaxX, const int MaxY, const bool Draw)
{
static double StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
static bool m_IsVisible;

StoredMinX = (MinX < MaxX) ? MinX: MaxX ;
StoredMinY = (MinY < MaxY) ? MinY: MaxY ;
StoredMaxX = (MinX > MaxX) ? MinX: MaxX ;
StoredMaxY = (MinY > MaxY) ? MinY: MaxY ;


QRect aRect;
aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));

if ( !myRectBand )
{
myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
myRectBand->setStyle(new QWindowsStyle);
myRectBand->setGeometry( aRect );
myRectBand->show();

QPalette palette;
palette.setColor(myRectBand->foregroundRole(), Qt::white);
myRectBand->setPalette(palette);
}

if ( m_IsVisible &amp;&amp; !Draw ) // move or up : erase at the old position
{
myRectBand->hide();
delete myRectBand;
myRectBand = 0;
m_IsVisible = false;
}

if (Draw) // move : draw
{
//aRect.setRect( StoredMinX, StoredMinY, abs(StoredMaxX-StoredMinX), abs(StoredMaxY-StoredMinY));
m_IsVisible = true;
myRectBand->setGeometry( aRect );
// myRectBand->show();
}
}

void GraphicsViewMesh::fitArea(double myXmin,double myXmax,double myYmin,double myYmax )
{

double w,h;
w = (myXmax-myXmin);
h = (myYmax-myYmin);
glViewport(GLint(myXmin),GLint(myYmin),(GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(myXmin, myXmax, myYmax, myYmin, -1, 1);
glMatrixMode(GL_MODELVIEW);
updateGL();
}


while doing the box zoom... rubberband rectangle is visible... but the problem is ... it is not correctly zooming the captured rectangle...

i think i had a mistake in glViewport() and glOrtho() in fitArea() function

can anyone help me...?

Thanks in Advance,
Muthulingam