Compare commits

...

2 Commits

Author SHA1 Message Date
395e58f94d Give UI elements proper names 2020-07-12 18:44:38 +02:00
200ad19d95 Add GUI layout for monitors and sensors 2020-07-12 18:13:53 +02:00
3 changed files with 526 additions and 55 deletions

View File

@ -1,13 +1,13 @@
<?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>
<y>0</y>
<width>406</width>
<height>306</height>
<width>450</width>
<height>555</height>
</rect>
</property>
<property name="windowTitle">
@ -17,48 +17,523 @@
<iconset resource="AdaptiveBrightness.qrc">
<normaloff>:/AdaptiveBrightness/resources/system.ico</normaloff>:/AdaptiveBrightness/resources/system.ico</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QFormLayout" name="formLayout_2">
<widget class="QWidget" name="mainWidget">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Manual brightness control</string>
<widget class="QTabWidget" name="tabs">
<property name="currentIndex">
<number>0</number>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSlider" name="horizontalSlider">
<property name="toolTip">
<string>Brightness</string>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
<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="monitorGroup">
<property name="title">
<string>Monitor</string>
</property>
<layout class="QGridLayout" name="gridLayout_11">
<item row="0" column="0">
<widget class="QComboBox" name="monitorDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1">
<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="monitorLimitsGroup">
<property name="title">
<string>Limits</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="1" column="1">
<widget class="QSlider" name="monitorMaxBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="monitorMinBrightnessLabel">
<property name="text">
<string>Minimum</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="monitorMinBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="monitorMaxBrightnessLabel">
<property name="text">
<string>Maximum</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="monitorMinBrightnessValueLabel">
<property name="text">
<string>0%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="monitorMaxBrightnessValueLabel">
<property name="text">
<string>100%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="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="monitorBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="monitorOverrideCheck">
<property name="text">
<string>Manual override</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="monitorBrightnessValueLabel">
<property name="text">
<string>50%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<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="monitorOverallMinBrightnessLabel">
<property name="text">
<string>Minimum</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="monitorOverallMinBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="monitorOverallMinBrightnessValueLabel">
<property name="text">
<string>0%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="monitorOverallMaxBrightnessLabel">
<property name="text">
<string>Maximum</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="monitorOverallMaxBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="monitorOverallMaxBrightnessValueLabel">
<property name="text">
<string>100%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<spacer name="monitorBottomSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>218</width>
<height>35</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0">
<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="monitorResetSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<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="monitorOverallBrightnessSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="monitorOverallBrightnessValueLabel">
<property name="text">
<string>50%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="monitorOverallOverrideCheck">
<property name="text">
<string>Manual override</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="monitorTopSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<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="sensorGroup">
<property name="title">
<string>Sensor module</string>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="0" column="1">
<widget class="QPushButton" name="sensorEnumerateButton">
<property name="text">
<string>Re-enumerate</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QComboBox" name="sensorDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<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="sensorReadoutValues">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="indentation">
<number>0</number>
</property>
<column>
<property name="text">
<string>Sensor</string>
</property>
</column>
<column>
<property name="text">
<string>Raw value</string>
</property>
</column>
<column>
<property name="text">
<string>Percentage</string>
</property>
</column>
<item>
<property name="text">
<string>LDR1: Front</string>
</property>
<property name="text">
<string>50</string>
</property>
<property name="text">
<string>50%</string>
</property>
</item>
<item>
<property name="text">
<string>LDR2: Bottom</string>
</property>
<property name="text">
<string>70</string>
</property>
<property name="text">
<string>70%</string>
</property>
</item>
<item>
<property name="text">
<string>LDR3: Top</string>
</property>
<property name="text">
<string>100</string>
</property>
<property name="text">
<string>100%</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2">
<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="sensorAggregationFunctionLabel">
<property name="text">
<string>Function</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="sensorAggregationFunctionDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="sensorAggregationResultLabel">
<property name="text">
<string>Module result:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="sensorAggregationValueLabel">
<property name="text">
<string>50%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<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="sensorResetSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<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="sensorTotalAggregationFunctionLabel">
<property name="text">
<string>Function</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QComboBox" name="sensorTotalAggregationFunctionDropdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="sensorTotalAggregationResultLabel">
<property name="text">
<string>Result:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="sensorTotalAggregationValueLabel">
<property name="text">
<string>50%</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<spacer name="sensorTopSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<spacer name="sensorBottomSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>406</width>
<height>21</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>

View File

@ -7,6 +7,9 @@
#include <QCloseEvent>
#include <QGroupBox>
#include <QSlider>
#include <QTabWidget>
#include <QWidget>
#include <QtDebug>
#include <QtGlobal>
@ -20,16 +23,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
qDebug(ltr("Creating main window"));
m_ui.setupUi(this);
m_manualBrightnessSlider = m_ui.centralWidget->findChild<QGroupBox*>("groupBox")->findChild<QSlider*>("horizontalSlider");
if(m_manualBrightnessSlider) {
connect(m_manualBrightnessSlider, &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;
});
}
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();
@ -201,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;