driverview.cc: cleanup paintEvent (#21531)
old-commit-hash: 30ec2bc403b9741520b0f580f8b78752cd111d8b
This commit is contained in:
@@ -26,7 +26,7 @@ void DriverViewWindow::mouseReleaseEvent(QMouseEvent* e) {
|
||||
}
|
||||
|
||||
DriverViewScene::DriverViewScene(QWidget* parent) : sm({"driverState"}), QWidget(parent) {
|
||||
face = QImage("../assets/img_driver_face.png").scaled(FACE_IMG_SIZE, FACE_IMG_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
face_img = QImage("../assets/img_driver_face.png").scaled(FACE_IMG_SIZE, FACE_IMG_SIZE, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
}
|
||||
|
||||
void DriverViewScene::showEvent(QShowEvent* event) {
|
||||
@@ -50,7 +50,7 @@ void DriverViewScene::paintEvent(QPaintEvent* event) {
|
||||
|
||||
// startup msg
|
||||
if (!frame_updated) {
|
||||
p.setPen(QColor(0xff, 0xff, 0xff));
|
||||
p.setPen(Qt::white);
|
||||
p.setRenderHint(QPainter::TextAntialiasing);
|
||||
configFont(p, "Inter", 100, "Bold");
|
||||
p.drawText(geometry(), Qt::AlignCenter, "camera starting");
|
||||
@@ -62,17 +62,10 @@ void DriverViewScene::paintEvent(QPaintEvent* event) {
|
||||
const QRect valid_rect = {is_rhd ? rect2.right() - rect2.height() / 2 : rect2.left(), rect2.top(), rect2.height() / 2, rect2.height()};
|
||||
|
||||
// blackout
|
||||
const int blackout_x_r = valid_rect.right();
|
||||
const QColor bg(0, 0, 0, 140);
|
||||
const QRect& blackout_rect = Hardware::TICI() ? rect() : rect2;
|
||||
const int blackout_w_r = blackout_rect.right() - valid_rect.right();
|
||||
const int blackout_x_l = blackout_rect.left();
|
||||
const int blackout_w_l = valid_rect.left() - blackout_x_l;
|
||||
|
||||
QColor bg(0, 0, 0, 140);
|
||||
p.setPen(QPen(bg));
|
||||
p.setBrush(QBrush(bg));
|
||||
p.drawRect(blackout_x_l, rect2.top(), blackout_w_l, rect2.height());
|
||||
p.drawRect(blackout_x_r, rect2.top(), blackout_w_r, rect2.height());
|
||||
p.fillRect(blackout_rect.adjusted(0, 0, valid_rect.left() - blackout_rect.right(), 0), bg);
|
||||
p.fillRect(blackout_rect.adjusted(valid_rect.right() - blackout_rect.left(), 0, 0, 0), bg);
|
||||
|
||||
// face bounding box
|
||||
cereal::DriverState::Reader driver_state = sm["driverState"].getDriverState();
|
||||
@@ -81,21 +74,16 @@ void DriverViewScene::paintEvent(QPaintEvent* event) {
|
||||
auto fxy_list = driver_state.getFacePosition();
|
||||
float face_x = fxy_list[0];
|
||||
float face_y = fxy_list[1];
|
||||
int fbox_x = valid_rect.center().x() + (is_rhd ? face_x : -face_x) * valid_rect.width();
|
||||
int fbox_y = valid_rect.center().y() + face_y * valid_rect.height();
|
||||
|
||||
float alpha = 0.2;
|
||||
face_x = std::abs(face_x);
|
||||
face_y = std::abs(face_y);
|
||||
if (face_x <= 0.35 && face_y <= 0.4) {
|
||||
alpha = 0.8 - (face_x > face_y ? face_x : face_y) * 0.6 / 0.375;
|
||||
float x = std::abs(face_x), y = std::abs(face_y);
|
||||
if (x <= 0.35 && y <= 0.4) {
|
||||
alpha = 0.8 - std::max(x, y) * 0.6 / 0.375;
|
||||
}
|
||||
|
||||
const int box_size = 0.6 * rect2.height() / 2;
|
||||
QPen pen(QColor(255, 255, 255, alpha * 255));
|
||||
pen.setWidth(10);
|
||||
p.setPen(pen);
|
||||
p.setBrush(Qt::NoBrush);
|
||||
int fbox_x = valid_rect.center().x() + (is_rhd ? face_x : -face_x) * valid_rect.width();
|
||||
int fbox_y = valid_rect.center().y() + face_y * valid_rect.height();
|
||||
p.setPen(QPen(QColor(255, 255, 255, alpha * 255), 10));
|
||||
p.drawRoundedRect(fbox_x - box_size / 2, fbox_y - box_size / 2, box_size, box_size, 35.0, 35.0);
|
||||
}
|
||||
|
||||
@@ -103,7 +91,6 @@ void DriverViewScene::paintEvent(QPaintEvent* event) {
|
||||
const int img_offset = 30;
|
||||
const int img_x = is_rhd ? rect2.right() - FACE_IMG_SIZE - img_offset : rect2.left() + img_offset;
|
||||
const int img_y = rect2.bottom() - FACE_IMG_SIZE - img_offset;
|
||||
p.setPen(Qt::NoPen);
|
||||
p.setOpacity(face_detected ? 1.0 : 0.3);
|
||||
p.drawImage(img_x, img_y, face);
|
||||
p.drawImage(img_x, img_y, face_img);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ protected:
|
||||
private:
|
||||
Params params;
|
||||
SubMaster sm;
|
||||
QImage face;
|
||||
QImage face_img;
|
||||
bool is_rhd = false;
|
||||
bool frame_updated = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user