mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-22 17:52:07 +08:00
Sidebar: repaint only when properties updated (#20929)
* use qt_property s * cleanup * little more Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> old-commit-hash: 179ff6e7ae0d3d1648860b3b2b1e7b4b96fb4756
This commit is contained in:
@@ -21,7 +21,7 @@ HomeWindow::HomeWindow(QWidget* parent) : QWidget(parent) {
|
||||
|
||||
sidebar = new Sidebar(this);
|
||||
layout->addWidget(sidebar);
|
||||
QObject::connect(this, &HomeWindow::update, sidebar, &Sidebar::update);
|
||||
QObject::connect(this, &HomeWindow::update, sidebar, &Sidebar::updateState);
|
||||
QObject::connect(sidebar, &Sidebar::openSettings, this, &HomeWindow::openSettings);
|
||||
|
||||
slayout = new QStackedLayout();
|
||||
|
||||
+31
-30
@@ -37,6 +37,8 @@ Sidebar::Sidebar(QWidget *parent) : QFrame(parent) {
|
||||
home_img = QImage("../assets/images/button_home.png").scaled(180, 180, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
settings_img = QImage("../assets/images/button_settings.png").scaled(settings_btn.width(), settings_btn.height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);;
|
||||
|
||||
connect(this, &Sidebar::valueChanged, [=] { update(); });
|
||||
|
||||
setFixedWidth(300);
|
||||
setMinimumHeight(vwp_h);
|
||||
setStyleSheet("background-color: rgb(57, 57, 57);");
|
||||
@@ -48,45 +50,44 @@ void Sidebar::mousePressEvent(QMouseEvent *event) {
|
||||
}
|
||||
}
|
||||
|
||||
void Sidebar::update(const UIState &s) {
|
||||
if (s.sm->frame % (6*UI_FREQ) == 0) {
|
||||
connect_str = "OFFLINE";
|
||||
connect_status = warning_color;
|
||||
auto last_ping = params.get<float>("LastAthenaPingTime");
|
||||
if (last_ping) {
|
||||
bool online = nanos_since_boot() - *last_ping < 80e9;
|
||||
connect_str = online ? "ONLINE" : "ERROR";
|
||||
connect_status = online ? good_color : danger_color;
|
||||
}
|
||||
repaint();
|
||||
void Sidebar::updateState(const UIState &s) {
|
||||
auto &sm = *(s.sm);
|
||||
|
||||
auto deviceState = sm["deviceState"].getDeviceState();
|
||||
setProperty("netType", (int)deviceState.getNetworkType());
|
||||
setProperty("netStrength", (int)deviceState.getNetworkStrength());
|
||||
|
||||
auto last_ping = deviceState.getLastAthenaPingTime();
|
||||
if (last_ping == 0) {
|
||||
setProperty("connectStr", "OFFLINE");
|
||||
setProperty("connectStatus", warning_color);
|
||||
} else {
|
||||
bool online = nanos_since_boot() - last_ping < 80e9;
|
||||
setProperty("connectStr", online ? "ONLINE" : "ERROR");
|
||||
setProperty("connectStatus", online ? good_color : danger_color);
|
||||
}
|
||||
|
||||
auto deviceState = (*s.sm)["deviceState"].getDeviceState();
|
||||
net_type = deviceState.getNetworkType();
|
||||
strength = deviceState.getNetworkStrength();
|
||||
|
||||
temp_status = danger_color;
|
||||
QColor tempStatus = danger_color;
|
||||
auto ts = deviceState.getThermalStatus();
|
||||
if (ts == cereal::DeviceState::ThermalStatus::GREEN) {
|
||||
temp_status = good_color;
|
||||
tempStatus = good_color;
|
||||
} else if (ts == cereal::DeviceState::ThermalStatus::YELLOW) {
|
||||
temp_status = warning_color;
|
||||
tempStatus = warning_color;
|
||||
}
|
||||
temp_val = (int)deviceState.getAmbientTempC();
|
||||
setProperty("tempStatus", tempStatus);
|
||||
setProperty("tempVal", (int)deviceState.getAmbientTempC());
|
||||
|
||||
panda_str = "VEHICLE\nONLINE";
|
||||
panda_status = good_color;
|
||||
QString pandaStr = "VEHICLE\nONLINE";
|
||||
QColor pandaStatus = good_color;
|
||||
if (s.scene.pandaType == cereal::PandaState::PandaType::UNKNOWN) {
|
||||
panda_status = danger_color;
|
||||
panda_str = "NO\nPANDA";
|
||||
pandaStatus = danger_color;
|
||||
pandaStr = "NO\nPANDA";
|
||||
} else if (Hardware::TICI() && s.scene.started) {
|
||||
panda_str = QString("SATS %1\nACC %2").arg(s.scene.satelliteCount).arg(fmin(10, s.scene.gpsAccuracy), 0, 'f', 2);
|
||||
panda_status = (*s.sm)["liveLocationKalman"].getLiveLocationKalman().getGpsOK() ? good_color : warning_color;
|
||||
}
|
||||
|
||||
if (s.sm->updated("deviceState") || s.sm->updated("pandaState")) {
|
||||
repaint();
|
||||
pandaStr = QString("SATS %1\nACC %2").arg(s.scene.satelliteCount).arg(fmin(10, s.scene.gpsAccuracy), 0, 'f', 2);
|
||||
pandaStatus = sm["liveLocationKalman"].getLiveLocationKalman().getGpsOK() ? good_color : warning_color;
|
||||
}
|
||||
setProperty("pandaStr", pandaStr);
|
||||
setProperty("pandaStatus", pandaStatus);
|
||||
}
|
||||
|
||||
void Sidebar::paintEvent(QPaintEvent *event) {
|
||||
@@ -101,7 +102,7 @@ void Sidebar::paintEvent(QPaintEvent *event) {
|
||||
p.drawImage(60, 1080 - 180 - 40, home_img);
|
||||
|
||||
// network
|
||||
p.drawImage(58, 196, signal_imgs[strength]);
|
||||
p.drawImage(58, 196, signal_imgs[net_strength]);
|
||||
configFont(p, "Open Sans", 35, "Regular");
|
||||
p.setPen(QColor(0xff, 0xff, 0xff));
|
||||
const QRect r = QRect(50, 247, 100, 50);
|
||||
|
||||
@@ -6,15 +6,24 @@
|
||||
|
||||
class Sidebar : public QFrame {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString connectStr MEMBER connect_str NOTIFY valueChanged);
|
||||
Q_PROPERTY(QColor connectStatus MEMBER connect_status NOTIFY valueChanged);
|
||||
Q_PROPERTY(QString pandaStr MEMBER panda_str NOTIFY valueChanged);
|
||||
Q_PROPERTY(QColor pandaStatus MEMBER panda_status NOTIFY valueChanged);
|
||||
Q_PROPERTY(int tempVal MEMBER temp_val NOTIFY valueChanged);
|
||||
Q_PROPERTY(QColor tempStatus MEMBER temp_status NOTIFY valueChanged);
|
||||
Q_PROPERTY(cereal::DeviceState::NetworkType netType MEMBER net_type NOTIFY valueChanged);
|
||||
Q_PROPERTY(cereal::DeviceState::NetworkStrength netStrength MEMBER net_strength NOTIFY valueChanged);
|
||||
|
||||
public:
|
||||
explicit Sidebar(QWidget* parent = 0);
|
||||
|
||||
signals:
|
||||
void openSettings();
|
||||
void valueChanged();
|
||||
|
||||
public slots:
|
||||
void update(const UIState &s);
|
||||
void updateState(const UIState &s);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
@@ -45,7 +54,6 @@ private:
|
||||
const QColor warning_color = QColor(218, 202, 37);
|
||||
const QColor danger_color = QColor(201, 34, 49);
|
||||
|
||||
Params params;
|
||||
QString connect_str = "OFFLINE";
|
||||
QColor connect_status = warning_color;
|
||||
QString panda_str = "NO\nPANDA";
|
||||
@@ -53,5 +61,5 @@ private:
|
||||
int temp_val = 0;
|
||||
QColor temp_status = warning_color;
|
||||
cereal::DeviceState::NetworkType net_type;
|
||||
cereal::DeviceState::NetworkStrength strength;
|
||||
cereal::DeviceState::NetworkStrength net_strength;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user