Rendering resets the size, which now recalculates the axes.
Therefore, plotDive() must be called. The callers were doing
the opposite: call plotDive() first, then draw().
To make it easier for the callers, present a single interface
that handles these subtleties.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The chart items were laid out in relative terms with respect
to a fixed scene size (100.0, 100.0). This simply does not
cut it when resizing the chart. Why should the axes always
occupy the same fraction of the chart independent of the size.
Moreover, this led to basically unmaintainable code.
Resize the scene according to the viewport and do
absolute placement of the items. This breaks the layout,
but at least now we have a chance to fix things
somewhat reasonably.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The profile would reload for many settings-changed signals.
It didn't listen to the deco-info-changed signal, because
that had no effect (which seems to be a bug).
Since this flag should indicate whether the deco-info is
shown and therefore a change should replot the profile,
let's listen to the corresponding signal.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The grid color is saved on construction, no need to pass a parameter.
Note that this fixes a bug where the color was passed as animation
speed. Ooops. That's what you get from weak typing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is less hassle, than passing these around as parameters.
Note: The values are stored but not yet used ("position" has
not use yet and gridColor is still passed as parameter).
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To properly layout the axes, it is necessary to specify on
which side of the chart they are located.
There is already an "Orientation" enum. However, that gives
the direction (top-to-bottom, etc.), but not the position.
It might become obsolete in the future, since the direction
can also be expressed by setting min and max accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
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>
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>
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>
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>
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>
Since there (currently) is no interactive widget on mobile, there
is no point in compiling it. This was a bit more complicated than
expected, since there were other source files (divehandler.cpp
and ruleritem.cpp) which reference ProfileWidget2 and therefore
need to be removed. Otherwise, the dreadful MOC produces unresolved
references.
We could now remove all the conditional compiles in
profilewidget2.cpp, but let's keep them for now. We might have
to readd a number of them later, when making the mobile-profile
interactive.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The print mode is passed on construction, not retroactively.
This function thus became unused.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Instead of using the interactive ProfileWidget2, just
use the ProfileScene to render the profile for printing,
export and mobile. One layer (QWidget) less.
This removes all the kludges for handling DPR on mobile.
Thus, the rendering will now be off and have to be fixed
by redoing the scaling code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Setting the profile and grayscale mode of the profile via
functions is from a time when the same profile widget was
used for printing and the UI. It is simpler to set the mode
when constructing the object and not deal with changes.
To prepare for this scenario, take the flag at construction
time. This still keeps the callers as-is. These will be
adapted later.
Logically, then the printFlag also has to be set in
DiveCartesianAxis at construction time.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The cartesian axes use animSpeed to animate changes. Instead
of passing down the value to the respective functions, the
speed was stored in the ProfileScene and the axes would
access it there. Very messy. Let's just pass down the speed.
There still are back-references from the axes to the scene,
notably to place labels "outside" of the scene. Let's try
to remove them later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This finalizes the split between interactive (ProfileWidget2)
and non-interactive (ProfileScene) parts of the profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the ProfileScene does the actual rendering, it needs
access to the "printMode", "isGrayScale" and "fontPrintScale"
variables. Move them down from ProfileView to ProfileScene.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The mode of the profile (profile, edit, plan) was set in
MainWindow and ProfileWidget. For consistency move the one
setProfileState() call from MainWindow to ProfileWidget.
This removes a direct access to the profile-view and
therefore improves encapsulation.
Also, clear the profile, when no dive is shown to remove
any potentially dangling references.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was moved to the desktop version. Enter the profile in
the constructor. Somewhat surprisingly, this seems to work.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The profile has an "empty state" showing the subsurface logo,
which is active when no dive is selected.
Switching to/from this mode is quite complex, because all the
chart features have to be hidden/shown, etc. Moreover, this mode
is not needed on mobile, where multiple ProfileWidgets can
be active at the same time and every dive has at least a
"faked" profile.
Therefore, implement this mode directly in the desktop
version of the widget. This makes the rescaling distinctly
less cumbersome. It is implemented using a QStackedWidget,
which switches between the profile and the logo.
This commit does not remove the empty state from the profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since using separate profile-instances for print/export,
we never exit print mode. Therefore, the mode parameter
can be removed. This is a preparatory commit for passing
the printMode at construction time.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Part of separating the static (for printing, export) and
dynamic (UI) parts of the profile. This is still quite messy
with many direct accesses from the ProfileWidget.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This simply subclasses QGraphicsScene and is used as
a drop-in replacement. The plan is to step-by-step
move rendering functions there until the non-interactive
code can only use the scene and doesn't have to use
the QGraphicsView. This will hopefully remove quite
some conditional code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The usage of the DiveProfileItems has changed (axes, etc. are passed
at construction time). Update a comment accordingly.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The font print scale is now set once on construction and this
function can therefore be removed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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>
The constructors of Time- and TemperatureAxis don't do anything.
In reasonable modern C++ we can simply reuse the constructor
of the base class with a "using" directive.
The point here is to simplify followup commits that will
add additional parameters to the constructors of the axes.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was only used internally - there is no point in an
accessor function. It only makes grepping more complicated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Not having to readjust the scale on-demand will make the
code distinctly simpler. Let's just pass it once.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Thus, we can keep the scale factor constant during existence
of the view. For now, this is simpler than adapting existing
text elements. We might want to make this more flexible later.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The current way of handling the "print scale factor" is
complex: The text fields are added and later resized via
signals. Things could be simplified by just redoing the
chart when changing the scale factor.
Moreover, in the future we will want to adapt the size of the
axes depending on the size of the texts.
As a first step, factor out the creation of the profile-widget.
This can then be used to recreate the profile when changing
the scale factor.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The alternative spelling "visibile" made searching for this
function very annoying. That makes removing it even more
satisfying.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Very annoyingly, to render the profile for printing / export,
the profile still had to be show()n, thus requiring a parent
window.
Analysis of qmlprofile.c showed that this was due to the
transformation matrix not being properly set up on non-show()n
scenes.
Instead, we can simply render via the QGraphicsScene
(circumventing the QGraphicsView).
The code was factored out into the ProfileWidget2::draw()
function. This will hopefully make it easier to change
the size-code of the profile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Create a new class that encapsulates the profile-widget UI.
This is called ProfileWidget, which might be confusing since
the actual display is called ProfileWidget2. However, the
plan is to rename the latter to ProfileView. After all, it
is also used to print and to show the profile on mobile.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The MainWindow::configureToolBar() function is called every
time plotCurrentDive() is called. Moreover, this is the only
time that it is called. We might just fold the former into
the latter.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Just as for printing, use an independent profile widget, so
that the UI widget doesn't have to be set/reset.
Also, make the size of the exported image independent from
the current window size.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When multiple profiles were exported, for every exported image
the profile-widget was switched to/from print mode.
Move this out of the loop, i.e. initialize and reset the profile
only once. This should slightly speed up export, but not by a lot,
since most of the time is spent by compressing the PNGs.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The exportProfile function uses the UI and therefore was
supposed to be declared in backend-shared/* but defined
separately for desktop and mobile. Currently, only the
desktop version exists.
The goal however should be that there is no need of the
UI for this function. In a first step, move the function
to the common backend-shared/* code and conditionally
compile for desktop. In upcoming commits, the function
will be made independent of the UI.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
In analogy to normal printing, don't misuse the mainwindow's
profile widget to do the printing.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
When printing the dives were rendered into the visible profile.
This meant setting a number of flags and reverting after printing.
That's obviously quite brittle.
Instead, use a separate profile instance, since we can have
different profiles showing different dives now.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>