From 6f6fe0d53d6a4abae99a97c52aad3b34ccabb9ad Mon Sep 17 00:00:00 2001 From: "P.L. Lucas" Date: Mon, 16 May 2022 19:11:39 +0200 Subject: [PATCH 1/2] lxqt-config-brightness: Advanced options to set minimun backlight. --- lxqt-config-brightness/brightnesssettings.cpp | 75 +++-- lxqt-config-brightness/brightnesssettings.h | 7 +- lxqt-config-brightness/brightnesssettings.ui | 302 +++++++++++------- lxqt-config-brightness/main.cpp | 7 +- 4 files changed, 241 insertions(+), 150 deletions(-) diff --git a/lxqt-config-brightness/brightnesssettings.cpp b/lxqt-config-brightness/brightnesssettings.cpp index 6e5b0e505..199949f6e 100644 --- a/lxqt-config-brightness/brightnesssettings.cpp +++ b/lxqt-config-brightness/brightnesssettings.cpp @@ -21,7 +21,7 @@ #include #include -BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent) +BrightnessSettings::BrightnessSettings(LXQt::Settings *settings, QWidget *parent):QDialog(parent) { ui = new Ui::BrightnessSettings(); ui->setupUi(this); @@ -31,8 +31,17 @@ BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent) mMonitorsInitial = mBrightness->getMonitorsInfo(); mBacklight = new LXQt::Backlight(this); - ui->headIconLabel->setPixmap(QIcon::fromTheme(QStringLiteral("display-brightness-symbolic")).pixmap(32, 32)); + // Get minimum backlight + mSettings = settings; + mSettings->beginGroup(QStringLiteral("Backlight")); + mMinBacklightValue = mSettings->value(QStringLiteral("min"), -1).toInt(); + if(mMinBacklightValue < 0) { + // Set the minimum to 5% of the maximum to prevent a black screen + mMinBacklightValue = qMax(qRound((qreal)(mBacklight->getMaxBacklight())*0.05), 1); + } + mInitialMinBacklightValue = mMinBacklightValue; + ui->minBacklightSlider->setEnabled(mBacklight->isBacklightAvailable() || mBacklight->isBacklightOff()); ui->backlightSlider->setEnabled(mBacklight->isBacklightAvailable() || mBacklight->isBacklightOff()); ui->backlightGroupBox->setEnabled(mBacklight->isBacklightAvailable() || mBacklight->isBacklightOff()); if(mBacklight->isBacklightAvailable()) { @@ -45,6 +54,34 @@ BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent) [this](bool){ ui->backlightSlider->setValue(ui->backlightSlider->value()-1); }); connect(ui->backlightUpButton, &QToolButton::clicked, [this](bool){ ui->backlightSlider->setValue(ui->backlightSlider->value()+1); }); + + ui->minBacklightSlider->setMinimum(0); + ui->minBacklightSlider->setMaximum(mBacklight->getMaxBacklight()); + ui->minBacklightSlider->setValue(mMinBacklightValue); + + connect(ui->minBacklightSlider, &QSlider::valueChanged, this, + [this](int){ + mMinBacklightValue = ui->minBacklightSlider->value(); + setBacklightSliderValue(mLastBacklightValue); + }); + + connect(ui->minBacklightDownButton, &QToolButton::clicked, + [this](bool){ + ui->minBacklightSlider->setValue(ui->minBacklightSlider->value()-1); + mMinBacklightValue = ui->minBacklightSlider->value(); + setBacklightSliderValue(mLastBacklightValue); + }); + connect(ui->minBacklightUpButton, &QToolButton::clicked, + [this](bool){ + ui->minBacklightSlider->setValue(ui->minBacklightSlider->value()+1); + mMinBacklightValue = ui->minBacklightSlider->value(); + setBacklightSliderValue(mLastBacklightValue); + }); + + connect(ui->checkMinBacklightButton, &QPushButton::pressed, + [this](){ mBacklight->setBacklight(ui->minBacklightSlider->value()); }); + connect(ui->checkMinBacklightButton, &QPushButton::released, + [this](){ mBacklight->setBacklight(mLastBacklightValue); }); } for(const MonitorInfo &monitor: qAsConst(mMonitors)) @@ -64,6 +101,13 @@ BrightnessSettings::BrightnessSettings(QWidget *parent):QDialog(parent) [this](QAbstractButton *button) { if(ui->buttonBox->button(QDialogButtonBox::Reset) == button) { revertValues(); + } else if(ui->buttonBox->button(QDialogButtonBox::Close) == button) { + close(); + } else if(ui->buttonBox->button(QDialogButtonBox::Save) == button) { + mSettings->setValue(QStringLiteral("min"), mMinBacklightValue); + QMessageBox msgBox; + msgBox.setText(tr("Backlight minimum value has been saved.")); + msgBox.exec(); } } ); } @@ -80,14 +124,8 @@ BrightnessSettings::~BrightnessSettings() void BrightnessSettings::setBacklight() { int value = ui->backlightSlider->value(); - // Set the minimum to 5% of the maximum to prevent a black screen - int minBacklight = qMax(qRound((qreal)(mBacklight->getMaxBacklight())*0.05), 1); - int maxBacklight = mBacklight->getMaxBacklight(); - int interval = maxBacklight - minBacklight; - if(interval > 100) - value = (value * maxBacklight) / 100; mBacklight->setBacklight(value); - + if (ui->confirmCB->isChecked()) mConfirmRequestTimer.start(); } @@ -160,6 +198,7 @@ void BrightnessSettings::revertValues() disconnect(ui->backlightSlider, &QSlider::valueChanged, this, &BrightnessSettings::setBacklight); mBacklight->setBacklight(mInitialBacklightValue); setBacklightSliderValue(mInitialBacklightValue); + ui->minBacklightSlider->setValue(mInitialMinBacklightValue); connect(ui->backlightSlider, &QSlider::valueChanged, this, &BrightnessSettings::setBacklight); } @@ -171,18 +210,10 @@ void BrightnessSettings::revertValues() void BrightnessSettings::setBacklightSliderValue(int value) { - // Set the minimum to 5% of the maximum to prevent a black screen - int minBacklight = qMax(qRound((qreal)(mBacklight->getMaxBacklight())*0.05), 1); + int minBacklight = mMinBacklightValue; int maxBacklight = mBacklight->getMaxBacklight(); - int interval = maxBacklight - minBacklight; - if(interval <= 100) { - ui->backlightSlider->setMaximum(maxBacklight); - ui->backlightSlider->setMinimum(minBacklight); - ui->backlightSlider->setValue(value); - } else { - ui->backlightSlider->setMaximum(100); - // Set the minimum to 5% of the maximum to prevent a black screen - ui->backlightSlider->setMinimum(5); - ui->backlightSlider->setValue( (value * 100) / maxBacklight); - } + + ui->backlightSlider->setMaximum(maxBacklight); + ui->backlightSlider->setMinimum(minBacklight); + ui->backlightSlider->setValue(value); } \ No newline at end of file diff --git a/lxqt-config-brightness/brightnesssettings.h b/lxqt-config-brightness/brightnesssettings.h index 1fa897335..8631bf359 100644 --- a/lxqt-config-brightness/brightnesssettings.h +++ b/lxqt-config-brightness/brightnesssettings.h @@ -25,13 +25,14 @@ #include "ui_brightnesssettings.h" #include +#include class BrightnessSettings: public QDialog { Q_OBJECT public: - BrightnessSettings(QWidget *parent =nullptr); + BrightnessSettings(LXQt::Settings *settings, QWidget *parent =nullptr); ~BrightnessSettings(); void revertValues(); @@ -55,7 +56,9 @@ public slots: LXQt::Backlight *mBacklight; int mLastBacklightValue; int mInitialBacklightValue; - + int mInitialMinBacklightValue; + int mMinBacklightValue; + LXQt::Settings *mSettings; }; diff --git a/lxqt-config-brightness/brightnesssettings.ui b/lxqt-config-brightness/brightnesssettings.ui index b776367c0..f3f7a6f3f 100644 --- a/lxqt-config-brightness/brightnesssettings.ui +++ b/lxqt-config-brightness/brightnesssettings.ui @@ -6,8 +6,8 @@ 0 0 - 466 - 252 + 557 + 403 @@ -19,94 +19,181 @@ - - - 10 - - - - - - 0 - 0 - - - - - - - - - - - <html><head/><body><p><span style=" font-weight:600;">Backlight and brightness settings:</span></p></body></html> - - - - - - - - - Backlight - - - - - - - - - true - - - - - - - Qt::Horizontal - - - - - - - - - - true - - - - - - - - - - Brightness - - - - 2 - - - 2 - - - - - - - - - - - Require confirmation after settings change - - - true + + + 0 + + + Backlight and brightness settings + + + + + + Backlight + + + + + + + + + true + + + + + + + Qt::Horizontal + + + + + + + + + + true + + + + + + + + + + Brightness + + + + 2 + + + 2 + + + + + + + + + + + Require confirmation after settings change + + + true + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + Advanced settings + + + + + + Backlight + + + + + + The minimun value for backlight value can be really brightness. +It is possible set this minimum value. +Warning: If a very low backlight is set, a black screen can be shown. + + + Minimum backlight + + + + + + + + + + + + + + + 1 + + + Qt::Horizontal + + + + + + + + + + + + + + + + + + + + + + + + + Check + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + @@ -115,45 +202,12 @@ Qt::Horizontal - QDialogButtonBox::Close|QDialogButtonBox::Reset + QDialogButtonBox::Close|QDialogButtonBox::Reset|QDialogButtonBox::Save - - - buttonBox - accepted() - BrightnessSettings - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - BrightnessSettings - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/lxqt-config-brightness/main.cpp b/lxqt-config-brightness/main.cpp index 2cddc427c..47887d858 100644 --- a/lxqt-config-brightness/main.cpp +++ b/lxqt-config-brightness/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include "brightnesssettings.h" @@ -159,8 +160,10 @@ int main(int argn, char* argv[]) Q_UNREACHABLE(); } + LXQt::Settings session_settings(QStringLiteral("session")); + if (config.mode == UiMode::GUI) { - BrightnessSettings brightnessSettings; + BrightnessSettings brightnessSettings(&session_settings); brightnessSettings.setWindowIcon(QIcon(QLatin1String(ICON_DIR) + QStringLiteral("/brightnesssettings.svg"))); brightnessSettings.show(); return app.exec(); @@ -184,7 +187,7 @@ int main(int argn, char* argv[]) const int currentBacklight = mBacklight->getBacklight(); const int maxBacklight = mBacklight->getMaxBacklight(); - int backlight = ( currentBacklight + sign*(maxBacklight/50 + 1) )*qAbs(sign) + brightnessValue*maxBacklight; + int backlight = ( currentBacklight + sign*(maxBacklight/10 + 1) )*qAbs(sign) + brightnessValue*maxBacklight; mBacklight->setBacklight(backlight); From a07f30c7a4672fc5a35c3dca75b2adc8a10bb842 Mon Sep 17 00:00:00 2001 From: "P.L. Lucas" Date: Mon, 16 May 2022 19:21:57 +0200 Subject: [PATCH 2/2] Fixing spelling --- lxqt-config-brightness/brightnesssettings.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxqt-config-brightness/brightnesssettings.ui b/lxqt-config-brightness/brightnesssettings.ui index f3f7a6f3f..7ec2e4166 100644 --- a/lxqt-config-brightness/brightnesssettings.ui +++ b/lxqt-config-brightness/brightnesssettings.ui @@ -121,7 +121,7 @@ - The minimun value for backlight value can be really brightness. + The minimum value for backlight value can be really brightness. It is possible set this minimum value. Warning: If a very low backlight is set, a black screen can be shown.