Add a zoom with z+wheel

This commit is contained in:
Maxime Gimeno 2020-09-30 16:28:25 +02:00
parent bd5d625e7b
commit 06995b543a
4 changed files with 50 additions and 6 deletions

View File

@ -2115,7 +2115,7 @@ void Camera::initFromDOMElement(const QDomElement &element) {
while (!child.isNull()) {
if (child.tagName() == "Parameters") {
// #CONNECTION# Default values set in constructor
setFieldOfView(DomUtils::qrealFromDom(child, "fieldOfView", CGAL_PI / 4.0));
//setFieldOfView(DomUtils::qrealFromDom(child, "fieldOfView", CGAL_PI / 4.0));
setZNearCoefficient(
DomUtils::qrealFromDom(child, "zNearCoefficient", 0.005));
setZClippingCoefficient(

View File

@ -424,6 +424,23 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->angleDelta().y())));
Q_EMIT manipulated();
break;
case ZOOM_FOV:
{
qreal delta = - wheelDelta(event);//- sign to keep the same behavior as for the ZOOM action.
qreal new_fov = delta/100 + camera->fieldOfView();
if(new_fov > CGAL_PI/180.0)
{
new_fov = delta + camera->fieldOfView();
}
if(new_fov > CGAL_PI/4.0)
new_fov = CGAL_PI/4.0;
if( new_fov >= 0.0)
{
camera->setFieldOfView(new_fov);
}
Q_EMIT manipulated();
break;
}
default:
break;
}
@ -447,7 +464,10 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
// isManipulated() returns false. But then fastDraw would not be used with
// wheel. Detecting the last wheel event and forcing a final draw() is done
// using the timer_.
if(action_ != ZOOM_FOV)
action_ = NO_MOUSE_ACTION;
//else done after postDraw().
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -606,6 +606,25 @@ void CGAL::QGLViewer::postDraw() {
painter.drawRect(QRect(camera()->frame()->pressPos_, mapFromGlobal(QCursor::pos())));
painter.end();
}
//zoom_fov indicator
if(camera()->frame()->action_ == qglviewer::ZOOM_FOV)
{
QPainter painter(this);
QPoint bot(width()-30,height()/2-0.33*height()),
top(width()-30, height()/2+0.33*height());
int fov_height = (top.y()-bot.y())*camera()->fieldOfView()*4.0/CGAL_PI + bot.y();
painter.setPen(QColor(120,120,120));
painter.drawLine(bot, top);
painter.fillRect(QRect(QPoint(width()-40, fov_height+10),
QPoint(width()-20, fov_height-10)),
QColor(120,120,120));
painter.end();
camera()->frame()->action_= qglviewer::NO_MOUSE_ACTION;
}
}
@ -740,6 +759,7 @@ void CGAL::QGLViewer::setDefaultMouseBindings() {
setWheelBinding(modifiers, mh, qglviewer::ZOOM);
}
setWheelBinding(::Qt::Key_Z, ::Qt::NoModifier, qglviewer::CAMERA, qglviewer::ZOOM_FOV);
// Z o o m o n r e g i o n
setMouseBinding(::Qt::ShiftModifier, ::Qt::MidButton, qglviewer::CAMERA, qglviewer::ZOOM_ON_REGION);
@ -761,6 +781,7 @@ void CGAL::QGLViewer::setDefaultMouseBindings() {
setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::LeftButton, qglviewer::ZOOM_ON_PIXEL);
setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::RightButton, qglviewer::ZOOM_TO_FIT);
#ifdef Q_OS_MAC
// Specific Mac bindings for touchpads. Two fingers emulate a wheelEvent which
// zooms. There is no right button available : make Option key + left emulate
@ -2730,14 +2751,16 @@ void CGAL::QGLViewer::setWheelBinding(::Qt::Key key, ::Qt::KeyboardModifiers mod
bool withConstraint) {
//#CONNECTION# ManipulatedFrame::wheelEvent and
// ManipulatedCameraFrame::wheelEvent switches
if ((action != qglviewer::ZOOM) && (action != qglviewer::MOVE_FORWARD) &&
(action != qglviewer::MOVE_BACKWARD) && (action != qglviewer::NO_MOUSE_ACTION)) {
if ((action != qglviewer::ZOOM) && (action != qglviewer::ZOOM_FOV) &&
(action != qglviewer::MOVE_FORWARD) && (action != qglviewer::MOVE_BACKWARD)
&& (action != qglviewer::NO_MOUSE_ACTION)) {
qWarning("Cannot bind %s to wheel",
mouseActionString(action).toLatin1().constData());
return;
}
if ((handler == qglviewer::FRAME) && (action != qglviewer::ZOOM) && (action != qglviewer::NO_MOUSE_ACTION)) {
if ((handler == qglviewer::FRAME) && (action != qglviewer::ZOOM)
&& (action != qglviewer::NO_MOUSE_ACTION)) {
qWarning("Cannot bind %s to FRAME wheel",
mouseActionString(action).toLatin1().constData());
return;

View File

@ -79,7 +79,8 @@ enum MouseAction {
ROLL,
DRIVE,
SCREEN_TRANSLATE,
ZOOM_ON_REGION
ZOOM_ON_REGION,
ZOOM_FOV
};
enum SnapShotBackground {