2021-06-09 03:09:30 +08:00
|
|
|
#include "selfdrive/ui/qt/window.h"
|
2021-05-09 13:15:17 +08:00
|
|
|
|
2021-06-16 15:08:02 +08:00
|
|
|
#include <QFontDatabase>
|
|
|
|
|
|
2021-03-28 03:53:03 -07:00
|
|
|
#include "selfdrive/hardware/hw.h"
|
2020-10-21 15:15:21 +02:00
|
|
|
|
2020-08-20 17:16:44 +02:00
|
|
|
MainWindow::MainWindow(QWidget *parent) : QWidget(parent) {
|
2021-06-13 12:28:17 +08:00
|
|
|
main_layout = new QStackedLayout(this);
|
2021-03-22 13:40:08 -07:00
|
|
|
main_layout->setMargin(0);
|
2020-08-20 17:16:44 +02:00
|
|
|
|
2020-12-02 20:47:47 -08:00
|
|
|
homeWindow = new HomeWindow(this);
|
|
|
|
|
main_layout->addWidget(homeWindow);
|
2021-04-29 11:18:59 -07:00
|
|
|
QObject::connect(homeWindow, &HomeWindow::openSettings, this, &MainWindow::openSettings);
|
|
|
|
|
QObject::connect(homeWindow, &HomeWindow::closeSettings, this, &MainWindow::closeSettings);
|
2020-08-20 17:16:44 +02:00
|
|
|
|
2020-11-20 13:21:18 +01:00
|
|
|
settingsWindow = new SettingsWindow(this);
|
2020-08-20 17:16:44 +02:00
|
|
|
main_layout->addWidget(settingsWindow);
|
2021-04-29 11:18:59 -07:00
|
|
|
QObject::connect(settingsWindow, &SettingsWindow::closeSettings, this, &MainWindow::closeSettings);
|
2021-06-19 07:01:22 +08:00
|
|
|
QObject::connect(settingsWindow, &SettingsWindow::reviewTrainingGuide, [=]() {
|
2021-09-12 09:18:58 +08:00
|
|
|
onboardingWindow->showTrainingGuide();
|
2021-06-19 07:01:22 +08:00
|
|
|
main_layout->setCurrentWidget(onboardingWindow);
|
|
|
|
|
});
|
2021-06-01 20:59:41 -07:00
|
|
|
QObject::connect(settingsWindow, &SettingsWindow::showDriverView, [=] {
|
|
|
|
|
homeWindow->showDriverView(true);
|
|
|
|
|
});
|
2020-08-20 17:16:44 +02:00
|
|
|
|
2021-09-12 09:18:58 +08:00
|
|
|
onboardingWindow = new OnboardingWindow(this);
|
|
|
|
|
main_layout->addWidget(onboardingWindow);
|
|
|
|
|
QObject::connect(onboardingWindow, &OnboardingWindow::onboardingDone, [=]() {
|
|
|
|
|
main_layout->setCurrentWidget(homeWindow);
|
|
|
|
|
});
|
|
|
|
|
if (!onboardingWindow->completed()) {
|
|
|
|
|
main_layout->setCurrentWidget(onboardingWindow);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-15 14:28:12 +08:00
|
|
|
QObject::connect(uiState(), &UIState::offroadTransition, [=](bool offroad) {
|
2021-06-19 07:01:22 +08:00
|
|
|
if (!offroad) {
|
|
|
|
|
closeSettings();
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-12-14 18:22:16 +08:00
|
|
|
QObject::connect(&device, &Device::interactiveTimout, [=]() {
|
|
|
|
|
if (main_layout->currentWidget() == settingsWindow) {
|
|
|
|
|
closeSettings();
|
|
|
|
|
}
|
2021-06-19 07:01:22 +08:00
|
|
|
});
|
2021-04-29 11:18:59 -07:00
|
|
|
|
2021-05-07 15:12:29 -07:00
|
|
|
// load fonts
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/opensans_regular.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/opensans_bold.ttf");
|
2021-10-28 13:07:39 -07:00
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/opensans_semibold.ttf");
|
2021-10-26 20:40:09 -07:00
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-Black.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-Bold.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-ExtraBold.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-ExtraLight.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-Medium.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-Regular.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-SemiBold.ttf");
|
|
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/Inter-Thin.ttf");
|
2021-05-07 15:12:29 -07:00
|
|
|
|
2021-02-28 18:10:50 -08:00
|
|
|
// no outline to prevent the focus rectangle
|
2020-08-20 17:16:44 +02:00
|
|
|
setStyleSheet(R"(
|
|
|
|
|
* {
|
2020-12-24 14:10:43 -08:00
|
|
|
font-family: Inter;
|
2021-02-28 18:10:50 -08:00
|
|
|
outline: none;
|
2020-08-20 17:16:44 +02:00
|
|
|
}
|
|
|
|
|
)");
|
2021-07-24 07:05:58 +08:00
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
2020-08-20 17:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-09 10:04:28 -07:00
|
|
|
void MainWindow::openSettings() {
|
2020-12-02 20:47:47 -08:00
|
|
|
main_layout->setCurrentWidget(settingsWindow);
|
2020-08-20 17:16:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-09 10:04:28 -07:00
|
|
|
void MainWindow::closeSettings() {
|
2021-06-19 07:01:22 +08:00
|
|
|
main_layout->setCurrentWidget(homeWindow);
|
2021-06-22 13:25:22 +02:00
|
|
|
|
2021-12-15 14:28:12 +08:00
|
|
|
if (uiState()->scene.started) {
|
2021-11-04 21:43:28 +08:00
|
|
|
homeWindow->showSidebar(false);
|
2021-06-22 13:25:22 +02:00
|
|
|
}
|
2021-03-25 17:36:44 -07:00
|
|
|
}
|
|
|
|
|
|
2021-06-11 16:17:52 +08:00
|
|
|
bool MainWindow::eventFilter(QObject *obj, QEvent *event) {
|
2021-07-29 22:24:24 -07:00
|
|
|
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::TouchBegin) {
|
2021-12-14 18:22:16 +08:00
|
|
|
device.resetInteractiveTimout();
|
2020-11-20 13:21:18 +01:00
|
|
|
}
|
2021-03-28 03:53:03 -07:00
|
|
|
|
|
|
|
|
#ifdef QCOM
|
2021-04-29 11:18:59 -07:00
|
|
|
// filter out touches while in android activity
|
2021-05-17 12:21:46 +08:00
|
|
|
const static QSet<QEvent::Type> filter_events({QEvent::MouseButtonPress, QEvent::MouseMove, QEvent::TouchBegin, QEvent::TouchUpdate, QEvent::TouchEnd});
|
2021-03-28 03:53:03 -07:00
|
|
|
if (HardwareEon::launched_activity && filter_events.contains(event->type())) {
|
|
|
|
|
HardwareEon::check_activity();
|
|
|
|
|
if (HardwareEon::launched_activity) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-11-20 13:21:18 +01:00
|
|
|
return false;
|
|
|
|
|
}
|