Hi All,
I want to zoom in a region on canvas. For that first I am drawing a rectangle on canvas, size of the rectangle is decided by mouse move event. Then zooming in the mouse movement area to full region. The problem is view of the canvas rectangle which I am drawing to show the selected region.If the region is from initial view port area then the the rectangle is visible. The problem is, by moving scroll bar if mouse is in different viewport region, then it is not showing the whole rectangle area. It is only showing the rectangle area which is in initial view port(scroll bar at zero position). However zooming in is done properly.
I am attaching the code part also. Please rectify my mistake.
Thanks
Jnana
void
DiagramView
:: contentsMouseMoveEvent(QMouseEvent* a_e
){
if(cursor().shape() == Qt::CrossCursor) {
//QPoint myPoint = viewportToContents(a_e->pos());
m_zoomEndPoint = (inverseWorldMatrix()).map(a_e->pos());
int width = m_zoomEndPoint.x()-m_zoomStartPoint.x();
int height = m_zoomEndPoint.y()-m_zoomStartPoint.y();
if((width>0)&&(height>0)) {
if(!m_zoomRegionRect) {
qDebug
(QString("%1 %2").
arg(width
).
arg(height
));
//! canvas item do not exist
m_zoomRegionRect = new Q3CanvasRectangle(m_zoomStartPoint.x(),
m_zoomStartPoint.y(),
width, height, canvas());
m_zoomRegionRect->setBrush(Qt::DiagCrossPattern);
m_zoomRegionRect
->setPen
(QPen(Qt
::darkGreen,
2, Qt::DashDotDotLine));
m_zoomRegionRect->setZ(100);
m_zoomRegionRect->show();
} else {
m_zoomRegionRect->setSize(width, height);
canvas()->setChanged(m_zoomRegionRect->boundingRect());
}
canvas()->update();
}
return;
}
}
void
DiagramView
:: contentsMousePressEvent(QMouseEvent* a_e
){
m_zoomStartPoint = (inverseWorldMatrix()).map(a_e->pos());
}
void
DiagramView
:: contentsMouseReleaseEvent(QMouseEvent* ){
if(cursor().shape() == Qt::CrossCursor) {
if(m_zoomRegionRect) {
m_zoomRegionRect->hide();
canvas()->update();
delete m_zoomRegionRect;
m_zoomRegionRect = 0;
m_zoomStartFlag = true;
emit ZoomToRegion(m_zoomStartPoint, m_zoomEndPoint);
canvas()->update();
}
return;
}
}
void
DiagramView :: contentsMouseMoveEvent(QMouseEvent* a_e)
{
if(cursor().shape() == Qt::CrossCursor) {
//QPoint myPoint = viewportToContents(a_e->pos());
m_zoomEndPoint = (inverseWorldMatrix()).map(a_e->pos());
int width = m_zoomEndPoint.x()-m_zoomStartPoint.x();
int height = m_zoomEndPoint.y()-m_zoomStartPoint.y();
if((width>0)&&(height>0)) {
if(!m_zoomRegionRect) {
qDebug(QString("%1 %2").arg(width).arg(height));
//! canvas item do not exist
m_zoomRegionRect = new Q3CanvasRectangle(m_zoomStartPoint.x(),
m_zoomStartPoint.y(),
width, height, canvas());
m_zoomRegionRect->setBrush(Qt::DiagCrossPattern);
m_zoomRegionRect->setPen(QPen(Qt::darkGreen,
2, Qt::DashDotDotLine));
m_zoomRegionRect->setZ(100);
m_zoomRegionRect->show();
} else {
m_zoomRegionRect->setSize(width, height);
canvas()->setChanged(m_zoomRegionRect->boundingRect());
}
canvas()->update();
}
return;
}
}
void
DiagramView :: contentsMousePressEvent(QMouseEvent* a_e)
{
m_zoomStartPoint = (inverseWorldMatrix()).map(a_e->pos());
}
void
DiagramView :: contentsMouseReleaseEvent(QMouseEvent* )
{
if(cursor().shape() == Qt::CrossCursor) {
if(m_zoomRegionRect) {
m_zoomRegionRect->hide();
canvas()->update();
delete m_zoomRegionRect;
m_zoomRegionRect = 0;
m_zoomStartFlag = true;
emit ZoomToRegion(m_zoomStartPoint, m_zoomEndPoint);
canvas()->update();
}
return;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks