mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-14 19:44:05 +08:00
81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
#include "selfdrive/ui/qt/home.h"
|
|
|
|
#include <QHBoxLayout>
|
|
#include <QMouseEvent>
|
|
|
|
#include "selfdrive/ui/qt/util.h"
|
|
|
|
// HomeWindow: the container for the offroad and onroad UIs
|
|
|
|
HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) {
|
|
QHBoxLayout *main_layout = new QHBoxLayout(this);
|
|
main_layout->setMargin(0);
|
|
main_layout->setSpacing(0);
|
|
|
|
sidebar = new Sidebar(this);
|
|
main_layout->addWidget(sidebar);
|
|
QObject::connect(sidebar, &Sidebar::openSettings, this, &HomeWindow::openSettings);
|
|
|
|
slayout = new QStackedLayout();
|
|
main_layout->addLayout(slayout);
|
|
|
|
home = new OffroadHome(this);
|
|
QObject::connect(home, &OffroadHome::openSettings, this, &HomeWindow::openSettings);
|
|
slayout->addWidget(home);
|
|
|
|
onroad = new OnroadWindow(this);
|
|
slayout->addWidget(onroad);
|
|
|
|
body = new BodyWindow(this);
|
|
slayout->addWidget(body);
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
|
QObject::connect(uiState(), &UIState::uiUpdate, this, &HomeWindow::updateState);
|
|
QObject::connect(uiState(), &UIState::offroadTransition, this, &HomeWindow::offroadTransition);
|
|
QObject::connect(uiState(), &UIState::offroadTransition, sidebar, &Sidebar::offroadTransition);
|
|
}
|
|
|
|
void HomeWindow::showSidebar(bool show) {
|
|
sidebar->setVisible(show);
|
|
}
|
|
|
|
void HomeWindow::updateState(const UIState &s) {
|
|
const SubMaster &sm = *(s.sm);
|
|
|
|
// switch to the generic robot UI
|
|
if (onroad->isVisible() && !body->isEnabled() && sm["carParams"].getCarParams().getNotCar()) {
|
|
body->setEnabled(true);
|
|
slayout->setCurrentWidget(body);
|
|
}
|
|
}
|
|
|
|
void HomeWindow::offroadTransition(bool offroad) {
|
|
body->setEnabled(false);
|
|
sidebar->setVisible(offroad);
|
|
if (offroad) {
|
|
slayout->setCurrentWidget(home);
|
|
} else {
|
|
slayout->setCurrentWidget(onroad);
|
|
}
|
|
}
|
|
|
|
void HomeWindow::mousePressEvent(QMouseEvent* e) {
|
|
// Handle sidebar collapsing
|
|
if ((onroad->isVisible() || body->isVisible()) && (!sidebar->isVisible() || e->x() > sidebar->width())) {
|
|
sidebar->setVisible(!sidebar->isVisible());
|
|
}
|
|
}
|
|
|
|
void HomeWindow::mouseDoubleClickEvent(QMouseEvent* e) {
|
|
HomeWindow::mousePressEvent(e);
|
|
const SubMaster &sm = *(uiState()->sm);
|
|
if (sm["carParams"].getCarParams().getNotCar()) {
|
|
if (onroad->isVisible()) {
|
|
slayout->setCurrentWidget(body);
|
|
} else if (body->isVisible()) {
|
|
slayout->setCurrentWidget(onroad);
|
|
}
|
|
showSidebar(false);
|
|
}
|
|
}
|