diff --git a/selfdrive/assets/offroad/tc.html b/selfdrive/assets/offroad/tc.html index 4ab7490711..35e791f7fc 100644 --- a/selfdrive/assets/offroad/tc.html +++ b/selfdrive/assets/offroad/tc.html @@ -5,12 +5,7 @@ openpilot Terms of Service diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index b80fed2d19..55de0f5f14 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -11,22 +13,6 @@ #include "util.h" -QLabel * title_label(QString text) { - QLabel *l = new QLabel(text); - l->setStyleSheet(R"( - font-size: 100px; - font-weight: 400; - )"); - return l; -} - -QWidget * layout2Widget(QLayout* l){ - QWidget *q = new QWidget; - q->setLayout(l); - return q; -} - - void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { int leftOffset = (geometry().width()-1620)/2; int mousex = e->x()-leftOffset; @@ -61,7 +47,8 @@ TrainingGuide::TrainingGuide(QWidget* parent) { slayout->addWidget(w); } - QWidget* sw = layout2Widget(slayout); + QWidget* sw = new QWidget(); + sw->setLayout(slayout); hlayout->addWidget(sw, 1, Qt::AlignCenter); setLayout(hlayout); setStyleSheet(R"( @@ -72,22 +59,23 @@ TrainingGuide::TrainingGuide(QWidget* parent) { QWidget* OnboardingWindow::terms_screen() { QVBoxLayout *main_layout = new QVBoxLayout; - main_layout->setContentsMargins(40, 0, 40, 0); + main_layout->setContentsMargins(40, 20, 40, 0); -#ifndef QCOM - view = new QWebEngineView(this); - view->settings()->setAttribute(QWebEngineSettings::ShowScrollBars, false); - QString html = QString::fromStdString(util::read_file("../assets/offroad/tc.html")); - view->setHtml(html); - main_layout->addWidget(view); - - QObject::connect(view->page(), SIGNAL(scrollPositionChanged(QPointF)), this, SLOT(scrollPositionChanged(QPointF))); -#endif + QString terms_html = QString::fromStdString(util::read_file("../assets/offroad/tc.html")); + terms_text = new QTextEdit(); + terms_text->setReadOnly(true); + terms_text->setTextInteractionFlags(Qt::NoTextInteraction); + terms_text->setHtml(terms_html); + main_layout->addWidget(terms_text); + // TODO: add decline page QHBoxLayout* buttons = new QHBoxLayout; + main_layout->addLayout(buttons); + buttons->addWidget(new QPushButton("Decline")); buttons->addSpacing(50); - accept_btn = new QPushButton("Scroll to accept"); + + QPushButton *accept_btn = new QPushButton("Scroll to accept"); accept_btn->setEnabled(false); buttons->addWidget(accept_btn); QObject::connect(accept_btn, &QPushButton::released, [=]() { @@ -95,15 +83,37 @@ QWidget* OnboardingWindow::terms_screen() { updateActiveScreen(); }); - QWidget* w = layout2Widget(buttons); - w->setFixedHeight(200); - main_layout->addWidget(w); + // TODO: tune the scrolling + auto sb = terms_text->verticalScrollBar(); +#ifdef QCOM2 + sb->setStyleSheet(R"( + QScrollBar { + width: 150px; + background: grey; + } + QScrollBar::handle { + background-color: white; + } + QScrollBar::add-line, QScrollBar::sub-line{ + width: 0; + height: 0; + } + )"); +#else + QScroller::grabGesture(terms_text, QScroller::TouchGesture); + terms_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); +#endif + QObject::connect(sb, &QScrollBar::valueChanged, [sb, accept_btn]() { + accept_btn->setEnabled(accept_btn->isEnabled() || (sb->value() == sb->maximum())); + }); QWidget *widget = new QWidget; widget->setLayout(main_layout); widget->setStyleSheet(R"( - QPushButton { + * { font-size: 50px; + } + QPushButton { padding: 50px; border-radius: 10px; background-color: #292929; @@ -133,11 +143,13 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { 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; - - //Don't initialize widgets unless neccesary. + + // TODO: fix this, training guide is slow + // Don't initialize widgets unless neccesary. if (accepted_terms && training_done) { return; } + addWidget(terms_screen()); TrainingGuide* tr = new TrainingGuide(this); @@ -165,12 +177,3 @@ OnboardingWindow::OnboardingWindow(QWidget *parent) : QStackedWidget(parent) { updateActiveScreen(); } - -void OnboardingWindow::scrollPositionChanged(QPointF position){ -#ifndef QCOM - if (position.y() > view->page()->contentsSize().height() - 1000){ - accept_btn->setEnabled(true); - accept_btn->setText("Accept"); - } -#endif -} diff --git a/selfdrive/ui/qt/offroad/onboarding.hpp b/selfdrive/ui/qt/offroad/onboarding.hpp index c872af9865..3d51e5c7d3 100644 --- a/selfdrive/ui/qt/offroad/onboarding.hpp +++ b/selfdrive/ui/qt/offroad/onboarding.hpp @@ -3,16 +3,8 @@ #include #include #include +#include #include -#include -#include - -#ifndef QCOM -#include -#include -#include -#endif - class TrainingGuide : public QFrame { Q_OBJECT @@ -26,6 +18,7 @@ protected: private: int currentIndex = 0; QStackedLayout* slayout; + // Vector of bounding boxes for the a given training guide step. (minx, maxx, miny, maxy) QVector> 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}, {1090, 1240, 550, 660}, {1050, 1580, 250, 900}, {320, 1130, 670, 1020}, {1010, 1580, 410, 750}, {1040, 1500, 230, 1030}, {300, 1190, 590, 920}, {1050, 1310, 170, 870}, {950, 1530, 460, 770}, {190, 970, 750, 970}}; @@ -43,20 +36,14 @@ public: private: std::string current_terms_version; std::string current_training_version; - QWidget * terms_screen(); - QWidget * training_screen(); - QPushButton* accept_btn; -#ifndef QCOM - QWebEngineView* view; -#endif + QTextEdit *terms_text; + QWidget *terms_screen(); + QWidget *training_screen(); signals: void onboardingDone(); public slots: void updateActiveScreen(); - -private slots: - void scrollPositionChanged(QPointF position); };