From 68088d60056cdc3ee6854c32c5c5cbff20cc98c2 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Thu, 30 Sep 2021 20:48:02 -0700 Subject: [PATCH] UI: auto wide detection on PC (#22392) * UI: auto wide detection on PC * invert width * cleanup --- selfdrive/ui/qt/maps/map_settings.cc | 3 +-- selfdrive/ui/qt/offroad/onboarding.cc | 7 +++++-- selfdrive/ui/qt/offroad/onboarding.h | 4 ++-- selfdrive/ui/qt/qt_window.h | 10 ++++++---- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/selfdrive/ui/qt/maps/map_settings.cc b/selfdrive/ui/qt/maps/map_settings.cc index 770b019023734f..9df155d62c44b8 100644 --- a/selfdrive/ui/qt/maps/map_settings.cc +++ b/selfdrive/ui/qt/maps/map_settings.cc @@ -4,7 +4,6 @@ #include "selfdrive/common/util.h" #include "selfdrive/ui/qt/util.h" -#include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/ui/qt/request_repeater.h" #include "selfdrive/ui/qt/widgets/controls.h" #include "selfdrive/ui/qt/widgets/scrollview.h" @@ -102,7 +101,7 @@ MapPanel::MapPanel(QWidget* parent) : QWidget(parent) { QLabel *screenshot = new QLabel; QPixmap pm = QPixmap("../assets/navigation/screenshot.png"); - screenshot->setPixmap(pm.scaledToWidth(vwp_w * 0.5, Qt::SmoothTransformation)); + screenshot->setPixmap(pm.scaledToWidth(1080, Qt::SmoothTransformation)); no_prime_layout->addWidget(screenshot, 0, Qt::AlignHCenter); QLabel *signup = new QLabel("Get turn-by-turn directions displayed and more with a comma \nprime subscription. Sign up now: https://connect.comma.ai"); diff --git a/selfdrive/ui/qt/offroad/onboarding.cc b/selfdrive/ui/qt/offroad/onboarding.cc index bc40a1328f8a8f..aa03ac63db2809 100644 --- a/selfdrive/ui/qt/offroad/onboarding.cc +++ b/selfdrive/ui/qt/offroad/onboarding.cc @@ -29,14 +29,17 @@ void TrainingGuide::mouseReleaseEvent(QMouseEvent *e) { if (currentIndex >= (boundingRect.size() - 1)) { emit completedTraining(); } else { - image.load(IMG_PATH + "step" + QString::number(currentIndex) + ".png"); + image.load(img_path + "step" + QString::number(currentIndex) + ".png"); update(); } } void TrainingGuide::showEvent(QShowEvent *event) { + img_path = width() == WIDE_WIDTH ? "../assets/training_wide/" : "../assets/training/"; + boundingRect = width() == WIDE_WIDTH ? boundingRectWide : boundingRectStandard; + currentIndex = 0; - image.load(IMG_PATH + "step0.png"); + image.load(img_path + "step0.png"); } void TrainingGuide::paintEvent(QPaintEvent *event) { diff --git a/selfdrive/ui/qt/offroad/onboarding.h b/selfdrive/ui/qt/offroad/onboarding.h index 291035c952613b..7ae72649d18ff4 100644 --- a/selfdrive/ui/qt/offroad/onboarding.h +++ b/selfdrive/ui/qt/offroad/onboarding.h @@ -72,8 +72,8 @@ class TrainingGuide : public QFrame { QRect(303, 755, 718, 189), }; - const QString IMG_PATH = WIDE_UI ? "../assets/training_wide/" : "../assets/training/"; - const QVector boundingRect = WIDE_UI ? boundingRectWide : boundingRectStandard; + QString img_path; + QVector boundingRect; signals: void completedTraining(); diff --git a/selfdrive/ui/qt/qt_window.h b/selfdrive/ui/qt/qt_window.h index a2dcbb425e4a3b..cd1ad928d19e3b 100644 --- a/selfdrive/ui/qt/qt_window.h +++ b/selfdrive/ui/qt/qt_window.h @@ -3,6 +3,7 @@ #include #include +#include #include #ifdef QCOM2 @@ -15,13 +16,14 @@ const QString ASSET_PATH = ":/"; -const bool WIDE_UI = Hardware::TICI() || getenv("WIDE_UI") != nullptr; -const int vwp_w = WIDE_UI ? 2160 : 1920; -const int vwp_h = 1080; +const int WIDE_WIDTH = 2160; inline void setMainWindow(QWidget *w) { + const bool wide = (QGuiApplication::primaryScreen()->size().width() >= WIDE_WIDTH) ^ + (getenv("INVERT_WIDTH") != NULL); const float scale = util::getenv("SCALE", 1.0f); - w->setFixedSize(vwp_w*scale, vwp_h*scale); + + w->setFixedSize(QSize(wide ? WIDE_WIDTH : 1920, 1080) * scale); w->show(); #ifdef QCOM2