profile: implement "empty state" in desktop's ProfileWidget

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>
This commit is contained in:
Berthold Stoeger 2021-06-30 07:17:40 +02:00 committed by Dirk Hohndel
parent 9f6e487790
commit 787a23f017
2 changed files with 78 additions and 4 deletions

View file

@ -8,6 +8,45 @@
#include <QToolBar>
#include <QHBoxLayout>
#include <QStackedWidget>
#include <QLabel>
// A resizing display of the Subsurface logo when no dive is shown
class EmptyView : public QLabel {
public:
EmptyView(QWidget *parent = nullptr);
~EmptyView();
private:
QPixmap logo;
void update();
void resizeEvent(QResizeEvent *) override;
};
EmptyView::EmptyView(QWidget *parent) : QLabel(parent),
logo(":poster-icon")
{
QPalette pal;
pal.setColor(QPalette::Window, getColor(::BACKGROUND));
setAutoFillBackground(true);
setPalette(pal);
setMinimumSize(1,1);
setAlignment(Qt::AlignHCenter);
update();
}
EmptyView::~EmptyView()
{
}
void EmptyView::update()
{
setPixmap(logo.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
void EmptyView::resizeEvent(QResizeEvent *)
{
update();
}
ProfileWidget::ProfileWidget()
{
@ -26,18 +65,25 @@ ProfileWidget::ProfileWidget()
ui.profHR, // very few dive computers support this
ui.profTissues }; // maybe less frequently used
emptyView.reset(new EmptyView);
view.reset(new ProfileWidget2(DivePlannerPointsModel::instance(), 1.0, this));
QToolBar *toolBar = new QToolBar(this);
for (QAction *a: toolbarActions)
toolBar->addAction(a);
toolBar->setOrientation(Qt::Vertical);
toolBar->setIconSize(QSize(24, 24));
stack = new QStackedWidget(this);
stack->addWidget(emptyView.get());
stack->addWidget(view.get());
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(toolBar);
layout->addWidget(view.get());
layout->addWidget(stack);
setLayout(layout);
// Toolbar Connections related to the Profile Update
@ -128,9 +174,33 @@ void ProfileWidget::setDive(const struct dive *d)
void ProfileWidget::plotCurrentDive()
{
setEnabledToolbar(current_dive != nullptr);
if (current_dive)
setDive(current_dive);
view->plotDive(current_dive, dc_number);
if (current_dive) {
stack->setCurrentIndex(1);
bool freeDiveMode = current_dive->dc.divemode == FREEDIVE;
ui.profCalcCeiling->setDisabled(freeDiveMode);
ui.profCalcCeiling->setDisabled(freeDiveMode);
ui.profCalcAllTissues ->setDisabled(freeDiveMode);
ui.profIncrement3m->setDisabled(freeDiveMode);
ui.profDcCeiling->setDisabled(freeDiveMode);
ui.profPhe->setDisabled(freeDiveMode);
ui.profPn2->setDisabled(freeDiveMode); //TODO is the same as scuba?
ui.profPO2->setDisabled(freeDiveMode); //TODO is the same as scuba?
ui.profTankbar->setDisabled(freeDiveMode);
ui.profMod->setDisabled(freeDiveMode);
ui.profNdl_tts->setDisabled(freeDiveMode);
ui.profDeco->setDisabled(freeDiveMode);
ui.profEad->setDisabled(freeDiveMode);
ui.profSAC->setDisabled(freeDiveMode);
ui.profTissues->setDisabled(freeDiveMode);
ui.profRuler->setDisabled(false);
ui.profScaled->setDisabled(false); // measuring and scaling
ui.profTogglePicture->setDisabled(false);
ui.profHR->setDisabled(false);
view->plotDive(current_dive, dc_number);
} else {
stack->setCurrentIndex(0);
}
}
void ProfileWidget::setPlanState(const struct dive *d, int dc)

View file

@ -10,6 +10,8 @@
#include <memory>
class ProfileWidget2;
class EmptyView;
class QStackedWidget;
class ProfileWidget : public QWidget {
Q_OBJECT
@ -26,8 +28,10 @@ slots:
void unsetProfHR();
void unsetProfTissues();
private:
std::unique_ptr<EmptyView> emptyView;
std::vector<QAction *> toolbarActions;
Ui::ProfileWidget ui;
QStackedWidget *stack;
void setDive(const struct dive *d);
};