mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-27 16:17:21 -08:00
MainWindow: Set battery icon every tab switch
This commit is contained in:
parent
9458a1a708
commit
31367c5357
2 changed files with 74 additions and 68 deletions
141
mainwindow.cpp
141
mainwindow.cpp
|
@ -101,74 +101,7 @@ 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
|
setBatteryIcon();
|
||||||
string_checkconfig_ro("/opt/inkbox_device");
|
|
||||||
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
|
|
||||||
// Hide brightness controls; they won't be very useful there anyway...
|
|
||||||
ui->brightnessBtn->hide();
|
|
||||||
ui->line_7->hide();
|
|
||||||
|
|
||||||
// Setting icons up
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
else if(batt_level_int >= 25 && batt_level_int <= 74) {
|
|
||||||
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
|
||||||
}
|
|
||||||
else if(batt_level_int >= 0 && batt_level_int <= 24) {
|
|
||||||
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Setting icons up
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
else if(batt_level_int >= 25 && batt_level_int <= 74) {
|
|
||||||
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
|
||||||
}
|
|
||||||
else if(batt_level_int >= 0 && batt_level_int <= 24) {
|
|
||||||
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
|
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
|
||||||
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
|
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||||
|
@ -742,6 +675,7 @@ void MainWindow::resetWindow(bool resetStackedWidget) {
|
||||||
global::mainwindow::tabSwitcher::settingsChooserWidgetSelected = false;
|
global::mainwindow::tabSwitcher::settingsChooserWidgetSelected = false;
|
||||||
|
|
||||||
resetIcons();
|
resetIcons();
|
||||||
|
setBatteryIcon();
|
||||||
if(global::mainwindow::tabSwitcher::repaint == true) {
|
if(global::mainwindow::tabSwitcher::repaint == true) {
|
||||||
this->repaint();
|
this->repaint();
|
||||||
}
|
}
|
||||||
|
@ -754,3 +688,74 @@ void MainWindow::resetIcons() {
|
||||||
ui->settingsBtn->setStyleSheet("background: white");
|
ui->settingsBtn->setStyleSheet("background: white");
|
||||||
ui->settingsBtn->setIcon(QIcon(":/resources/settings.png"));
|
ui->settingsBtn->setIcon(QIcon(":/resources/settings.png"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setBatteryIcon() {
|
||||||
|
// Battery
|
||||||
|
string_checkconfig_ro("/opt/inkbox_device");
|
||||||
|
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n") {
|
||||||
|
// Hide brightness controls; they won't be very useful there anyway...
|
||||||
|
ui->brightnessBtn->hide();
|
||||||
|
ui->line_7->hide();
|
||||||
|
|
||||||
|
// Setting icons up
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else if(batt_level_int >= 25 && batt_level_int <= 74) {
|
||||||
|
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
||||||
|
}
|
||||||
|
else if(batt_level_int >= 0 && batt_level_int <= 24) {
|
||||||
|
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Setting icons up
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else if(batt_level_int >= 25 && batt_level_int <= 74) {
|
||||||
|
ui->batteryIcon->setPixmap(scaledHalfPixmap);
|
||||||
|
}
|
||||||
|
else if(batt_level_int >= 0 && batt_level_int <= 24) {
|
||||||
|
ui->batteryIcon->setPixmap(scaledEmptyPixmap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
void openUsbmsDialog();
|
void openUsbmsDialog();
|
||||||
void resetWindow(bool resetStackedWidget);
|
void resetWindow(bool resetStackedWidget);
|
||||||
void resetIcons();
|
void resetIcons();
|
||||||
|
void setBatteryIcon();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue