FileWatcher/code/src/mainwindow.cpp

92 lines
2.3 KiB
C++

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QCloseEvent>
#include <QResource>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//QResource::registerResource("res.qrc");
ui->setupUi(this);
m_pActiveIcon = new QPixmap(":/images/res/stock_3d-texture-and-shading_16x16.png");
m_pInactiveIcon = new QPixmap(":/images/res/stock_3d-texture-spherical_16x16.png");
const bool activeNotNull = QIcon(":/images/res/stock_3d-texture-and-shading_16x16.png").isNull();
const bool inactiveNotNull = QIcon(":/images/res/stock_3d-texture-spherical_16x16.png").isNull();
m_pExitAction = new QAction(tr("&Exit"), this);
connect(m_pExitAction, SIGNAL(triggered()), this, SLOT(exit()));
m_pTrayIconMenu = new QMenu(this);
m_pTrayIconMenu->addAction(m_pExitAction);
m_pTrayIcon = new QSystemTrayIcon(this);
m_pTrayIcon->setContextMenu(m_pTrayIconMenu);
m_pTrayIcon->setIcon(QIcon(":/images/res/stock_3d-texture-and-shading_16x16.png"));
m_pTrayIcon->show();
connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save()));
connect(ui->actionHide, SIGNAL(triggered()), this, SLOT(hide()));
connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(exit()));
connect(
m_pTrayIcon,
SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,
SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
}
MainWindow::~MainWindow()
{
delete m_pInactiveIcon;
delete m_pActiveIcon;
delete m_pExitAction;
delete m_pTrayIcon;
delete m_pTrayIconMenu;
delete ui;
}
void MainWindow::save()
{
}
void MainWindow::exit()
{
qApp->exit();
}
void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch(reason){
case QSystemTrayIcon::Trigger:
break;
case QSystemTrayIcon::DoubleClick:
if (this->isHidden())
{
this->show();
}
break;
}
}
void MainWindow::closeEvent(QCloseEvent* event)
{
event->ignore();
hide();
}
void MainWindow::hideEvent(QHideEvent* event)
{
m_pTrayIcon->setIcon(QIcon(":/images/res/stock_3d-texture-spherical_16x16.png"));
}
void MainWindow::showEvent(QShowEvent* event)
{
m_pTrayIcon->setIcon(QIcon(":/images/res/stock_3d-texture-and-shading_16x16.png"));
}