mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
Minimize to tray if available
This commit is contained in:
parent
c5b5775dd4
commit
8bcf70b5aa
@ -24,10 +24,9 @@ along with TuxClocker. If not, see <https://www.gnu.org/licenses/>.*/
|
|||||||
#include "nvidia.h"
|
#include "nvidia.h"
|
||||||
#include <NVCtrl/NVCtrl.h>
|
#include <NVCtrl/NVCtrl.h>
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent) :
|
MainWindow::MainWindow(QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow)
|
ui(new Ui::MainWindow), trayIcon(new QSystemTrayIcon(this))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -128,6 +127,26 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
|
|
||||||
connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int)));
|
connect(ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(tabHandler(int)));
|
||||||
connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor()));
|
connect(monitorUpdater, SIGNAL(timeout()), SLOT(updateMonitor()));
|
||||||
|
|
||||||
|
/*Create tray icon */
|
||||||
|
{
|
||||||
|
auto appIcon = QIcon(":/icons/gpuonfire.svg");
|
||||||
|
|
||||||
|
if (!QSystemTrayIcon::isSystemTrayAvailable())
|
||||||
|
{
|
||||||
|
#ifdef dbg
|
||||||
|
std::cout << "Qt: System tray unavailable.\n";
|
||||||
|
#endif
|
||||||
|
ignore_closeEvent = false;
|
||||||
|
MainWindow::show();
|
||||||
|
}
|
||||||
|
|
||||||
|
this->trayIcon->setIcon(appIcon);
|
||||||
|
auto menu = this->createMenu();
|
||||||
|
this->trayIcon->setContextMenu(menu);
|
||||||
|
this->trayIcon->setToolTip(QString("TuxClocker"));
|
||||||
|
this->trayIcon->show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
@ -1127,3 +1146,25 @@ void MainWindow::on_GPUComboBox_currentIndexChanged(int index)
|
|||||||
curmaxmemclk->setText(1, QString::number(nv->GPUList[index].maxMemClk) + "MHz");
|
curmaxmemclk->setText(1, QString::number(nv->GPUList[index].maxMemClk) + "MHz");
|
||||||
curmaxclk->setText(1, QString::number(nv->GPUList[index].maxCoreClk) + "MHz");
|
curmaxclk->setText(1, QString::number(nv->GPUList[index].maxCoreClk) + "MHz");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMenu* MainWindow::createMenu()
|
||||||
|
{
|
||||||
|
auto menu = new QMenu(this);
|
||||||
|
|
||||||
|
QAction* show = new QAction("&Open settings", this);
|
||||||
|
connect(show, &QAction::triggered, this, [=]{MainWindow::show();});
|
||||||
|
menu->addAction(show);
|
||||||
|
|
||||||
|
QAction* quit = new QAction("&Quit", this);
|
||||||
|
connect(quit, &QAction::triggered, this, [=]{QApplication::quit();});
|
||||||
|
menu->addAction(quit);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent* e)
|
||||||
|
{
|
||||||
|
MainWindow::hide();
|
||||||
|
if(ignore_closeEvent) e->ignore();
|
||||||
|
}
|
||||||
|
@ -251,6 +251,10 @@ private:
|
|||||||
plotCmds fanspeedplot;
|
plotCmds fanspeedplot;
|
||||||
QVector <plotCmds> plotCmdsList;
|
QVector <plotCmds> plotCmdsList;
|
||||||
|
|
||||||
|
QSystemTrayIcon* trayIcon;
|
||||||
|
QMenu* createMenu();
|
||||||
|
void closeEvent(QCloseEvent *);
|
||||||
|
bool ignore_closeEvent = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
Loading…
Reference in New Issue
Block a user