|
|
@ -4,34 +4,34 @@ |
|
|
|
#include <QHBoxLayout> |
|
|
|
#include <QHBoxLayout> |
|
|
|
#include <QLabel> |
|
|
|
#include <QLabel> |
|
|
|
#include <QPainter> |
|
|
|
#include <QPainter> |
|
|
|
|
|
|
|
#include <QScrollBar> |
|
|
|
|
|
|
|
|
|
|
|
#include "selfdrive/ui/qt/widgets/scrollview.h" |
|
|
|
#include "selfdrive/ui/qt/widgets/scrollview.h" |
|
|
|
#include "selfdrive/ui/qt/util.h" |
|
|
|
#include "selfdrive/ui/qt/util.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NetworkStrengthWidget::paintEvent(QPaintEvent* event) { |
|
|
|
QLabel *networkStrengthWidget(const unsigned int strength_) { |
|
|
|
QPainter p(this); |
|
|
|
QLabel *strength = new QLabel(); |
|
|
|
p.setRenderHint(QPainter::Antialiasing); |
|
|
|
QVector<QString> imgs({"low", "medium", "high", "full"}); |
|
|
|
p.setPen(Qt::NoPen); |
|
|
|
QPixmap pix("../assets/offroad/icon_wifi_strength_" + imgs.at(strength_) + ".svg"); |
|
|
|
const QColor gray(0x54, 0x54, 0x54); |
|
|
|
strength->setPixmap(pix.scaledToHeight(68, Qt::SmoothTransformation)); |
|
|
|
for (int i = 0, x = 0; i < 5; ++i) { |
|
|
|
strength->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
p.setBrush(i < strength_ ? Qt::white : gray); |
|
|
|
strength->setStyleSheet("padding: 0px; margin-left: 50px; margin-right: 80px "); |
|
|
|
p.drawEllipse(x, 0, 15, 15); |
|
|
|
return strength; |
|
|
|
x += 20; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Networking functions
|
|
|
|
// Networking functions
|
|
|
|
|
|
|
|
|
|
|
|
Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), show_advanced(show_advanced) { |
|
|
|
Networking::Networking(QWidget* parent, bool show_advanced) : QFrame(parent) { |
|
|
|
main_layout = new QStackedLayout(this); |
|
|
|
main_layout = new QStackedLayout(this); |
|
|
|
|
|
|
|
|
|
|
|
wifi = new WifiManager(this); |
|
|
|
wifi = new WifiManager(this); |
|
|
|
connect(wifi, &WifiManager::wrongPassword, this, &Networking::wrongPassword); |
|
|
|
|
|
|
|
connect(wifi, &WifiManager::refreshSignal, this, &Networking::refresh); |
|
|
|
connect(wifi, &WifiManager::refreshSignal, this, &Networking::refresh); |
|
|
|
|
|
|
|
connect(wifi, &WifiManager::wrongPassword, this, &Networking::wrongPassword); |
|
|
|
|
|
|
|
|
|
|
|
QWidget* wifiScreen = new QWidget(this); |
|
|
|
QWidget* wifiScreen = new QWidget(this); |
|
|
|
QVBoxLayout* vlayout = new QVBoxLayout(wifiScreen); |
|
|
|
QVBoxLayout* vlayout = new QVBoxLayout(wifiScreen); |
|
|
|
|
|
|
|
vlayout->setContentsMargins(20, 20, 20, 20); |
|
|
|
if (show_advanced) { |
|
|
|
if (show_advanced) { |
|
|
|
QPushButton* advancedSettings = new QPushButton("Advanced"); |
|
|
|
QPushButton* advancedSettings = new QPushButton("Advanced"); |
|
|
|
advancedSettings->setObjectName("advancedBtn"); |
|
|
|
advancedSettings->setObjectName("advancedBtn"); |
|
|
@ -46,14 +46,22 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), s |
|
|
|
wifiWidget = new WifiUI(this, wifi); |
|
|
|
wifiWidget = new WifiUI(this, wifi); |
|
|
|
wifiWidget->setObjectName("wifiWidget"); |
|
|
|
wifiWidget->setObjectName("wifiWidget"); |
|
|
|
connect(wifiWidget, &WifiUI::connectToNetwork, this, &Networking::connectToNetwork); |
|
|
|
connect(wifiWidget, &WifiUI::connectToNetwork, this, &Networking::connectToNetwork); |
|
|
|
vlayout->addWidget(new ScrollView(wifiWidget, this), 1); |
|
|
|
|
|
|
|
|
|
|
|
ScrollView *wifiScroller = new ScrollView(wifiWidget, this); |
|
|
|
|
|
|
|
wifiScroller->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
|
|
|
|
|
|
|
vlayout->addWidget(wifiScroller, 1); |
|
|
|
main_layout->addWidget(wifiScreen); |
|
|
|
main_layout->addWidget(wifiScreen); |
|
|
|
|
|
|
|
|
|
|
|
an = new AdvancedNetworking(this, wifi); |
|
|
|
an = new AdvancedNetworking(this, wifi); |
|
|
|
connect(an, &AdvancedNetworking::backPress, [=]() { main_layout->setCurrentWidget(wifiScreen); }); |
|
|
|
connect(an, &AdvancedNetworking::backPress, [=]() { main_layout->setCurrentWidget(wifiScreen); }); |
|
|
|
main_layout->addWidget(an); |
|
|
|
main_layout->addWidget(an); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: revisit pressed colors
|
|
|
|
setStyleSheet(R"( |
|
|
|
setStyleSheet(R"( |
|
|
|
|
|
|
|
Networking { |
|
|
|
|
|
|
|
border-radius: 13px; |
|
|
|
|
|
|
|
background-color: #292929; |
|
|
|
|
|
|
|
} |
|
|
|
#wifiWidget > QPushButton, #back_btn, #advancedBtn { |
|
|
|
#wifiWidget > QPushButton, #back_btn, #advancedBtn { |
|
|
|
font-size: 50px; |
|
|
|
font-size: 50px; |
|
|
|
margin: 0px; |
|
|
|
margin: 0px; |
|
|
@ -63,10 +71,6 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), s |
|
|
|
color: #dddddd; |
|
|
|
color: #dddddd; |
|
|
|
background-color: #444444; |
|
|
|
background-color: #444444; |
|
|
|
} |
|
|
|
} |
|
|
|
#wifiWidget > QPushButton:disabled { |
|
|
|
|
|
|
|
color: #777777; |
|
|
|
|
|
|
|
background-color: #222222; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
)"); |
|
|
|
)"); |
|
|
|
main_layout->setCurrentWidget(wifiScreen); |
|
|
|
main_layout->setCurrentWidget(wifiScreen); |
|
|
|
} |
|
|
|
} |
|
|
@ -169,74 +173,119 @@ void AdvancedNetworking::toggleTethering(bool enabled) { |
|
|
|
|
|
|
|
|
|
|
|
WifiUI::WifiUI(QWidget *parent, WifiManager* wifi) : QWidget(parent), wifi(wifi) { |
|
|
|
WifiUI::WifiUI(QWidget *parent, WifiManager* wifi) : QWidget(parent), wifi(wifi) { |
|
|
|
main_layout = new QVBoxLayout(this); |
|
|
|
main_layout = new QVBoxLayout(this); |
|
|
|
|
|
|
|
main_layout->setContentsMargins(0, 0, 0, 0); |
|
|
|
|
|
|
|
main_layout->setSpacing(0); |
|
|
|
|
|
|
|
|
|
|
|
// Scan on startup
|
|
|
|
QLabel *scanning = new QLabel("Scanning for networks..."); |
|
|
|
QLabel *scanning = new QLabel("Scanning for networks"); |
|
|
|
scanning->setStyleSheet("font-size: 65px;"); |
|
|
|
scanning->setStyleSheet(R"(font-size: 65px;)"); |
|
|
|
|
|
|
|
main_layout->addWidget(scanning, 0, Qt::AlignCenter); |
|
|
|
main_layout->addWidget(scanning, 0, Qt::AlignCenter); |
|
|
|
main_layout->setSpacing(25); |
|
|
|
|
|
|
|
|
|
|
|
setStyleSheet(R"( |
|
|
|
|
|
|
|
QScrollBar::handle:vertical { |
|
|
|
|
|
|
|
min-height: 0px; |
|
|
|
|
|
|
|
border-radius: 4px; |
|
|
|
|
|
|
|
background-color: #8A8A8A; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#forgetBtn { |
|
|
|
|
|
|
|
font-size: 32px; |
|
|
|
|
|
|
|
font-weight: 600; |
|
|
|
|
|
|
|
color: #292929; |
|
|
|
|
|
|
|
background-color: #BDBDBD; |
|
|
|
|
|
|
|
border-width: 1px solid #828282; |
|
|
|
|
|
|
|
border-radius: 5px; |
|
|
|
|
|
|
|
padding: 40px; |
|
|
|
|
|
|
|
padding-bottom: 16px; |
|
|
|
|
|
|
|
padding-top: 16px; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
)"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void WifiUI::refresh() { |
|
|
|
void WifiUI::refresh() { |
|
|
|
|
|
|
|
// TODO: don't rebuild this every time
|
|
|
|
clearLayout(main_layout); |
|
|
|
clearLayout(main_layout); |
|
|
|
|
|
|
|
|
|
|
|
if (wifi->seen_networks.size() == 0) { |
|
|
|
if (wifi->seen_networks.size() == 0) { |
|
|
|
QLabel *scanning = new QLabel("No networks found. Scanning..."); |
|
|
|
QLabel *scanning = new QLabel("No networks found. Scanning..."); |
|
|
|
scanning->setStyleSheet(R"(font-size: 65px;)"); |
|
|
|
scanning->setStyleSheet("font-size: 65px;"); |
|
|
|
main_layout->addWidget(scanning, 0, Qt::AlignCenter); |
|
|
|
main_layout->addWidget(scanning, 0, Qt::AlignCenter); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// add networks
|
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
for (Network &network : wifi->seen_networks) { |
|
|
|
for (Network &network : wifi->seen_networks) { |
|
|
|
QHBoxLayout *hlayout = new QHBoxLayout; |
|
|
|
QHBoxLayout *hlayout = new QHBoxLayout; |
|
|
|
|
|
|
|
hlayout->setContentsMargins(44, 0, 0, 0); |
|
|
|
ElidedLabel *ssid_label = new ElidedLabel(network.ssid); |
|
|
|
hlayout->setSpacing(0); |
|
|
|
ssid_label->setStyleSheet("font-size: 55px;"); |
|
|
|
|
|
|
|
hlayout->addWidget(ssid_label, 1, Qt::AlignLeft); |
|
|
|
// Clickable SSID label
|
|
|
|
|
|
|
|
QPushButton *ssid_label = new QPushButton(network.ssid); |
|
|
|
|
|
|
|
ssid_label->setEnabled(network.connected != ConnectedType::CONNECTED && |
|
|
|
|
|
|
|
network.connected != ConnectedType::CONNECTING && |
|
|
|
|
|
|
|
network.security_type != SecurityType::UNSUPPORTED); |
|
|
|
|
|
|
|
int weight = network.connected == ConnectedType::DISCONNECTED ? 300 : 500; |
|
|
|
|
|
|
|
ssid_label->setStyleSheet(QString(R"( |
|
|
|
|
|
|
|
font-size: 55px; |
|
|
|
|
|
|
|
font-weight: %1; |
|
|
|
|
|
|
|
text-align: left; |
|
|
|
|
|
|
|
border: none; |
|
|
|
|
|
|
|
padding-top: 50px; |
|
|
|
|
|
|
|
padding-bottom: 50px; |
|
|
|
|
|
|
|
background-color: transparent; |
|
|
|
|
|
|
|
)").arg(weight)); |
|
|
|
|
|
|
|
QObject::connect(ssid_label, &QPushButton::clicked, this, [=]() { emit connectToNetwork(network); }); |
|
|
|
|
|
|
|
hlayout->addWidget(ssid_label, 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Forget button
|
|
|
|
if (wifi->isKnownConnection(network.ssid) && !wifi->isTetheringEnabled()) { |
|
|
|
if (wifi->isKnownConnection(network.ssid) && !wifi->isTetheringEnabled()) { |
|
|
|
QPushButton *forgetBtn = new QPushButton(); |
|
|
|
QPushButton *forgetBtn = new QPushButton("FORGET"); |
|
|
|
QPixmap pix("../assets/offroad/icon_close.svg"); |
|
|
|
forgetBtn->setObjectName("forgetBtn"); |
|
|
|
|
|
|
|
|
|
|
|
forgetBtn->setIcon(QIcon(pix)); |
|
|
|
|
|
|
|
forgetBtn->setIconSize(QSize(35, 35)); |
|
|
|
|
|
|
|
forgetBtn->setStyleSheet("QPushButton { background-color: #E22C2C; }"); |
|
|
|
|
|
|
|
forgetBtn->setFixedSize(100, 90); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QObject::connect(forgetBtn, &QPushButton::released, [=]() { |
|
|
|
QObject::connect(forgetBtn, &QPushButton::released, [=]() { |
|
|
|
if (ConfirmationDialog::confirm("Are you sure you want to forget " + QString::fromUtf8(network.ssid) + "?", this)) { |
|
|
|
if (ConfirmationDialog::confirm("Are you sure you want to forget " + QString::fromUtf8(network.ssid) + "?", this)) { |
|
|
|
wifi->forgetConnection(network.ssid); |
|
|
|
wifi->forgetConnection(network.ssid); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
hlayout->addWidget(forgetBtn, 0, Qt::AlignRight); |
|
|
|
hlayout->addWidget(forgetBtn, 0, Qt::AlignRight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Status icon
|
|
|
|
|
|
|
|
if (network.connected == ConnectedType::CONNECTED) { |
|
|
|
|
|
|
|
QLabel *connectIcon = new QLabel(); |
|
|
|
|
|
|
|
QPixmap pix("../assets/offroad/icon_checkmark.svg"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connectIcon->setPixmap(pix.scaledToWidth(49, Qt::SmoothTransformation)); |
|
|
|
|
|
|
|
connectIcon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
|
|
|
|
connectIcon->setStyleSheet("margin: 0px; padding-left: 51px; padding-right: 0px "); |
|
|
|
|
|
|
|
hlayout->addWidget(connectIcon, 0, Qt::AlignRight); |
|
|
|
|
|
|
|
} else if (network.connected == ConnectedType::CONNECTING) { |
|
|
|
|
|
|
|
QLabel *connectIcon = new QLabel(); |
|
|
|
|
|
|
|
// TODO replace connecting icon with proper widget/icon
|
|
|
|
|
|
|
|
QPixmap pix(network.connected == ConnectedType::CONNECTED ? "../assets/offroad/icon_checkmark.svg" : "../assets/navigation/direction_rotary.png"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
connectIcon->setPixmap(pix.scaledToWidth(49, Qt::SmoothTransformation)); |
|
|
|
|
|
|
|
connectIcon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
|
|
|
|
connectIcon->setStyleSheet("margin: 0px; padding-left: 51px; padding-right: 0px "); |
|
|
|
|
|
|
|
hlayout->addWidget(connectIcon, 0, Qt::AlignRight); |
|
|
|
} else if (network.security_type == SecurityType::WPA) { |
|
|
|
} else if (network.security_type == SecurityType::WPA) { |
|
|
|
QLabel *lockIcon = new QLabel(); |
|
|
|
QLabel *lockIcon = new QLabel(); |
|
|
|
QPixmap pix("../assets/offroad/icon_lock_closed.svg"); |
|
|
|
QPixmap pix("../assets/offroad/icon_lock_closed.svg"); |
|
|
|
lockIcon->setPixmap(pix.scaledToWidth(35, Qt::SmoothTransformation)); |
|
|
|
|
|
|
|
lockIcon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
|
|
|
|
lockIcon->setStyleSheet("QLabel { margin: 0px; padding-left: 15px; padding-right: 15px; }"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lockIcon->setPixmap(pix.scaledToHeight(49, Qt::SmoothTransformation)); |
|
|
|
|
|
|
|
lockIcon->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
|
|
|
|
|
|
lockIcon->setStyleSheet("padding: 0px; margin-left: 62px; margin-right: 0px "); |
|
|
|
hlayout->addWidget(lockIcon, 0, Qt::AlignRight); |
|
|
|
hlayout->addWidget(lockIcon, 0, Qt::AlignRight); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// strength indicator
|
|
|
|
// Strength indicator
|
|
|
|
unsigned int strength_scale = network.strength / 17; |
|
|
|
hlayout->addWidget(networkStrengthWidget(network.strength / 26), 0, Qt::AlignRight); |
|
|
|
hlayout->addWidget(new NetworkStrengthWidget(strength_scale), 0, Qt::AlignRight); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// connect button
|
|
|
|
|
|
|
|
QPushButton* btn = new QPushButton(network.security_type == SecurityType::UNSUPPORTED ? "Unsupported" : (network.connected == ConnectedType::CONNECTED ? "Connected" : (network.connected == ConnectedType::CONNECTING ? "Connecting" : "Connect"))); |
|
|
|
|
|
|
|
btn->setDisabled(network.connected == ConnectedType::CONNECTED || network.connected == ConnectedType::CONNECTING || network.security_type == SecurityType::UNSUPPORTED); |
|
|
|
|
|
|
|
btn->setFixedWidth(350); |
|
|
|
|
|
|
|
QObject::connect(btn, &QPushButton::clicked, this, [=]() { emit connectToNetwork(network); }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hlayout->addWidget(btn, 0, Qt::AlignRight); |
|
|
|
|
|
|
|
main_layout->addLayout(hlayout, 1); |
|
|
|
main_layout->addLayout(hlayout, 1); |
|
|
|
|
|
|
|
|
|
|
|
// Don't add the last horizontal line
|
|
|
|
// Don't add the last horizontal line
|
|
|
|
if (i+1 < wifi->seen_networks.size()) { |
|
|
|
if (i+1 < wifi->seen_networks.size()) { |
|
|
|
main_layout->addWidget(horizontal_line(), 0); |
|
|
|
main_layout->addWidget(horizontal_line(), 0); |
|
|
|
} |
|
|
|
} |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
} |
|
|
|
main_layout->addStretch(3); |
|
|
|
main_layout->addStretch(1); |
|
|
|
} |
|
|
|
} |
|
|
|