UI: refactor onboarding (#21223)
* refactor onboarding * skip training guide if is dashcam * apply review * cleanup include * move public ctro up * slots is private * cleanup headers * set style sheet in onboardingwindow * rebase master * match ui Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 8781f586c573be5e93cbc43ef88d201bcbdc43c9
This commit is contained in:
@@ -345,7 +345,7 @@ def thermald_thread():
|
||||
# with 2% left, we killall, otherwise the phone will take a long time to boot
|
||||
startup_conditions["free_space"] = msg.deviceState.freeSpacePercent > 2
|
||||
startup_conditions["completed_training"] = params.get("CompletedTrainingVersion") == training_version or \
|
||||
(current_branch in ['dashcam', 'dashcam-staging'])
|
||||
params.get_bool("Passive")
|
||||
startup_conditions["not_driver_view"] = not params.get_bool("IsDriverViewEnabled")
|
||||
startup_conditions["not_taking_snapshot"] = not params.get_bool("IsTakingSnapshot")
|
||||
# if any CPU gets above 107 or the battery gets above 63, kill all processes
|
||||
|
||||
@@ -88,15 +88,6 @@ void TermsPage::showEvent(QShowEvent *event) {
|
||||
accept_btn->setEnabled(false);
|
||||
buttons->addWidget(accept_btn);
|
||||
QObject::connect(accept_btn, &QPushButton::released, this, &TermsPage::acceptedTerms);
|
||||
|
||||
setStyleSheet(R"(
|
||||
QPushButton {
|
||||
padding: 50px;
|
||||
font-size: 50px;
|
||||
border-radius: 10px;
|
||||
background-color: #292929;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
void TermsPage::enableAccept() {
|
||||
@@ -137,23 +128,14 @@ void DeclinePage::showEvent(QShowEvent *event) {
|
||||
Params().putBool("DoUninstall", true);
|
||||
}
|
||||
});
|
||||
|
||||
setStyleSheet(R"(
|
||||
QPushButton {
|
||||
padding: 50px;
|
||||
font-size: 50px;
|
||||
border-radius: 10px;
|
||||
background-color: #292929;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
void OnboardingWindow::updateActiveScreen() {
|
||||
updateOnboardingStatus();
|
||||
|
||||
accepted_terms = params.get("HasAcceptedTerms") == current_terms_version;
|
||||
training_done = params.get("CompletedTrainingVersion") == current_training_version;
|
||||
if (!accepted_terms) {
|
||||
setCurrentIndex(0);
|
||||
} else if (!training_done) {
|
||||
} else if (!training_done && !params.getBool("Passive")) {
|
||||
setCurrentIndex(1);
|
||||
} else {
|
||||
emit onboardingDone();
|
||||
@@ -161,35 +143,27 @@ void OnboardingWindow::updateActiveScreen() {
|
||||
}
|
||||
|
||||
OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
|
||||
params = Params();
|
||||
current_terms_version = params.get("TermsVersion", false);
|
||||
current_training_version = params.get("TrainingVersion", false);
|
||||
current_terms_version = params.get("TermsVersion");
|
||||
current_training_version = params.get("TrainingVersion");
|
||||
|
||||
TermsPage* terms = new TermsPage(this);
|
||||
addWidget(terms);
|
||||
|
||||
connect(terms, &TermsPage::acceptedTerms, [=]() {
|
||||
Params().put("HasAcceptedTerms", current_terms_version);
|
||||
updateActiveScreen();
|
||||
});
|
||||
connect(terms, &TermsPage::declinedTerms, [=]() { setCurrentIndex(2); });
|
||||
|
||||
TrainingGuide* tr = new TrainingGuide(this);
|
||||
addWidget(tr);
|
||||
connect(tr, &TrainingGuide::completedTraining, [=]() {
|
||||
Params().put("CompletedTrainingVersion", current_training_version);
|
||||
updateActiveScreen();
|
||||
});
|
||||
addWidget(tr);
|
||||
|
||||
DeclinePage* declinePage = new DeclinePage(this);
|
||||
addWidget(declinePage);
|
||||
|
||||
connect(terms, &TermsPage::declinedTerms, [=]() {
|
||||
setCurrentIndex(2);
|
||||
});
|
||||
|
||||
connect(declinePage, &DeclinePage::getBack, [=]() {
|
||||
updateActiveScreen();
|
||||
});
|
||||
connect(declinePage, &DeclinePage::getBack, [=]() { updateActiveScreen(); });
|
||||
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
@@ -198,7 +172,8 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
|
||||
}
|
||||
QPushButton {
|
||||
padding: 50px;
|
||||
border-radius: 30px;
|
||||
font-size: 50px;
|
||||
border-radius: 10px;
|
||||
background-color: #292929;
|
||||
}
|
||||
QPushButton:disabled {
|
||||
@@ -206,16 +181,8 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
|
||||
background-color: #222222;
|
||||
}
|
||||
)");
|
||||
}
|
||||
|
||||
void OnboardingWindow::showEvent(QShowEvent *event) {
|
||||
updateActiveScreen();
|
||||
}
|
||||
|
||||
void OnboardingWindow::updateOnboardingStatus() {
|
||||
accepted_terms = params.get("HasAcceptedTerms", false).compare(current_terms_version) == 0;
|
||||
training_done = params.get("CompletedTrainingVersion", false).compare(current_training_version) == 0;
|
||||
}
|
||||
|
||||
bool OnboardingWindow::isOnboardingDone() {
|
||||
updateOnboardingStatus();
|
||||
return accepted_terms && training_done;
|
||||
}
|
||||
|
||||
@@ -14,12 +14,11 @@ class TrainingGuide : public QFrame {
|
||||
public:
|
||||
explicit TrainingGuide(QWidget *parent = 0) : QFrame(parent) {};
|
||||
|
||||
protected:
|
||||
private:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent* e) override;
|
||||
|
||||
private:
|
||||
QImage image;
|
||||
QPoint imageCorner;
|
||||
int currentIndex = 0;
|
||||
@@ -58,16 +57,15 @@ class TermsPage : public QFrame {
|
||||
public:
|
||||
explicit TermsPage(QWidget *parent = 0) : QFrame(parent) {};
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
QPushButton *accept_btn;
|
||||
QPushButton *decline_btn;
|
||||
|
||||
public slots:
|
||||
void enableAccept();
|
||||
|
||||
private:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
QPushButton *accept_btn;
|
||||
QPushButton *decline_btn;
|
||||
|
||||
signals:
|
||||
void acceptedTerms();
|
||||
void declinedTerms();
|
||||
@@ -79,10 +77,8 @@ class DeclinePage : public QFrame {
|
||||
public:
|
||||
explicit DeclinePage(QWidget *parent = 0) : QFrame(parent) {};
|
||||
|
||||
protected:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
private:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
QPushButton *back_btn;
|
||||
QPushButton *uninstall_btn;
|
||||
|
||||
@@ -95,20 +91,17 @@ class OnboardingWindow : public QStackedWidget {
|
||||
|
||||
public:
|
||||
explicit OnboardingWindow(QWidget *parent = 0);
|
||||
bool isOnboardingDone();
|
||||
|
||||
private:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
void updateActiveScreen();
|
||||
|
||||
Params params;
|
||||
std::string current_terms_version;
|
||||
std::string current_training_version;
|
||||
bool accepted_terms = false;
|
||||
bool training_done = false;
|
||||
void updateOnboardingStatus();
|
||||
|
||||
signals:
|
||||
void onboardingDone();
|
||||
void resetTrainingGuide();
|
||||
|
||||
public slots:
|
||||
void updateActiveScreen();
|
||||
};
|
||||
|
||||
@@ -147,13 +147,16 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||
resetCalibBtn->setDescription(desc);
|
||||
});
|
||||
|
||||
auto retrainingBtn = new ButtonControl("Review Training Guide", "REVIEW", "Review the rules, features, and limitations of openpilot");
|
||||
connect(retrainingBtn, &ButtonControl::released, [=]() {
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?", this)) {
|
||||
Params().remove("CompletedTrainingVersion");
|
||||
emit reviewTrainingGuide();
|
||||
}
|
||||
});
|
||||
ButtonControl *retrainingBtn = nullptr;
|
||||
if (!params.getBool("Passive")) {
|
||||
retrainingBtn = new ButtonControl("Review Training Guide", "REVIEW", "Review the rules, features, and limitations of openpilot");
|
||||
connect(retrainingBtn, &ButtonControl::released, [=]() {
|
||||
if (ConfirmationDialog::confirm("Are you sure you want to review the training guide?", this)) {
|
||||
Params().remove("CompletedTrainingVersion");
|
||||
emit reviewTrainingGuide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
auto uninstallBtn = new ButtonControl("Uninstall " + getBrand(), "UNINSTALL");
|
||||
connect(uninstallBtn, &ButtonControl::released, [=]() {
|
||||
@@ -163,9 +166,11 @@ DevicePanel::DevicePanel(QWidget* parent) : QWidget(parent) {
|
||||
});
|
||||
|
||||
for (auto btn : {dcamBtn, resetCalibBtn, retrainingBtn, uninstallBtn}) {
|
||||
main_layout->addWidget(horizontal_line());
|
||||
connect(parent, SIGNAL(offroadTransition(bool)), btn, SLOT(setEnabled(bool)));
|
||||
main_layout->addWidget(btn);
|
||||
if (btn) {
|
||||
main_layout->addWidget(horizontal_line());
|
||||
connect(parent, SIGNAL(offroadTransition(bool)), btn, SLOT(setEnabled(bool)));
|
||||
main_layout->addWidget(btn);
|
||||
}
|
||||
}
|
||||
|
||||
// power buttons
|
||||
|
||||
@@ -8,6 +8,12 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
|
||||
main_layout = new QStackedLayout(this);
|
||||
main_layout->setMargin(0);
|
||||
|
||||
onboardingWindow = new OnboardingWindow(this);
|
||||
main_layout->addWidget(onboardingWindow);
|
||||
QObject::connect(onboardingWindow, &OnboardingWindow::onboardingDone, [=]() {
|
||||
main_layout->setCurrentWidget(homeWindow);
|
||||
});
|
||||
|
||||
homeWindow = new HomeWindow(this);
|
||||
main_layout->addWidget(homeWindow);
|
||||
QObject::connect(homeWindow, &HomeWindow::openSettings, this, &MainWindow::openSettings);
|
||||
@@ -21,26 +27,25 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
|
||||
main_layout->addWidget(settingsWindow);
|
||||
QObject::connect(settingsWindow, &SettingsWindow::closeSettings, this, &MainWindow::closeSettings);
|
||||
QObject::connect(&qs, &QUIState::offroadTransition, settingsWindow, &SettingsWindow::offroadTransition);
|
||||
QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, this, &MainWindow::reviewTrainingGuide);
|
||||
QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, [=]() {
|
||||
main_layout->setCurrentWidget(onboardingWindow);
|
||||
});
|
||||
QObject::connect(settingsWindow, &SettingsWindow::showDriverView, [=] {
|
||||
homeWindow->showDriverView(true);
|
||||
});
|
||||
|
||||
onboardingWindow = new OnboardingWindow(this);
|
||||
onboardingDone = onboardingWindow->isOnboardingDone();
|
||||
main_layout->addWidget(onboardingWindow);
|
||||
|
||||
main_layout->setCurrentWidget(onboardingWindow);
|
||||
QObject::connect(onboardingWindow, &OnboardingWindow::onboardingDone, [=]() {
|
||||
onboardingDone = true;
|
||||
closeSettings();
|
||||
});
|
||||
onboardingWindow->updateActiveScreen();
|
||||
|
||||
device.setAwake(true, true);
|
||||
QObject::connect(&qs, &QUIState::uiUpdate, &device, &Device::update);
|
||||
QObject::connect(&qs, &QUIState::offroadTransition, this, &MainWindow::offroadTransition);
|
||||
QObject::connect(&device, &Device::displayPowerChanged, this, &MainWindow::closeSettings);
|
||||
QObject::connect(&qs, &QUIState::offroadTransition, [=](bool offroad) {
|
||||
if (!offroad) {
|
||||
closeSettings();
|
||||
}
|
||||
});
|
||||
QObject::connect(&device, &Device::displayPowerChanged, [=]() {
|
||||
if(main_layout->currentWidget() != onboardingWindow) {
|
||||
closeSettings();
|
||||
}
|
||||
});
|
||||
|
||||
// load fonts
|
||||
QFontDatabase::addApplicationFont("../assets/fonts/opensans_regular.ttf");
|
||||
@@ -56,26 +61,12 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
|
||||
)");
|
||||
}
|
||||
|
||||
void MainWindow::offroadTransition(bool offroad) {
|
||||
if(!offroad) {
|
||||
closeSettings();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::openSettings() {
|
||||
main_layout->setCurrentWidget(settingsWindow);
|
||||
}
|
||||
|
||||
void MainWindow::closeSettings() {
|
||||
if(onboardingDone) {
|
||||
main_layout->setCurrentWidget(homeWindow);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::reviewTrainingGuide() {
|
||||
onboardingDone = false;
|
||||
main_layout->setCurrentWidget(onboardingWindow);
|
||||
onboardingWindow->updateActiveScreen();
|
||||
main_layout->setCurrentWidget(homeWindow);
|
||||
}
|
||||
|
||||
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
#include "selfdrive/ui/qt/home.h"
|
||||
#include "selfdrive/ui/qt/offroad/onboarding.h"
|
||||
#include "selfdrive/ui/qt/offroad/settings.h"
|
||||
#include "selfdrive/ui/ui.h"
|
||||
|
||||
class MainWindow : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||
void openSettings();
|
||||
void closeSettings();
|
||||
|
||||
Device device;
|
||||
QUIState qs;
|
||||
|
||||
@@ -25,11 +25,4 @@ private:
|
||||
HomeWindow *homeWindow;
|
||||
SettingsWindow *settingsWindow;
|
||||
OnboardingWindow *onboardingWindow;
|
||||
bool onboardingDone = false;
|
||||
|
||||
public slots:
|
||||
void offroadTransition(bool offroad);
|
||||
void openSettings();
|
||||
void closeSettings();
|
||||
void reviewTrainingGuide();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user