Skip to content

Commit

Permalink
Merge pull request #1605 from janbar/add_movement_pivotby
Browse files Browse the repository at this point in the history
introduce the new movement pivotBy, using linear progression
  • Loading branch information
Framstag authored Sep 21, 2024
2 parents d7f5183 + 1c247b4 commit 1f95d83
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
7 changes: 5 additions & 2 deletions libosmscout-client-qt/include/osmscoutclientqt/InputHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class OSMSCOUT_CLIENT_QT_API InputHandler : public QObject{
virtual bool move(const QVector2D &vector); // move vector in pixels
virtual bool rotateTo(double angle);
virtual bool rotateBy(double angleChange);
virtual bool pivotBy(double angleChange);
virtual bool touch(const QTouchEvent &event);
virtual bool currentPosition(bool locationValid, osmscout::GeoCoord currentPosition);
virtual bool vehiclePosition(const VehiclePosition &vehiclePosition, bool autoRotateMap);
Expand Down Expand Up @@ -306,8 +307,9 @@ class OSMSCOUT_CLIENT_QT_API MoveHandler : public InputHandler {
MapView startMapView;
QVector2D _move;
osmscout::Magnification targetMagnification;
double targetAngle;
int animationDuration;
double targetAngle = 0.0;
int animationDuration = 0;
bool linearProgression = false;

const int MOVE_ANIMATION_DURATION = 1000; // ms
const int ZOOM_ANIMATION_DURATION = 500; // ms
Expand Down Expand Up @@ -335,6 +337,7 @@ private slots:
bool move(const QVector2D &vector) override; // move vector in pixels
bool rotateTo(double angle) override;
bool rotateBy(double angleChange) override;
bool pivotBy(double angleChange) override;
bool touch(const QTouchEvent &event) override;
};

Expand Down
1 change: 1 addition & 0 deletions libosmscout-client-qt/include/osmscoutclientqt/MapWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public slots:
void rotateTo(double angle);
void rotateLeft();
void rotateRight();
void pivotBy(double angleChange);

void toggleDaylight();
void reloadStyle();
Expand Down
35 changes: 33 additions & 2 deletions libosmscout-client-qt/src/osmscoutclientqt/InputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ bool InputHandler::rotateBy(double /*angleChange*/)
{
return false;
}
bool InputHandler::pivotBy(double /*angleChange*/)
{
return false;
}
bool InputHandler::touch(const QTouchEvent &/*event*/)
{
return false;
Expand Down Expand Up @@ -271,8 +275,11 @@ void MoveHandler::onTimeout()
progress = 1.0;
timer.stop();
}
//double scale = std::log( progress * (M_E - 1) + 1);
double scale = std::log10( progress * (10 - 1) + 1);
double scale = progress;
if (!linearProgression) {
//scale = std::log( progress * (M_E - 1) + 1);
scale = std::log10( progress * (10 - 1) + 1);
}

osmscout::MercatorProjection projection;

Expand Down Expand Up @@ -359,6 +366,7 @@ bool MoveHandler::zoom(double zoomFactor, const QPoint &widgetPosition, const QR
}
}
//emit viewChanged(view);
linearProgression = false;
animationDuration = ZOOM_ANIMATION_DURATION;
animationStart.restart();
timer.setInterval(ANIMATION_TICK);
Expand All @@ -377,6 +385,7 @@ bool MoveHandler::move(const QVector2D &move)
_move.setX(move.x());
_move.setY(move.y());

linearProgression = false;
animationDuration = MOVE_ANIMATION_DURATION;
animationStart.restart();
timer.setInterval(ANIMATION_TICK);
Expand Down Expand Up @@ -429,6 +438,7 @@ bool MoveHandler::rotateTo(double angle)
_move.setX(0);
_move.setY(0);

linearProgression = false;
animationDuration = ROTATE_ANIMATION_DURATION;
animationStart.restart();
timer.setInterval(ANIMATION_TICK);
Expand All @@ -449,6 +459,7 @@ bool MoveHandler::rotateBy(double angleChange)
_move.setX(0);
_move.setY(0);

linearProgression = false;
animationDuration = ROTATE_ANIMATION_DURATION;
animationStart.restart();
timer.setInterval(ANIMATION_TICK);
Expand All @@ -458,6 +469,26 @@ bool MoveHandler::rotateBy(double angleChange)
return true;
}

bool MoveHandler::pivotBy(double angleChange)
{
startMapView = view;
targetMagnification = view.magnification;

targetAngle = view.angle.AsRadians()+angleChange;

_move.setX(0);
_move.setY(0);

linearProgression = true;
animationDuration = ROTATE_ANIMATION_DURATION;
animationStart.restart();
timer.setInterval(ANIMATION_TICK);
timer.start();
onTimeout();

return true;
}

ZoomGestureHandler::ZoomGestureHandler(const MapView &view, const QPoint &p, double zoomDistance):
InputHandler(view),
startMag(view.magnification),
Expand Down
9 changes: 9 additions & 0 deletions libosmscout-client-qt/src/osmscoutclientqt/MapWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,15 @@ void MapWidget::rotateRight()
}
}

void MapWidget::pivotBy(double angleChange)
{
vehicle.lastGesture.restart();
if (!inputHandler->pivotBy(angleChange)){
setupInputHandler(new MoveHandler(*view));
inputHandler->pivotBy(angleChange);
}
}

void MapWidget::toggleDaylight()
{
DBThreadRef dbThread=OSMScoutQt::GetInstance().GetDBThread();
Expand Down

0 comments on commit 1f95d83

Please sign in to comment.