Skip to content

Commit

Permalink
UI: auto wide detection on PC (commaai#22392)
Browse files Browse the repository at this point in the history
* UI: auto wide detection on PC

* invert width

* cleanup
  • Loading branch information
adeebshihadeh authored and Aragon7777 committed Oct 1, 2021
1 parent a765328 commit 68088d6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions selfdrive/ui/qt/maps/map_settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down
7 changes: 5 additions & 2 deletions selfdrive/ui/qt/offroad/onboarding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/ui/qt/offroad/onboarding.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<QRect> boundingRect = WIDE_UI ? boundingRectWide : boundingRectStandard;
QString img_path;
QVector<QRect> boundingRect;

signals:
void completedTraining();
Expand Down
10 changes: 6 additions & 4 deletions selfdrive/ui/qt/qt_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>

#include <QApplication>
#include <QScreen>
#include <QWidget>

#ifdef QCOM2
Expand All @@ -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
Expand Down

0 comments on commit 68088d6

Please sign in to comment.