sidebar: draw network strength without images (#21185)

* draw network strength without images

* Trigger Build
old-commit-hash: 48696105ae
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent f70a79b838
commit 7e5def641e
  1. 11
      selfdrive/ui/qt/sidebar.cc
  2. 11
      selfdrive/ui/qt/sidebar.h

@ -55,7 +55,7 @@ void Sidebar::updateState(const UIState &s) {
auto deviceState = sm["deviceState"].getDeviceState(); auto deviceState = sm["deviceState"].getDeviceState();
setProperty("netType", network_type[deviceState.getNetworkType()]); setProperty("netType", network_type[deviceState.getNetworkType()]);
setProperty("netStrength", signal_imgs[deviceState.getNetworkStrength()]); setProperty("netStrength", (int)deviceState.getNetworkStrength());
auto last_ping = deviceState.getLastAthenaPingTime(); auto last_ping = deviceState.getLastAthenaPingTime();
if (last_ping == 0) { if (last_ping == 0) {
@ -102,7 +102,14 @@ void Sidebar::paintEvent(QPaintEvent *event) {
p.drawImage(60, 1080 - 180 - 40, home_img); p.drawImage(60, 1080 - 180 - 40, home_img);
// network // network
p.drawImage(58, 196, net_strength); int x = 58;
const QColor gray(0x54, 0x54, 0x54);
for (int i = 0; i < 5; ++i) {
p.setBrush(i < net_strength ? Qt::white : gray);
p.drawEllipse(x, 196, 27, 27);
x += 37;
}
configFont(p, "Open Sans", 35, "Regular"); configFont(p, "Open Sans", 35, "Regular");
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);

@ -13,7 +13,7 @@ class Sidebar : public QFrame {
Q_PROPERTY(int tempVal MEMBER temp_val NOTIFY valueChanged); Q_PROPERTY(int tempVal MEMBER temp_val NOTIFY valueChanged);
Q_PROPERTY(QColor tempStatus MEMBER temp_status NOTIFY valueChanged); Q_PROPERTY(QColor tempStatus MEMBER temp_status NOTIFY valueChanged);
Q_PROPERTY(QString netType MEMBER net_type NOTIFY valueChanged); Q_PROPERTY(QString netType MEMBER net_type NOTIFY valueChanged);
Q_PROPERTY(QImage netStrength MEMBER net_strength NOTIFY valueChanged); Q_PROPERTY(int netStrength MEMBER net_strength NOTIFY valueChanged);
public: public:
explicit Sidebar(QWidget* parent = 0); explicit Sidebar(QWidget* parent = 0);
@ -41,13 +41,6 @@ private:
{cereal::DeviceState::NetworkType::CELL4_G, "LTE"}, {cereal::DeviceState::NetworkType::CELL4_G, "LTE"},
{cereal::DeviceState::NetworkType::CELL5_G, "5G"} {cereal::DeviceState::NetworkType::CELL5_G, "5G"}
}; };
const QMap<cereal::DeviceState::NetworkStrength, QImage> signal_imgs = {
{cereal::DeviceState::NetworkStrength::UNKNOWN, QImage("../assets/images/network_0.png")},
{cereal::DeviceState::NetworkStrength::POOR, QImage("../assets/images/network_1.png")},
{cereal::DeviceState::NetworkStrength::MODERATE, QImage("../assets/images/network_2.png")},
{cereal::DeviceState::NetworkStrength::GOOD, QImage("../assets/images/network_3.png")},
{cereal::DeviceState::NetworkStrength::GREAT, QImage("../assets/images/network_4.png")},
};
const QRect settings_btn = QRect(50, 35, 200, 117); const QRect settings_btn = QRect(50, 35, 200, 117);
const QColor good_color = QColor(255, 255, 255); const QColor good_color = QColor(255, 255, 255);
@ -61,5 +54,5 @@ private:
int temp_val = 0; int temp_val = 0;
QColor temp_status = warning_color; QColor temp_status = warning_color;
QString net_type; QString net_type;
QImage net_strength; int net_strength = 0;
}; };

Loading…
Cancel
Save