Commit graph

11 commits

Author SHA1 Message Date
Berthold Stoeger
176a62f752 profile: improve calculation of the right border
The time axis might need some space and the average depth item
puts a formatted depth at to right of the profile. Consider
these when calculating the right border.

Since I found no way to turn of the average depth, this creates
a permanent border, which might or might not be a good thing.

Contains some refactoring of the label-size functions provided
by DiveTextItem.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
322e2baa8d profile: calculate maximum label sizes on construction
Instead of calculating the label sizes of the axes when
relayouting the chart, calculate them at construction time.

To do so, pass the digits before and after the decimal comma
to the constructor.

This is not so much an optimization thing, but rather an
first stab at more general label rendering. Time, of course,
will always be an exception. But hopefully the remaining
values can be done more generally.

Note that currently this code is a total mess. For example,
the labels for the temperature axes are not converted to
F if needed. And therefore also not shown. This will need
some major rethinking.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
15f20961c7 profile: render DiveTextItem onto a pixmap
The DiveTextItems were redrawn on every paint() call. This was
a prohibitively expensive operation (converting the text into
a path, drawing an outline, etc.), which was called numerous
times.

Instead, render the text only when changing into a QPixmap
and blit that pixmap in the paint() call.

This will make it possible to do absolutely positioned
DiveTextItems. So far they were placed relatively in
scene coordinates ranging from 0-100(!).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
04e0d96bae profile: set text and brush of DiveTextItem concurrently
The text and the brush are the two properties of text items
that change dynamically. To avoid complexities concerning
redrawing, set them concurrently instead of in two separate
calls.

Since setting one of the properties requires a full redraw,
there is no performance advantage in setting them individually.

This fixes a theoretical bug: the colors of axis labels were not
updated appropriately. However, it seems like value-dependent
labels weren't used anyway.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
2ebe6e3684 profile: set alignment and scale of DiveTextItem at construction
Alignment and scale of DiveTextItems are never changed. Therefore,
pass them at construction time. This makes things much easier
if we want to cache the rendered text [currently the text is
rerendered at every paint() event].

This also removes the "parent=0" default parameter of the
constructor, because inadvertently leaving out the last argument
led to a subtle bug.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
8343691a38 profile: add height() member function to DiveTextItem
To layout the profile we need to determine the height
of texts. Add versions for a DiveTextItem and a static
function, which is passed the scale and dpr. The latter
is used to setup items, where we do not necessarily
have a text at creation time (e.g. the tankbar).

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
7dd9b65df0 profile: add width() function to DiveCartesian axis
To properly layout the profile we need to know the expected space
required by the vertical axes. In the general case, format the
the text "999". For the partial-pressure-axis, use "0.99".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
f713858ba4 profile: rename printFontScale to dpr (device pixel ratio)
The printFontScale is used to scale up fonts (and icons) when
rendering to high-DPI devices. With absolute scaling, this
will also be used to scale the size of different chart
regions, line thickness, etc. Therefore, give it an more
appropriate name. "Device pixel ratio", which is a well
established term, seems to appropriately describe the
concept.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Berthold Stoeger
01983c65c3 profile: pass fontPrintScale at construction time
Instead of intializing the text fields and then changing the
font scale via signal-rigmarole, pass down the font-scale
at construction time.

Since the fontPrintScale is only set in print mode, we also
can access it directly instead of testing for printMode.

Since the DiveTextItem is not updated using signals anymore,
the connected flag can be removed.

The commit is larger than I had hoped for, but this makes
things ultimately less brittle.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-12-17 11:54:23 -08:00
Dirk Hohndel
49d0bb8406 Add SPDX header to profile widgets
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29 13:32:55 -07:00
Tomaz Canabrava
1d6683f3e0 Move Profile widget out of desktop-widgets
The reason for that is, even if profile widget is made with qpainter
and for that reason it should be a desktop widget, it's being used
on the mobile version because of a lack of QML plotting library that
is fast and reliable.

We discovered that it was faster just to encapsulate our Profile in
a QML class and call it directly.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2015-10-30 10:36:49 -07:00
Renamed from desktop-widgets/profile/divetextitem.h (Browse further)