Compare commits
2 Commits
d1d2d4ae0a
...
eb18ab9f1e
Author | SHA1 | Date | |
---|---|---|---|
eb18ab9f1e | |||
2253a25011 |
@ -5,6 +5,7 @@
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QGroupBox>
|
||||
#include <QSlider>
|
||||
#include <QtDebug>
|
||||
@ -52,7 +53,7 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
m_visibility = !m_visibility;
|
||||
});
|
||||
m_trayIconMenu->addSeparator();
|
||||
m_trayIconMenu->addAction(tr("Quit"), this, &QWidget::close);
|
||||
m_trayIconMenu->addAction(tr("Quit"), this, &QCoreApplication::quit);
|
||||
|
||||
qDebug(ltr("Tray icon context menu initialized"));
|
||||
|
||||
@ -64,9 +65,13 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
qDebug(ltr("Tray icon initialized"));
|
||||
}
|
||||
|
||||
m_timer = new QTimer(this);
|
||||
connect(m_timer, &QTimer::timeout, this, &MainWindow::updateState);
|
||||
m_timer->start(1000);
|
||||
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"));
|
||||
|
||||
@ -77,6 +82,17 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
qDebug(ltr("Destroying main window"));
|
||||
|
||||
m_timerThread->quit();
|
||||
if(!m_timerThread->wait()) {
|
||||
qCritical(ltr("Timer thread did not terminate cleanly"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent* event)
|
||||
{
|
||||
m_showHideAction->activate(QAction::Trigger);
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
void MainWindow::loadIcons()
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <QMainWindow>
|
||||
#include <QMenu>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QThread>
|
||||
#include <QTimer>
|
||||
|
||||
#include "monitor.hpp"
|
||||
@ -24,6 +25,8 @@ class MainWindow : public QMainWindow {
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
void closeEvent(QCloseEvent* event) override;
|
||||
|
||||
void loadIcons();
|
||||
|
||||
void updateState();
|
||||
@ -39,6 +42,7 @@ class MainWindow : public QMainWindow {
|
||||
QMenu* m_trayIconMenu = nullptr;
|
||||
QSystemTrayIcon* m_trayIcon = nullptr;
|
||||
|
||||
QThread* m_timerThread = nullptr;
|
||||
QTimer* m_timer = nullptr;
|
||||
|
||||
float m_brightness = 0.5f;
|
||||
|
Loading…
Reference in New Issue
Block a user