2023-08-27 21:16:48 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
struct StatisticalChart;
|
|
|
|
} // namespace Data
|
|
|
|
|
|
|
|
namespace Statistic {
|
|
|
|
|
|
|
|
struct Limits;
|
|
|
|
|
2023-09-19 10:02:50 +00:00
|
|
|
struct PaintContext final {
|
|
|
|
const Data::StatisticalChart &chartData;
|
|
|
|
const Limits &xIndices;
|
|
|
|
const Limits &xPercentageLimits;
|
|
|
|
const Limits &heightLimits;
|
|
|
|
const QRect ▭
|
|
|
|
bool footer = false;
|
|
|
|
};
|
|
|
|
|
2023-08-27 21:16:48 +00:00
|
|
|
class AbstractChartView {
|
|
|
|
public:
|
|
|
|
virtual ~AbstractChartView() = default;
|
|
|
|
|
2023-09-19 10:02:50 +00:00
|
|
|
virtual void paint(QPainter &p, const PaintContext &c) = 0;
|
2023-08-27 21:16:48 +00:00
|
|
|
|
|
|
|
virtual void paintSelectedXIndex(
|
|
|
|
QPainter &p,
|
2023-09-19 10:02:50 +00:00
|
|
|
const PaintContext &c,
|
2023-09-05 14:03:08 +00:00
|
|
|
int selectedXIndex,
|
|
|
|
float64 progress) = 0;
|
2023-08-27 21:16:48 +00:00
|
|
|
|
2023-09-05 17:04:37 +00:00
|
|
|
[[nodiscard]] virtual int findXIndexByPosition(
|
|
|
|
const Data::StatisticalChart &chartData,
|
|
|
|
const Limits &xPercentageLimits,
|
|
|
|
const QRect &rect,
|
|
|
|
float64 x) = 0;
|
|
|
|
|
2023-08-27 21:16:48 +00:00
|
|
|
virtual void setEnabled(int id, bool enabled, crl::time now) = 0;
|
|
|
|
[[nodiscard]] virtual bool isEnabled(int id) const = 0;
|
|
|
|
[[nodiscard]] virtual bool isFinished() const = 0;
|
|
|
|
[[nodiscard]] virtual float64 alpha(int id) const = 0;
|
|
|
|
|
2023-08-27 21:39:17 +00:00
|
|
|
struct HeightLimits final {
|
|
|
|
Limits full;
|
|
|
|
Limits ranged;
|
|
|
|
};
|
|
|
|
|
|
|
|
[[nodiscard]] virtual HeightLimits heightLimits(
|
|
|
|
Data::StatisticalChart &chartData,
|
|
|
|
Limits xIndices) = 0;
|
|
|
|
|
2023-08-27 21:16:48 +00:00
|
|
|
virtual void tick(crl::time now) = 0;
|
2023-09-08 09:15:35 +00:00
|
|
|
virtual void update(float64 dt) {
|
|
|
|
};
|
2023-08-27 21:16:48 +00:00
|
|
|
|
2023-09-25 12:20:43 +00:00
|
|
|
struct LocalZoomResult final {
|
|
|
|
bool hasZoom = false;
|
2023-09-25 23:44:05 +00:00
|
|
|
Limits limitIndices;
|
2023-09-25 12:20:43 +00:00
|
|
|
Limits range;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LocalZoomArgs final {
|
|
|
|
enum class Type {
|
|
|
|
Prepare,
|
|
|
|
SkipCalculation,
|
|
|
|
CheckAvailability,
|
|
|
|
Process,
|
|
|
|
SaveZoomFromFooter,
|
|
|
|
};
|
|
|
|
const Data::StatisticalChart &chartData;
|
|
|
|
Type type;
|
|
|
|
float64 progress = 0.;
|
|
|
|
int xIndex = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual LocalZoomResult maybeLocalZoom(const LocalZoomArgs &args) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2023-09-26 20:09:44 +00:00
|
|
|
virtual void handleMouseMove(
|
|
|
|
const Data::StatisticalChart &chartData,
|
|
|
|
const QRect &rect,
|
|
|
|
const QPoint &p) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void setUpdateCallback(Fn<void()> callback) {
|
|
|
|
_updateCallback = std::move(callback);
|
|
|
|
}
|
|
|
|
void update() {
|
|
|
|
if (_updateCallback) {
|
|
|
|
_updateCallback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Fn<void()> _updateCallback;
|
|
|
|
|
2023-08-27 21:16:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Statistic
|