mirror of
https://github.com/Quill-OS/quill.git
synced 2024-10-31 21:33:22 -07:00
Brightness dialog: set lighting warmth option
This commit is contained in:
parent
4c714d4abd
commit
c509474ff3
6 changed files with 272 additions and 78 deletions
|
@ -19,10 +19,64 @@ brightnessDialog::brightnessDialog(QWidget *parent) :
|
|||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
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...
|
||||
int value;
|
||||
int warmthValue;
|
||||
if(global::isN705 == true or global::isN905C == true or global::isN873 == true) {
|
||||
value = get_brightness();
|
||||
if(global::isN873 == true) {
|
||||
warmthValue = get_warmth();
|
||||
ui->warmthSlider->setValue(warmthValue);
|
||||
}
|
||||
}
|
||||
else if(global::isN613 == true) {
|
||||
setDefaultWorkDir();
|
||||
|
@ -39,21 +93,12 @@ brightnessDialog::brightnessDialog(QWidget *parent) :
|
|||
QString valueStr = QString::number(value);
|
||||
valueStr = valueStr.append("%");
|
||||
ui->valueLabel->setText(valueStr);
|
||||
|
||||
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");
|
||||
// Warmth value label
|
||||
if(global::isN873 == true) {
|
||||
warmthValue = get_warmth();
|
||||
QString warmthValueStr = QString::number(warmthValue);
|
||||
ui->warmthValueLabel->setText(warmthValueStr);
|
||||
}
|
||||
|
||||
// UI fonts
|
||||
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
|
||||
if(global::isN705 == true or global::isN905C == true or global::isN873 == true) {
|
||||
oldValue = get_brightness();
|
||||
if(global::isN873 == true) {
|
||||
oldWarmthValue = get_warmth();
|
||||
}
|
||||
}
|
||||
else if(global::isN613 == true) {
|
||||
setDefaultWorkDir();
|
||||
|
@ -84,9 +132,15 @@ void brightnessDialog::on_quitBtn_clicked()
|
|||
{
|
||||
// Reverting back to the old value
|
||||
brightnessDialog::pre_set_brightness(oldValue);
|
||||
if(global::isN873 == true) {
|
||||
set_warmth(oldWarmthValue);
|
||||
}
|
||||
|
||||
// Just in case ;)
|
||||
brightness_writeconfig(oldValue);
|
||||
if(global::isN873 == true) {
|
||||
warmth_writeconfig(oldWarmthValue);
|
||||
}
|
||||
|
||||
// Leaving
|
||||
brightnessDialog::close();
|
||||
|
@ -117,10 +171,15 @@ void brightnessDialog::on_decBtn_clicked()
|
|||
void brightnessDialog::on_okBtn_clicked()
|
||||
{
|
||||
// Get set brightness value
|
||||
int value = ui->horizontalSlider->value();
|
||||
int brightnessValue = ui->horizontalSlider->value();
|
||||
int warmthValue;
|
||||
|
||||
// Write brightness config
|
||||
brightness_writeconfig(value);
|
||||
brightness_writeconfig(brightnessValue);
|
||||
if(global::isN873 == true) {
|
||||
warmthValue = ui->warmthSlider->value();
|
||||
warmth_writeconfig(warmthValue);
|
||||
}
|
||||
|
||||
// Leaving
|
||||
brightnessDialog::close();
|
||||
|
@ -137,3 +196,27 @@ void brightnessDialog::pre_set_brightness(int 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class brightnessDialog : public QDialog
|
|||
public:
|
||||
QString checkconfig_str_val;
|
||||
int oldValue;
|
||||
int oldWarmthValue;
|
||||
void pre_set_brightness(int brightnessValue);
|
||||
explicit brightnessDialog(QWidget *parent = nullptr);
|
||||
~brightnessDialog();
|
||||
|
@ -26,6 +27,9 @@ private slots:
|
|||
void on_incBtn_clicked();
|
||||
void on_decBtn_clicked();
|
||||
void on_okBtn_clicked();
|
||||
void on_warmthSlider_valueChanged(int value);
|
||||
void on_warmthDecBtn_clicked();
|
||||
void on_warmthIncBtn_clicked();
|
||||
|
||||
private:
|
||||
Ui::brightnessDialog *ui;
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>128</height>
|
||||
<height>216</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -25,8 +25,93 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<item row="5" column="0">
|
||||
<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">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
|
@ -38,16 +123,6 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</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">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<property name="bottomMargin">
|
||||
|
@ -111,42 +186,8 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<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">
|
||||
<item row="3" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
|
@ -158,6 +199,16 @@
|
|||
</property>
|
||||
</spacer>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
32
functions.h
32
functions.h
|
@ -75,6 +75,9 @@ namespace global {
|
|||
inline bool modalToast;
|
||||
inline bool indefiniteToast;
|
||||
}
|
||||
namespace device {
|
||||
inline bool isWifiAble;
|
||||
}
|
||||
inline QString systemInfoText;
|
||||
inline bool forbidOpenSearchDialog;
|
||||
inline bool isN705;
|
||||
|
@ -202,6 +205,12 @@ namespace {
|
|||
fhandler << value;
|
||||
fhandler.close();
|
||||
}
|
||||
void warmth_writeconfig(int value) {
|
||||
std::ofstream fhandler;
|
||||
fhandler.open(".config/03-brightness/config-warmth");
|
||||
fhandler << value;
|
||||
fhandler.close();
|
||||
}
|
||||
int get_brightness() {
|
||||
string_checkconfig_ro("/opt/inkbox_device");
|
||||
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
|
||||
|
|
6
main.cpp
6
main.cpp
|
@ -144,6 +144,12 @@ int main(int argc, char *argv[])
|
|||
global::isN905C = false;
|
||||
global::isN613 = true;
|
||||
}
|
||||
else if(checkconfig_str_val == "n873\n") {
|
||||
global::isN705 = false;
|
||||
global::isN905C = false;
|
||||
global::isN613 = false;
|
||||
global::isN873 = true;
|
||||
}
|
||||
else {
|
||||
;
|
||||
}
|
||||
|
|
|
@ -127,7 +127,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
|
||||
|
||||
setWifiIcon();
|
||||
updateWifiIcon(0);
|
||||
if(global::device::isWifiAble == true) {
|
||||
updateWifiIcon(0);
|
||||
}
|
||||
setBatteryIcon();
|
||||
|
||||
int id = QFontDatabase::addApplicationFont(":/resources/fonts/CrimsonPro-Regular.ttf");
|
||||
|
@ -742,10 +744,6 @@ void MainWindow::setBatteryIcon() {
|
|||
ui->brightnessBtn->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
|
||||
stdIconWidth = sW / 16;
|
||||
|
@ -823,6 +821,18 @@ void MainWindow::setInitialBrightness() {
|
|||
string_writeconfig("/tmp/inkbox-cinematicBrightness_ran", "true");
|
||||
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() {
|
||||
|
@ -897,19 +907,27 @@ bool MainWindow::checkWifiState() {
|
|||
}
|
||||
|
||||
void MainWindow::setWifiIcon() {
|
||||
if(checkWifiState() == true) {
|
||||
if(testPing() == 0) {
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-connected.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
if(checkconfig("/run/wifi_able") == true) {
|
||||
global::device::isWifiAble = true;
|
||||
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-standby.png"));
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->wifiBtn->setIcon(QIcon(":/resources/wifi-off.png"));
|
||||
ui->wifiBtn->setIconSize(QSize(wifiIconWidth, wifiIconHeight));
|
||||
global::device::isWifiAble = false;
|
||||
ui->wifiBtn->hide();
|
||||
ui->line_9->hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue