Show battery state in MainWindow; fixed USBMS icon scaling for all

devices
This commit is contained in:
Nicolas Mailloux 2021-03-29 08:04:46 -04:00
parent d3362890be
commit 6cf633dd9e
6 changed files with 93 additions and 12 deletions

View file

@ -53,14 +53,14 @@ MainWindow::MainWindow(QWidget *parent)
if(checkconfig_str_val == "n705\n") { if(checkconfig_str_val == "n705\n") {
stdIconWidth = sW / 12; stdIconWidth = sW / 12;
stdIconHeight = sH / 12; stdIconHeight = sH / 12;
brightnessIconWidth = sW / 30; brightnessIconWidth = sW / 24;
brightnessIconHeight = sH / 30; brightnessIconHeight = sH / 24;
} }
else { else {
stdIconWidth = sW / 14; stdIconWidth = sW / 14;
stdIconHeight = sH / 14; stdIconHeight = sH / 14;
brightnessIconWidth = sW / 28; brightnessIconWidth = sW / 26;
brightnessIconHeight = sH / 28; brightnessIconHeight = sH / 26;
} }
// Setting icons up // Setting icons up
@ -78,14 +78,81 @@ 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));
// Battery
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n705\n") {
stdIconWidth = sW / 16;
stdIconHeight = sH / 16;
QPixmap chargingPixmap(":/resources/battery_charging.png");
QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap fullPixmap(":/resources/battery_full.png");
QPixmap scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap halfPixmap(":/resources/battery_half.png");
QPixmap scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap emptyPixmap(":/resources/battery_empty.png");
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
ui->batteryIcon->setPixmap(scaledChargingPixmap);
}
else {
get_battery_level();
if(batt_level_int >= 75 && batt_level_int <= 100) {
ui->batteryIcon->setPixmap(scaledFullPixmap);
}
if(batt_level_int >= 25 && batt_level_int <= 74) {
ui->batteryIcon->setPixmap(scaledHalfPixmap);
}
if(batt_level_int >= 0 && batt_level_int <= 24) {
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
}
}
}
else {
stdIconWidth = sW / 19;
stdIconHeight = sH / 19;
QPixmap chargingPixmap(":/resources/battery_charging.png");
QPixmap scaledChargingPixmap = chargingPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap fullPixmap(":/resources/battery_full.png");
QPixmap scaledFullPixmap = fullPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap halfPixmap(":/resources/battery_half.png");
QPixmap scaledHalfPixmap = halfPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
QPixmap emptyPixmap(":/resources/battery_empty.png");
QPixmap scaledEmptyPixmap = emptyPixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
// Checking battery level and status, then displaying the relevant icon on batteryIconLabel
string_checkconfig_ro("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/status");
if(checkconfig_str_val == "Charging\n") {
ui->batteryIcon->setPixmap(scaledChargingPixmap);
}
else {
get_battery_level();
if(batt_level_int >= 75 && batt_level_int <= 100) {
ui->batteryIcon->setPixmap(scaledFullPixmap);
}
if(batt_level_int >= 25 && batt_level_int <= 74) {
ui->batteryIcon->setPixmap(scaledHalfPixmap);
}
if(batt_level_int >= 0 && batt_level_int <= 24) {
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
}
}
}
ui->book1Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book1Btn->setStyleSheet("font-size: 11pt; padding: 25px");
ui->book2Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book2Btn->setStyleSheet("font-size: 11pt; padding: 25px");
ui->book3Btn->setStyleSheet("font-size: 11pt; padding: 25px"); ui->book3Btn->setStyleSheet("font-size: 11pt; padding: 25px");
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: 10px; padding-right: 10px;"); ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 8px; padding-right: 8px;");
ui->batteryIcon->setStyleSheet("font-size: 5pt"); ui->batteryIcon->setStyleSheet("font-size: 5pt; padding-bottom: 0px; padding-top: 0px; padding-left: 8px; padding-right: 8px;");
ui->line_7->setStyleSheet("padding: 0px");
ui->batteryIcon->setText(""); ui->batteryIcon->setText("");
ui->batteryLabel->setText("");
ui->timeLabel->setText("");
ui->batteryLabel->setStyleSheet("padding-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px");
ui->book1Btn->hide(); ui->book1Btn->hide();
ui->book2Btn->hide(); ui->book2Btn->hide();
@ -372,9 +439,9 @@ void MainWindow::on_pushButton_clicked()
void MainWindow::on_searchBtn_clicked() void MainWindow::on_searchBtn_clicked()
{ {
// Testing // Testing
/*alertWindow = new alert(); /*usbmsWindow = new usbms_splash();
alertWindow->setAttribute(Qt::WA_DeleteOnClose); usbmsWindow->setAttribute(Qt::WA_DeleteOnClose);
alertWindow->showFullScreen();*/ usbmsWindow->showFullScreen();*/
} }
void MainWindow::on_quitBtn_clicked() void MainWindow::on_quitBtn_clicked()

View file

@ -7,6 +7,7 @@
#include "reader.h" #include "reader.h"
#include "quit.h" #include "quit.h"
#include "alert.h" #include "alert.h"
#include "usbms_splash.h"
#include <iostream> #include <iostream>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
@ -156,5 +157,6 @@ private:
reader *readerWindow; reader *readerWindow;
quit *quitWindow; quit *quitWindow;
alert *alertWindow; alert *alertWindow;
usbms_splash *usbmsWindow;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View file

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>519</width> <width>524</width>
<height>601</height> <height>601</height>
</rect> </rect>
</property> </property>
@ -48,7 +48,7 @@
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>batteryLevel</string> <string>batt</string>
</property> </property>
</widget> </widget>
</item> </item>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

@ -2,6 +2,7 @@
#include "ui_usbms_splash.h" #include "ui_usbms_splash.h"
#include <QPixmap> #include <QPixmap>
#include <QScreen>
usbms_splash::usbms_splash(QWidget *parent) : usbms_splash::usbms_splash(QWidget *parent) :
QWidget(parent), QWidget(parent),
@ -9,12 +10,21 @@ usbms_splash::usbms_splash(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
// Getting the screen's size
float sW = QGuiApplication::screens()[0]->size().width();
float sH = QGuiApplication::screens()[0]->size().height();
// Defining what the default icon size will be
float stdIconWidth = sW / 1.15;
float stdIconHeight = sH / 1.15;
this->setStyleSheet("background-color:black;"); this->setStyleSheet("background-color:black;");
ui->label->setStyleSheet("QLabel { background-color : black; color : white; }"); ui->label->setStyleSheet("QLabel { background-color : black; color : white; }");
ui->label_3->setStyleSheet("QLabel { background-color : black; color : white; font-size: 9pt}"); ui->label_3->setStyleSheet("QLabel { background-color : black; color : white; font-size: 9pt}");
QPixmap pixmap(":/resources/usbms.png"); QPixmap pixmap(":/resources/usbms.png");
ui->label_2->setPixmap(pixmap); QPixmap scaledPixmap = pixmap.scaled(stdIconWidth, stdIconHeight, Qt::KeepAspectRatio);
ui->label_2->setPixmap(scaledPixmap);
} }
usbms_splash::~usbms_splash() usbms_splash::~usbms_splash()

View file

@ -2,6 +2,8 @@
#define USBMS_SPLASH_H #define USBMS_SPLASH_H
#include <QWidget> #include <QWidget>
#include <QFile>
#include <QTextStream>
namespace Ui { namespace Ui {
class usbms_splash; class usbms_splash;