Compare commits

..

2 Commits

2 changed files with 60 additions and 41 deletions

View File

@ -111,25 +111,11 @@ void MainWindow::setupMonitorsTab()
{
connect(m_ui.monitorDropdown, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &MainWindow::updateCurrentMonitorGUI);
m_ui.monitorBrightnessSlider->setDisabled(true);
m_ui.monitorOverallBrightnessSlider->setDisabled(true);
m_ui.monitorOverrideCheck->setChecked(false);
connect(m_ui.monitorOverrideCheck, &QCheckBox::stateChanged,
[this](int state) { m_ui.monitorBrightnessSlider->setEnabled(state == Qt::CheckState::Checked); });
m_ui.monitorOverallOverrideCheck->setChecked(false);
connect(m_ui.monitorOverallOverrideCheck, &QCheckBox::stateChanged,
[this](int state) { m_ui.monitorOverallBrightnessSlider->setEnabled(state == Qt::CheckState::Checked); });
connect(m_ui.monitorBrightnessSlider, &QSlider::valueChanged, [this](int value) {
const auto newBrightness = utils::map(value, 0, 100, 0.f, 1.f);
qDebug(ltr("Overriding brightness with %1").arg(newBrightness));
m_brightness = newBrightness;
});
setupLimitsSlider();
setupOverallLimitsSlider();
setupBrightness();
setupOverallBrightness();
}
void MainWindow::setupLimitsSlider()
@ -141,7 +127,6 @@ void MainWindow::setupLimitsSlider()
}
const auto curIdx = m_ui.monitorDropdown->currentIndex();
m_monitors[curIdx].minBrightness = utils::map(value, 0, 100, 0.f, 1.f);
updateCurrentMonitorGUI(curIdx);
});
connect(m_ui.monitorMaxBrightnessSlider, &QSlider::valueChanged, [this](int value) {
m_ui.monitorMaxBrightnessValueLabel->setText(tr("%1%").arg(value, 3));
@ -150,7 +135,6 @@ void MainWindow::setupLimitsSlider()
}
const auto curIdx = m_ui.monitorDropdown->currentIndex();
m_monitors[curIdx].maxBrightness = utils::map(value, 0, 100, 0.f, 1.f);
updateCurrentMonitorGUI(curIdx);
});
}
@ -178,6 +162,50 @@ void MainWindow::setupOverallLimitsSlider()
});
}
void MainWindow::setupBrightness()
{
m_ui.monitorBrightnessSlider->setDisabled(true);
connect(m_ui.monitorBrightnessSlider, &QSlider::valueChanged, [this](int value) {
m_ui.monitorBrightnessValueLabel->setText(tr("%1%").arg(value, 3));
const auto newBrightness = utils::map(value, 0, 100, 0.f, 1.f);
qDebug(ltr("Overriding brightness with %1").arg(newBrightness));
const auto curIdx = m_ui.monitorDropdown->currentIndex();
m_monitors[curIdx].brightness = newBrightness;
});
m_ui.monitorOverrideCheck->setChecked(false);
connect(m_ui.monitorOverrideCheck, &QCheckBox::stateChanged, [this](int state) {
m_ui.monitorBrightnessSlider->setEnabled(state == Qt::CheckState::Checked);
const auto curIdx = m_ui.monitorDropdown->currentIndex();
m_monitors[curIdx].manualOverride = state == Qt::CheckState::Checked;
});
}
void MainWindow::setupOverallBrightness()
{
m_ui.monitorOverallBrightnessSlider->setDisabled(true);
connect(m_ui.monitorOverallBrightnessSlider, &QSlider::valueChanged, [this](int value) {
m_ui.monitorOverallBrightnessValueLabel->setText(tr("%1%").arg(value, 3));
const auto newBrightness = utils::map(value, 0, 100, 0.f, 1.f);
qDebug(ltr("Overriding overall brightness with %1").arg(newBrightness));
for(auto& monitor: m_monitors) {
monitor.brightness = newBrightness;
}
updateCurrentMonitorGUI(m_ui.monitorDropdown->currentIndex());
});
m_ui.monitorOverallOverrideCheck->setChecked(false);
connect(m_ui.monitorOverallOverrideCheck, &QCheckBox::stateChanged, [this](int state) {
m_ui.monitorOverallBrightnessSlider->setEnabled(state == Qt::CheckState::Checked);
for(auto& monitor: m_monitors) {
monitor.manualOverride = state == Qt::CheckState::Checked;
}
updateCurrentMonitorGUI(m_ui.monitorDropdown->currentIndex());
});
}
void MainWindow::setupTrayIcon()
{
loadIcons();
@ -231,19 +259,9 @@ void MainWindow::setupCallbackTimer()
void MainWindow::updateCurrentMonitorGUI(int index)
{
const auto brightness = utils::map(m_monitors[index].brightness, 0.f, 1.f, 0, 100);
const auto minimum = utils::map(m_monitors[index].minBrightness, 0.f, 1.f, 0, 100);
const auto maximum = utils::map(m_monitors[index].maxBrightness, 0.f, 1.f, 0, 100);
m_ui.monitorMinBrightnessSlider->setValue(minimum);
m_ui.monitorMinBrightnessValueLabel->setText(QString("%1%").arg(minimum, 3));
m_ui.monitorMaxBrightnessSlider->setValue(maximum);
m_ui.monitorMaxBrightnessValueLabel->setText(QString("%1%").arg(maximum, 3));
m_ui.monitorBrightnessSlider->setValue(brightness);
m_ui.monitorBrightnessValueLabel->setText(QString("%1%").arg(brightness, 3));
m_ui.monitorMinBrightnessSlider->setValue(utils::map(m_monitors[index].minBrightness, 0.f, 1.f, 0, 100));
m_ui.monitorMaxBrightnessSlider->setValue(utils::map(m_monitors[index].maxBrightness, 0.f, 1.f, 0, 100));
m_ui.monitorBrightnessSlider->setValue(utils::map(m_monitors[index].brightness, 0.f, 1.f, 0, 100));
m_ui.monitorOverrideCheck->setChecked(m_monitors[index].manualOverride);
}
@ -280,22 +298,25 @@ void MainWindow::updateState()
bool errorOccurred = false;
for(auto& monitor: m_monitors) {
if(!monitor.driver.setBrightness(brightness)) {
monitor.brightness = monitor.manualOverride ? monitor.brightness : brightness;
if(!monitor.driver.setBrightness(monitor.brightness)) {
errorOccurred = true;
}
}
return !errorOccurred;
};
if(!getAverageSensorValue(m_brightness)) {
auto brightness = 0.5f;
if(!getAverageSensorValue(brightness)) {
enumSensors();
qInfo(ltr("At least one sensor became invalid, re-enumerating sensors found %1 valid sensor(s)").arg(m_sensors.size()));
sensorError = true;
}
const auto iconBrightness = utils::map(m_brightness, 0.f, 1.f, size_t{0}, size_t{8});
const auto iconBrightness = utils::map(brightness, 0.f, 1.f, size_t{0}, size_t{8});
if(!setAllMonitorsBrightness(m_brightness)) {
if(!setAllMonitorsBrightness(brightness)) {
enumMonitors();
qInfo(ltr("At least one monitor became invalid, re-enumerating monitors found %1 valid monitor(s)").arg(m_monitors.size()));
monitorError = true;
@ -312,10 +333,8 @@ void MainWindow::updateState()
}
if(m_trayIcon) {
m_trayIcon->setToolTip(tr("AdaptiveBrightness - %1%").arg(m_brightness * 100, 0, 'f', 0));
m_trayIcon->setToolTip(tr("AdaptiveBrightness - %1%").arg(brightness * 100, 0, 'f', 0));
}
m_ui.monitorBrightnessSlider->setValue(utils::map(m_brightness, 0.f, 1.f, 0, 100));
}
void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason)

View File

@ -36,6 +36,8 @@ class MainWindow : public QMainWindow {
void setupMonitorsTab();
void setupLimitsSlider();
void setupOverallLimitsSlider();
void setupBrightness();
void setupOverallBrightness();
void setupTrayIcon();
void setupCallbackTimer();
@ -60,8 +62,6 @@ class MainWindow : public QMainWindow {
QThread* m_timerThread = nullptr;
QTimer* m_timer = nullptr;
float m_brightness = 0.5f;
struct SensorData {
Sensor driver;
};