Give UI elements proper names

This commit is contained in:
BlackMark 2020-07-12 18:44:38 +02:00
parent 200ad19d95
commit 395e58f94d
3 changed files with 62 additions and 72 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AdaptiveBrightnessClass</class>
<widget class="QMainWindow" name="AdaptiveBrightnessClass">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
@ -17,26 +17,26 @@
<iconset resource="AdaptiveBrightness.qrc">
<normaloff>:/AdaptiveBrightness/resources/system.ico</normaloff>:/AdaptiveBrightness/resources/system.ico</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="mainWidget">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<widget class="QTabWidget" name="tabWidget">
<widget class="QTabWidget" name="tabs">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<widget class="QWidget" name="monitorTab">
<attribute name="title">
<string>Monitors</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_12">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="monitorGroup">
<property name="title">
<string>Monitor</string>
</property>
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<widget class="QComboBox" name="comboBox">
<widget class="QComboBox" name="monitorDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -46,48 +46,48 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton">
<widget class="QPushButton" name="monitorEnumerateButton">
<property name="text">
<string>Re-enumerate</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_7">
<widget class="QGroupBox" name="monitorLimitsGroup">
<property name="title">
<string>Limits</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider_3">
<widget class="QSlider" name="monitorMaxBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<widget class="QLabel" name="monitorMinBrightnessLabel">
<property name="text">
<string>Minimum</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider_2">
<widget class="QSlider" name="monitorMinBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<widget class="QLabel" name="monitorMaxBrightnessLabel">
<property name="text">
<string>Maximum</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_10">
<widget class="QLabel" name="monitorMinBrightnessValueLabel">
<property name="text">
<string>0%</string>
</property>
@ -97,7 +97,7 @@
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_11">
<widget class="QLabel" name="monitorMaxBrightnessValueLabel">
<property name="text">
<string>100%</string>
</property>
@ -110,27 +110,27 @@
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="monitorBrightnessGroup">
<property name="title">
<string>Brightness</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QSlider" name="horizontalSlider">
<widget class="QSlider" name="monitorBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="monitorOverrideCheck">
<property name="text">
<string>Manual override</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_2">
<widget class="QLabel" name="monitorBrightnessValueLabel">
<property name="text">
<string>50%</string>
</property>
@ -146,27 +146,27 @@
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_8">
<widget class="QGroupBox" name="monitorOverallLimitsGroup">
<property name="title">
<string>Overall limits</string>
</property>
<layout class="QGridLayout" name="gridLayout_10">
<item row="0" column="0">
<widget class="QLabel" name="label_12">
<widget class="QLabel" name="monitorOverallMinBrightnessLabel">
<property name="text">
<string>Minimum</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider_4">
<widget class="QSlider" name="monitorOverallMinBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_14">
<widget class="QLabel" name="monitorOverallMinBrightnessValueLabel">
<property name="text">
<string>0%</string>
</property>
@ -176,21 +176,21 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_13">
<widget class="QLabel" name="monitorOverallMaxBrightnessLabel">
<property name="text">
<string>Maximum</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSlider_5">
<widget class="QSlider" name="monitorOverallMaxBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_15">
<widget class="QLabel" name="monitorOverallMaxBrightnessValueLabel">
<property name="text">
<string>100%</string>
</property>
@ -203,7 +203,7 @@
</widget>
</item>
<item row="4" column="0" colspan="2">
<spacer name="verticalSpacer_4">
<spacer name="monitorBottomSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -216,14 +216,14 @@
</spacer>
</item>
<item row="5" column="0">
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="monitorResetButton">
<property name="text">
<string>Restore all monitors to defaults</string>
</property>
</widget>
</item>
<item row="5" column="1">
<spacer name="horizontalSpacer">
<spacer name="monitorResetSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -236,20 +236,20 @@
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_9">
<widget class="QGroupBox" name="monitorOverallBrightnessGroup">
<property name="title">
<string>Overall brightness</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSlider" name="horizontalSlider_6">
<widget class="QSlider" name="monitorOverallBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label_16">
<widget class="QLabel" name="monitorOverallBrightnessValueLabel">
<property name="text">
<string>50%</string>
</property>
@ -259,7 +259,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox_2">
<widget class="QCheckBox" name="monitorOverallOverrideCheck">
<property name="text">
<string>Manual override</string>
</property>
@ -269,7 +269,7 @@
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer_2">
<spacer name="monitorTopSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -283,26 +283,26 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<widget class="QWidget" name="sensorsTab">
<attribute name="title">
<string>Sensors</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_3">
<widget class="QGroupBox" name="sensorGroup">
<property name="title">
<string>Sensor module</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_3">
<widget class="QPushButton" name="sensorEnumerateButton">
<property name="text">
<string>Re-enumerate</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QComboBox" name="comboBox_2">
<widget class="QComboBox" name="sensorDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -312,13 +312,13 @@
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_4">
<widget class="QGroupBox" name="sensorReadoutGroup">
<property name="title">
<string>Readout</string>
</property>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QTreeWidget" name="treeWidget">
<widget class="QTreeWidget" name="sensorReadoutValues">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -394,20 +394,20 @@
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_5">
<widget class="QGroupBox" name="sensorAggregationGroup">
<property name="title">
<string>Sensor aggregation</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="sensorAggregationFunctionLabel">
<property name="text">
<string>Function</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="comboBox_3">
<widget class="QComboBox" name="sensorAggregationFunctionDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -417,14 +417,14 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label">
<widget class="QLabel" name="sensorAggregationResultLabel">
<property name="text">
<string>Module result:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="sensorAggregationValueLabel">
<property name="text">
<string>50%</string>
</property>
@ -440,14 +440,14 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pushButton_4">
<widget class="QPushButton" name="sensorResetButton">
<property name="text">
<string>Restore all sensors to defaults</string>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="horizontalSpacer_2">
<spacer name="sensorResetSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -460,20 +460,20 @@
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_6">
<widget class="QGroupBox" name="sensorTotalAggregationGroup">
<property name="title">
<string>Total aggregation</string>
</property>
<layout class="QGridLayout" name="gridLayout_7">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<widget class="QLabel" name="sensorTotalAggregationFunctionLabel">
<property name="text">
<string>Function</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="comboBox_4">
<widget class="QComboBox" name="sensorTotalAggregationFunctionDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
@ -483,14 +483,14 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_6">
<widget class="QLabel" name="sensorTotalAggregationResultLabel">
<property name="text">
<string>Result:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_7">
<widget class="QLabel" name="sensorTotalAggregationValueLabel">
<property name="text">
<string>50%</string>
</property>
@ -503,7 +503,7 @@
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="verticalSpacer">
<spacer name="sensorTopSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
@ -516,7 +516,7 @@
</spacer>
</item>
<item row="3" column="0" colspan="2">
<spacer name="verticalSpacer_3">
<spacer name="sensorBottomSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>

View File

@ -24,18 +24,12 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
m_ui.setupUi(this);
const auto tabs = m_ui.centralWidget->findChild<QTabWidget*>("tabWidget");
const auto tab = tabs->findChild<QWidget*>("tab");
m_manualBrightnessSlider = tab->findChild<QSlider*>("horizontalSlider");
if(m_manualBrightnessSlider) {
connect(m_manualBrightnessSlider, &QSlider::valueChanged, [this](int value) {
connect(m_ui.monitorBrightnessSlider, &QSlider::valueChanged, [this](int value) {
const auto mappedBrightness = utils::map(value, 0, 100, 0.f, 1.f);
const auto newBrightness = std::clamp(mappedBrightness, 0.f, 1.f);
qDebug(ltr("Overriding brightness with %1").arg(newBrightness));
m_brightness = newBrightness;
});
}
loadIcons();
@ -207,9 +201,7 @@ void MainWindow::updateState()
m_trayIcon->setToolTip(tr("AdaptiveBrightness - %1%").arg(m_brightness * 100, 0, 'f', 0));
}
if(m_manualBrightnessSlider) {
m_manualBrightnessSlider->setValue(utils::map(m_brightness, 0.f, 1.f, 0, 100));
}
m_ui.monitorBrightnessSlider->setValue(utils::map(m_brightness, 0.f, 1.f, 0, 100));
}
void MainWindow::trayIconClicked(QSystemTrayIcon::ActivationReason reason)

View File

@ -34,7 +34,7 @@ class MainWindow : public QMainWindow {
void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
Ui::AdaptiveBrightnessClass m_ui;
Ui::MainWindow m_ui;
std::array<std::unique_ptr<QIcon>, 9> m_noSensorStateIcons;
std::array<std::unique_ptr<QIcon>, 9> m_sensorStateIcons;
@ -48,8 +48,6 @@ class MainWindow : public QMainWindow {
QThread* m_timerThread = nullptr;
QTimer* m_timer = nullptr;
QSlider* m_manualBrightnessSlider = nullptr;
float m_brightness = 0.5f;
std::vector<Sensor> m_sensors;