Wi-Fi button/icon in MainWindow

Dialog's coming soon, hopefully ...
This commit is contained in:
Nicolas Mailloux 2021-07-13 15:18:59 -04:00
parent d8dee343a4
commit a532d00f48
5 changed files with 188 additions and 78 deletions

View file

@ -57,5 +57,8 @@
<file>resources/fonts/IbarraRealNova-Medium.ttf</file> <file>resources/fonts/IbarraRealNova-Medium.ttf</file>
<file>resources/fonts/IbarraRealNova-BoldItalic.ttf</file> <file>resources/fonts/IbarraRealNova-BoldItalic.ttf</file>
<file>resources/fonts/IbarraRealNova-Bold.ttf</file> <file>resources/fonts/IbarraRealNova-Bold.ttf</file>
<file>resources/wifi-connected.png</file>
<file>resources/wifi-off.png</file>
<file>resources/wifi-standby.png</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -36,6 +36,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->pushButton->setProperty("type", "borderless"); ui->pushButton->setProperty("type", "borderless");
ui->brightnessBtn->setProperty("type", "borderless"); ui->brightnessBtn->setProperty("type", "borderless");
ui->homeBtn->setProperty("type", "borderless"); ui->homeBtn->setProperty("type", "borderless");
ui->wifiBtn->setProperty("type", "borderless");
ui->settingsBtn->setText(""); ui->settingsBtn->setText("");
ui->appsBtn->setText(""); ui->appsBtn->setText("");
@ -45,6 +46,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->brightnessBtn->setText(""); ui->brightnessBtn->setText("");
ui->homeBtn->setText(""); ui->homeBtn->setText("");
ui->quoteLabel->setText(""); ui->quoteLabel->setText("");
ui->wifiBtn->setText("");
ui->quotePictureLabel->setText(""); ui->quotePictureLabel->setText("");
@ -72,6 +74,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 24; brightnessIconHeight = sH / 24;
homeIconWidth = sW / 18; homeIconWidth = sW / 18;
homeIconHeight = sW / 18; homeIconHeight = sW / 18;
wifiIconWidth = sW / 20;
wifiIconHeight = sH / 20;
} }
else if(checkconfig_str_val == "n905\n") { else if(checkconfig_str_val == "n905\n") {
stdIconWidth = sW / 14; stdIconWidth = sW / 14;
@ -80,6 +84,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 26; brightnessIconHeight = sH / 26;
homeIconWidth = sW / 20; homeIconWidth = sW / 20;
homeIconHeight = sW / 20; homeIconHeight = sW / 20;
wifiIconWidth = sW / 22;
wifiIconHeight = sH / 22;
} }
else if(checkconfig_str_val == "n613\n") { else if(checkconfig_str_val == "n613\n") {
stdIconWidth = sW / 12.5; stdIconWidth = sW / 12.5;
@ -88,6 +94,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 24.5; brightnessIconHeight = sH / 24.5;
homeIconWidth = sW / 18.5; homeIconWidth = sW / 18.5;
homeIconHeight = sW / 18.5; homeIconHeight = sW / 18.5;
wifiIconWidth = sW / 20.5;
wifiIconHeight = sH / 20.5;
} }
else { else {
stdIconWidth = sW / 14; stdIconWidth = sW / 14;
@ -96,6 +104,8 @@ MainWindow::MainWindow(QWidget *parent)
brightnessIconHeight = sH / 26; brightnessIconHeight = sH / 26;
homeIconWidth = sW / 20; homeIconWidth = sW / 20;
homeIconHeight = sW / 20; homeIconHeight = sW / 20;
wifiIconWidth = sW / 22;
wifiIconHeight = sH / 22;
} }
// Setting icons up // Setting icons up
@ -116,6 +126,8 @@ MainWindow::MainWindow(QWidget *parent)
ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png")); ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png"));
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
setWifiIcon();
updateWifiIcon(0);
setBatteryIcon(); setBatteryIcon();
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf"); int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
@ -132,6 +144,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->book4Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book4Btn->setStyleSheet("font-size: 11pt; padding: 25px");
ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 8px; padding-right: 8px;"); ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 8px; padding-right: 8px;");
ui->wifiBtn->setStyleSheet("font-size: 9pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px");
// Checking if we have a Mini or Touch there // Checking if we have a Mini or Touch there
string_checkconfig_ro("/opt/inkbox_device"); string_checkconfig_ro("/opt/inkbox_device");
@ -141,6 +154,9 @@ MainWindow::MainWindow(QWidget *parent)
else if(checkconfig_str_val == "n613\n") { else if(checkconfig_str_val == "n613\n") {
ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px;"); ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px;");
} }
else if(checkconfig_str_val == "n873\n") {
ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px;");
}
else { else {
ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px;"); ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px;");
} }
@ -823,3 +839,71 @@ void MainWindow::setupSearchDialog() {
; ;
} }
} }
int MainWindow::testPing() {
QString pingProg = "ping";
QStringList pingArgs;
pingArgs << "-c" << "1" << "1.1.1.1";
QProcess *pingProcess = new QProcess();
pingProcess->start(pingProg, pingArgs);
pingProcess->waitForFinished();
return pingProcess->exitCode();
}
void MainWindow::updateWifiIcon(int mode) {
/* Usage:
* mode 0: auto
* mode 1: off
* mode 2: standby
* mode 3: connected
*/
if(mode == 0) {
QTimer *wifiIconTimer = new QTimer(this);
wifiIconTimer->setInterval(60000);
connect(wifiIconTimer, SIGNAL(timeout()), this, SLOT(setWifiIcon()));
wifiIconTimer->start();
}
if(mode == 1) {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
if(mode == 2) {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
if(mode == 3) {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
bool MainWindow::checkWifiState() {
/* Return value:
* true: interface UP
* false: interface DOWN
*/
string_checkconfig_ro("/sys/class/net/eth0/operstate");
if(checkconfig_str_val == "up\n") {
return true;
}
else {
return false;
}
}
void MainWindow::setWifiIcon() {
if(checkWifiState() == true) {
if(testPing() == 0) {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
else {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}
else {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
}
}

View file

@ -36,6 +36,8 @@ public:
float brightnessIconHeight; float brightnessIconHeight;
float homeIconWidth; float homeIconWidth;
float homeIconHeight; float homeIconHeight;
float wifiIconWidth;
float wifiIconHeight;
float sW; float sW;
float sH; float sH;
@ -51,6 +53,9 @@ public:
void resetWindow(bool resetStackedWidget); void resetWindow(bool resetStackedWidget);
void resetIcons(); void resetIcons();
void setBatteryIcon(); void setBatteryIcon();
void updateWifiIcon(int mode);
int testPing();
bool checkWifiState();
public slots: public slots:
@ -70,6 +75,7 @@ private slots:
void on_homeBtn_clicked(); void on_homeBtn_clicked();
void refreshScreen(); void refreshScreen();
void setupSearchDialog(); void setupSearchDialog();
void setWifiIcon();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;

View file

@ -17,60 +17,20 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="5"> <item row="0" column="14">
<spacer name="horizontalSpacer_2"> <widget class="Line" name="line_8">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="6">
<widget class="QPushButton" name="brightnessBtn">
<property name="text">
<string>Brightness</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="9"> <item row="0" column="0">
<widget class="QLabel" name="batteryLabel"> <widget class="QPushButton" name="homeBtn">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text"> <property name="text">
<string>batt</string> <string>Home</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="label_2">
<property name="text">
<string>―</string>
</property>
</widget>
</item>
<item row="0" column="11">
<widget class="QLabel" name="timeLabel">
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>time</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property> </property>
</widget> </widget>
</item> </item>
@ -89,13 +49,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="8">
<widget class="QLabel" name="batteryIcon">
<property name="text">
<string>batteryIcon</string>
</property>
</widget>
</item>
<item row="0" column="2"> <item row="0" column="2">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
@ -103,6 +56,57 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="4">
<widget class="QLabel" name="label_2">
<property name="text">
<string>―</string>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="QPushButton" name="wifiBtn">
<property name="text">
<string>Wi-Fi</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QPushButton" name="brightnessBtn">
<property name="text">
<string>Brightness</string>
</property>
</widget>
</item>
<item row="0" column="11">
<widget class="Line" name="line_7">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="12">
<widget class="QLabel" name="batteryIcon">
<property name="text">
<string>batteryIcon</string>
</property>
</widget>
</item>
<item row="0" column="5">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1"> <item row="0" column="1">
<spacer name="horizontalSpacer"> <spacer name="horizontalSpacer">
<property name="orientation"> <property name="orientation">
@ -116,30 +120,43 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="7"> <item row="0" column="13">
<widget class="Line" name="line_7"> <widget class="QLabel" name="batteryLabel">
<property name="frameShadow"> <property name="font">
<enum>QFrame::Plain</enum> <font>
<weight>75</weight>
<bold>true</bold>
</font>
</property> </property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="10">
<widget class="Line" name="line_8">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="homeBtn">
<property name="text"> <property name="text">
<string>Home</string> <string>batt</string>
</property>
</widget>
</item>
<item row="0" column="15">
<widget class="QLabel" name="timeLabel">
<property name="font">
<font>
<pointsize>11</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>time</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="Line" name="line_9">
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property> </property>
</widget> </widget>
</item> </item>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB