QGeoView  1.0
QGeoView documentation
QGVCamera.h
1 /***************************************************************************
2  * QGeoView is a Qt / C ++ widget for visualizing geographic data.
3  * Copyright (C) 2018-2025 Andrey Yaroshenko.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, see https://www.gnu.org/licenses.
17  ****************************************************************************/
18 
19 #pragma once
20 
21 #include "QGVGlobal.h"
22 
23 #include <QAbstractAnimation>
24 #include <QEasingCurve>
25 
26 class QGVMap;
27 class QGVProjection;
28 
29 class QGV_LIB_DECL QGVCameraState
30 {
31 public:
32  explicit QGVCameraState(QGVMap* geoMap, double azimuth, double scale, const QRectF& projRect, bool animation);
33  QGVCameraState(const QGVCameraState& other);
34  QGVCameraState(const QGVCameraState&& other);
35  QGVCameraState& operator=(const QGVCameraState& other);
36  QGVCameraState& operator=(const QGVCameraState&& other);
37 
38  QGVMap* getMap() const;
39  QGVProjection* getProjection() const;
40 
41  double scale() const;
42  double azimuth() const;
43  QRectF projRect() const;
44  QPointF projCenter() const;
45  bool animation() const;
46 
47  bool operator==(const QGVCameraState& other) const;
48  bool operator!=(const QGVCameraState& other) const;
49 
50 private:
51  QGVMap* mGeoMap;
52  double mScale;
53  double mAzimuth;
54  QRectF mProjRect;
55  bool mAnimation;
56 };
57 
58 class QGV_LIB_DECL QGVCameraActions
59 {
60 public:
61  explicit QGVCameraActions(QGVMap* geoMap);
62 
63  const QGVCameraState& origin() const;
64 
65  QGVCameraActions& rebase(const QGVCameraState& origin);
66  QGVCameraActions& reset();
67  QGVCameraActions& reset(const QGVCameraState& origin);
68  QGVCameraActions& scaleBy(double factor);
69  QGVCameraActions& scaleTo(double scale);
70  QGVCameraActions& scaleTo(const QRectF& projRect);
71  QGVCameraActions& scaleTo(const QGV::GeoRect& geoRect);
72  QGVCameraActions& rotateBy(double angle);
73  QGVCameraActions& rotateTo(double azimuth);
74  QGVCameraActions& moveTo(const QPointF& projPos);
75  QGVCameraActions& moveTo(const QGV::GeoPos& geoPos);
76 
77  double scale() const;
78  double azimuth() const;
79  QPointF projCenter() const;
80 
81 private:
82  QGVCameraState mOrigin;
83  double mScale;
84  double mAzimuth;
85  QPointF mProjCenter;
86 };
87 
88 class QGV_LIB_DECL QGVCameraAnimation : public QAbstractAnimation
89 {
90 public:
91  explicit QGVCameraAnimation(const QGVCameraActions& actions, QObject* parent = nullptr);
92 
93  void setDuration(int msecs);
94  int duration() const override;
95  QGVCameraActions& actions();
96 
97 protected:
98  virtual void onStart();
99  virtual void onStop();
100  virtual void onProgress(double progress, QGVCameraActions& target) = 0;
101 
102  static double interpolateScale(double from, double to, double progress);
103  static double interpolateAzimuth(double from, double to, double progress);
104  static QPointF interpolatePos(QPointF from, QPointF to, double progress);
105 
106 private:
107  void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) override;
108  void updateCurrentTime(int currentTime) override;
109  void onStateChanged(QGV::MapState state);
110 
111 private:
112  int mDuration;
113  QGVCameraActions mActions;
114 };
115 
116 class QGV_LIB_DECL QGVCameraSimpleAnimation : public QGVCameraAnimation
117 {
118 public:
119  explicit QGVCameraSimpleAnimation(const QGVCameraActions& actions, QObject* parent = nullptr);
120 
121  void setEasingCurve(const QEasingCurve& easing);
122 
123 private:
124  void onProgress(double progress, QGVCameraActions& target) override;
125 
126 private:
127  QEasingCurve mEasing;
128 };
129 
130 class QGV_LIB_DECL QGVCameraFlyAnimation : public QGVCameraAnimation
131 {
132 public:
133  explicit QGVCameraFlyAnimation(const QGVCameraActions& actions, QObject* parent = nullptr);
134 
135 private:
136  void onStart() override;
137  void onProgress(double progress, QGVCameraActions& target) override;
138 
139 private:
140  double mFlyScale;
141  QPointF mFlyAnchor;
142 };
Definition: QGVCamera.h:59
Definition: QGVCamera.h:89
Definition: QGVCamera.h:131
Definition: QGVCamera.h:117
Definition: QGVCamera.h:30
Definition: QGVMap.h:35
Definition: QGVProjection.h:24
Definition: QGVGlobal.h:105
Definition: QGVGlobal.h:134