filewatcher/code/src/mainwindow.cpp
Brian c7914480e0 Got the app hiding in the system tray, though icon isn't working.
When you hit the close button on the window, it hides in the system
tray, or when you hit File>Hide or Ctrl+H while the application has
focus.  I have some testing code in to see why the icon isn't being set,
but still can't figure it out.  The icon is definitely loading, it's
just when I set it to the icon it's no visible.  I'm even not getting
console output saying no icon is being set.
2013-12-23 01:43:10 -07:00

91 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"));
}