From d44ee69b24f530e7b5bde681f331642a32f0d265 Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Thu, 20 May 2021 09:59:56 -0400 Subject: [PATCH] UI: add decline page for the Terms and Conditions (#20919) * add decline page * change action + keep the same layout --- selfdrive/ui/qt/offroad/onboarding.cc | 63 ++++++++++++++++++++++++++- selfdrive/ui/qt/offroad/onboarding.h | 19 ++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index ea34b35e6a..c0ede84a64 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -10,6 +10,8 @@ #include "selfdrive/common/params.h" #include "selfdrive/common/util.h" #include "selfdrive/ui/qt/home.h" +#include "selfdrive/ui/qt/widgets/input.h" + void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { QPoint touch = QPoint(e->x(), e->y()) - imageCorner; @@ -77,11 +79,13 @@ void TermsPage::showEvent(QShowEvent *event) { QObject *obj = (QObject*)text->rootObject(); QObject::connect(obj, SIGNAL(qmlSignal()), SLOT(enableAccept())); - // TODO: add decline page QHBoxLayout* buttons = new QHBoxLayout; main_layout->addLayout(buttons); - buttons->addWidget(new QPushButton("Decline")); + decline_btn = new QPushButton("Decline"); + buttons->addWidget(decline_btn); + QObject::connect(decline_btn, &QPushButton::released, this, &TermsPage::declinedTerms); + buttons->addSpacing(50); accept_btn = new QPushButton("Scroll to accept"); @@ -106,6 +110,50 @@ void TermsPage::enableAccept(){ return; } +void DeclinePage::showEvent(QShowEvent *event) { + if (layout()) { + return; + } + + QVBoxLayout *main_layout = new QVBoxLayout; + main_layout->setMargin(40); + main_layout->setSpacing(40); + + QLabel *text = new QLabel(this); + text->setText("You must accept the Terms and Conditions in order to use openpilot!"); + text->setStyleSheet(R"(font-size: 50px;)"); + main_layout->addWidget(text, 0, Qt::AlignCenter); + + QHBoxLayout* buttons = new QHBoxLayout; + main_layout->addLayout(buttons); + + back_btn = new QPushButton("Back"); + buttons->addWidget(back_btn); + buttons->addSpacing(50); + + QObject::connect(back_btn, &QPushButton::released, this, &DeclinePage::getBack); + + uninstall_btn = new QPushButton("Decline, uninstall openpilot"); + uninstall_btn->setStyleSheet("background-color: #E22C2C;"); + buttons->addWidget(uninstall_btn); + + QObject::connect(uninstall_btn, &QPushButton::released, [=](){ + if (ConfirmationDialog::confirm("Are you sure you want to uninstall?", this)) { + Params().putBool("DoUninstall", true); + } + }); + + setLayout(main_layout); + setStyleSheet(R"( + QPushButton { + padding: 50px; + font-size: 50px; + border-radius: 10px; + background-color: #292929; + } + )"); +} + void OnboardingWindow::updateActiveScreen() { updateOnboardingStatus(); @@ -138,6 +186,17 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { }); addWidget(tr); + DeclinePage* declinePage = new DeclinePage(this); + addWidget(declinePage); + + connect(terms, &TermsPage::declinedTerms, [=](){ + setCurrentIndex(2); + }); + + connect(declinePage, &DeclinePage::getBack, [=](){ + updateActiveScreen(); + }); + setStyleSheet(R"( * { color: white; diff --git a/selfdrive/ui/qt/offroad/onboarding.h b/selfdrive/ui/qt/offroad/onboarding.h index 92a9b971fc..51a055d878 100644 --- a/selfdrive/ui/qt/offroad/onboarding.h +++ b/selfdrive/ui/qt/offroad/onboarding.h @@ -64,12 +64,31 @@ protected: private: QPushButton *accept_btn; + QPushButton *decline_btn; public slots: void enableAccept(); signals: void acceptedTerms(); + void declinedTerms(); +}; + +class DeclinePage : public QFrame { + Q_OBJECT + +public: + explicit DeclinePage(QWidget *parent = 0) : QFrame(parent) {}; + +protected: + void showEvent(QShowEvent *event) override; + +private: + QPushButton *back_btn; + QPushButton *uninstall_btn; + +signals: + void getBack(); }; class OnboardingWindow : public QStackedWidget {