From 2e07e45bedf7edbcb2b9621bb52ec2cb96dce5f8 Mon Sep 17 00:00:00 2001 From: grekiki Date: Tue, 8 Dec 2020 12:00:51 +0100 Subject: [PATCH] UI style improvements with improved keyboard (#2710) * fix spaces and make spacebar dynamically sized * some spaces and a comment * more spaces * const Co-authored-by: Comma Device old-commit-hash: 3e466aa528dfaf40063c209189bb3c9ece3bf26b --- selfdrive/common/params.cc | 2 +- selfdrive/ui/android/ui.cc | 2 +- selfdrive/ui/paint.cc | 8 +-- selfdrive/ui/qt/home.cc | 24 +++---- selfdrive/ui/qt/offroad/settings.cc | 8 +-- selfdrive/ui/qt/offroad/wifi.cc | 34 ++++----- selfdrive/ui/qt/offroad/wifiManager.cc | 86 +++++++++++------------ selfdrive/ui/qt/setup/installer.cc | 16 ++--- selfdrive/ui/qt/setup/setup.cc | 4 +- selfdrive/ui/qt/widgets/input_field.cc | 8 +-- selfdrive/ui/qt/widgets/keyboard.cc | 39 +++++----- selfdrive/ui/qt/widgets/offroad_alerts.cc | 14 ++-- selfdrive/ui/ui.cc | 2 +- 13 files changed, 125 insertions(+), 122 deletions(-) diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index da799d71d..ce079a996 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -25,7 +25,7 @@ std::string getenv_default(const char* env_var, const char * suffix, const char* const char* env_val = getenv(env_var); if (env_val != NULL){ return std::string(env_val) + std::string(suffix); - } else{ + } else { return std::string(default_val); } } diff --git a/selfdrive/ui/android/ui.cc b/selfdrive/ui/android/ui.cc index 08b734a6e..7017bd283 100644 --- a/selfdrive/ui/android/ui.cc +++ b/selfdrive/ui/android/ui.cc @@ -134,7 +134,7 @@ int main(int argc, char* argv[]) { float brightness_b = 0, brightness_m = 0; int result = read_param(&brightness_b, "BRIGHTNESS_B", true); result += read_param(&brightness_m, "BRIGHTNESS_M", true); - if(result != 0) { + if (result != 0) { brightness_b = LEON ? 10.0 : 5.0; brightness_m = LEON ? 2.6 : 1.3; write_param_float(brightness_b, "BRIGHTNESS_B", true); diff --git a/selfdrive/ui/paint.cc b/selfdrive/ui/paint.cc index 459e3f04f..fb03390ae 100644 --- a/selfdrive/ui/paint.cc +++ b/selfdrive/ui/paint.cc @@ -153,7 +153,7 @@ static void update_track_data(UIState *s, const cereal::ModelDataV2::XYZTData::R const float off = 0.5; int max_idx = 0; float lead_d; - if(s->sm->updated("radarState")) { + if (s->sm->updated("radarState")) { lead_d = scene->lead_data[0].getDRel()*2.; } else { lead_d = MAX_DRAW_DISTANCE; @@ -230,7 +230,7 @@ static void ui_draw_vision_lane_lines(UIState *s) { // paint lanelines line_vertices_data *pvd_ll = &s->lane_line_vertices[0]; for (int ll_idx = 0; ll_idx < 4; ll_idx++) { - if(s->sm->updated("modelV2")) { + if (s->sm->updated("modelV2")) { update_line_data(s, scene->model.getLaneLines()[ll_idx], 0.025*scene->model.getLaneLineProbs()[ll_idx], pvd_ll + ll_idx, scene->max_distance); } NVGcolor color = nvgRGBAf(1.0, 1.0, 1.0, scene->lane_line_probs[ll_idx]); @@ -240,7 +240,7 @@ static void ui_draw_vision_lane_lines(UIState *s) { // paint road edges line_vertices_data *pvd_re = &s->road_edge_vertices[0]; for (int re_idx = 0; re_idx < 2; re_idx++) { - if(s->sm->updated("modelV2")) { + if (s->sm->updated("modelV2")) { update_line_data(s, scene->model.getRoadEdges()[re_idx], 0.025, pvd_re + re_idx, scene->max_distance); } NVGcolor color = nvgRGBAf(1.0, 0.0, 0.0, std::clamp(1.0-scene->road_edge_stds[re_idx], 0.0, 1.0)); @@ -248,7 +248,7 @@ static void ui_draw_vision_lane_lines(UIState *s) { } // paint path - if(s->sm->updated("modelV2")) { + if (s->sm->updated("modelV2")) { update_track_data(s, scene->model.getPosition(), &s->track_vertices); } ui_draw_track(s, &s->track_vertices); diff --git a/selfdrive/ui/qt/home.cc b/selfdrive/ui/qt/home.cc index 41c0e2535..0e4d9acc7 100644 --- a/selfdrive/ui/qt/home.cc +++ b/selfdrive/ui/qt/home.cc @@ -85,12 +85,12 @@ void OffroadHome::refresh() { // update alerts alerts_widget->refresh(); - if (!alerts_widget->alerts.size() && !alerts_widget->updateAvailable){ + if (!alerts_widget->alerts.size() && !alerts_widget->updateAvailable) { alert_notification->setVisible(false); return; } - if (alerts_widget->updateAvailable){ + if (alerts_widget->updateAvailable) { // There is a new release alert_notification->setText("UPDATE"); } else { @@ -148,7 +148,7 @@ void HomeWindow::mousePressEvent(QMouseEvent *e) { } // Vision click - if (ui_state->started && (e->x() >= ui_state->scene.viz_rect.x - bdr_s)){ + if (ui_state->started && (e->x() >= ui_state->scene.viz_rect.x - bdr_s)) { ui_state->scene.uilayout_sidebarcollapsed = !ui_state->scene.uilayout_sidebarcollapsed; } } @@ -161,14 +161,14 @@ static void handle_display_state(UIState *s, int dt, bool user_input) { if (user_input || s->ignition || s->started) { s->awake = true; awake_timeout = 30*UI_FREQ; - } else if (awake_timeout == 0){ + } else if (awake_timeout == 0) { s->awake = false; } } -static void set_backlight(int brightness){ +static void set_backlight(int brightness) { std::ofstream brightness_control("/sys/class/backlight/panel0-backlight/brightness"); - if (brightness_control.is_open()){ + if (brightness_control.is_open()) { brightness_control << brightness << "\n"; brightness_control.close(); } @@ -184,7 +184,7 @@ GLWindow::GLWindow(QWidget *parent) : QOpenGLWidget(parent) { int result = read_param(&brightness_b, "BRIGHTNESS_B", true); result += read_param(&brightness_m, "BRIGHTNESS_M", true); - if(result != 0) { + if (result != 0) { brightness_b = 200.0; brightness_m = 10.0; } @@ -215,7 +215,7 @@ void GLWindow::initializeGL() { backlight_timer->start(BACKLIGHT_DT * 100); } -void GLWindow::backlightUpdate(){ +void GLWindow::backlightUpdate() { // Update brightness float k = (BACKLIGHT_DT / BACKLIGHT_TS) / (1.0f + BACKLIGHT_DT / BACKLIGHT_TS); @@ -223,7 +223,7 @@ void GLWindow::backlightUpdate(){ smooth_brightness = clipped_brightness * k + smooth_brightness * (1.0f - k); int brightness = smooth_brightness; - if (!ui_state->awake){ + if (!ui_state->awake) { brightness = 0; } @@ -231,7 +231,7 @@ void GLWindow::backlightUpdate(){ } void GLWindow::timerUpdate() { - if (ui_state->started != onroad){ + if (ui_state->started != onroad) { onroad = ui_state->started; emit offroadTransition(!onroad); #ifdef QCOM2 @@ -255,9 +255,9 @@ void GLWindow::paintGL() { ui_draw(ui_state); } -void GLWindow::wake(){ +void GLWindow::wake() { // UI state might not be initialized yet - if (ui_state != nullptr){ + if (ui_state != nullptr) { handle_display_state(ui_state, 1, true); } } diff --git a/selfdrive/ui/qt/offroad/settings.cc b/selfdrive/ui/qt/offroad/settings.cc index 50b42f4e8..4e650a0c4 100644 --- a/selfdrive/ui/qt/offroad/settings.cc +++ b/selfdrive/ui/qt/offroad/settings.cc @@ -24,13 +24,13 @@ ParamsToggle::ParamsToggle(QString param, QString title, QString description, QS // Parameter image hlayout->addSpacing(25); - if (icon_path.length()){ + if (icon_path.length()) { QPixmap pix(icon_path); QLabel *icon = new QLabel(); icon->setPixmap(pix.scaledToWidth(100, Qt::SmoothTransformation)); icon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); hlayout->addWidget(icon); - } else{ + } else { hlayout->addSpacing(100); } hlayout->addSpacing(25); @@ -50,7 +50,7 @@ ParamsToggle::ParamsToggle(QString param, QString title, QString description, QS hlayout->addSpacing(20); setLayout(hlayout); - if(Params().read_db_bool(param.toStdString().c_str())){ + if (Params().read_db_bool(param.toStdString().c_str())) { toggle_switch->togglePosition(); } @@ -66,7 +66,7 @@ ParamsToggle::ParamsToggle(QString param, QString title, QString description, QS QObject::connect(toggle_switch, SIGNAL(stateChanged(int)), this, SLOT(checkboxClicked(int))); } -void ParamsToggle::checkboxClicked(int state){ +void ParamsToggle::checkboxClicked(int state) { char value = state ? '1': '0'; Params().write_db_value(param.toStdString().c_str(), &value, 1); } diff --git a/selfdrive/ui/qt/offroad/wifi.cc b/selfdrive/ui/qt/offroad/wifi.cc index eb2697f9b..e7792ef26 100644 --- a/selfdrive/ui/qt/offroad/wifi.cc +++ b/selfdrive/ui/qt/offroad/wifi.cc @@ -10,7 +10,7 @@ void clearLayout(QLayout* layout) { while (QLayoutItem* item = layout->takeAt(0)) { - if (QWidget* widget = item->widget()){ + if (QWidget* widget = item->widget()) { widget->deleteLater(); } if (QLayout* childLayout = item->layout()) { @@ -37,7 +37,7 @@ WifiUI::WifiUI(QWidget *parent, int page_length) : QWidget(parent), networks_per Toggle* toggle_switch = new Toggle(this); toggle_switch->setFixedSize(150, 100); tethering_field->addWidget(toggle_switch); - if (wifi->tetheringEnabled()){ + if (wifi->tetheringEnabled()) { toggle_switch->togglePosition(); } QObject::connect(toggle_switch, SIGNAL(stateChanged(int)), this, SLOT(toggleTethering(int))); @@ -97,9 +97,9 @@ void WifiUI::refresh() { int i = 0; int countWidgets = 0; int button_height = static_cast(this->height() / (networks_per_page + 1) * 0.6); - for (Network &network : wifi->seen_networks){ + for (Network &network : wifi->seen_networks) { QHBoxLayout *hlayout = new QHBoxLayout; - if(page * networks_per_page <= i && i < (page + 1) * networks_per_page){ + if (page * networks_per_page <= i && i < (page + 1) * networks_per_page) { // SSID hlayout->addSpacing(50); hlayout->addWidget(new QLabel(QString::fromUtf8(network.ssid))); @@ -148,7 +148,7 @@ void WifiUI::refresh() { } // Pad vlayout to prevert oversized network widgets in case of low visible network count - for(int i = countWidgets; i < networks_per_page; i++) { + for (int i = countWidgets; i < networks_per_page; i++) { QWidget *w = new QWidget; vlayout->addWidget(w); } @@ -187,10 +187,10 @@ void WifiUI::refresh() { -void WifiUI::toggleTethering(int enable){ - if(enable){ +void WifiUI::toggleTethering(int enable) { + if (enable) { wifi->enableTethering(); - }else{ + } else { wifi->disableTethering(); } } @@ -201,14 +201,14 @@ void WifiUI::handleButton(QAbstractButton* button) { connectToNetwork(n); } -void WifiUI::connectToNetwork(Network n){ +void WifiUI::connectToNetwork(Network n) { timer->stop(); - if(n.security_type == SecurityType::OPEN){ + if (n.security_type == SecurityType::OPEN) { wifi->connect(n); - } else if (n.security_type == SecurityType::WPA){ + } else if (n.security_type == SecurityType::WPA) { input_field->setPromptText("Enter password for \"" + n.ssid + "\""); QString password = getStringFromUser(); - if(password.size()){ + if (password.size()) { wifi->connect(n, password); } } @@ -216,7 +216,7 @@ void WifiUI::connectToNetwork(Network n){ timer->start(); } -QString WifiUI::getStringFromUser(){ +QString WifiUI::getStringFromUser() { emit openKeyboard(); swidget->setCurrentIndex(1); loop.exec(); @@ -231,12 +231,12 @@ void WifiUI::receiveText(QString t) { } -void WifiUI::wrongPassword(QString ssid){ - if(loop.isRunning()){ +void WifiUI::wrongPassword(QString ssid) { + if (loop.isRunning()) { return; } - for(Network n : wifi->seen_networks){ - if(n.ssid == ssid){ + for (Network n : wifi->seen_networks) { + if (n.ssid == ssid) { input_field->setPromptText("Wrong password for \"" + n.ssid +"\""); connectToNetwork(n); } diff --git a/selfdrive/ui/qt/offroad/wifiManager.cc b/selfdrive/ui/qt/offroad/wifiManager.cc index a06164138..eea4ebecf 100644 --- a/selfdrive/ui/qt/offroad/wifiManager.cc +++ b/selfdrive/ui/qt/offroad/wifiManager.cc @@ -40,14 +40,14 @@ const int state_need_auth = 60; const int reason_wrong_password = 8; template -T get_response(QDBusMessage response){ +T get_response(QDBusMessage response) { QVariant first = response.arguments().at(0); QDBusVariant dbvFirst = first.value(); QVariant vFirst = dbvFirst.variant(); return vFirst.value(); } -bool compare_by_strength(const Network &a, const Network &b){ +bool compare_by_strength(const Network &a, const Network &b) { if (a.connected == ConnectedType::CONNECTED) return true; if (b.connected == ConnectedType::CONNECTED) return false; if (a.connected == ConnectedType::CONNECTING) return true; @@ -56,13 +56,13 @@ bool compare_by_strength(const Network &a, const Network &b){ } -WifiManager::WifiManager(){ +WifiManager::WifiManager() { qDBusRegisterMetaType(); qDBusRegisterMetaType(); connecting_to_network = ""; adapter = get_adapter(); has_adapter = adapter != ""; - if (has_adapter){ + if (has_adapter) { QDBusInterface nm(nm_service, adapter, device_iface, bus); bus.connect(nm_service, adapter, device_iface, "StateChanged", this, SLOT(change(unsigned int, unsigned int, unsigned int))); @@ -75,20 +75,20 @@ WifiManager::WifiManager(){ // Compute tethering ssid as "Weedle" + first 4 characters of a dongle id tethering_ssid = "weedle"; std::string bytes = Params().get("DongleId"); - if (bytes.length() >= 4){ + if (bytes.length() >= 4) { tethering_ssid+="-"+QString::fromStdString(bytes.substr(0,4)); } } -void WifiManager::refreshNetworks(){ +void WifiManager::refreshNetworks() { if (!has_adapter) return; bus = QDBusConnection::systemBus(); seen_networks.clear(); seen_ssids.clear(); - for (Network &network : get_networks()){ - if (seen_ssids.count(network.ssid)){ + for (Network &network : get_networks()) { + if (seen_ssids.count(network.ssid)) { continue; } seen_ssids.push_back(network.ssid); @@ -96,7 +96,7 @@ void WifiManager::refreshNetworks(){ } } -QList WifiManager::get_networks(){ +QList WifiManager::get_networks() { QList r; QDBusInterface nm(nm_service, adapter, wireless_device_iface, bus); QDBusMessage response = nm.call("GetAllAccessPoints"); @@ -113,18 +113,18 @@ QList WifiManager::get_networks(){ unsigned int strength = get_ap_strength(path.path()); SecurityType security = getSecurityType(path.path()); ConnectedType ctype; - if (path.path() != active_ap){ + if (path.path() != active_ap) { ctype = ConnectedType::DISCONNECTED; - }else { - if (ssid == connecting_to_network){ + } else { + if (ssid == connecting_to_network) { ctype = ConnectedType::CONNECTING; - }else { + } else { ctype = ConnectedType::CONNECTED; } } Network network = {path.path(), ssid, strength, ctype, security}; - if (ssid.length()){ + if (ssid.length()) { r.push_back(network); } } @@ -134,7 +134,7 @@ QList WifiManager::get_networks(){ return r; } -SecurityType WifiManager::getSecurityType(QString path){ +SecurityType WifiManager::getSecurityType(QString path) { int sflag = get_property(path, "Flags").toInt(); int wpaflag = get_property(path, "WpaFlags").toInt(); int rsnflag = get_property(path, "RsnFlags").toInt(); @@ -143,7 +143,7 @@ SecurityType WifiManager::getSecurityType(QString path){ // obtained by looking at flags of networks in the office as reported by an Android phone const int supports_wpa = NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104 | NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104 | NM_802_11_AP_SEC_KEY_MGMT_PSK; - if (sflag == 0){ + if (sflag == 0) { return SecurityType::OPEN; } else if ((sflag & NM_802_11_AP_FLAGS_PRIVACY) && (wpa_props & supports_wpa) && !(wpa_props & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) { return SecurityType::WPA; @@ -152,22 +152,22 @@ SecurityType WifiManager::getSecurityType(QString path){ } } -void WifiManager::connect(Network n){ +void WifiManager::connect(Network n) { return connect(n, "", ""); } -void WifiManager::connect(Network n, QString password){ +void WifiManager::connect(Network n, QString password) { return connect(n, "", password); } -void WifiManager::connect(Network n, QString username, QString password){ +void WifiManager::connect(Network n, QString username, QString password) { connecting_to_network = n.ssid; disconnect(); clear_connections(n.ssid); //Clear all connections that may already exist to the network we are connecting connect(n.ssid, username, password, n.security_type); } -void WifiManager::connect(QByteArray ssid, QString username, QString password, SecurityType security_type){ +void WifiManager::connect(QByteArray ssid, QString username, QString password, SecurityType security_type) { Connection connection; connection["connection"]["type"] = "802-11-wireless"; connection["connection"]["uuid"] = QUuid::createUuid().toString().remove('{').remove('}'); @@ -177,7 +177,7 @@ void WifiManager::connect(QByteArray ssid, QString username, QString password, S connection["802-11-wireless"]["ssid"] = ssid; connection["802-11-wireless"]["mode"] = "infrastructure"; - if (security_type == SecurityType::WPA){ + if (security_type == SecurityType::WPA) { connection["802-11-wireless-security"]["key-mgmt"] = "wpa-psk"; connection["802-11-wireless-security"]["auth-alg"] = "open"; connection["802-11-wireless-security"]["psk"] = password; @@ -190,20 +190,20 @@ void WifiManager::connect(QByteArray ssid, QString username, QString password, S nm_settings.call("AddConnection", QVariant::fromValue(connection)); } -void WifiManager::deactivate_connections(QString ssid){ - for (QDBusObjectPath active_connection_raw : get_active_connections()){ +void WifiManager::deactivate_connections(QString ssid) { + for (QDBusObjectPath active_connection_raw : get_active_connections()) { QString active_connection = active_connection_raw.path(); QDBusInterface nm(nm_service, active_connection, props_iface, bus); QDBusObjectPath pth = get_response(nm.call("Get", connection_iface, "SpecificObject")); QString Ssid = get_property(pth.path(), "Ssid"); - if (Ssid == ssid){ + if (Ssid == ssid) { QDBusInterface nm2(nm_service, nm_path, nm_iface, bus); nm2.call("DeactivateConnection", QVariant::fromValue(active_connection_raw)); } } } -QVector WifiManager::get_active_connections(){ +QVector WifiManager::get_active_connections() { QDBusInterface nm(nm_service, nm_path, props_iface, bus); QDBusMessage response = nm.call("Get", nm_iface, "ActiveConnections"); QDBusArgument arr = get_response(response); @@ -211,14 +211,14 @@ QVector WifiManager::get_active_connections(){ QDBusObjectPath path; arr.beginArray(); - while (!arr.atEnd()){ + while (!arr.atEnd()) { arr >> path; conns.push_back(path); } return conns; } -void WifiManager::clear_connections(QString ssid){ +void WifiManager::clear_connections(QString ssid) { QDBusInterface nm(nm_service, nm_settings_path, nm_settings_iface, bus); QDBusMessage response = nm.call("ListConnections"); QVariant first = response.arguments().at(0); @@ -237,9 +237,9 @@ void WifiManager::clear_connections(QString ssid){ for (QString outer_key : map.keys()) { QMap innerMap = map.value(outer_key); for (QString inner_key : innerMap.keys()) { - if (inner_key == "ssid"){ + if (inner_key == "ssid") { QString value = innerMap.value(inner_key).value(); - if (value == ssid){ + if (value == ssid) { nm2.call("Delete"); } } @@ -248,40 +248,40 @@ void WifiManager::clear_connections(QString ssid){ } } -void WifiManager::request_scan(){ +void WifiManager::request_scan() { if (!has_adapter) return; QDBusInterface nm(nm_service, adapter, wireless_device_iface, bus); nm.call("RequestScan", QVariantMap()); } -uint WifiManager::get_wifi_device_state(){ +uint WifiManager::get_wifi_device_state() { QDBusInterface device_props(nm_service, adapter, props_iface, bus); QDBusMessage response = device_props.call("Get", device_iface, "State"); uint resp = get_response(response); return resp; } -QString WifiManager::get_active_ap(){ +QString WifiManager::get_active_ap() { QDBusInterface device_props(nm_service, adapter, props_iface, bus); QDBusMessage response = device_props.call("Get", wireless_device_iface, "ActiveAccessPoint"); QDBusObjectPath r = get_response(response); return r.path(); } -QByteArray WifiManager::get_property(QString network_path ,QString property){ +QByteArray WifiManager::get_property(QString network_path ,QString property) { QDBusInterface device_props(nm_service, network_path, props_iface, bus); QDBusMessage response = device_props.call("Get", ap_iface, property); return get_response(response); } -unsigned int WifiManager::get_ap_strength(QString network_path){ +unsigned int WifiManager::get_ap_strength(QString network_path) { QDBusInterface device_props(nm_service, network_path, props_iface, bus); QDBusMessage response = device_props.call("Get", ap_iface, "Strength"); return get_response(response); } -QString WifiManager::get_adapter(){ +QString WifiManager::get_adapter() { QDBusInterface nm(nm_service, nm_path, nm_iface, bus); QDBusMessage response = nm.call("GetDevices"); @@ -310,25 +310,25 @@ QString WifiManager::get_adapter(){ return adapter_path; } -void WifiManager::change(unsigned int new_state,unsigned int previous_state,unsigned int change_reason){ +void WifiManager::change(unsigned int new_state,unsigned int previous_state,unsigned int change_reason) { raw_adapter_state = new_state; - if (new_state == state_need_auth && change_reason == reason_wrong_password){ + if (new_state == state_need_auth && change_reason == reason_wrong_password) { emit wrongPassword(connecting_to_network); - }else if (new_state == state_connected){ + } else if (new_state == state_connected) { connecting_to_network = ""; } } -void WifiManager::disconnect(){ +void WifiManager::disconnect() { QString active_ap = get_active_ap(); - if (active_ap!="" && active_ap!="/"){ + if (active_ap!="" && active_ap!="/") { deactivate_connections(get_property(active_ap, "Ssid")); } } //Functions for tethering -void WifiManager::enableTethering(){ +void WifiManager::enableTethering() { disconnect(); Connection connection; connection["connection"]["id"] = "Hotspot"; @@ -359,11 +359,11 @@ void WifiManager::enableTethering(){ } -void WifiManager::disableTethering(){ +void WifiManager::disableTethering() { clear_connections(tethering_ssid); } -bool WifiManager::tetheringEnabled(){ +bool WifiManager::tetheringEnabled() { QString active_ap = get_active_ap(); return get_property(active_ap, "Ssid") == tethering_ssid; } diff --git a/selfdrive/ui/qt/setup/installer.cc b/selfdrive/ui/qt/setup/installer.cc index 40b57a78e..abfde8491 100644 --- a/selfdrive/ui/qt/setup/installer.cc +++ b/selfdrive/ui/qt/setup/installer.cc @@ -25,20 +25,20 @@ int fresh_clone() { // Cleanup err = std::system("rm -rf /tmp/openpilot"); - if(err) return 1; + if (err) return 1; err = std::system("rm -rf /data/openpilot"); - if(err) return 1; + if (err) return 1; // Clone err = std::system("git clone " GIT_URL " -b " BRANCH " --depth=1 /tmp/openpilot"); - if(err) return 1; + if (err) return 1; err = std::system("cd /tmp/openpilot && git submodule update --init"); - if(err) return 1; + if (err) return 1; err = std::system("cd /tmp/openpilot && git remote set-url origin --push " GIT_SSH_URL); - if(err) return 1; + if (err) return 1; err = std::system("mv /tmp/openpilot /data"); - if(err) return 1; + if (err) return 1; return 0; } @@ -56,11 +56,11 @@ int install() { std::cout << "Doing fresh clone\n"; err = fresh_clone(); - if(err) return 1; + if (err) return 1; // Write continue.sh err = std::system("cp /data/openpilot/installer/continue_openpilot.sh " CONTINUE_PATH); - if(err == -1) return 1; + if (err == -1) return 1; return 0; } diff --git a/selfdrive/ui/qt/setup/setup.cc b/selfdrive/ui/qt/setup/setup.cc index 0a684c076..5b7845740 100644 --- a/selfdrive/ui/qt/setup/setup.cc +++ b/selfdrive/ui/qt/setup/setup.cc @@ -76,10 +76,10 @@ QWidget * Setup::network_setup() { WifiUI *wifi = new WifiUI(this, 6); main_layout->addWidget(wifi); - QObject::connect(wifi, &WifiUI::openKeyboard, this, [=](){ + QObject::connect(wifi, &WifiUI::openKeyboard, this, [=]() { this->continue_btn->setVisible(false); }); - QObject::connect(wifi, &WifiUI::closeKeyboard, this, [=](){ + QObject::connect(wifi, &WifiUI::closeKeyboard, this, [=]() { this->continue_btn->setVisible(true); }); diff --git a/selfdrive/ui/qt/widgets/input_field.cc b/selfdrive/ui/qt/widgets/input_field.cc index 8492f36d8..858c1c75a 100644 --- a/selfdrive/ui/qt/widgets/input_field.cc +++ b/selfdrive/ui/qt/widgets/input_field.cc @@ -44,18 +44,18 @@ void InputField::emitEmpty() { } void InputField::getText(QString s) { - if(!QString::compare(s,"⌫")){ + if (!QString::compare(s,"⌫")) { line->backspace(); } - if(!QString::compare(s,"⏎")){ + if (!QString::compare(s,"⏎")) { emitText(line->text()); line->setText(""); } QVector control_buttons {"⇧", "↑", "ABC", "⏎", "#+=", "⌫", "123"}; - for(QString c : control_buttons){ - if(!QString::compare(s, c)){ + for(QString c : control_buttons) { + if (!QString::compare(s, c)) { return; } } diff --git a/selfdrive/ui/qt/widgets/keyboard.cc b/selfdrive/ui/qt/widgets/keyboard.cc index 0f7dd58ca..bf192aa5d 100644 --- a/selfdrive/ui/qt/widgets/keyboard.cc +++ b/selfdrive/ui/qt/widgets/keyboard.cc @@ -7,34 +7,37 @@ #include "keyboard.hpp" -KeyboardLayout::KeyboardLayout(QWidget* parent, std::vector> layout) : QWidget(parent) { +const int DEFAULT_WIDTH = 1; +const int SPACEBAR_WIDTH = 3; + +KeyboardLayout::KeyboardLayout(QWidget *parent, std::vector> layout) : QWidget(parent) { QVBoxLayout* vlayout = new QVBoxLayout; QButtonGroup* btn_group = new QButtonGroup(this); QObject::connect(btn_group, SIGNAL(buttonClicked(QAbstractButton*)), parent, SLOT(handleButton(QAbstractButton*))); int i = 0; - for(auto s : layout){ + for (auto s : layout) { QHBoxLayout *hlayout = new QHBoxLayout; - if (i == 1){ + if (i == 1) { hlayout->addSpacing(90); } - for(QString p : s){ + for (QString p : s) { QPushButton* btn = new QPushButton(p); btn->setFixedHeight(120); - - if (p == QString(" ")){ - btn->setFixedWidth(1024); - } - btn_group->addButton(btn); hlayout->addSpacing(10); - hlayout->addWidget(btn); + if (p == QString(" ")) { + hlayout->addWidget(btn, SPACEBAR_WIDTH); + } else { + hlayout->addWidget(btn, DEFAULT_WIDTH); + } + } - if (i == 1){ + if (i == 1) { hlayout->addSpacing(90); } @@ -99,24 +102,24 @@ Keyboard::Keyboard(QWidget *parent) : QWidget(parent) { } -void Keyboard::handleButton(QAbstractButton* m_button){ +void Keyboard::handleButton(QAbstractButton* m_button) { QString id = m_button->text(); - if(!QString::compare(m_button->text(),"↑")||!QString::compare(m_button->text(),"ABC")){ + if (!QString::compare(m_button->text(), "↑") || !QString::compare(m_button->text(), "ABC")) { main_layout->setCurrentIndex(0); } - if(!QString::compare(m_button->text(),"⇧")){ + if (!QString::compare(m_button->text(), "⇧")) { main_layout->setCurrentIndex(1); } - if(!QString::compare(m_button->text(),"123")){ + if (!QString::compare(m_button->text(), "123")) { main_layout->setCurrentIndex(2); } - if(!QString::compare(m_button->text(),"#+=")){ + if (!QString::compare(m_button->text(), "#+=")) { main_layout->setCurrentIndex(3); } - if(!QString::compare(m_button->text(),"⏎")){ + if (!QString::compare(m_button->text(), "⏎")) { main_layout->setCurrentIndex(0); } - if("A" <= id && id <= "Z"){ + if ("A" <= id && id <= "Z") { main_layout->setCurrentIndex(0); } emit emitButton(m_button->text()); diff --git a/selfdrive/ui/qt/widgets/offroad_alerts.cc b/selfdrive/ui/qt/widgets/offroad_alerts.cc index 452ee1021..08c8bcde6 100644 --- a/selfdrive/ui/qt/widgets/offroad_alerts.cc +++ b/selfdrive/ui/qt/widgets/offroad_alerts.cc @@ -12,7 +12,7 @@ void cleanLayout(QLayout* layout) { while (QLayoutItem* item = layout->takeAt(0)) { - if (QWidget* widget = item->widget()){ + if (QWidget* widget = item->widget()) { widget->deleteLater(); } if (QLayout* childLayout = item->layout()) { @@ -22,11 +22,11 @@ void cleanLayout(QLayout* layout) { } } -QString vectorToQString(std::vector v){ +QString vectorToQString(std::vector v) { return QString::fromStdString(std::string(v.begin(), v.end())); } -OffroadAlert::OffroadAlert(QWidget* parent){ +OffroadAlert::OffroadAlert(QWidget* parent) { vlayout = new QVBoxLayout; refresh(); setLayout(vlayout); @@ -38,7 +38,7 @@ void OffroadAlert::refresh() { updateAvailable = false; std::vector bytes = Params().read_db_bytes("UpdateAvailable"); - if (bytes.size() && bytes[0] == '1'){ + if (bytes.size() && bytes[0] == '1') { updateAvailable = true; } @@ -91,7 +91,7 @@ void OffroadAlert::refresh() { } else { vlayout->addSpacing(60); - for (auto alert : alerts){ + for (auto alert : alerts) { QLabel *l = new QLabel(alert.text); l->setWordWrap(true); l->setMargin(60); @@ -122,7 +122,7 @@ void OffroadAlert::refresh() { QObject::connect(hide_btn, SIGNAL(released()), this, SIGNAL(closeAlerts())); } -void OffroadAlert::parse_alerts(){ +void OffroadAlert::parse_alerts() { alerts.clear(); // We launch in selfdrive/ui QFile inFile("../controls/lib/alerts_offroad.json"); @@ -139,7 +139,7 @@ void OffroadAlert::parse_alerts(){ for (const QString& key : json.keys()) { std::vector bytes = Params().read_db_bytes(key.toStdString().c_str()); - if (bytes.size()){ + if (bytes.size()) { QJsonDocument doc_par = QJsonDocument::fromJson(QByteArray(bytes.data(), bytes.size())); QJsonObject obj = doc_par.object(); Alert alert = {obj.value("text").toString(), obj.value("severity").toInt()}; diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index c9f321b09..8a0ceded0 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -138,7 +138,7 @@ void update_sockets(UIState *s) { s->status = STATUS_WARNING; } else if (alertStatus == cereal::ControlsState::AlertStatus::CRITICAL) { s->status = STATUS_ALERT; - } else{ + } else { s->status = scene.controls_state.getEnabled() ? STATUS_ENGAGED : STATUS_DISENGAGED; }