Files
clearpilot/selfdrive/ui/qt/ready.cc
Your Name fbd09ad9bd wip
2024-05-09 21:17:20 -05:00

64 lines
1.7 KiB
C++

#include "selfdrive/ui/qt/ready.h"
#include <cmath>
#include <algorithm>
#include <QPainter>
#include <QStackedLayout>
#include <QApplication>
#include <QGridLayout>
#include <QString>
#include <QTransform>
#include <QPixmap>
#include "common/params.h"
#include "common/timing.h"
#include "system/hardware/hw.h"
#include "selfdrive/ui/qt/qt_window.h"
#include "selfdrive/ui/qt/util.h"
ReadyWindow::ReadyWindow(QWidget *parent) : QWidget(parent) {
QGridLayout *layout = new QGridLayout(this);
layout->setSpacing(0);
layout->setMargin(0);
setAttribute(Qt::WA_OpaquePaintEvent);
setStyleSheet("ReadyWindow { background-color: black; }");
}
void ReadyWindow::paintEvent(QPaintEvent *event) {
QPainter painter(this);
QPixmap *img_shown = nullptr;
if (is_hot) {
if (img_hot.isNull()) {
img_hot.load("/data/openpilot/selfdrive/clearpilot/theme/clearpilot/images/hot.png");
}
img_shown = &img_hot;
} else {
if (img_ready.isNull()) {
img_ready.load("/data/openpilot/selfdrive/clearpilot/theme/clearpilot/images/ready.png");
}
img_shown = &img_ready;
}
int x = (width() - img_shown->width()) / 2;
int y = (height() - img_shown->height()) / 2;
painter.drawPixmap(x, y, *img_shown);
}
void ReadyWindow::refresh() {
std::string bytes = params.get("Offroad_TemperatureTooHigh");
if (!bytes.empty()) {
auto doc = QJsonDocument::fromJson(bytes.data());
is_hot = true;
cur_temp = doc["extra"].toString();
update();
} else if (is_hot) {
is_hot = false;
update();
}
}