|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
#include <QLabel> |
|
|
|
|
#include <QString> |
|
|
|
|
#include <QScroller> |
|
|
|
|
#include <QScrollBar> |
|
|
|
|
#include <QPushButton> |
|
|
|
|
#include <QGridLayout> |
|
|
|
|
#include <QVBoxLayout> |
|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|