Menu

#7 Scaffold View Zoom Behaviour Change

open
nobody
None
5
2012-02-03
2012-02-03
No

I'd like better control of the zoom in/out on the scaffold view. In particular I'd like to unlink the x/y zoom. I have rewritten the Qt code for this zooming such that left-click zooms the x-axis and right-click zooms the y-axis and the zoom factor is calculated depending on weather the zoom in or zoom out tool is selected.

I've rewritten the InsertField::contentsMousePressEvent() function as follows (sorry I'd have submitted a patch if it wasn't late Friday afternoon!):

void InsertField::contentsMousePressEvent( QMouseEvent* e )
{
QPoint real = inverseWorldMatrix().map(e->pos());
Q3CanvasItemList l = canvas()->collisions(real);

int gindex = 16*real.x() - m_hoffset;
int jumptoread = 0;

bool jump = true;

int xpos = real.x();
int ypos = real.y();

double xZoomFactor = 2;
double yZoomFactor = 1.25;

if (m_toolstate == 0) {
// Select tool active - center
QString s;

for (Q3CanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it)
{
processItemSelection(s, it, jumptoread, jump,
e->button() == Qt::RightButton,
e->state() == Qt::ControlButton,
real.x());
}

s += "<b><em>Click</em></b><br>";
s += "<table>";
s += "<tr><td><b>Position</b></td><td>"
+ QString::number(gindex) + "</td></tr>";
s += "</table>";

emit setDetails(s);

if (jump)
emit setGindex(gindex);

if (jumptoread)
emit jumpToRead(jumptoread);

} else if (m_toolstate == 1) {
// zoom in tool active
// set zoom depending on left/right mouse click
if(e->button() == Qt::LeftButton) {
// zoom x axis
yZoomFactor = 1;
} else if (e->button() == Qt::RightButton) {
// zoom y axis
xZoomFactor = 1;
}
} else if(m_toolstate == 2) {
// zoom out tool active
// set zoom depending on left/right mouse click
if(e->button() == Qt::LeftButton) {
// zoom x axis
xZoomFactor = 1/xZoomFactor;
yZoomFactor = 1;
} else if (e->button() == Qt::RightButton) {
// zoom y axis
xZoomFactor = 1;
yZoomFactor = 1/yZoomFactor;
}
}

if (m_toolstate == 1 || m_toolstate == 2) {
// Perform the actual zoom now
QMatrix m = worldMatrix();
QMatrix newzoom(m.m11()*xZoomFactor, m.m12(), m.m21(), m.m22()*yZoomFactor, m.dx(), m.dy());

setWorldMatrix(newzoom);

setContentsPos((int)(xpos*newzoom.m11() - visibleWidth()/2),
(int)(ypos*newzoom.m22() - visibleHeight()/2));

emit updateVisibleRange();
}
}

Discussion


Log in to post a comment.