cleanup training guide

old-commit-hash: d3756bc475
commatwo_master
Adeeb Shihadeh 4 years ago
parent 9518779d56
commit 48282f36a4
  1. 37
      selfdrive/ui/qt/offroad/onboarding.cc
  2. 6
      selfdrive/ui/qt/offroad/onboarding.hpp

@ -3,14 +3,10 @@
#include <QPushButton> #include <QPushButton>
#include <QGridLayout> #include <QGridLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QDebug>
#include <QGuiApplication>
#include <QScreen>
#include <QApplication>
#include <QDesktopWidget> #include <QDesktopWidget>
#include "onboarding.hpp"
#include "common/params.h" #include "common/params.h"
#include "onboarding.hpp"
#include "home.hpp" #include "home.hpp"
@ -20,22 +16,20 @@ QLabel * title_label(QString text) {
return l; return l;
} }
QWidget* layout2Widget(QLayout* l){ QWidget * layout2Widget(QLayout* l){
QWidget* q = new QWidget; QWidget *q = new QWidget;
q->setLayout(l); q->setLayout(l);
return q; return q;
} }
void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) {
int leftOffset = (geometry().width()-1620)/2; int leftOffset = (geometry().width()-1620)/2;
int mousex = e->x()-leftOffset; int mousex = e->x()-leftOffset;
int mousey = e->y(); int mousey = e->y();
// Check for restart // Check for restart
if (currentIndex == numberOfFrames-1) { if (currentIndex == boundingBox.size()-1) {
if (1050 <= mousex && mousex <= 1500 && 773 <= mousey && mousey <= 954){ if (1050 <= mousex && mousex <= 1500 && 773 <= mousey && mousey <= 954){
slayout->setCurrentIndex(0); slayout->setCurrentIndex(0);
currentIndex = 0; currentIndex = 0;
@ -46,7 +40,7 @@ void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) {
if (boundingBox[currentIndex][0] <= mousex && mousex <= boundingBox[currentIndex][1] && boundingBox[currentIndex][2] <= mousey && mousey <= boundingBox[currentIndex][3]) { if (boundingBox[currentIndex][0] <= mousex && mousex <= boundingBox[currentIndex][1] && boundingBox[currentIndex][2] <= mousey && mousey <= boundingBox[currentIndex][3]) {
slayout->setCurrentIndex(++currentIndex); slayout->setCurrentIndex(++currentIndex);
} }
if (currentIndex >= numberOfFrames) { if (currentIndex >= boundingBox.size()) {
emit completedTraining(); emit completedTraining();
return; return;
} }
@ -56,7 +50,7 @@ TrainingGuide::TrainingGuide(QWidget* parent) {
QHBoxLayout* hlayout = new QHBoxLayout; QHBoxLayout* hlayout = new QHBoxLayout;
slayout = new QStackedLayout(this); slayout = new QStackedLayout(this);
for (int i = 0; i <= 14; i++) { for (int i = 0; i < boundingBox.size(); i++) {
QWidget* w = new QWidget; QWidget* w = new QWidget;
w->setStyleSheet(".QWidget {background-image: url(../assets/training/step" + QString::number(i) + ".jpg);}"); w->setStyleSheet(".QWidget {background-image: url(../assets/training/step" + QString::number(i) + ".jpg);}");
w->setFixedSize(1620, 1080); w->setFixedSize(1620, 1080);
@ -90,7 +84,7 @@ QWidget* OnboardingWindow::terms_screen() {
QPushButton *accept_btn = new QPushButton("Accept"); QPushButton *accept_btn = new QPushButton("Accept");
main_layout->addWidget(accept_btn, 2, 1); main_layout->addWidget(accept_btn, 2, 1);
QObject::connect(accept_btn, &QPushButton::released, [=]() { QObject::connect(accept_btn, &QPushButton::released, [=]() {
Params().write_db_value("HasAcceptedTerms", current_terms_version.toStdString()); Params().write_db_value("HasAcceptedTerms", current_terms_version);
updateActiveScreen(); updateActiveScreen();
}); });
@ -112,9 +106,9 @@ QWidget* OnboardingWindow::terms_screen() {
void OnboardingWindow::updateActiveScreen() { void OnboardingWindow::updateActiveScreen() {
Params params = Params(); Params params = Params();
bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version.toStdString()) == 0; bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0;
bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version.toStdString()) == 0; bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0;
if (!accepted_terms) { if (!accepted_terms) {
setCurrentIndex(0); setCurrentIndex(0);
} else if (!training_done) { } else if (!training_done) {
@ -126,11 +120,16 @@ void OnboardingWindow::updateActiveScreen() {
OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
Params params = Params(); Params params = Params();
current_terms_version = QString::fromStdString(params.get("TermsVersion", false)); current_terms_version = params.get("TermsVersion", false);
current_training_version = QString::fromStdString(params.get("TrainingVersion", false)); current_training_version = params.get("TrainingVersion", false);
addWidget(terms_screen()); addWidget(terms_screen());
TrainingGuide* tr = new TrainingGuide(this); TrainingGuide* tr = new TrainingGuide(this);
connect(tr, &TrainingGuide::completedTraining, [=](){Params().write_db_value("CompletedTrainingVersion", current_training_version.toStdString()); updateActiveScreen();}); connect(tr, &TrainingGuide::completedTraining, [=](){
Params().write_db_value("CompletedTrainingVersion", current_training_version);
updateActiveScreen();
});
addWidget(tr); addWidget(tr);
setStyleSheet(R"( setStyleSheet(R"(

@ -14,9 +14,9 @@ public:
protected: protected:
void mouseReleaseEvent(QMouseEvent* e) override; void mouseReleaseEvent(QMouseEvent* e) override;
private: private:
int currentIndex = 0; int currentIndex = 0;
const int numberOfFrames = 15;
QStackedLayout* slayout; QStackedLayout* slayout;
//Vector of bounding boxes for the next step. (minx, maxx, miny, maxy) //Vector of bounding boxes for the next step. (minx, maxx, miny, maxy)
QVector<QVector<int>> boundingBox {{250, 930, 750, 900}, {280, 1280, 650, 950}, {330, 1130, 590, 900}, {910, 1580, 500, 1000}, {1180, 1300, 630, 720}, {290, 1050, 590, 960}, QVector<QVector<int>> boundingBox {{250, 930, 750, 900}, {280, 1280, 650, 950}, {330, 1130, 590, 900}, {910, 1580, 500, 1000}, {1180, 1300, 630, 720}, {290, 1050, 590, 960},
@ -33,8 +33,8 @@ public:
explicit OnboardingWindow(QWidget *parent = 0); explicit OnboardingWindow(QWidget *parent = 0);
private: private:
QString current_terms_version; std::string current_terms_version;
QString current_training_version; std::string current_training_version;
QWidget * terms_screen(); QWidget * terms_screen();
QWidget * training_screen(); QWidget * training_screen();

Loading…
Cancel
Save