ui: remove function `configFont`. use `struct InterFont ` (#28773)

old-commit-hash: 219590885f
beeps
Dean Lee 2 years ago committed by GitHub
parent 7f10d2c5b4
commit ccba136b64
  1. 2
      selfdrive/ui/qt/offroad/driverview.cc
  2. 24
      selfdrive/ui/qt/onroad.cc
  3. 4
      selfdrive/ui/qt/sidebar.cc
  4. 7
      selfdrive/ui/qt/util.cc
  5. 8
      selfdrive/ui/qt/util.h

@ -52,7 +52,7 @@ void DriverViewScene::paintEvent(QPaintEvent* event) {
if (!frame_updated) { if (!frame_updated) {
p.setPen(Qt::white); p.setPen(Qt::white);
p.setRenderHint(QPainter::TextAntialiasing); p.setRenderHint(QPainter::TextAntialiasing);
configFont(p, "Inter", 100, "Bold"); p.setFont(InterFont(100, QFont::Bold));
p.drawText(geometry(), Qt::AlignCenter, tr("camera starting")); p.drawText(geometry(), Qt::AlignCenter, tr("camera starting"));
return; return;
} }

@ -181,18 +181,18 @@ void OnroadAlerts::paintEvent(QPaintEvent *event) {
p.setPen(QColor(0xff, 0xff, 0xff)); p.setPen(QColor(0xff, 0xff, 0xff));
p.setRenderHint(QPainter::TextAntialiasing); p.setRenderHint(QPainter::TextAntialiasing);
if (alert.size == cereal::ControlsState::AlertSize::SMALL) { if (alert.size == cereal::ControlsState::AlertSize::SMALL) {
configFont(p, "Inter", 74, "SemiBold"); p.setFont(InterFont(74, QFont::DemiBold));
p.drawText(r, Qt::AlignCenter, alert.text1); p.drawText(r, Qt::AlignCenter, alert.text1);
} else if (alert.size == cereal::ControlsState::AlertSize::MID) { } else if (alert.size == cereal::ControlsState::AlertSize::MID) {
configFont(p, "Inter", 88, "Bold"); p.setFont(InterFont(88, QFont::Bold));
p.drawText(QRect(0, c.y() - 125, width(), 150), Qt::AlignHCenter | Qt::AlignTop, alert.text1); p.drawText(QRect(0, c.y() - 125, width(), 150), Qt::AlignHCenter | Qt::AlignTop, alert.text1);
configFont(p, "Inter", 66, "Regular"); p.setFont(InterFont(66));
p.drawText(QRect(0, c.y() + 21, width(), 90), Qt::AlignHCenter, alert.text2); p.drawText(QRect(0, c.y() + 21, width(), 90), Qt::AlignHCenter, alert.text2);
} else if (alert.size == cereal::ControlsState::AlertSize::FULL) { } else if (alert.size == cereal::ControlsState::AlertSize::FULL) {
bool l = alert.text1.length() > 15; bool l = alert.text1.length() > 15;
configFont(p, "Inter", l ? 132 : 177, "Bold"); p.setFont(InterFont(l ? 132 : 177, QFont::Bold));
p.drawText(QRect(0, r.y() + (l ? 240 : 270), width(), 600), Qt::AlignHCenter | Qt::TextWordWrap, alert.text1); p.drawText(QRect(0, r.y() + (l ? 240 : 270), width(), 600), Qt::AlignHCenter | Qt::TextWordWrap, alert.text1);
configFont(p, "Inter", 88, "Regular"); p.setFont(InterFont(88));
p.drawText(QRect(0, r.height() - (l ? 361 : 420), width(), 300), Qt::AlignHCenter | Qt::TextWordWrap, alert.text2); p.drawText(QRect(0, r.height() - (l ? 361 : 420), width(), 300), Qt::AlignHCenter | Qt::TextWordWrap, alert.text2);
} }
} }
@ -363,10 +363,10 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) {
max_color = QColor(0xa6, 0xa6, 0xa6, 0xff); max_color = QColor(0xa6, 0xa6, 0xa6, 0xff);
set_speed_color = QColor(0x72, 0x72, 0x72, 0xff); set_speed_color = QColor(0x72, 0x72, 0x72, 0xff);
} }
configFont(p, "Inter", 40, "SemiBold"); p.setFont(InterFont(40, QFont::DemiBold));
p.setPen(max_color); p.setPen(max_color);
p.drawText(set_speed_rect.adjusted(0, 27, 0, 0), Qt::AlignTop | Qt::AlignHCenter, tr("MAX")); p.drawText(set_speed_rect.adjusted(0, 27, 0, 0), Qt::AlignTop | Qt::AlignHCenter, tr("MAX"));
configFont(p, "Inter", 90, "Bold"); p.setFont(InterFont(90, QFont::Bold));
p.setPen(set_speed_color); p.setPen(set_speed_color);
p.drawText(set_speed_rect.adjusted(0, 77, 0, 0), Qt::AlignTop | Qt::AlignHCenter, setSpeedStr); p.drawText(set_speed_rect.adjusted(0, 77, 0, 0), Qt::AlignTop | Qt::AlignHCenter, setSpeedStr);
@ -379,10 +379,10 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) {
p.setPen(QPen(blackColor(), 6)); p.setPen(QPen(blackColor(), 6));
p.drawRoundedRect(sign_rect.adjusted(9, 9, -9, -9), 16, 16); p.drawRoundedRect(sign_rect.adjusted(9, 9, -9, -9), 16, 16);
configFont(p, "Inter", 28, "SemiBold"); p.setFont(InterFont(28, QFont::DemiBold));
p.drawText(sign_rect.adjusted(0, 22, 0, 0), Qt::AlignTop | Qt::AlignHCenter, tr("SPEED")); p.drawText(sign_rect.adjusted(0, 22, 0, 0), Qt::AlignTop | Qt::AlignHCenter, tr("SPEED"));
p.drawText(sign_rect.adjusted(0, 51, 0, 0), Qt::AlignTop | Qt::AlignHCenter, tr("LIMIT")); p.drawText(sign_rect.adjusted(0, 51, 0, 0), Qt::AlignTop | Qt::AlignHCenter, tr("LIMIT"));
configFont(p, "Inter", 70, "Bold"); p.setFont(InterFont(70, QFont::Bold));
p.drawText(sign_rect.adjusted(0, 85, 0, 0), Qt::AlignTop | Qt::AlignHCenter, speedLimitStr); p.drawText(sign_rect.adjusted(0, 85, 0, 0), Qt::AlignTop | Qt::AlignHCenter, speedLimitStr);
} }
@ -394,15 +394,15 @@ void AnnotatedCameraWidget::drawHud(QPainter &p) {
p.setPen(QPen(Qt::red, 20)); p.setPen(QPen(Qt::red, 20));
p.drawEllipse(sign_rect.adjusted(16, 16, -16, -16)); p.drawEllipse(sign_rect.adjusted(16, 16, -16, -16));
configFont(p, "Inter", (speedLimitStr.size() >= 3) ? 60 : 70, "Bold"); p.setFont(InterFont((speedLimitStr.size() >= 3) ? 60 : 70, QFont::Bold));
p.setPen(blackColor()); p.setPen(blackColor());
p.drawText(sign_rect, Qt::AlignCenter, speedLimitStr); p.drawText(sign_rect, Qt::AlignCenter, speedLimitStr);
} }
// current speed // current speed
configFont(p, "Inter", 176, "Bold"); p.setFont(InterFont(176, QFont::Bold));
drawText(p, rect().center().x(), 210, speedStr); drawText(p, rect().center().x(), 210, speedStr);
configFont(p, "Inter", 66, "Regular"); p.setFont(InterFont(66));
drawText(p, rect().center().x(), 290, speedUnit, 200); drawText(p, rect().center().x(), 290, speedUnit, 200);
p.restore(); p.restore();

