lanpaper/TrayIco.cpp

57 lines
1.3 KiB
C++
Raw Normal View History

#include "TrayIco.h"
TrayIco::TrayIco(QObject *parent) :
QObject(parent),normalIcon(":/ico/smileico"),flashIcon(":/ico/flashsmileico"),timer(0)
//QObject(parent),normalIcon("c:/bpa/emoticon.ico"),flashIcon("c:/bpa/big_smile.ico"),timer(0)
{
this->trayIco.setIcon(this->normalIcon);
this->trayIco.show();
connect(&this->trayIco,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(activated(QSystemTrayIcon::ActivationReason)) );
}
void TrayIco::activated(QSystemTrayIcon::ActivationReason reason)
{
if(reason==QSystemTrayIcon::Trigger)
{
LanPaper *mainWin=(LanPaper *)this->parent();
this->setFlash(false);
mainWin->showNormal();
mainWin->activateWindow();
}
}
void TrayIco::setFlash(bool flash)
{
if(flash)
{
if(this->timer!=0)
{
return;
}
this->flashFlag=true;
this->timer=this->startTimer(500);
}
else
{
this->trayIco.setIcon(this->normalIcon);
this->killTimer(this->timer);
this->timer=0;
}
}
void TrayIco::timerEvent(QTimerEvent *e)
{
if(this->flashFlag)
{
this->trayIco.setIcon(this->flashIcon);
this->flashFlag=false;
}
else
{
this->trayIco.setIcon(this->normalIcon);
this->flashFlag=true;
}
}