Sign in to follow this  

implementing boxzoom

This topic is 2572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 area need to be zoom..

but the problem is while doing the box zoom it is not exactly zoom the Rectangle area,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 && !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...to understand the glViewport() and glOrtho()?

Thanks in Advance,
Muthulingam

Share this post


Link to post
Share on other sites

This topic is 2572 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this