@ -20,7 +20,7 @@ void Sidebar::drawMetric(QPainter &p, const QPair<QString, QString> &label, QCol
p.drawRoundedRect(rect, 20, 20); p.drawRoundedRect(rect, 20, 20);
p.setPen(QColor(0xff, 0xff, 0xff)); p.setPen(QColor(0xff, 0xff, 0xff));
configFont(p, "Inter", 35, "SemiBold"); p.setFont(InterFont(35, QFont::DemiBold));
p.drawText(rect.adjusted(22, 0, 0, 0), Qt::AlignCenter, label.first + "\n" + label.second); p.drawText(rect.adjusted(22, 0, 0, 0), Qt::AlignCenter, label.first + "\n" + label.second);
} }
@ -129,7 +129,7 @@ void Sidebar::paintEvent(QPaintEvent *event) {
x += 37; x += 37;
} }
configFont(p, "Inter", 35, "Regular"); p.setFont(InterFont(35));
p.setPen(QColor(0xff, 0xff, 0xff)); p.setPen(QColor(0xff, 0xff, 0xff));
const QRect r = QRect(50, 247, 100, 50); const QRect r = QRect(50, 247, 100, 50);
p.drawText(r, Qt::AlignCenter, net_type); p.drawText(r, Qt::AlignCenter, net_type);

@ -51,13 +51,6 @@ QMap<QString, QString> getSupportedLanguages() {
return map; return map;
} }
void configFont(QPainter &p, const QString &family, int size, const QString &style) {
QFont f(family);
f.setPixelSize(size);
f.setStyleName(style);
p.setFont(f);
}
void clearLayout(QLayout* layout) { void clearLayout(QLayout* layout) {
while (layout->count() > 0) { while (layout->count() > 0) {
QLayoutItem* item = layout->takeAt(0); QLayoutItem* item = layout->takeAt(0);

@ -16,7 +16,6 @@ QString getBrand();
QString getUserAgent(); QString getUserAgent();
std::optional<QString> getDongleId(); std::optional<QString> getDongleId();
QMap<QString, QString> getSupportedLanguages(); QMap<QString, QString> getSupportedLanguages();
void configFont(QPainter &p, const QString &family, int size, const QString &style);
void clearLayout(QLayout* layout); void clearLayout(QLayout* layout);
void setQtSurfaceFormat(); void setQtSurfaceFormat();
void sigTermHandler(int s); void sigTermHandler(int s);
@ -30,3 +29,10 @@ QPixmap bootstrapPixmap(const QString &id);
void drawRoundedRect(QPainter &painter, const QRectF &rect, qreal xRadiusTop, qreal yRadiusTop, qreal xRadiusBottom, qreal yRadiusBottom); void drawRoundedRect(QPainter &painter, const QRectF &rect, qreal xRadiusTop, qreal yRadiusTop, qreal xRadiusBottom, qreal yRadiusBottom);
QColor interpColor(float xv, std::vector<float> xp, std::vector<QColor> fp); QColor interpColor(float xv, std::vector<float> xp, std::vector<QColor> fp);
bool hasLongitudinalControl(const cereal::CarParams::Reader &car_params); bool hasLongitudinalControl(const cereal::CarParams::Reader &car_params);
struct InterFont : public QFont {
InterFont(int pixel_size, QFont::Weight weight = QFont::Normal) : QFont("Inter") {
setPixelSize(pixel_size);
setWeight(weight);
}
};

Loading…
Cancel
Save