Brightness dialog: set lighting warmth option

This commit is contained in:
Nicolas Mailloux 2021-07-16 16:41:36 -04:00
parent 4c714d4abd
commit c509474ff3
6 changed files with 272 additions and 78 deletions

View file

@ -19,10 +19,64 @@ brightnessDialog::brightnessDialog(QWidget *parent) :
this->setStyleSheet(stylesheetFile.readAll()); this->setStyleSheet(stylesheetFile.readAll());
stylesheetFile.close(); stylesheetFile.close();
ui->quitBtn->setProperty("type", "borderless");
ui->quitBtn->setText("");
ui->quitBtn->setIcon(QIcon(":/resources/close.png"));
ui->okBtn->setProperty("type", "borderless");
ui->okBtn->setText("");
ui->okBtn->setIcon(QIcon(":/resources/check.png"));
ui->decBtn->setProperty("type", "borderless");
ui->decBtn->setText("");
ui->decBtn->setIcon(QIcon(":/resources/minus.png"));
ui->incBtn->setProperty("type", "borderless");
ui->incBtn->setText("");
ui->incBtn->setIcon(QIcon(":/resources/plus.png"));
ui->brightnessLabel->setStyleSheet("font-size: 11pt; padding-left: 125px; padding-right: 125px; font:bold");
ui->valueLabel->setStyleSheet("font-size: 9pt");
ui->warmthValueLabel->setStyleSheet("font-size: 9pt");
if(global::isN705 == true or global::isN905C == true or global::isN613 == true) {
ui->warmthSlider->hide();
ui->warmthDecBtn->hide();
ui->warmthIncBtn->hide();
ui->warmthValueLabel->hide();
ui->warmthSlider->deleteLater();
ui->warmthDecBtn->deleteLater();
ui->warmthIncBtn->deleteLater();
ui->gridLayout_5->deleteLater();
ui->warmthValueLabel->deleteLater();
this->adjustSize();
}
else if (global::isN873 == true){
ui->warmthDecBtn->setProperty("type", "borderless");
ui->warmthIncBtn->setProperty("type", "borderless");
ui->warmthDecBtn->setText("");
ui->warmthIncBtn->setText("");
ui->warmthDecBtn->setIcon(QIcon(":/resources/nightmode-empty.png"));
ui->warmthIncBtn->setIcon(QIcon(":/resources/nightmode-full.png"));
}
else {
ui->warmthSlider->hide();
ui->warmthDecBtn->hide();
ui->warmthIncBtn->hide();
ui->warmthValueLabel->hide();
ui->warmthSlider->deleteLater();
ui->warmthDecBtn->deleteLater();
ui->warmthIncBtn->deleteLater();
ui->gridLayout_5->deleteLater();
ui->warmthValueLabel->deleteLater();
this->adjustSize();
}
// I know, Mini and Touch don't have frontlights but that's a template to include others later... // I know, Mini and Touch don't have frontlights but that's a template to include others later...
int value; int value;
int warmthValue;
if(global::isN705 == true or global::isN905C == true or global::isN873 == true) { if(global::isN705 == true or global::isN905C == true or global::isN873 == true) {
value = get_brightness(); value = get_brightness();
if(global::isN873 == true) {
warmthValue = get_warmth();
ui->warmthSlider->setValue(warmthValue);
}
} }
else if(global::isN613 == true) { else if(global::isN613 == true) {
setDefaultWorkDir(); setDefaultWorkDir();
@ -39,21 +93,12 @@ brightnessDialog::brightnessDialog(QWidget *parent) :
QString valueStr = QString::number(value); QString valueStr = QString::number(value);
valueStr = valueStr.append("%"); valueStr = valueStr.append("%");
ui->valueLabel->setText(valueStr); ui->valueLabel->setText(valueStr);
// Warmth value label
ui->quitBtn->setProperty("type", "borderless"); if(global::isN873 == true) {
ui->quitBtn->setText(""); warmthValue = get_warmth();
ui->quitBtn->setIcon(QIcon(":/resources/close.png")); QString warmthValueStr = QString::number(warmthValue);
ui->okBtn->setProperty("type", "borderless"); ui->warmthValueLabel->setText(warmthValueStr);
ui->okBtn->setText(""); }
ui->okBtn->setIcon(QIcon(":/resources/check.png"));
ui->decBtn->setProperty("type", "borderless");
ui->decBtn->setText("");
ui->decBtn->setIcon(QIcon(":/resources/minus.png"));
ui->incBtn->setProperty("type", "borderless");
ui->incBtn->setText("");
ui->incBtn->setIcon(QIcon(":/resources/plus.png"));
ui->brightnessLabel->setStyleSheet("font-size: 11pt; padding-left: 125px; padding-right: 125px; font:bold");
ui->valueLabel->setStyleSheet("font-size: 9pt");
// UI fonts // UI fonts
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Bold.ttf"); int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Bold.ttf");
@ -65,6 +110,9 @@ brightnessDialog::brightnessDialog(QWidget *parent) :
// Saving current brightness value in case we want to go backwards // Saving current brightness value in case we want to go backwards
if(global::isN705 == true or global::isN905C == true or global::isN873 == true) { if(global::isN705 == true or global::isN905C == true or global::isN873 == true) {
oldValue = get_brightness(); oldValue = get_brightness();
if(global::isN873 == true) {
oldWarmthValue = get_warmth();
}
} }
else if(global::isN613 == true) { else if(global::isN613 == true) {
setDefaultWorkDir(); setDefaultWorkDir();
@ -84,9 +132,15 @@ void brightnessDialog::on_quitBtn_clicked()
{ {
// Reverting back to the old value // Reverting back to the old value
brightnessDialog::pre_set_brightness(oldValue); brightnessDialog::pre_set_brightness(oldValue);
if(global::isN873 == true) {
set_warmth(oldWarmthValue);
}
// Just in case ;) // Just in case ;)
brightness_writeconfig(oldValue); brightness_writeconfig(oldValue);
if(global::isN873 == true) {
warmth_writeconfig(oldWarmthValue);
}
// Leaving // Leaving
brightnessDialog::close(); brightnessDialog::close();
@ -117,10 +171,15 @@ void brightnessDialog::on_decBtn_clicked()
void brightnessDialog::on_okBtn_clicked() void brightnessDialog::on_okBtn_clicked()
{ {
// Get set brightness value // Get set brightness value
int value = ui->horizontalSlider->value(); int brightnessValue = ui->horizontalSlider->value();
int warmthValue;
// Write brightness config // Write brightness config
brightness_writeconfig(value); brightness_writeconfig(brightnessValue);
if(global::isN873 == true) {
warmthValue = ui->warmthSlider->value();
warmth_writeconfig(warmthValue);
}
// Leaving // Leaving
brightnessDialog::close(); brightnessDialog::close();
@ -137,3 +196,27 @@ void brightnessDialog::pre_set_brightness(int brightnessValue) {
set_brightness(brightnessValue); set_brightness(brightnessValue);
} }
} }
void brightnessDialog::on_warmthSlider_valueChanged(int value)
{
set_warmth(value);
QString valueStr = QString::number(value);
ui->warmthValueLabel->setText(valueStr);
}
void brightnessDialog::on_warmthDecBtn_clicked()
{
int value = ui->warmthSlider->value();
value = value - 1;
ui->warmthSlider->setValue(value);
}
void brightnessDialog::on_warmthIncBtn_clicked()
{
int value = ui->warmthSlider->value();
value = value + 1;
ui->warmthSlider->setValue(value);
}

View file

@ -16,6 +16,7 @@ class brightnessDialog : public QDialog
public: public:
QString checkconfig_str_val; QString checkconfig_str_val;
int oldValue; int oldValue;
int oldWarmthValue;
void pre_set_brightness(int brightnessValue); void pre_set_brightness(int brightnessValue);
explicit brightnessDialog(QWidget *parent = nullptr); explicit brightnessDialog(QWidget *parent = nullptr);
~brightnessDialog(); ~brightnessDialog();
@ -26,6 +27,9 @@ private slots:
void on_incBtn_clicked(); void on_incBtn_clicked();
void on_decBtn_clicked(); void on_decBtn_clicked();
void on_okBtn_clicked(); void on_okBtn_clicked();
void on_warmthSlider_valueChanged(int value);
void on_warmthDecBtn_clicked();
void on_warmthIncBtn_clicked();
private: private:
Ui::brightnessDialog *ui; Ui::brightnessDialog *ui;

View file

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>400</width> <width>400</width>
<height>128</height> <height>216</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
@ -25,8 +25,93 @@
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="3" column="0"> <item row="5" column="0">
<spacer name="verticalSpacer"> <layout class="QGridLayout" name="gridLayout_3">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="1" column="1">
<layout class="QGridLayout" name="gridLayout_4">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="decBtn">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider">
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="incBtn">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
<layout class="QGridLayout" name="gridLayout_5">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QSlider" name="warmthSlider">
<property name="maximum">
<number>10</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="warmthDecBtn">
<property name="text">
<string>Colder</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="warmthIncBtn">
<property name="text">
<string>Warmer</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QLabel" name="valueLabel">
<property name="text">
<string>Brightness Value</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
@ -38,16 +123,6 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="7" column="0">
<widget class="QLabel" name="valueLabel">
<property name="text">
<string>Brightness Value</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="0"> <item row="1" column="0">
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="bottomMargin"> <property name="bottomMargin">
@ -111,42 +186,8 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="5" column="0"> <item row="3" column="0">
<layout class="QGridLayout" name="gridLayout_3"> <spacer name="verticalSpacer">
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider">
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="incBtn">
<property name="text">
<string>Up</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="decBtn">
<property name="text">
<string>Down</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
@ -158,6 +199,16 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="0">
<widget class="QLabel" name="warmthValueLabel">
<property name="text">
<string>Warmth Value</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View file

@ -75,6 +75,9 @@ namespace global {
inline bool modalToast; inline bool modalToast;
inline bool indefiniteToast; inline bool indefiniteToast;
} }
namespace device {
inline bool isWifiAble;
}
inline QString systemInfoText; inline QString systemInfoText;
inline bool forbidOpenSearchDialog; inline bool forbidOpenSearchDialog;
inline bool isN705; inline bool isN705;
@ -202,6 +205,12 @@ namespace {
fhandler << value; fhandler << value;
fhandler.close(); fhandler.close();
} }
void warmth_writeconfig(int value) {
std::ofstream fhandler;
fhandler.open(".config/03-brightness/config-warmth");
fhandler << value;
fhandler.close();
}
int get_brightness() { int get_brightness() {
string_checkconfig_ro("/opt/inkbox_device"); string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n613\n") { if(checkconfig_str_val == "n613\n") {
@ -478,5 +487,28 @@ namespace {
} }
} }
} }
int get_warmth() {
QString sysfsWarmthPath;
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n873\n") {
sysfsWarmthPath = "/sys/class/backlight/lm3630a_led/color";
}
string_checkconfig_ro(sysfsWarmthPath);
int warmthValue = checkconfig_str_val.toInt();
warmthValue = 10 - warmthValue;
return warmthValue;
}
void set_warmth(int warmthValue) {
// Value 0 gives a warmer lighting than value 10
warmthValue = 10 - warmthValue;
std::string warmthValueStr = std::to_string(warmthValue);
std::string sysfsWarmthPath;
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n873\n") {
sysfsWarmthPath = "/sys/class/backlight/lm3630a_led/color";
}
string_writeconfig(sysfsWarmthPath, warmthValueStr);
}
} }
#endif // FUNCTIONS_H #endif // FUNCTIONS_H

