Skip to content

Commit a968cf9

Browse files
committedJun 6, 2019
Add behavior for zoom in/out buttons.
1 parent 4d9b79d commit a968cf9

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed
 

‎src/3d/qgscameracontroller.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,18 @@ void QgsCameraController::onPositionChanged( Qt3DInput::QMouseEvent *mouse )
327327
}
328328
else if ( hasRightButton && !hasShift && !hasCtrl )
329329
{
330+
zoom(dy);
331+
}
332+
333+
mMousePos = QPoint( mouse->x(), mouse->y() );
334+
}
335+
336+
void QgsCameraController::zoom(float factor){
330337
// zoom in/out
331338
float dist = mCameraPose.distanceFromCenterPoint();
332-
dist -= dist * dy * 0.01f;
339+
dist -= dist * factor * 0.01f;
333340
mCameraPose.setDistanceFromCenterPoint( dist );
334341
updateCameraFromPose();
335-
}
336-
337-
mMousePos = QPoint( mouse->x(), mouse->y() );
338342
}
339343

340344
void QgsCameraController::onWheel( Qt3DInput::QWheelEvent *wheel )

‎src/3d/qgscameracontroller.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ class _3D_EXPORT QgsCameraController : public Qt3DCore::QEntity
135135
//! Reads camera configuration from the given DOM element
136136
void readXml( const QDomElement &elem );
137137

138+
void zoom(float factor);
139+
138140
private:
139141
void rotateCamera( float diffPitch, float diffYaw );
140142
void updateCameraFromPose( bool centerPointChanged = false );

‎src/app/3d/qgs3dmapcanvas.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
4141
} );
4242

4343
mContainer = QWidget::createWindowContainer( mEngine->window() );
44-
45-
mNavigationWidget = new Qgs3DNavigationWidget();
46-
mNavigationWidget->setParent(this);
44+
mNavigationWidget = new Qgs3DNavigationWidget(this);
4745

4846
QHBoxLayout *hLayout = new QHBoxLayout( this );
4947
hLayout->setMargin( 0 );

‎src/app/3d/qgs3dnavigationwidget.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
#include <QGridLayout>
22
#include <QPushButton>
33
#include <QDial>
4+
#include <QObject>
45

56
#include "qgs3dnavigationwidget.h"
7+
#include "qgscameracontroller.h"
68

7-
Qgs3DNavigationWidget::Qgs3DNavigationWidget(QWidget *parent) : QWidget(parent)
9+
Qgs3DNavigationWidget::Qgs3DNavigationWidget(Qgs3DMapCanvas *parent) : QWidget(parent)
810
{
911
// Zoom in button
1012
mZoomInButton = new QPushButton(this);
1113
mZoomInButton->setText(QStringLiteral("+"));
1214
mZoomInButton->setToolTip(QStringLiteral("Zoom In"));
1315
mZoomInButton->setAutoRepeat(true);
1416

17+
QObject::connect(
18+
mZoomInButton,
19+
&QPushButton::clicked,
20+
parent,
21+
[ = ]{
22+
parent->cameraController()->zoom(5);
23+
}
24+
);
25+
1526
// Zoom out button
1627
mZoomOutButton = new QPushButton(this);
1728
mZoomOutButton->setText(QStringLiteral("-"));
1829
mZoomOutButton->setToolTip(QStringLiteral("Zoom Out"));
1930
mZoomOutButton->setAutoRepeat(true);
2031

32+
QObject::connect(
33+
mZoomOutButton,
34+
&QPushButton::clicked,
35+
parent,
36+
[ = ]{
37+
parent->cameraController()->zoom(-5);
38+
}
39+
);
40+
2141
// Tilt up button
2242
mTiltUpButton = new QPushButton(this);
2343
mTiltUpButton->setText(QString::fromUtf8("\u25B3"));

‎src/app/3d/qgs3dnavigationwidget.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
#include <QDial>
2222
#include <QGridLayout>
2323

24+
#include "qgs3dmapcanvas.h"
25+
#include "qgscameracontroller.h"
26+
2427
class Qgs3DNavigationWidget : public QWidget
2528
{
2629
Q_OBJECT
2730
public:
28-
Qgs3DNavigationWidget(QWidget *parent = nullptr);
31+
Qgs3DNavigationWidget(Qgs3DMapCanvas *parent = nullptr);
2932
~Qgs3DNavigationWidget();
3033

3134
signals:

0 commit comments

Comments
 (0)