2023-05-20 14:27:20 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef PROFILE_VIEW_H
|
|
|
|
#define PROFILE_VIEW_H
|
|
|
|
|
|
|
|
#include "qt-quick/chartview.h"
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
class ChartGraphicsSceneItem;
|
2023-05-20 15:22:02 +02:00
|
|
|
class ProfileAnimation;
|
2023-05-20 14:27:20 +02:00
|
|
|
class ProfileScene;
|
2023-06-16 18:24:22 +02:00
|
|
|
class ToolTipItem;
|
2023-05-20 14:27:20 +02:00
|
|
|
|
|
|
|
class ProfileView : public ChartView {
|
|
|
|
Q_OBJECT
|
2023-05-20 20:58:38 +02:00
|
|
|
|
|
|
|
// Communication with the mobile interface is via properties. I hate it.
|
|
|
|
Q_PROPERTY(int diveId READ getDiveId WRITE setDiveId)
|
|
|
|
Q_PROPERTY(int numDC READ numDC NOTIFY numDCChanged)
|
|
|
|
Q_PROPERTY(double zoomLevel MEMBER zoomLevel NOTIFY zoomLevelChanged)
|
2023-05-20 14:27:20 +02:00
|
|
|
public:
|
|
|
|
ProfileView();
|
|
|
|
ProfileView(QQuickItem *parent);
|
|
|
|
~ProfileView();
|
|
|
|
|
|
|
|
struct RenderFlags {
|
|
|
|
static constexpr int None = 0;
|
|
|
|
static constexpr int Instant = 1 << 0;
|
|
|
|
static constexpr int DontRecalculatePlotInfo = 1 << 1;
|
|
|
|
static constexpr int EditMode = 1 << 2;
|
|
|
|
static constexpr int PlanMode = 1 << 3;
|
|
|
|
};
|
|
|
|
|
|
|
|
void plotDive(const struct dive *d, int dc, int flags = RenderFlags::None);
|
|
|
|
void clear();
|
2023-05-20 17:12:33 +02:00
|
|
|
void resetZoom();
|
2023-05-20 15:22:02 +02:00
|
|
|
void anim(double fraction);
|
2023-05-20 20:58:38 +02:00
|
|
|
|
|
|
|
// For mobile
|
|
|
|
Q_INVOKABLE void pinchStart();
|
|
|
|
Q_INVOKABLE void pinch(double factor);
|
|
|
|
Q_INVOKABLE void nextDC();
|
|
|
|
Q_INVOKABLE void prevDC();
|
|
|
|
Q_INVOKABLE void panStart(double x, double y);
|
|
|
|
Q_INVOKABLE void pan(double x, double y);
|
|
|
|
signals:
|
|
|
|
void numDCChanged();
|
|
|
|
void zoomLevelChanged();
|
2023-05-20 14:27:20 +02:00
|
|
|
private:
|
|
|
|
const struct dive *d;
|
|
|
|
int dc;
|
2023-06-16 18:24:22 +02:00
|
|
|
double dpr;
|
2023-05-20 20:58:38 +02:00
|
|
|
double zoomLevel, zoomLevelPinchStart;
|
2023-05-20 14:27:20 +02:00
|
|
|
double zoomedPosition; // Position when zoomed: 0.0 = beginning, 1.0 = end.
|
2023-05-20 17:12:33 +02:00
|
|
|
bool panning; // Currently panning.
|
|
|
|
double panningOriginalMousePosition;
|
|
|
|
double panningOriginalProfilePosition;
|
2023-05-20 14:27:20 +02:00
|
|
|
bool empty; // No dive shown.
|
|
|
|
bool shouldCalculateMax; // Calculate maximum time and depth (default). False when dragging handles.
|
2023-05-20 15:22:02 +02:00
|
|
|
QColor background;
|
2023-05-20 14:27:20 +02:00
|
|
|
std::unique_ptr<ProfileScene> profileScene;
|
|
|
|
ChartItemPtr<ChartGraphicsSceneItem> profileItem;
|
2023-05-20 15:22:02 +02:00
|
|
|
std::unique_ptr<ProfileAnimation> animation;
|
2023-05-20 14:27:20 +02:00
|
|
|
|
|
|
|
void plotAreaChanged(const QSizeF &size) override;
|
|
|
|
void resetPointers() override;
|
2023-05-20 15:37:11 +02:00
|
|
|
void replot();
|
2023-05-20 20:58:38 +02:00
|
|
|
void setZoom(double level);
|
2023-05-20 17:12:33 +02:00
|
|
|
|
2023-06-16 18:24:22 +02:00
|
|
|
void hoverEnterEvent(QHoverEvent *event) override;
|
|
|
|
void hoverMoveEvent(QHoverEvent *event) override;
|
2023-05-20 17:12:33 +02:00
|
|
|
void wheelEvent(QWheelEvent *event) override;
|
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
2023-05-20 20:58:38 +02:00
|
|
|
|
2023-06-16 18:24:22 +02:00
|
|
|
ChartItemPtr<ToolTipItem> tooltip;
|
2023-07-06 16:08:19 +02:00
|
|
|
void updateTooltip(QPointF pos, bool plannerMode, int animSpeed);
|
|
|
|
std::unique_ptr<ProfileAnimation> tooltip_animation;
|
|
|
|
|
|
|
|
QPointF previousHoveMovePosition;
|
2023-06-16 18:24:22 +02:00
|
|
|
|
2023-05-20 20:58:38 +02:00
|
|
|
// For mobile
|
|
|
|
int getDiveId() const;
|
|
|
|
void setDiveId(int id);
|
|
|
|
int numDC() const;
|
|
|
|
void rotateDC(int dir);
|
2023-05-20 14:27:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|