View file

@ -144,6 +144,12 @@ int main(int argc, char *argv[])
global::isN905C = false; global::isN905C = false;
global::isN613 = true; global::isN613 = true;
} }
else if(checkconfig_str_val == "n873\n") {
global::isN705 = false;
global::isN905C = false;
global::isN613 = false;
global::isN873 = true;
}
else { else {
; ;
} }

View file

@ -127,7 +127,9 @@ MainWindow::MainWindow(QWidget *parent)
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight)); ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
setWifiIcon(); setWifiIcon();
updateWifiIcon(0); if(global::device::isWifiAble == true) {
updateWifiIcon(0);
}
setBatteryIcon(); setBatteryIcon();
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf"); int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
@ -742,10 +744,6 @@ void MainWindow::setBatteryIcon() {
ui->brightnessBtn->hide(); ui->brightnessBtn->hide();
ui->line_7->hide(); ui->line_7->hide();
} }
if(checkconfig_str_val == "n705\n" or checkconfig_str_val == "n905\n" or checkconfig_str_val == "n613\n") {
ui->wifiBtn->hide();
ui->line_9->hide();
}
// Setting icons up // Setting icons up
stdIconWidth = sW / 16; stdIconWidth = sW / 16;
@ -823,6 +821,18 @@ void MainWindow::setInitialBrightness() {
string_writeconfig("/tmp/inkbox-cinematicBrightness_ran", "true"); string_writeconfig("/tmp/inkbox-cinematicBrightness_ran", "true");
cinematicBrightness(brightness_value, 0); cinematicBrightness(brightness_value, 0);
} }
string_checkconfig_ro("/opt/inkbox_device");
if(checkconfig_str_val == "n873\n") {
int warmth;
string_checkconfig_ro(".config/03-brightness/config-warmth");
if(checkconfig_str_val == "") {
warmth = 0;
}
else {
warmth = checkconfig_str_val.toInt();
}
set_warmth(warmth);
}
} }
void MainWindow::refreshScreen() { void MainWindow::refreshScreen() {
@ -897,19 +907,27 @@ bool MainWindow::checkWifiState() {
} }
void MainWindow::setWifiIcon() { void MainWindow::setWifiIcon() {
if(checkWifiState() == true) { if(checkconfig("/run/wifi_able") == true) {
if(testPing() == 0) { global::device::isWifiAble = true;
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png")); if(checkWifiState() == true) {
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); 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 { else {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-standby.png")); ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
} }
} }
else { else {
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png")); global::device::isWifiAble = false;
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight)); ui->wifiBtn->hide();
ui->line_9->hide();
} }
} }