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>
|
|
|
|
|
|
2022-06-11 16:38:24 -07:00
|
|
|
#include "system/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();
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-07-12 18:36:44 -07:00
|
|
|
QObject::connect(device(), &Device::interactiveTimeout, [=]() {
|
2021-12-14 18:22:16 +08:00
|
|
|
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
|
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");
|
2022-11-15 22:18:26 -08:00
|
|
|
QFontDatabase::addApplicationFont("../assets/fonts/JetBrainsMono-Medium.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
|
|
|
}
|
|
|
|
|
|
2022-11-15 22:18:26 -08:00
|
|
|
void MainWindow::openSettings(int index, const QString ¶m) {
|
2020-12-02 20:47:47 -08:00
|
|
|
main_layout->setCurrentWidget(settingsWindow);
|
2022-11-15 22:18:26 -08:00
|
|
|
settingsWindow->setCurrentPanel(index, param);
|
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);
|
2023-07-11 14:49:19 -07:00
|
|
|
// Map is always shown when using navigate on openpilot
|
|
|
|
|
if (uiState()->scene.navigate_on_openpilot) {
|
|
|
|
|
homeWindow->showMapPanel(true);
|
|
|
|
|
}
|
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) {
|
2023-06-29 09:01:31 +08:00
|
|
|
bool ignore = false;
|
2023-05-25 11:45:58 +08:00
|
|
|
switch (event->type()) {
|
|
|
|
|
case QEvent::TouchBegin:
|
|
|
|
|
case QEvent::TouchUpdate:
|
|
|
|
|
case QEvent::TouchEnd:
|
|
|
|
|
case QEvent::MouseButtonPress:
|
2023-06-29 09:01:31 +08:00
|
|
|
case QEvent::MouseMove: {
|
2023-07-12 13:09:42 -07:00
|
|
|
// ignore events when device is awakened by resetInteractiveTimeout
|
2023-07-12 18:36:44 -07:00
|
|
|
ignore = !device()->isAwake();
|
|
|
|
|
device()->resetInteractiveTimeout();
|
2023-05-25 11:45:58 +08:00
|
|
|
break;
|
2023-06-29 09:01:31 +08:00
|
|
|
}
|
2023-05-25 11:45:58 +08:00
|
|
|
default:
|
|
|
|
|
break;
|
2022-01-14 11:20:22 +08:00
|
|
|
}
|
2023-06-29 09:01:31 +08:00
|
|
|
return ignore;
|
2020-11-20 13:21:18 +01:00
|
|
|
}
|