@ -4,34 +4,34 @@
# include <QHBoxLayout>
# include <QLabel>
# include <QPainter>
# include <QScrollBar>
# include "selfdrive/ui/qt/widgets/scrollview.h"
# include "selfdrive/ui/qt/util.h"
void NetworkStrengthWidget : : paintEvent ( QPaintEvent * event ) {
QPainter p ( this ) ;
p . setRenderHint ( QPainter : : Antialiasing ) ;
p . setPen ( Qt : : NoPen ) ;
const QColor gray ( 0x54 , 0x54 , 0x54 ) ;
for ( int i = 0 , x = 0 ; i < 5 ; + + i ) {
p . setBrush ( i < strength_ ? Qt : : white : gray ) ;
p . drawEllipse ( x , 0 , 15 , 15 ) ;
x + = 20 ;
}
QLabel * networkStrengthWidget ( const unsigned int strength_ ) {
QLabel * strength = new QLabel ( ) ;
QVector < QString > imgs ( { " low " , " medium " , " high " , " full " } ) ;
QPixmap pix ( " ../assets/offroad/icon_wifi_strength_ " + imgs . at ( strength_ ) + " .svg " ) ;
strength - > setPixmap ( pix . scaledToHeight ( 68 , Qt : : SmoothTransformation ) ) ;
strength - > setSizePolicy ( QSizePolicy ( QSizePolicy : : Fixed , QSizePolicy : : Fixed ) ) ;
strength - > setStyleSheet ( " padding: 0px; margin-left: 50px; margin-right: 80px " ) ;
return strength ;
}
// 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 ) ;
wifi = new WifiManager ( this ) ;
connect ( wifi , & WifiManager : : wrongPassword , this , & Networking : : wrongPassword ) ;
connect ( wifi , & WifiManager : : refreshSignal , this , & Networking : : refresh ) ;
connect ( wifi , & WifiManager : : wrongPassword , this , & Networking : : wrongPassword ) ;
QWidget * wifiScreen = new QWidget ( this ) ;
QVBoxLayout * vlayout = new QVBoxLayout ( wifiScreen ) ;
vlayout - > setContentsMargins ( 20 , 20 , 20 , 20 ) ;
if ( show_advanced ) {
QPushButton * advancedSettings = new QPushButton ( " Advanced " ) ;
advancedSettings - > setObjectName ( " advancedBtn " ) ;
@ -46,14 +46,22 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), s
wifiWidget = new WifiUI ( this , wifi ) ;
wifiWidget - > setObjectName ( " wifiWidget " ) ;
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 ) ;
an = new AdvancedNetworking ( this , wifi ) ;
connect ( an , & AdvancedNetworking : : backPress , [ = ] ( ) { main_layout - > setCurrentWidget ( wifiScreen ) ; } ) ;
main_layout - > addWidget ( an ) ;
// TODO: revisit pressed colors
setStyleSheet ( R " (
Networking {
border - radius : 13 px ;
background - color : # 292929 ;
}
# wifiWidget > QPushButton, #back_btn, #advancedBtn {
font - size : 50 px ;
margin : 0 px ;
@ -63,10 +71,6 @@ Networking::Networking(QWidget* parent, bool show_advanced) : QWidget(parent), s
color : # dddddd ;
background - color : # 444444 ;
}
# wifiWidget > QPushButton:disabled {
color : # 777777 ;
background - color : # 222222 ;
}
) " );
main_layout - > setCurrentWidget ( wifiScreen ) ;
}
@ -169,74 +173,119 @@ void AdvancedNetworking::toggleTethering(bool enabled) {
WifiUI : : WifiUI ( QWidget * parent , WifiManager * wifi ) : QWidget ( parent ) , wifi ( wifi ) {
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 " ) ;
scanning - > setStyleSheet ( R " (font-size: 65px;) " ) ;
QLabel * scanning = new QLabel ( " Scanning for networks... " ) ;
scanning - > setStyleSheet ( " font-size: 65px; " ) ;
main_layout - > addWidget ( scanning , 0 , Qt : : AlignCenter ) ;
main_layout - > setSpacing ( 25 ) ;
setStyleSheet ( R " (
QScrollBar : : handle : vertical {
min - height : 0 px ;
border - radius : 4 px ;
background - color : # 8 A8A8A ;
}
# forgetBtn {
font - size : 32 px ;
font - weight : 600 ;
color : # 292929 ;
background - color : # BDBDBD ;
border - width : 1 px solid # 828282 ;
border - radius : 5 px ;
padding : 40 px ;
padding - bottom : 16 px ;
padding - top : 16 px ;
}
) " );
}
void WifiUI : : refresh ( ) {
// TODO: don't rebuild this every time
clearLayout ( main_layout ) ;
if ( wifi - > seen_networks . size ( ) = = 0 ) {
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 ) ;
return ;
}
// add networks
int i = 0 ;
for ( Network & network : wifi - > seen_networks ) {
QHBoxLayout * hlayout = new QHBoxLayout ;
ElidedLabel * ssid_label = new ElidedLabel ( network . ssid ) ;
ssid_label - > setStyleSheet ( " font-size: 55px; " ) ;
hlayout - > addWidget ( ssid_label , 1 , Qt : : AlignLeft ) ;
hlayout - > setContentsMargins ( 44 , 0 , 0 , 0 ) ;
hlayout - > setSpacing ( 0 ) ;
// 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 : 55 px ;
font - weight : % 1 ;
text - align : left ;
border : none ;
padding - top : 50 px ;
padding - bottom : 50 px ;
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 ( ) ) {
QPushButton * forgetBtn = new QPushButton ( ) ;
QPixmap pix ( " ../assets/offroad/icon_close.svg " ) ;
forgetBtn - > setIcon ( QIcon ( pix ) ) ;
forgetBtn - > setIconSize ( QSize ( 35 , 35 ) ) ;
forgetBtn - > setStyleSheet ( " QPushButton { background-color: #E22C2C; } " ) ;
forgetBtn - > setFixedSize ( 100 , 90 ) ;
QPushButton * forgetBtn = new QPushButton ( " FORGET " ) ;
forgetBtn - > setObjectName ( " forgetBtn " ) ;
QObject : : connect ( forgetBtn , & QPushButton : : released , [ = ] ( ) {
if ( ConfirmationDialog : : confirm ( " Are you sure you want to forget " + QString : : fromUtf8 ( network . ssid ) + " ? " , this ) ) {
wifi - > forgetConnection ( network . ssid ) ;
}
} ) ;
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 ) {
QLabel * lockIcon = new QLabel ( ) ;
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 ) ;
}
// strength indicator
unsigned int strength_scale = network . strength / 17 ;
hlayout - > addWidget ( new NetworkStrengthWidget ( strength_scale ) , 0 , Qt : : AlignRight ) ;
// Strength indicator
hlayout - > addWidget ( networkStrengthWidget ( network . strength / 26 ) , 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 ) ;
// Don't add the last horizontal line
if ( i + 1 < wifi - > seen_networks . size ( ) ) {
main_layout - > addWidget ( horizontal_line ( ) , 0 ) ;
}
i + + ;
}
main_layout - > addStretch ( 3 ) ;
main_layout - > addStretch ( 1 ) ;
}