nopenpilot/selfdrive/ui/qt/offroad/onboarding.cc

113 lines
2.9 KiB
C++
Raw Normal View History

#include <QLabel>
2020-11-12 22:37:02 -07:00
#include <QString>
#include <QPushButton>
#include <QGridLayout>
2020-11-12 22:37:02 -07:00
#include "onboarding.hpp"
#include "common/params.h"
2020-11-12 22:37:02 -07:00
QLabel * title_label(QString text) {
QLabel *l = new QLabel(text);
l->setStyleSheet(R"(font-size: 100px;)");
l->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
return l;
}
QWidget * OnboardingWindow::terms_screen() {
2020-11-12 22:37:02 -07:00
QGridLayout *main_layout = new QGridLayout();
main_layout->setMargin(30);
main_layout->setSpacing(30);
2020-11-12 22:37:02 -07:00
main_layout->addWidget(title_label("Review Terms"), 0, 0, 1, -1);
QLabel *terms = new QLabel("See terms at https://my.comma.ai/terms");
terms->setAlignment(Qt::AlignCenter);
2020-11-12 22:37:02 -07:00
terms->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
terms->setStyleSheet(R"(
2020-11-12 22:37:02 -07:00
font-size: 75px;
border-radius: 10px;
background-color: #292929;
)");
2020-11-12 22:37:02 -07:00
main_layout->addWidget(terms, 1, 0, 1, -1);
2020-11-12 22:37:02 -07:00
main_layout->addWidget(new QPushButton("Decline"), 2, 0);
QPushButton *accept_btn = new QPushButton("Accept");
2020-11-12 22:37:02 -07:00
main_layout->addWidget(accept_btn, 2, 1);
QObject::connect(accept_btn, &QPushButton::released, [=]() {
Params().write_db_value("HasAcceptedTerms", LATEST_TERMS_VERSION);
updateActiveScreen();
});
QWidget *widget = new QWidget;
widget->setLayout(main_layout);
widget->setStyleSheet(R"(
QPushButton {
font-size: 50px;
padding: 50px;
border-radius: 10px;
background-color: #292929;
}
)");
return widget;
}
2020-11-12 22:37:02 -07:00
QWidget * OnboardingWindow::training_screen() {
QGridLayout *main_layout = new QGridLayout();
main_layout->setMargin(30);
main_layout->setSpacing(30);
main_layout->addWidget(title_label("Training Guide"), 0, 0);
QPushButton *btn = new QPushButton("Continue");
main_layout->addWidget(btn, 1, 0);
QObject::connect(btn, &QPushButton::released, [=]() {
Params().write_db_value("CompletedTrainingVersion", LATEST_TRAINING_VERSION);
updateActiveScreen();
});
QWidget *widget = new QWidget;
widget->setLayout(main_layout);
return widget;
}
void OnboardingWindow::updateActiveScreen() {
Params params = Params();
bool accepted_terms = params.get("HasAcceptedTerms", false).compare(LATEST_TERMS_VERSION) == 0;
2020-11-12 22:37:02 -07:00
bool training_done = params.get("CompletedTrainingVersion", false).compare(LATEST_TRAINING_VERSION) == 0;
2020-11-12 22:37:02 -07:00
if (!accepted_terms) {
layout->setCurrentIndex(0);
} else if (!training_done) {
layout->setCurrentIndex(1);
} else {
emit onboardingDone();
}
}
OnboardingWindow::OnboardingWindow(QWidget *parent) : QWidget(parent) {
2020-11-12 22:37:02 -07:00
layout = new QStackedLayout();
layout->addWidget(terms_screen());
layout->addWidget(training_screen());
2020-11-12 22:37:02 -07:00
setLayout(layout);
setStyleSheet(R"(
* {
background-color: black;
}
2020-11-12 22:37:02 -07:00
QPushButton {
font-size: 50px;
padding: 50px;
border-radius: 10px;
background-color: #292929;
}
)");
updateActiveScreen();
}