diff --git a/selfdrive/ui/main.cc b/selfdrive/ui/main.cc index 35268bd880..63bbffa7af 100644 --- a/selfdrive/ui/main.cc +++ b/selfdrive/ui/main.cc @@ -8,10 +8,9 @@ int main(int argc, char *argv[]) { qInstallMessageHandler(swagLogMessageHandler); - setQtSurfaceFormat(); + initApp(); if (Hardware::EON()) { - QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); QSslConfiguration ssl = QSslConfiguration::defaultConfiguration(); ssl.setCaCertificates(QSslCertificate::fromPath("/usr/etc/tls/cert.pem")); QSslConfiguration::setDefaultConfiguration(ssl); diff --git a/selfdrive/ui/qt/spinner.cc b/selfdrive/ui/qt/spinner.cc index 2404f3c982..0dcae6d97b 100644 --- a/selfdrive/ui/qt/spinner.cc +++ b/selfdrive/ui/qt/spinner.cc @@ -16,15 +16,19 @@ TrackWidget::TrackWidget(QWidget *parent) : QWidget(parent) { setFixedSize(spinner_size); - setAutoFillBackground(false); - - comma_img = QPixmap("../assets/img_spinner_comma.png").scaled(spinner_size, Qt::KeepAspectRatio, Qt::SmoothTransformation); + setAutoFillBackground(true); + setPalette(Qt::black); // pre-compute all the track imgs. make this a gif instead? - QTransform transform; + QPixmap comma_img = QPixmap("../assets/img_spinner_comma.png").scaled(spinner_size, Qt::KeepAspectRatio, Qt::SmoothTransformation); + QTransform transform(1, 0, 0, 1, width() / 2, height() / 2); QPixmap track_img = QPixmap("../assets/img_spinner_track.png").scaled(spinner_size, Qt::KeepAspectRatio, Qt::SmoothTransformation); - for (auto &img : track_imgs) { - img = track_img.transformed(transform.rotate(360/spinner_fps), Qt::SmoothTransformation); + for (QPixmap &img : track_imgs) { + img = comma_img; + QPainter p(&img); + p.setRenderHint(QPainter::SmoothPixmapTransform); + p.setTransform(transform.rotate(360 / spinner_fps)); + p.drawPixmap(-width() / 2, -height() / 2, track_img); } m_anim.setDuration(1000); @@ -37,18 +41,7 @@ TrackWidget::TrackWidget(QWidget *parent) : QWidget(parent) { void TrackWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); - QRect bg(0, 0, painter.device()->width(), painter.device()->height()); - QBrush bgBrush("#000000"); - painter.fillRect(bg, bgBrush); - - int track_idx = m_anim.currentValue().toInt(); - QRect rect(track_imgs[track_idx].rect()); - rect.moveCenter(bg.center()); - painter.drawPixmap(rect.topLeft(), track_imgs[track_idx]); - - rect = comma_img.rect(); - rect.moveCenter(bg.center()); - painter.drawPixmap(rect.topLeft(), comma_img); + painter.drawPixmap(0, 0, track_imgs[m_anim.currentValue().toInt()]); } // Spinner @@ -75,12 +68,10 @@ Spinner::Spinner(QWidget *parent) : QWidget(parent) { Spinner { background-color: black; } - * { - background-color: transparent; - } QLabel { color: white; font-size: 80px; + background-color: transparent; } QProgressBar { background-color: #373737; @@ -114,11 +105,7 @@ void Spinner::update(int n) { } int main(int argc, char *argv[]) { - setQtSurfaceFormat(); - - Hardware::set_display_power(true); - Hardware::set_brightness(65); - + initApp(); QApplication a(argc, argv); Spinner spinner; setMainWindow(&spinner); diff --git a/selfdrive/ui/qt/spinner.h b/selfdrive/ui/qt/spinner.h index c54aea1032..43d90a75b0 100644 --- a/selfdrive/ui/qt/spinner.h +++ b/selfdrive/ui/qt/spinner.h @@ -1,7 +1,6 @@ #include #include -#include #include #include #include @@ -19,7 +18,6 @@ public: private: void paintEvent(QPaintEvent *event) override; std::array track_imgs; - QPixmap comma_img; QVariantAnimation m_anim; }; diff --git a/selfdrive/ui/qt/text.cc b/selfdrive/ui/qt/text.cc index 5d2012ea14..2d4ff88269 100644 --- a/selfdrive/ui/qt/text.cc +++ b/selfdrive/ui/qt/text.cc @@ -6,17 +6,16 @@ #include #include "selfdrive/hardware/hw.h" +#include "selfdrive/ui/qt/util.h" #include "selfdrive/ui/qt/qt_window.h" #include "selfdrive/ui/qt/widgets/scrollview.h" int main(int argc, char *argv[]) { + initApp(); QApplication a(argc, argv); QWidget window; setMainWindow(&window); - Hardware::set_display_power(true); - Hardware::set_brightness(65); - QGridLayout *main_layout = new QGridLayout(&window); main_layout->setMargin(50); diff --git a/selfdrive/ui/qt/util.cc b/selfdrive/ui/qt/util.cc index c077883d28..1091624aca 100644 --- a/selfdrive/ui/qt/util.cc +++ b/selfdrive/ui/qt/util.cc @@ -1,10 +1,12 @@ #include "selfdrive/ui/qt/util.h" +#include #include #include #include "selfdrive/common/params.h" #include "selfdrive/common/swaglog.h" +#include "selfdrive/hardware/hw.h" QString getBrand() { return Params().getBool("Passive") ? "dashcam" : "openpilot"; @@ -67,6 +69,15 @@ void setQtSurfaceFormat() { QSurfaceFormat::setDefaultFormat(fmt); } +void initApp() { + Hardware::set_display_power(true); + Hardware::set_brightness(65); + setQtSurfaceFormat(); + if (Hardware::EON()) { + QApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + } +} + ClickableWidget::ClickableWidget(QWidget *parent) : QWidget(parent) { } void ClickableWidget::mouseReleaseEvent(QMouseEvent *event) { diff --git a/selfdrive/ui/qt/util.h b/selfdrive/ui/qt/util.h index 6b9d4512b8..96af6ff26e 100644 --- a/selfdrive/ui/qt/util.h +++ b/selfdrive/ui/qt/util.h @@ -14,6 +14,7 @@ void clearLayout(QLayout* layout); void setQtSurfaceFormat(); QString timeAgo(const QDateTime &date); void swagLogMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg); +void initApp(); class ClickableWidget : public QWidget {