2017-04-27 18:26:36 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-01-14 18:20:15 +00:00
|
|
|
#ifndef DIVECARTESIANAXIS_H
|
|
|
|
#define DIVECARTESIANAXIS_H
|
|
|
|
|
2021-12-02 22:53:17 +00:00
|
|
|
#include <memory>
|
2014-01-14 18:20:15 +00:00
|
|
|
#include <QGraphicsLineItem>
|
2021-09-01 19:18:38 +00:00
|
|
|
#include <QPen>
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "core/color.h"
|
2021-06-28 18:29:46 +00:00
|
|
|
#include "core/units.h"
|
2014-01-22 19:10:18 +00:00
|
|
|
|
2021-06-28 18:29:46 +00:00
|
|
|
class ProfileScene;
|
2014-01-14 18:20:15 +00:00
|
|
|
class DiveTextItem;
|
|
|
|
class DiveLineItem;
|
|
|
|
|
2021-12-02 22:53:17 +00:00
|
|
|
class DiveCartesianAxis : public QGraphicsLineItem {
|
2015-10-11 11:21:14 +00:00
|
|
|
private:
|
|
|
|
bool printMode;
|
2014-01-14 18:20:15 +00:00
|
|
|
public:
|
2021-08-28 17:25:52 +00:00
|
|
|
enum class Position {
|
|
|
|
Left, Right, Bottom
|
|
|
|
};
|
2021-09-22 18:56:13 +00:00
|
|
|
|
2021-10-03 20:29:18 +00:00
|
|
|
DiveCartesianAxis(Position position, bool inverted, int integralDigits, int fractionalDigits, color_index_t gridColor,
|
2021-10-03 20:10:00 +00:00
|
|
|
QColor textColor, bool textVisible, bool linesVisible,
|
2021-10-03 19:51:56 +00:00
|
|
|
double dpr, double labelScale, bool printMode, bool isGrayscale, ProfileScene &scene);
|
2018-07-31 05:41:19 +00:00
|
|
|
~DiveCartesianAxis();
|
2021-09-11 19:57:49 +00:00
|
|
|
void setBounds(double min, double max);
|
2021-09-22 18:56:13 +00:00
|
|
|
void setTransform(double a, double b = 0.0);
|
2014-01-14 18:20:15 +00:00
|
|
|
double minimum() const;
|
|
|
|
double maximum() const;
|
2021-08-29 20:13:26 +00:00
|
|
|
std::pair<double, double> screenMinMax() const;
|
2021-12-02 22:53:17 +00:00
|
|
|
double valueAt(const QPointF &p) const;
|
|
|
|
double posAtValue(double value) const;
|
2021-09-28 08:32:41 +00:00
|
|
|
void setPosition(const QRectF &rect);
|
2021-10-26 07:40:38 +00:00
|
|
|
double screenPosition(double pos) const; // 0.0 = begin, 1.0 = end of axis, independent of represented values
|
2021-10-26 14:37:38 +00:00
|
|
|
double pointInRange(double pos) const; // Point on screen is in range of axis
|
2014-02-12 16:24:19 +00:00
|
|
|
void setTextVisible(bool arg1);
|
2014-02-16 00:54:41 +00:00
|
|
|
void setLinesVisible(bool arg1);
|
2021-09-26 17:10:39 +00:00
|
|
|
void updateTicks(int animSpeed);
|
2021-08-28 12:25:04 +00:00
|
|
|
double width() const; // only for vertical axes
|
|
|
|
double height() const; // only for horizontal axes
|
2021-11-13 17:05:31 +00:00
|
|
|
double horizontalOverhang() const; // space needed for labels of horizontal axes
|
2021-12-02 22:53:17 +00:00
|
|
|
void anim(double fraction);
|
2014-02-12 16:24:19 +00:00
|
|
|
|
2021-10-16 18:43:19 +00:00
|
|
|
// The minimum space between two labels on the plot in seconds
|
|
|
|
int getMinLabelDistance(const DiveCartesianAxis &timeAxis) const;
|
|
|
|
|
2021-10-03 19:51:56 +00:00
|
|
|
private:
|
2021-12-02 22:53:17 +00:00
|
|
|
struct Label {
|
|
|
|
double value;
|
|
|
|
double opacityStart;
|
|
|
|
double opacityEnd; // If 0.0, label will be removed at end of animation
|
|
|
|
QPointF labelPosStart;
|
|
|
|
QPointF labelPosEnd;
|
|
|
|
QLineF lineStart;
|
|
|
|
QLineF lineEnd;
|
|
|
|
std::unique_ptr<DiveTextItem> label;
|
|
|
|
std::unique_ptr<DiveLineItem> line;
|
|
|
|
};
|
2021-08-28 18:12:36 +00:00
|
|
|
Position position;
|
2021-10-03 20:29:18 +00:00
|
|
|
bool inverted; // Top-to-bottom or right-to-left axis.
|
2021-09-22 18:56:13 +00:00
|
|
|
int fractionalDigits;
|
2021-08-28 21:36:09 +00:00
|
|
|
QRectF rect; // Rectangle to fill with grid lines
|
2021-09-01 19:18:38 +00:00
|
|
|
QPen gridPen;
|
2021-10-03 20:10:00 +00:00
|
|
|
QColor textColor;
|
2021-06-28 18:29:46 +00:00
|
|
|
ProfileScene &scene;
|
2021-12-02 22:53:17 +00:00
|
|
|
double posAtValue(double value, double max, double min) const;
|
|
|
|
QPointF labelPos(double pos) const;
|
|
|
|
QLineF linePos(double pos) const;
|
|
|
|
void updateLabel(Label &label, double opacityEnd, double pos) const;
|
2021-12-04 20:45:46 +00:00
|
|
|
Label createLabel(double value, double pos, double dataMinOld, double dataMaxOld, int animSpeed, bool noLabel);
|
2021-10-03 19:15:36 +00:00
|
|
|
QString textForValue(double value) const;
|
2021-12-02 22:53:17 +00:00
|
|
|
std::vector<Label> labels;
|
2021-09-26 17:10:39 +00:00
|
|
|
double dataMin, dataMax;
|
|
|
|
double min, max;
|
2014-02-12 16:24:19 +00:00
|
|
|
bool textVisibility;
|
2014-02-16 00:54:41 +00:00
|
|
|
bool lineVisibility;
|
2014-02-15 19:15:57 +00:00
|
|
|
double labelScale;
|
2021-08-09 14:48:08 +00:00
|
|
|
double dpr;
|
2021-09-20 19:13:19 +00:00
|
|
|
double labelWidth, labelHeight; // maximum expected sizes of label width and height
|
2021-09-22 18:56:13 +00:00
|
|
|
|
|
|
|
// To format the labels and choose the label positions, the
|
|
|
|
// axis has to be aware of the displayed values. Thankfully,
|
|
|
|
// the conversion between internal data (eg. mm) and displayed
|
|
|
|
// data (e.g. ft) can be represented by an affine map ax+b.
|
|
|
|
struct Transform {
|
|
|
|
double a, b;
|
|
|
|
double to(double x) const;
|
|
|
|
double from(double y) const;
|
|
|
|
} transform;
|
2021-10-03 19:51:56 +00:00
|
|
|
|
2021-12-02 22:53:17 +00:00
|
|
|
void updateLabels(int numTicks, double firstPosScreen, double firstValue, double stepScreen, double stepValue,
|
|
|
|
int animSpeed, double dataMinOld, double dataMaxOld);
|
2014-01-14 18:20:15 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVECARTESIANAXIS_H
|