代码拉取完成,页面将自动刷新
#include "gugu.h"
#include "ui_gugu.h"
#include <QAction>
#include <QMenu>
#include <QTimer>
#include <QDateTime>
#if _DEBUG
#include <QtDebug>
#endif
gugu::gugu(QWidget *parent) :
QDialog(parent),
ui(new Ui::gugu)
{
ui->setupUi(this);
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint); // remove "?" on dialog window
setWindowIcon(QIcon(":/icon/misaki"));
setWindowTitle("lalala");
start_hr = 900;
end_hr = 1800;
noon_start_hr = 1200;
noon_end_hr = 1400;
skip_noon = true;
week_mode = WEEKDAY;
half_hour = false;
resetDayHr();
createActions();
createTrayIcon();
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(updateTimer()));
timer->start(1000);
menuLastEvents.push_back(QEvent::None);
menuLastEvents.push_back(QEvent::None);
}
gugu::~gugu()
{
delete ui;
}
void gugu::createActions()
{
check_half_hour_action = new QAction(tr("&half-hour gu"), this);
check_half_hour_action->setCheckable(true);
check_half_hour_action->setChecked(half_hour);
connect(check_half_hour_action, &QAction::changed, this, &gugu::half_hour_checked);
}
void gugu::createTrayIcon()
{
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(check_half_hour_action);
trayIconMenu->installEventFilter(this);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setIcon(QIcon(":/icon/misaki"));
trayIcon->show();
}
void gugu::updateTimer()
{
QDateTime now = QDateTime::currentDateTime();
int day = now.date().dayOfWeek();
if(!checkDay(day))
return;
int hhmm = now.toString("hhmm").toInt();
if(checkTime(hhmm))
evokeAlarm();
}
bool gugu::checkDay(int day_of_week)
{
if(today != day_of_week)
resetDayHr();
switch(week_mode) {
case WEEKDAY:
if(day_of_week >=1 && day_of_week <= 5)
return true;
break;
case EVERYDAY:
return true;
}
return false;
}
bool gugu::checkTime(int hhmm)
{
if(today_start_hr > end_hr)
resetDayHr();
if(hhmm > today_start_hr && hhmm <= end_hr) {
if(skip_noon && (hhmm > noon_start_hr && hhmm < noon_end_hr))
return false;
if(hhmm % 100 == 0) {
today_start_hr = hhmm + 1;
return true;
}
else if(half_hour && hhmm % 100 == 30) {
return true;
}
}
return false;
}
void gugu::evokeAlarm()
{
trayIcon->showMessage("gugu",
"gu gu",
QIcon(":/misaki"),
2000);
}
void gugu::half_hour_checked()
{
if(check_half_hour_action->isChecked())
half_hour = true;
else if(!check_half_hour_action->isChecked())
half_hour = false;
}
void gugu::resetDayHr()
{
today = QDate::currentDate().dayOfWeek();
today_start_hr = start_hr;
}
bool gugu::eventFilter(QObject *obj, QEvent *event)
{
if(obj == trayIconMenu) {
menuLastEvents.pop_front();
menuLastEvents.push_back(event->type());
if(menuLastEvents[0] == QEvent::MouseButtonRelease &&
menuLastEvents[1] == QEvent::Close)
return true;
if(event->type() == QEvent::MouseButtonRelease) {
qDebug() << "mouse release";
return true;
}
else if(event->type() == QEvent::Close) {
qDebug() << "close";
return true;
}
}
return false;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。