mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-14 06:52:08 +08:00
Refactor onboarding process and terms page in Sunnypilot
The code modifications refactor the onboarding window and terms page in Sunnypilot. It includes moving OnboardingWindow to the protective area, and changing OnboardingWindowSP into a subclass of OnboardingWindow, which enhances code encapsulation and reusability. The expressions for the terms agreement pages are also refined for better readability. initial onboarding
This commit is contained in:
@@ -106,8 +106,7 @@ void TermsPage::showEvent(QShowEvent *event) {
|
||||
text->setAttribute(Qt::WA_AlwaysStackOnTop);
|
||||
text->setClearColor(QColor("#1B1B1B"));
|
||||
|
||||
std::string tc_text = sunnypilot_tc ? "../assets/offroad/sp_tc.html" : "../assets/offroad/tc.html";
|
||||
QString text_view = util::read_file(tc_text).c_str();
|
||||
QString text_view = util::read_file("../assets/offroad/tc.html").c_str();
|
||||
text->rootContext()->setContextProperty("text_view", text_view);
|
||||
|
||||
text->setSource(QUrl::fromLocalFile("qt/offroad/text_view.qml"));
|
||||
@@ -186,8 +185,6 @@ void OnboardingWindow::updateActiveScreen() {
|
||||
setCurrentIndex(0);
|
||||
} else if (!training_done) {
|
||||
setCurrentIndex(1);
|
||||
} else if (!accepted_terms_sp) {
|
||||
setCurrentIndex(3);
|
||||
} else {
|
||||
emit onboardingDone();
|
||||
}
|
||||
@@ -195,13 +192,11 @@ void OnboardingWindow::updateActiveScreen() {
|
||||
|
||||
OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
|
||||
std::string current_terms_version = params.get("TermsVersion");
|
||||
std::string current_terms_version_sp = params.get("TermsVersionSunnypilot");
|
||||
std::string current_training_version = params.get("TrainingVersion");
|
||||
accepted_terms = params.get("HasAcceptedTerms") == current_terms_version;
|
||||
accepted_terms_sp = params.get("HasAcceptedTermsSP") == current_terms_version_sp;
|
||||
training_done = params.get("CompletedTrainingVersion") == current_training_version;
|
||||
|
||||
TermsPage* terms = new TermsPage(false, this);
|
||||
TermsPage* terms = new TermsPage(this);
|
||||
addWidget(terms);
|
||||
connect(terms, &TermsPage::acceptedTerms, [=]() {
|
||||
params.put("HasAcceptedTerms", current_terms_version);
|
||||
@@ -222,15 +217,6 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
|
||||
addWidget(declinePage);
|
||||
connect(declinePage, &DeclinePage::getBack, [=]() { updateActiveScreen(); });
|
||||
|
||||
TermsPage* terms_sp = new TermsPage(true, this);
|
||||
addWidget(terms_sp); // index = 3
|
||||
connect(terms_sp, &TermsPage::acceptedTerms, [=]() {
|
||||
params.put("HasAcceptedTermsSP", current_terms_version_sp);
|
||||
accepted_terms_sp = true;
|
||||
updateActiveScreen();
|
||||
});
|
||||
connect(terms_sp, &TermsPage::declinedTerms, [=]() { setCurrentIndex(2); });
|
||||
|
||||
setStyleSheet(R"(
|
||||
* {
|
||||
color: white;
|
||||
@@ -245,4 +231,4 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) {
|
||||
}
|
||||
)");
|
||||
updateActiveScreen();
|
||||
}
|
||||
}
|
||||
@@ -63,16 +63,17 @@ class TermsPage : public QFrame {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TermsPage(bool sunnypilot = false, QWidget *parent = 0) : QFrame(parent), sunnypilot_tc(sunnypilot) {}
|
||||
explicit TermsPage(QWidget *parent = 0) : QFrame(parent) {}
|
||||
|
||||
public slots:
|
||||
void enableAccept();
|
||||
|
||||
protected:
|
||||
QPushButton *accept_btn;
|
||||
|
||||
private:
|
||||
void showEvent(QShowEvent *event) override;
|
||||
|
||||
QPushButton *accept_btn;
|
||||
bool sunnypilot_tc = false;
|
||||
|
||||
signals:
|
||||
void acceptedTerms();
|
||||
@@ -98,14 +99,14 @@ class OnboardingWindow : public QStackedWidget {
|
||||
public:
|
||||
explicit OnboardingWindow(QWidget *parent = 0);
|
||||
inline void showTrainingGuide() { setCurrentIndex(1); }
|
||||
inline bool completed() const { return accepted_terms && accepted_terms_sp && training_done; }
|
||||
virtual inline bool completed() const { return accepted_terms && training_done; }
|
||||
|
||||
private:
|
||||
void updateActiveScreen();
|
||||
protected:
|
||||
virtual void updateActiveScreen();
|
||||
|
||||
Params params;
|
||||
bool accepted_terms = false, accepted_terms_sp = false, training_done = false;
|
||||
bool accepted_terms = false, training_done = false;
|
||||
|
||||
signals:
|
||||
void onboardingDone();
|
||||
};
|
||||
};
|
||||
@@ -17,6 +17,7 @@ protected:
|
||||
explicit MainWindow(QWidget* parent, HomeWindow* hw = nullptr, SettingsWindow* sw = nullptr, OnboardingWindow* ow = nullptr);
|
||||
HomeWindow *homeWindow;
|
||||
SettingsWindow *settingsWindow;
|
||||
OnboardingWindow *onboardingWindow;
|
||||
virtual void closeSettings();
|
||||
|
||||
private:
|
||||
@@ -24,5 +25,4 @@ private:
|
||||
void openSettings(int index = 0, const QString ¶m = "");
|
||||
|
||||
QStackedLayout *main_layout;
|
||||
OnboardingWindow *onboardingWindow;
|
||||
};
|
||||
@@ -45,6 +45,7 @@ qt_src = [
|
||||
"sunnypilot/qt/sp_priv_home.cc",
|
||||
"sunnypilot/qt/sp_priv_offroad_home.cc",
|
||||
"sunnypilot/qt/sp_priv_sidebar.cc",
|
||||
"sunnypilot/qt/offroad/settings/sp_priv_onboarding.cc",
|
||||
"sunnypilot/qt/offroad/settings/sp_priv_device_panel.cc",
|
||||
"sunnypilot/qt/offroad/settings/sp_priv_settings.cc",
|
||||
"sunnypilot/qt/onroad/sp_priv_buttons.cc",
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/sp_priv_onboarding.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <QQmlContext>
|
||||
#include <QQuickWidget>
|
||||
#include <common/swaglog.h>
|
||||
|
||||
#include "common/util.h"
|
||||
#include "common/params.h"
|
||||
#include "selfdrive/ui/qt/util.h"
|
||||
#include "selfdrive/ui/qt/widgets/input.h"
|
||||
|
||||
void TermsPageSP::showEvent(QShowEvent *event) {
|
||||
// late init, building QML widget takes 200ms
|
||||
if (layout()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QVBoxLayout *main_layout = new QVBoxLayout(this);
|
||||
main_layout->setContentsMargins(45, 35, 45, 45);
|
||||
main_layout->setSpacing(0);
|
||||
|
||||
QLabel *title = new QLabel(tr("Terms & Conditions"));
|
||||
title->setStyleSheet("font-size: 90px; font-weight: 600;");
|
||||
main_layout->addWidget(title);
|
||||
|
||||
main_layout->addSpacing(30);
|
||||
|
||||
QQuickWidget *text = new QQuickWidget(this);
|
||||
text->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
text->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
text->setAttribute(Qt::WA_AlwaysStackOnTop);
|
||||
text->setClearColor(QColor("#1B1B1B"));
|
||||
|
||||
std::string tc_text = sunnypilot_tc ? "../assets/offroad/sp_tc.html" : "../assets/offroad/tc.html";
|
||||
QString text_view = util::read_file(tc_text).c_str();
|
||||
text->rootContext()->setContextProperty("text_view", text_view);
|
||||
|
||||
text->setSource(QUrl::fromLocalFile("qt/offroad/text_view.qml"));
|
||||
|
||||
main_layout->addWidget(text, 1);
|
||||
main_layout->addSpacing(50);
|
||||
|
||||
QObject *obj = (QObject*)text->rootObject();
|
||||
QObject::connect(obj, SIGNAL(scroll()), SLOT(enableAccept()));
|
||||
|
||||
QHBoxLayout* buttons = new QHBoxLayout;
|
||||
buttons->setMargin(0);
|
||||
buttons->setSpacing(45);
|
||||
main_layout->addLayout(buttons);
|
||||
|
||||
QPushButton *decline_btn = new QPushButton(tr("Decline"));
|
||||
buttons->addWidget(decline_btn);
|
||||
QObject::connect(decline_btn, &QPushButton::clicked, this, &TermsPage::declinedTerms);
|
||||
|
||||
accept_btn = new QPushButton(tr("Scroll to accept"));
|
||||
accept_btn->setEnabled(false);
|
||||
accept_btn->setStyleSheet(R"(
|
||||
QPushButton {
|
||||
background-color: #465BEA;
|
||||
}
|
||||
QPushButton:pressed {
|
||||
background-color: #3049F4;
|
||||
}
|
||||
QPushButton:disabled {
|
||||
background-color: #4F4F4F;
|
||||
}
|
||||
)");
|
||||
buttons->addWidget(accept_btn);
|
||||
QObject::connect(accept_btn, &QPushButton::clicked, this, &TermsPage::acceptedTerms);
|
||||
}
|
||||
|
||||
void OnboardingWindowSP::updateActiveScreen() {
|
||||
if(accepted_terms && training_done && !accepted_terms_sp) {
|
||||
setCurrentIndex(3);
|
||||
} else {
|
||||
OnboardingWindow::updateActiveScreen();
|
||||
}
|
||||
}
|
||||
|
||||
OnboardingWindowSP::OnboardingWindowSP(QWidget *parent) : OnboardingWindow(parent) {
|
||||
std::string current_terms_version_sp = params.get("TermsVersionSunnypilot");
|
||||
accepted_terms_sp = params.get("HasAcceptedTermsSP") == current_terms_version_sp;
|
||||
LOGD("accepted_terms_sp: %s", params.get("HasAcceptedTermsSP").c_str());
|
||||
|
||||
auto* terms_sp = new TermsPageSP(true, parent);
|
||||
addWidget(terms_sp); // index = 3
|
||||
connect(terms_sp, &TermsPageSP::acceptedTerms, [=]() {
|
||||
params.put("HasAcceptedTermsSP", current_terms_version_sp);
|
||||
accepted_terms_sp = true;
|
||||
updateActiveScreen();
|
||||
});
|
||||
connect(terms_sp, &TermsPageSP::declinedTerms, [=]() { setCurrentIndex(2); });
|
||||
|
||||
OnboardingWindowSP::updateActiveScreen();
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <selfdrive/ui/qt/offroad/onboarding.h>
|
||||
|
||||
#include "common/params.h"
|
||||
#include "selfdrive/ui/qt/qt_window.h"
|
||||
|
||||
class TermsPageSP : public TermsPage {
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
explicit TermsPageSP(bool sunnypilot = false, QWidget *parent = 0) : TermsPage(parent), sunnypilot_tc(sunnypilot) {}
|
||||
|
||||
|
||||
private:
|
||||
bool sunnypilot_tc = false;
|
||||
void showEvent(QShowEvent *event) override;
|
||||
};
|
||||
|
||||
class OnboardingWindowSP : public OnboardingWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OnboardingWindowSP(QWidget *parent = 0);
|
||||
inline bool completed() const override { return accepted_terms && accepted_terms_sp && training_done; }
|
||||
|
||||
private:
|
||||
bool accepted_terms_sp = false;
|
||||
void updateActiveScreen() override;
|
||||
};
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "sp_priv_window.h"
|
||||
|
||||
MainWindowSP::MainWindowSP(QWidget *parent) : MainWindow(parent, new HomeWindowSP(parent),
|
||||
new SettingsWindowSP(parent), new OnboardingWindow(parent)) {
|
||||
new SettingsWindowSP(parent), new OnboardingWindowSP(parent)) {
|
||||
homeWindow = dynamic_cast<HomeWindowSP*>(MainWindow::homeWindow);
|
||||
settingsWindow = dynamic_cast<SettingsWindowSP*>(MainWindow::settingsWindow);
|
||||
onboardingWindow = dynamic_cast<OnboardingWindowSP*>(MainWindow::onboardingWindow);
|
||||
}
|
||||
|
||||
void MainWindowSP::closeSettings() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "selfdrive/ui/qt/window.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/sp_priv_home.h"
|
||||
#include "selfdrive/ui/sunnypilot/qt/offroad/settings/sp_priv_settings.h"
|
||||
#include "offroad/settings/sp_priv_onboarding.h"
|
||||
|
||||
class MainWindowSP : public MainWindow {
|
||||
Q_OBJECT
|
||||
@@ -13,5 +14,6 @@ explicit MainWindowSP(QWidget *parent = 0);
|
||||
private:
|
||||
HomeWindowSP *homeWindow;
|
||||
SettingsWindowSP *settingsWindow;
|
||||
OnboardingWindowSP *onboardingWindow;
|
||||
void closeSettings() override;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user