mirror of https://github.com/CGAL/cgal
Add a zoom with z+wheel
This commit is contained in:
parent
bd5d625e7b
commit
06995b543a
|
|
@ -2115,7 +2115,7 @@ void Camera::initFromDOMElement(const QDomElement &element) {
|
||||||
while (!child.isNull()) {
|
while (!child.isNull()) {
|
||||||
if (child.tagName() == "Parameters") {
|
if (child.tagName() == "Parameters") {
|
||||||
// #CONNECTION# Default values set in constructor
|
// #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(
|
setZNearCoefficient(
|
||||||
DomUtils::qrealFromDom(child, "zNearCoefficient", 0.005));
|
DomUtils::qrealFromDom(child, "zNearCoefficient", 0.005));
|
||||||
setZClippingCoefficient(
|
setZClippingCoefficient(
|
||||||
|
|
|
||||||
|
|
@ -424,6 +424,23 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
|
||||||
inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->angleDelta().y())));
|
inverseTransformOf(Vec(0.0, 0.0, 0.2 * flySpeed() * event->angleDelta().y())));
|
||||||
Q_EMIT manipulated();
|
Q_EMIT manipulated();
|
||||||
break;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -447,7 +464,10 @@ void ManipulatedCameraFrame::wheelEvent(QWheelEvent *const event,
|
||||||
// isManipulated() returns false. But then fastDraw would not be used with
|
// isManipulated() returns false. But then fastDraw would not be used with
|
||||||
// wheel. Detecting the last wheel event and forcing a final draw() is done
|
// wheel. Detecting the last wheel event and forcing a final draw() is done
|
||||||
// using the timer_.
|
// using the timer_.
|
||||||
|
if(action_ != ZOOM_FOV)
|
||||||
action_ = NO_MOUSE_ACTION;
|
action_ = NO_MOUSE_ACTION;
|
||||||
|
//else done after postDraw().
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -606,6 +606,25 @@ void CGAL::QGLViewer::postDraw() {
|
||||||
painter.drawRect(QRect(camera()->frame()->pressPos_, mapFromGlobal(QCursor::pos())));
|
painter.drawRect(QRect(camera()->frame()->pressPos_, mapFromGlobal(QCursor::pos())));
|
||||||
painter.end();
|
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(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
|
// Z o o m o n r e g i o n
|
||||||
setMouseBinding(::Qt::ShiftModifier, ::Qt::MidButton, qglviewer::CAMERA, qglviewer::ZOOM_ON_REGION);
|
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::LeftButton, qglviewer::ZOOM_ON_PIXEL);
|
||||||
setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::RightButton, qglviewer::ZOOM_TO_FIT);
|
setMouseBinding(::Qt::Key_Z, ::Qt::NoModifier, ::Qt::RightButton, qglviewer::ZOOM_TO_FIT);
|
||||||
|
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
// Specific Mac bindings for touchpads. Two fingers emulate a wheelEvent which
|
// Specific Mac bindings for touchpads. Two fingers emulate a wheelEvent which
|
||||||
// zooms. There is no right button available : make Option key + left emulate
|
// 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) {
|
bool withConstraint) {
|
||||||
//#CONNECTION# ManipulatedFrame::wheelEvent and
|
//#CONNECTION# ManipulatedFrame::wheelEvent and
|
||||||
// ManipulatedCameraFrame::wheelEvent switches
|
// ManipulatedCameraFrame::wheelEvent switches
|
||||||
if ((action != qglviewer::ZOOM) && (action != qglviewer::MOVE_FORWARD) &&
|
if ((action != qglviewer::ZOOM) && (action != qglviewer::ZOOM_FOV) &&
|
||||||
(action != qglviewer::MOVE_BACKWARD) && (action != qglviewer::NO_MOUSE_ACTION)) {
|
(action != qglviewer::MOVE_FORWARD) && (action != qglviewer::MOVE_BACKWARD)
|
||||||
|
&& (action != qglviewer::NO_MOUSE_ACTION)) {
|
||||||
qWarning("Cannot bind %s to wheel",
|
qWarning("Cannot bind %s to wheel",
|
||||||
mouseActionString(action).toLatin1().constData());
|
mouseActionString(action).toLatin1().constData());
|
||||||
return;
|
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",
|
qWarning("Cannot bind %s to FRAME wheel",
|
||||||
mouseActionString(action).toLatin1().constData());
|
mouseActionString(action).toLatin1().constData());
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,8 @@ enum MouseAction {
|
||||||
ROLL,
|
ROLL,
|
||||||
DRIVE,
|
DRIVE,
|
||||||
SCREEN_TRANSLATE,
|
SCREEN_TRANSLATE,
|
||||||
ZOOM_ON_REGION
|
ZOOM_ON_REGION,
|
||||||
|
ZOOM_FOV
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SnapShotBackground {
|
enum SnapShotBackground {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue