From 3e64b5d14cb073decaafbeb8390d37324c2d049f Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sat, 20 Mar 2021 03:11:54 -0700 Subject: [PATCH] clean up --- selfdrive/ui/qt/offroad/onboarding.cc | 33 ++++++++++---------------- selfdrive/ui/qt/offroad/onboarding.hpp | 5 ++-- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index a0e1641fdb..002dab7b87 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -7,6 +7,7 @@ #include #include #include + #include "common/params.h" #include "onboarding.hpp" #include "home.hpp" @@ -20,18 +21,21 @@ void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { int mousey = e->y(); // Check for restart - if (currentIndex == (boundingBox.size() - 1) && 1050 <= mousex && mousex <= 1500 && 773 <= mousey && mousey <= 954) { + if (currentIndex == (boundingBox.size() - 1) && 1050 <= mousex && mousex <= 1500 && + 773 <= mousey && mousey <= 954) { currentIndex = 0; - } else if (boundingBox[currentIndex][0] <= mousex && mousex <= boundingBox[currentIndex][1] && boundingBox[currentIndex][2] <= mousey && mousey <= boundingBox[currentIndex][3]) { - ++currentIndex; + } else if (boundingBox[currentIndex][0] <= mousex && mousex <= boundingBox[currentIndex][1] && + boundingBox[currentIndex][2] <= mousey && mousey <= boundingBox[currentIndex][3]) { + currentIndex += 1; } + if (currentIndex >= boundingBox.size()) { emit completedTraining(); return; + } else { + image.load("../assets/training/step" + QString::number(currentIndex) + ".jpg"); + update(); } - - image.load("../assets/training/step" + QString::number(currentIndex) + ".jpg"); - repaint(); } TrainingGuide::TrainingGuide(QWidget* parent) { @@ -79,16 +83,6 @@ QWidget* OnboardingWindow::terms_screen() { // TODO: tune the scrolling auto sb = terms_text->verticalScrollBar(); - QScrollerProperties sp; - - sp.setScrollMetric(QScrollerProperties::DragStartDistance, 0.001); - sp.setScrollMetric(QScrollerProperties::DecelerationFactor, 0.4); - sp.setScrollMetric(QScrollerProperties::DragVelocitySmoothingFactor, 0.5); - sp.setScrollMetric(QScrollerProperties::MaximumVelocity, 1.0); - - scroller = QScroller::scroller(terms_text); - scroller->setScrollerProperties(sp); - #ifdef QCOM2 sb->setStyleSheet(R"( QScrollBar { @@ -133,10 +127,9 @@ QWidget* OnboardingWindow::terms_screen() { } void OnboardingWindow::updateActiveScreen() { - Params params = Params(); - bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; + if (!accepted_terms) { setCurrentIndex(0); } else if (!training_done) { @@ -147,11 +140,9 @@ void OnboardingWindow::updateActiveScreen() { } OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { - Params params = Params(); + params = Params(); current_terms_version = params.get("TermsVersion", false); current_training_version = params.get("TrainingVersion", false); - bool accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0; - bool training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0; addWidget(terms_screen()); diff --git a/selfdrive/ui/qt/offroad/onboarding.hpp b/selfdrive/ui/qt/offroad/onboarding.hpp index 250caadae9..e307bb63a5 100644 --- a/selfdrive/ui/qt/offroad/onboarding.hpp +++ b/selfdrive/ui/qt/offroad/onboarding.hpp @@ -1,12 +1,13 @@ #pragma once #include -#include #include #include #include #include +#include "selfdrive/common/params.h" + class TrainingGuide : public QFrame { Q_OBJECT @@ -36,13 +37,13 @@ public: explicit OnboardingWindow(QWidget *parent = 0); private: + Params params; std::string current_terms_version; std::string current_training_version; QTextEdit *terms_text; QWidget *terms_screen(); QWidget *training_screen(); - QScroller *scroller; signals: void onboardingDone();