mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: move axis animation code to ProfileView
This feels quite a bit slower than the non-QtQuick version. This makes sense, as there is an additional level of indirection. Instead of painting directly, we paint into an QImage and turn that into a QSGTexture. Ultimately one would think that we should render directly using QtQuick. Alas, we can't, since that would mean no more printing/ exporting of profiles. How sad. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
15ea0440ad
commit
196a33ba4b
4 changed files with 58 additions and 49 deletions
|
@ -19,37 +19,9 @@
|
|||
#include "core/subsurface-string.h"
|
||||
#include "core/settings/qPrefDisplay.h"
|
||||
#include "qt-models/diveplannermodel.h"
|
||||
#include <QAbstractAnimation>
|
||||
|
||||
static const double diveComputerTextBorder = 1.0;
|
||||
|
||||
// Class for animations (if any). Might want to do our own.
|
||||
class ProfileAnimation : public QAbstractAnimation {
|
||||
ProfileScene &scene;
|
||||
// For historical reasons, speed is actually the duration
|
||||
// (i.e. the reciprocal of speed). Ouch, that hurts.
|
||||
int speed;
|
||||
|
||||
int duration() const override
|
||||
{
|
||||
return speed;
|
||||
}
|
||||
void updateCurrentTime(int time) override
|
||||
{
|
||||
// Note: we explicitly pass 1.0 at the end, so that
|
||||
// the callee can do a simple float comparison for "end".
|
||||
scene.anim(time == speed ? 1.0
|
||||
: static_cast<double>(time) / speed);
|
||||
}
|
||||
public:
|
||||
ProfileAnimation(ProfileScene &scene, int animSpeed) :
|
||||
scene(scene),
|
||||
speed(animSpeed)
|
||||
{
|
||||
start();
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, class... Args>
|
||||
T *ProfileScene::createItem(const DiveCartesianAxis &vAxis, DataAccessor accessor, int z, Args&&... args)
|
||||
{
|
||||
|
@ -404,8 +376,8 @@ static double max_gas(const plot_info &pi, double gas_pressures::*gas)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsModel *plannerModel,
|
||||
bool inPlanner, bool instant, bool keepPlotInfo, bool calcMax, double zoom, double zoomedPosition)
|
||||
void ProfileScene::plotDive(const struct dive *dIn, int dcIn, int animSpeed, DivePlannerPointsModel *plannerModel,
|
||||
bool inPlanner, bool keepPlotInfo, bool calcMax, double zoom, double zoomedPosition)
|
||||
{
|
||||
d = dIn;
|
||||
dc = dcIn;
|
||||
|
@ -439,8 +411,6 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
keepPlotInfo = false;
|
||||
empty = false;
|
||||
|
||||
int animSpeed = instant || printMode ? 0 : qPrefDisplay::animation_speed();
|
||||
|
||||
// A non-null planner_ds signals to create_plot_info_new that the dive is currently planned.
|
||||
struct deco_state *planner_ds = inPlanner && plannerModel ? &plannerModel->final_deco_state : nullptr;
|
||||
|
||||
|
@ -589,12 +559,6 @@ void ProfileScene::plotDive(const struct dive *dIn, int dcIn, DivePlannerPointsM
|
|||
if (nr > 1)
|
||||
dcText += tr(" (#%1 of %2)").arg(dc + 1).arg(nr);
|
||||
diveComputerText->set(dcText, getColor(TIME_TEXT, isGrayscale));
|
||||
|
||||
// Reset animation.
|
||||
if (animSpeed <= 0)
|
||||
animation.reset();
|
||||
else
|
||||
animation = std::make_unique<ProfileAnimation>(*this, animSpeed);
|
||||
}
|
||||
|
||||
void ProfileScene::anim(double fraction)
|
||||
|
@ -609,7 +573,7 @@ void ProfileScene::draw(QPainter *painter, const QRect &pos,
|
|||
{
|
||||
QSize size = pos.size();
|
||||
resize(QSizeF(size));
|
||||
plotDive(d, dc, plannerModel, inPlanner, true, false, true);
|
||||
plotDive(d, dc, 0, plannerModel, inPlanner, false, true);
|
||||
|
||||
QImage image(pos.size(), QImage::Format_ARGB32);
|
||||
image.fill(getColor(::BACKGROUND, isGrayscale));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue