Compare commits
2 Commits
cb9a57a24a
...
69a68ce67c
Author | SHA1 | Date | |
---|---|---|---|
69a68ce67c | |||
afd6de62a0 |
@ -24,60 +24,14 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
|
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
if(!QSystemTrayIcon::isSystemTrayAvailable()) {
|
|
||||||
qWarning(ltr("System tray is not available -> tray icon will be disabled"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug(ltr("System tray is available"));
|
|
||||||
|
|
||||||
m_trayIconMenu = new QMenu(this);
|
|
||||||
m_showHideAction = m_trayIconMenu->addAction(tr("Show"), [this]() {
|
|
||||||
if(m_visibility) {
|
|
||||||
m_showHideAction->setText(tr("Show"));
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_showHideAction->setText(tr("Hide"));
|
|
||||||
show();
|
|
||||||
}
|
|
||||||
m_visibility = !m_visibility;
|
|
||||||
});
|
|
||||||
m_trayIconMenu->addSeparator();
|
|
||||||
m_trayIconMenu->addAction(tr("Quit"), this, &QCoreApplication::quit);
|
|
||||||
|
|
||||||
qDebug(ltr("Tray icon context menu initialized"));
|
|
||||||
|
|
||||||
m_trayIcon = new QSystemTrayIcon(this);
|
|
||||||
m_trayIcon->setIcon(*m_errorIcon);
|
|
||||||
m_trayIcon->setContextMenu(m_trayIconMenu);
|
|
||||||
m_trayIcon->show();
|
|
||||||
m_trayIcon->setToolTip(tr("AdaptiveBrightness"));
|
|
||||||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconClicked);
|
|
||||||
|
|
||||||
qDebug(ltr("Tray icon initialized"));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_timerThread = new QThread(this);
|
|
||||||
m_timer = new QTimer(nullptr);
|
|
||||||
m_timer->setInterval(1000);
|
|
||||||
m_timer->moveToThread(m_timerThread);
|
|
||||||
m_timerThread->connect(m_timer, &QTimer::timeout, this, &MainWindow::updateState, Qt::DirectConnection);
|
|
||||||
m_timer->connect(m_timerThread, SIGNAL(started()), SLOT(start()));
|
|
||||||
m_timerThread->start();
|
|
||||||
|
|
||||||
qDebug(ltr("Tray icon update timer started"));
|
|
||||||
|
|
||||||
m_sensors = enumerateSensors();
|
m_sensors = enumerateSensors();
|
||||||
m_monitors = enumerateMonitors();
|
m_monitors = enumerateMonitors();
|
||||||
|
|
||||||
|
setupMonitorsTab();
|
||||||
|
|
||||||
|
setupTrayIcon();
|
||||||
|
|
||||||
|
setupCallbackTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -131,6 +85,67 @@ void MainWindow::loadIcons()
|
|||||||
qDebug(ltr("Icons loaded"));
|
qDebug(ltr("Icons loaded"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupMonitorsTab()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupTrayIcon()
|
||||||
|
{
|
||||||
|
loadIcons();
|
||||||
|
|
||||||
|
if(!QSystemTrayIcon::isSystemTrayAvailable()) {
|
||||||
|
qWarning(ltr("System tray is not available -> tray icon will be disabled"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug(ltr("System tray is available"));
|
||||||
|
|
||||||
|
m_trayIconMenu = new QMenu(this);
|
||||||
|
m_showHideAction = m_trayIconMenu->addAction(tr("Show"), [this]() {
|
||||||
|
if(m_visibility) {
|
||||||
|
m_showHideAction->setText(tr("Show"));
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
m_showHideAction->setText(tr("Hide"));
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
m_visibility = !m_visibility;
|
||||||
|
});
|
||||||
|
m_trayIconMenu->addSeparator();
|
||||||
|
m_trayIconMenu->addAction(tr("Quit"), this, &QCoreApplication::quit);
|
||||||
|
|
||||||
|
qDebug(ltr("Tray icon context menu initialized"));
|
||||||
|
|
||||||
|
m_trayIcon = new QSystemTrayIcon(this);
|
||||||
|
m_trayIcon->setIcon(*m_errorIcon);
|
||||||
|
m_trayIcon->setContextMenu(m_trayIconMenu);
|
||||||
|
m_trayIcon->show();
|
||||||
|
m_trayIcon->setToolTip(tr("AdaptiveBrightness"));
|
||||||
|
connect(m_trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconClicked);
|
||||||
|
|
||||||
|
qDebug(ltr("Tray icon initialized"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupCallbackTimer()
|
||||||
|
{
|
||||||
|
m_timerThread = new QThread(this);
|
||||||
|
m_timer = new QTimer(nullptr);
|
||||||
|
m_timer->setInterval(1000);
|
||||||
|
m_timer->moveToThread(m_timerThread);
|
||||||
|
m_timerThread->connect(m_timer, &QTimer::timeout, this, &MainWindow::updateState, Qt::DirectConnection);
|
||||||
|
m_timer->connect(m_timerThread, SIGNAL(started()), SLOT(start()));
|
||||||
|
m_timerThread->start();
|
||||||
|
|
||||||
|
qDebug(ltr("Callback timer started"));
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::updateState()
|
void MainWindow::updateState()
|
||||||
{
|
{
|
||||||
qDebug(ltr("Updating state"));
|
qDebug(ltr("Updating state"));
|
||||||
|
@ -30,6 +30,10 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
void loadIcons();
|
void loadIcons();
|
||||||
|
|
||||||
|
void setupMonitorsTab();
|
||||||
|
void setupTrayIcon();
|
||||||
|
void setupCallbackTimer();
|
||||||
|
|
||||||
void updateState();
|
void updateState();
|
||||||
|
|
||||||
void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
|
void trayIconClicked(QSystemTrayIcon::ActivationReason reason);
|
||||||
|
Loading…
Reference in New Issue
Block a user