3675 lines
126 KiB
C++
3675 lines
126 KiB
C++
/*
|
||
* Copyright (C) 2019 Tianjin KYLIN Information Technology Co., Ltd.
|
||
*
|
||
* This program is free software; you can redistribute it and/or modify
|
||
* it under the terms of the GNU General Public License as published by
|
||
* the Free Software Foundation; either version 3, or (at your option)
|
||
* any later version.
|
||
*
|
||
* This program is distributed in the hope that it will be useful,
|
||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
* GNU General Public License for more details.
|
||
*
|
||
* You should have received a copy of the GNU General Public License
|
||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||
*
|
||
*/
|
||
#include "clock.h"
|
||
#include "ui_clock.h"
|
||
#include <QMessageBox>
|
||
#include "fieldvalidutil.h"
|
||
#include <QThread>
|
||
#include "mediaplayerpool.h"
|
||
#include <QLibraryInfo>
|
||
#include "coreplayer/playcontroller.h"
|
||
|
||
using std::string;
|
||
using clockInterface::ReturnMsg;
|
||
using clockInterface::STATUS_CODE;
|
||
|
||
|
||
extern void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed);
|
||
const double PI=3.141592;
|
||
|
||
|
||
#define SWITCH_BTN_HIGHLIGHT_BACK_COLOR 61,107,229,255
|
||
|
||
const static int DIALOG_MOVE_WIDTH = 16;
|
||
const static int DIALOG_WIDTH = 340;
|
||
|
||
Clock::Clock(QWidget *parent) :
|
||
QWidget(parent),
|
||
ui(new Ui::Clock)
|
||
{
|
||
//异步初始化
|
||
// MediaPlayerPool::getInstance();
|
||
music = new QMediaPlayer();
|
||
//右键菜单,选择”create new translation file“;项目中会添加一个以”.ts“为后缀的文件,例如”testtranslator_zh.ts“;
|
||
//使用Qt Linguist打开该文件,就可以为指定的字符串设置译文;
|
||
//在相应的“.ts”文件的右键菜单中点击“lupdate”项,才会更新。
|
||
//翻译完成后,点击”文件“菜单下的”发布“项,就会生成.qm文件;
|
||
QTranslator *translator = new QTranslator;
|
||
// Get system locale
|
||
//切换英文
|
||
QLocale en_us = QLocale("en_US");
|
||
QLocale current = QLocale();
|
||
if (translator->load(current, QLatin1String("ukui-clock"), QLatin1String("_"), QLatin1String("/usr/share/ukui-clock/ukui31"))){
|
||
QApplication::installTranslator(translator);
|
||
}
|
||
else{
|
||
qDebug() << "cannot load translator ukui-clock_" << QLocale::system().name() << ".qm!";
|
||
}
|
||
//加载Qt翻译
|
||
|
||
QTranslator * qtTranslator = new QTranslator;
|
||
QString translationsPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
|
||
if(qtTranslator->load(QLocale(), QStringLiteral("qt"), QLatin1String("_"), translationsPath)){
|
||
QApplication::installTranslator(qtTranslator);
|
||
}else{
|
||
qDebug()<<"dbq- cannot load qt"<< QLocale::system().name() << ".qm!";
|
||
}
|
||
|
||
//ui 构造代码
|
||
ui->setupUi(this);
|
||
currentTheme = new theme();
|
||
//创建或打开数据库
|
||
clock_sql::createConnection();
|
||
//in order to use the same world in English
|
||
this->setWindowTitle(tr(CLOCK_TITLE_NAME));
|
||
ui->clockTitleLabel->setText(tr(CLOCK_TITLE_NAME));
|
||
|
||
//创建用户手册dbus客户端
|
||
createUserGuideDebusClient();
|
||
mousePressed = 0;
|
||
//设置数据库
|
||
model_setup = clock_sql::getSetupTable(this);
|
||
model_setup->select();
|
||
//创建数据库
|
||
m_bellQueryModel = clock_sql::getBellTable(this);
|
||
bellIni();
|
||
//闹钟按钮图片初始化
|
||
buttonImageInit();
|
||
//倒计时 运行光圈页初始化
|
||
CountdownInit();
|
||
//秒表初始化
|
||
stopwatchInit();
|
||
//闹钟页初始化
|
||
clockInit();
|
||
setupInit();
|
||
this->setFixedSize(390,580);
|
||
/*实现鼠标左键滑动效果
|
||
*Realize the sliding effect of left mouse button*/
|
||
ui->alarmListWidget -> setFrameShape(QListWidget::NoFrame);
|
||
ui->timeListWidget -> setFrameShape(QListWidget::NoFrame);
|
||
QScroller::grabGesture(ui->alarmListWidget,QScroller::LeftMouseButtonGesture); /*设置鼠标左键拖动 Set left mouse drag*/
|
||
QScroller::grabGesture(ui->timeListWidget,QScroller::LeftMouseButtonGesture); /*设置鼠标左键拖动 Set left mouse drag*/
|
||
ui->alarmListWidget -> setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); /*设置像素级滑动 Set pixel level slide*/
|
||
ui->timeListWidget -> setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); /*设置像素级滑动 Set pixel level slide*/
|
||
ui->alarmListWidget->setProperty("contextMenuPolicy", Qt::CustomContextMenu); /*重要:设置QListWidget的contextMenuPolicy属性,不然不能显示右键菜单*/
|
||
ui->alarmListWidget ->setGridSize(QSize(340, 108+15));
|
||
ui->timeListWidget ->setGridSize(QSize(340, 58+10));
|
||
//主屏信息
|
||
primaryManager = new PrimaryManager();
|
||
//闹钟居中
|
||
//move((m_pSreenInfo->m_screenWidth - this->width() + m_pSreenInfo->m_nScreen_x )/2, (m_pSreenInfo->m_screenHeight - this->height())/2);
|
||
utils = new Utils();
|
||
utils->centerToScreen(this);
|
||
ui->switchClock->setFixedSize(40,40);
|
||
navigationBtnStyle(ui->switchClock);
|
||
ui->switchClock->setToolTip(tr(CLOCK_TITLE_NAME));
|
||
ui->switchCountdown->setFixedSize(40,40);
|
||
navigationBtnStyle(ui->switchCountdown);
|
||
ui->switchCountdown->setToolTip(tr("Count down"));
|
||
|
||
ui->switchStopwatch->setFixedSize(40,40);
|
||
navigationBtnStyle(ui->switchStopwatch);
|
||
ui->switchStopwatch->setToolTip(tr("Watch"));
|
||
|
||
connect(ui->switchCountdown, SIGNAL(clicked()), this, SLOT( CountdownPageSwitch ()));
|
||
connect(ui->switchClock, SIGNAL(clicked()), this, SLOT( AlarmPageSwitch ()));
|
||
connect(ui->switchStopwatch, SIGNAL(clicked()), this, SLOT( StopwatchPageSwitch ()));
|
||
|
||
AlarmPageSwitch ();/*初始显示闹钟界面
|
||
Initial display alarm interface*/
|
||
|
||
close_or_hide_page = new close_or_hide(this);
|
||
|
||
shadow->installEventFilter(this);
|
||
ui->alarmListWidget->installEventFilter(this);
|
||
//蓝色
|
||
QPalette palette = ui->suspendCountdownBtn->palette();
|
||
QColor ColorPlaceholderText(248,163,76,255);
|
||
QBrush brush3;
|
||
brush3.setColor(ColorPlaceholderText);
|
||
//主题框架1.0.6-5kylin2
|
||
palette.setColor(QPalette::Highlight,QColor(248,163,76,255));
|
||
palette.setColor(QPalette::Button,QColor(248,163,76,255));
|
||
palette.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
ui->suspendCountdownBtn->setPalette(palette);
|
||
startCountSingle->setEnabled(false);
|
||
ui->countdownStackedW->setCurrentIndex(0);
|
||
drawNoAlarmPrompt();//绘制无闹钟提示图标
|
||
onMin_5btnClicked();//倒计时初始时间默认五分钟
|
||
//字体设置
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(38);
|
||
ui->timeShowBig->setFont(f);
|
||
//监听主题
|
||
settingsStyle();
|
||
//主题框架1.0.6-5kylin2
|
||
//配置重要按钮
|
||
|
||
//添加
|
||
ui->addAlarmBtn->setProperty("isImportant", true);
|
||
//新建闹钟保存
|
||
ui->saveBtnOnEditAlarm->setProperty("isImportant", true);
|
||
//倒计时 滚轮页设置页,开始
|
||
startCountSingle->setProperty("isImportant", true);
|
||
//倒计时,运行页,开始结束
|
||
// ui->count_stat->setProperty("isImportant", true);
|
||
//秒表 开始结束
|
||
ui->startStopwatch->setProperty("isImportant", true);
|
||
// 倒计时 暂停继续
|
||
ui->suspendCountdownBtn->setProperty("isImportant", true);
|
||
//倒计时 开始结束
|
||
ui->startCountdownBtn->setProperty("useButtonPalette", true);
|
||
//闹钟编辑 取消
|
||
ui->cancelbtnOnEditAlarm->setProperty("useButtonPalette", true);
|
||
//秒表 计次
|
||
ui->ringBtn->setProperty("useButtonPalette", true);
|
||
//迷你窗口
|
||
updateTinyBtn();
|
||
//倒计时上的小闹钟
|
||
// ui->countdownAlarmIcon->setProperty("useButtonPalette", true);
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
Clock::~Clock()
|
||
{
|
||
delete timer;
|
||
delete timer_2;
|
||
delete countdown_timer;
|
||
delete model;
|
||
delete model_setup;
|
||
delete dialog_repeat;
|
||
delete dialog_music;
|
||
delete count_music_sellect;
|
||
delete ui->countdownRunPage;
|
||
delete ui;
|
||
delete utils;
|
||
delete primaryManager;
|
||
delete alarmNoticeDialog;
|
||
delete countdownNoticeDialog;
|
||
delete tinycountdownDia;
|
||
delete currentTheme;
|
||
}
|
||
//重写关闭事件
|
||
void Clock::closeEvent(QCloseEvent *event)
|
||
{
|
||
closeHandel();
|
||
|
||
if(close_or_hide_page->close_flag==1){
|
||
event->ignore();
|
||
setWindowState(Qt::WindowMinimized);
|
||
close_or_hide_page->close_flag = 0;
|
||
}else if(close_or_hide_page->close_flag==2){
|
||
event->accept();
|
||
exit(0);
|
||
}else{
|
||
event->ignore();
|
||
}
|
||
}
|
||
void Clock::closeHandel()
|
||
{
|
||
QPointF position = this->pos();
|
||
XAtomHelper::setStandardWindowHint(close_or_hide_page->winId());
|
||
close_or_hide_page->move(position.x()+20,position.y()+200);
|
||
close_or_hide_page->exec();
|
||
}
|
||
|
||
void Clock::enableTrayIcon()
|
||
{
|
||
if (m_trayIcon) {
|
||
return;
|
||
}
|
||
QAction *quitAction = new QAction(tr("Quit"), this);
|
||
connect(quitAction, &QAction::triggered, qApp,
|
||
&QCoreApplication::quit);
|
||
QMenu *trayIconMenu = new QMenu();
|
||
trayIconMenu->addAction(quitAction);
|
||
m_trayIcon = new QSystemTrayIcon();
|
||
setDefaultTrayIconTooltip();
|
||
m_trayIcon->setContextMenu(trayIconMenu);
|
||
QIcon trayicon = QIcon::fromTheme("kylin-alarm-clock");
|
||
m_trayIcon->setIcon(trayicon);
|
||
connect(m_trayIcon, &QSystemTrayIcon::activated, this, [=](QSystemTrayIcon::ActivationReason r){
|
||
if (r == QSystemTrayIcon::Trigger) {
|
||
this->show();
|
||
}
|
||
});
|
||
m_trayIcon->show();
|
||
}
|
||
void Clock::updateTrayIconTooltip(QString info)
|
||
{
|
||
if (m_trayIcon) {
|
||
m_trayIcon->setToolTip(info);
|
||
}
|
||
}
|
||
|
||
void Clock::setDefaultTrayIconTooltip()
|
||
{
|
||
if (m_trayIcon) {
|
||
if(m_trayIconTooltip!=""){
|
||
m_trayIcon->setToolTip(m_trayIconTooltip);
|
||
}else{
|
||
m_trayIcon->setToolTip(tr(CLOCK_TITLE_NAME));
|
||
}
|
||
}
|
||
}
|
||
void Clock::disableTrayIcon()
|
||
{
|
||
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
|
||
if (m_trayIcon) {
|
||
m_trayIcon->deleteLater();
|
||
}
|
||
#endif
|
||
}
|
||
/*
|
||
*监听主题
|
||
*/
|
||
void Clock::settingsStyle()
|
||
{
|
||
|
||
GsettingSubject * subject = GsettingSubject::getInstance();
|
||
connect(subject,&GsettingSubject::blackStyle, this,[=](){
|
||
this->blackStyle();
|
||
});
|
||
connect(subject,&GsettingSubject::whiteStyle, this,[=](){
|
||
this->whiteStyle();
|
||
});
|
||
connect(subject,&GsettingSubject::iconChnaged, this,[=](){
|
||
ui->titleIcon->setPixmap(QIcon::fromTheme("kylin-alarm-clock").pixmap(24,24));
|
||
});
|
||
|
||
|
||
connect(subject,&GsettingSubject::timeZoneChanged, this,[=](QString timeZone){
|
||
this->m_timeZone =timeZone;
|
||
});
|
||
|
||
connect(subject,&GsettingSubject::fontChanged, this,[=](int size){
|
||
this->CURRENT_FONT_SIZE=size;
|
||
this->updateFront(size);
|
||
});
|
||
|
||
subject->iniWidgetStyle();
|
||
subject->iniFontSize();
|
||
subject->iniTimeZone();
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 闹钟按钮图片初始化 Alarm button picture initialization
|
||
*/
|
||
void Clock::buttonImageInit()
|
||
{
|
||
pixmap4 = QPixmap(":/image/icon-4-16x16.png");
|
||
//“重复”下拉框对号勾选
|
||
repeat_on_Pixmap = QPixmap(":/image/object-select-symbolic.png");
|
||
repeat_off_Pixmap = QPixmap("");
|
||
//启用主题框架不需要代码
|
||
// this->setWindowIcon(QIcon::fromTheme("kylin-alarm-clock",QIcon(":/image/kylin-alarm-clock.svg")));
|
||
//左上角闹钟图标
|
||
ui->titleIcon->setPixmap(QIcon::fromTheme("kylin-alarm-clock").pixmap(24,24));
|
||
//倒计时上的小闹钟图标
|
||
ui->countdownAlarmIcon->setPixmap(pixmap4);
|
||
ui->countdownAlarmIcon->setVisible(true);
|
||
ui->countdownAlarmIcon->setFocusPolicy(Qt::NoFocus);
|
||
|
||
muteBtnStyle();
|
||
minBtnStyle();
|
||
menuBtnStyle();
|
||
closeBtnStyle();
|
||
|
||
|
||
|
||
|
||
//提醒铃声 倒计时设置页
|
||
musicSelectOnCountdownSet = new Btn_new(0, tr(" bell"),Btn_new::SELECT_BTN, ui->countdownSetPage);
|
||
//提醒铃声 倒计时页面运行页
|
||
musicSelectOnCountdownRun = new Btn_new( 0,tr(" bell"),Btn_new::SELECT_BTN, ui->countdownRunPage);
|
||
int moveHeight = 310;
|
||
int moveWidth = DIALOG_MOVE_WIDTH;
|
||
updateCountdownSelectBtnStyle(musicSelectOnCountdownSet,moveWidth,moveHeight);
|
||
updateCountdownSelectBtnStyle(musicSelectOnCountdownRun,moveWidth,moveHeight);
|
||
//闹钟名称 新建闹钟
|
||
clockEditOnClockNew = new Btn_new( 0,tr(" name"),Btn_new::LINE_EDIT, ui->editAlarmPage);
|
||
updateCountdownSelectBtnStyle(clockEditOnClockNew,moveWidth,180);
|
||
//重复 新建闹钟
|
||
int selectHeight = 240;
|
||
int selectGap = 60;
|
||
repeatSelectOnClockNew = new Btn_new( 0,tr(" repeat"),Btn_new::SELECT_BTN, ui->addAlarmPage);
|
||
updateClockSelectBtnStyle(repeatSelectOnClockNew,selectHeight);
|
||
selectHeight+=selectGap;
|
||
//提醒铃声 新建闹钟
|
||
musicSelectOnClockNew = new Btn_new( 0,tr(" bell"),Btn_new::SELECT_BTN, ui->addAlarmPage);
|
||
updateClockSelectBtnStyle(musicSelectOnClockNew,selectHeight);
|
||
selectHeight+=selectGap;
|
||
//稍后提醒 新建闹钟
|
||
remindSelectOnClockNew = new Btn_new( 0,tr(" remind"),Btn_new::SELECT_BTN, ui->addAlarmPage);
|
||
updateClockSelectBtnStyle(remindSelectOnClockNew,selectHeight);
|
||
|
||
}
|
||
/*
|
||
*倒计时页初始化
|
||
*Countdown page initialization
|
||
*/
|
||
void Clock::CountdownInit()
|
||
{
|
||
/*初始化定时器
|
||
Initialize timer*/
|
||
countdown_timer = new QTimer();
|
||
/*信号和槽
|
||
Signals and slots*/
|
||
//倒计时开始-结束
|
||
connect(ui->startCountdownBtn, SIGNAL(clicked()), this, SLOT(startbtnCountdown()) );
|
||
// connect(tinycountdownDia, SIGNAL(finishClick()), this, SLOT(tinyCountdownFinish()) );
|
||
//倒计时执行
|
||
connect(countdown_timer, SIGNAL(timeout()), this, SLOT(statCountdownMsec()));
|
||
/*设置定时器每个多少毫秒发送一个timeout()信号
|
||
Set the timer to send a timeout () signal every milliseconds*/
|
||
countdown_timer->setInterval(10);
|
||
countdown_hour = 0;
|
||
countdown_minute = 0;
|
||
countdown_second = 9;
|
||
countdown_pushflag = 0;
|
||
|
||
countdown_isStarted = 0;
|
||
countdown_isStarted_2 = 0;
|
||
ui->countdownRunPage->countdownRunRoundBar->setRange(0,COUNTDOWN_TIME);
|
||
/*初始化倒计时进度圈
|
||
Initialize countdown progress circle*/
|
||
ui->countdownRunPage->countdownRunRoundBar->setValue(COUNTDOWN_TIME);
|
||
//父的顶部
|
||
ui->startCountdownBtn->raise();
|
||
//初始化倒计时弹窗
|
||
countdownNoticeDialog = new Natice_alarm(60,-1);
|
||
countdownNoticeDialog->timer->stop();
|
||
countdownNoticeDialog->timer_xumhuan->stop();
|
||
countdownNoticeDialog->m_musicPlayer->stop();
|
||
//小型窗体
|
||
if(tinycountdownDia==nullptr){
|
||
tinycountdownDia = new tinyCountdown();
|
||
}
|
||
//绑定主窗体操作
|
||
connect(tinycountdownDia,SIGNAL(mainWindowClick()),this,SLOT(activeWindow()));
|
||
//结束
|
||
connect(tinycountdownDia, &tinyCountdown::finishClick, this, [=](){
|
||
tinyCountdownFinish();
|
||
} );
|
||
//暂停
|
||
connect(tinycountdownDia, &tinyCountdown::suspendClick, this, [=](int onRun){
|
||
countdown_isStarted_2 = onRun;
|
||
onCountPushClicked();
|
||
} );
|
||
}
|
||
|
||
/*
|
||
*秒表页初始化
|
||
*Stopwatch page initialization
|
||
*/
|
||
void Clock::stopwatchInit()
|
||
{
|
||
/*初始化定时器
|
||
Initialize timer*/
|
||
timer = new QTimer();
|
||
/*信号和槽
|
||
Signals and slots*/
|
||
connect(timer, SIGNAL(timeout()), this, SLOT(CountDown()));
|
||
/*设置定时器每个多少毫秒发送一个timeout()信号
|
||
Set the timer to send a timeout () signal every milliseconds*/
|
||
timer->setInterval(10);
|
||
//显示时间大
|
||
ui->timeShowBig->setText("00:00.00");
|
||
//显示时间小
|
||
ui->timeShowSmall->setText("00:00.00");
|
||
isStarted = 0;
|
||
hour=0;
|
||
minute=0;
|
||
second=0;
|
||
pushflag=0 ;
|
||
/*时间间隔定时器
|
||
Time interval timer*/
|
||
timer_2 = new QTimer();
|
||
//秒表的 每次计次后清零重新计算的时间
|
||
connect(timer_2, SIGNAL(timeout()), this, SLOT(stopwatchJg()));
|
||
timer_2->setInterval(10);
|
||
stopwatch_hour = 0;
|
||
stopwatch_minute = 0;
|
||
stopwatch_second = 0;
|
||
stopwatch_isStarted = 0;
|
||
|
||
ui->timeShowBig->move(90,125);
|
||
ui->timeShowSmall->move(90,190);
|
||
ui->timeListWidget->move(25,230);
|
||
ui->startStopwatch->raise();
|
||
ui->ringBtn->raise();
|
||
//计次间隔时间最长,最短
|
||
timeSepOrderIndex = new QMap<long,int>();
|
||
hisLongShortIndex = new QList<int>();
|
||
}
|
||
|
||
/*
|
||
*闹钟页初始化
|
||
*Alarm page initialization
|
||
*/
|
||
void Clock::clockInit()
|
||
{
|
||
// alarmNoticeDialog = new Natice_alarm(60,-1);
|
||
QTimer *timer_clock = new QTimer(this);
|
||
//动态监控闹钟与本地时间
|
||
connect(timer_clock, SIGNAL(timeout()), this, SLOT(timerUpdate()) );/*动态获取时间
|
||
Dynamic acquisition time*/
|
||
timer_clock->start(1000);
|
||
connect( ui->addAlarmBtn, SIGNAL(clicked()), this, SLOT(setAlarmClock()) );/*添加闹钟
|
||
Add alarm*/
|
||
ui->timeShowBig->setAlignment(Qt::AlignHCenter);
|
||
ui->timeShowSmall->setAlignment(Qt::AlignHCenter);
|
||
ui->remainTime->setAlignment(Qt::AlignHCenter);
|
||
//单个表读取和写入数据库记录的高级接口
|
||
model = new QSqlTableModel(this);
|
||
model->setTable("clock");
|
||
model->setEditStrategy(QSqlTableModel::OnManualSubmit);
|
||
model->select(); /*选取整个表的所有行
|
||
Select all rows of the entire table*/
|
||
/*初始化一个包含两个Action(Delete和ClearAll)的菜单*/
|
||
popMenu_In_ListWidget_ = new QMenu(this);
|
||
action_Delete_In_ListWidget_ = new QAction(tr("Delete"), this);
|
||
action_Clear_In_ListWidget_ = new QAction(tr("ClearAll"), this);
|
||
action_edit_In_ListWidget_ = new QAction(tr("edit"), this);
|
||
popMenu_In_ListWidget_->addAction(action_edit_In_ListWidget_);
|
||
popMenu_In_ListWidget_->addAction(action_Delete_In_ListWidget_);
|
||
|
||
connect(this->action_Delete_In_ListWidget_, SIGNAL(triggered()), this, SLOT(deleteAlarm()));
|
||
//编辑
|
||
connect(this->action_edit_In_ListWidget_, SIGNAL(triggered()), this, SLOT(listdoubleClickslot()));
|
||
connect(ui->alarmListWidget,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(listdoubleClickslot()));
|
||
connect(ui->saveBtnOnEditAlarm, SIGNAL(clicked()), this, SLOT(setAlarmSave()) );
|
||
connect(ui->startStopwatch, SIGNAL(clicked()), this, SLOT(onPushbuttonStartClicked()));
|
||
connect(ui->ringBtn, SIGNAL(clicked()), this, SLOT(onPushbuttonRingClicked()));
|
||
connect(ui->cancelbtnOnEditAlarm, SIGNAL(clicked()), this, SLOT(alarmCancelSave()) );
|
||
//与下拉框绑定
|
||
connect(repeatSelectOnClockNew, SIGNAL(clicked()), this, SLOT(alarmRepeat()) );
|
||
connect(musicSelectOnClockNew, SIGNAL(clicked()), this, SLOT(selectAlarmMusic()) );
|
||
connect(remindSelectOnClockNew, SIGNAL(clicked()), this, SLOT(selectRemindLate()) );
|
||
connect(musicSelectOnCountdownSet, SIGNAL(clicked()), this, SLOT(countdownMusicSellect()));
|
||
connect(musicSelectOnCountdownRun, SIGNAL(clicked()), this, SLOT(countdownMusicSellect()));
|
||
|
||
|
||
//暂停继续按钮
|
||
connect(ui->suspendCountdownBtn, SIGNAL(clicked()), this, SLOT(onCountPushClicked()));
|
||
|
||
|
||
connect(ui->tinyWindowBtn, SIGNAL(clicked()), this, SLOT(onTinyClicked()));
|
||
/*绑定右键显示菜单:在单击右键之后会执行槽函数, 槽函数中负责弹出右键菜单*/
|
||
connect(ui->alarmListWidget, SIGNAL(customContextMenuRequested(const QPoint &)),
|
||
this, SLOT(onCustomContextMenuRequested(const QPoint &)));
|
||
|
||
//初始化SystemTimeFlag,不然初始值可能不为0或者1
|
||
iniSystemTimeFlag();
|
||
//绘制闹钟列表
|
||
updateAlarmClock();
|
||
|
||
}
|
||
|
||
void Clock::keyPressEvent(QKeyEvent *event)
|
||
{
|
||
if(16777264==event->key()){
|
||
callUserGuide();
|
||
}
|
||
|
||
}
|
||
|
||
void Clock::callUserGuide()
|
||
{
|
||
if(userGuideInterface!=nullptr){
|
||
userGuideInterface->call(QString("showGuide"), "ukui-clock");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
* 事件处理函数
|
||
*/
|
||
void Clock::onCustomContextMenuRequested(const QPoint &pos)
|
||
{
|
||
/*弹出右键菜单*/
|
||
if(ui->alarmListWidget->itemAt(pos)!=NULL){
|
||
//右键弹窗与闹钟绑定
|
||
popMenu_In_ListWidget_->exec(QCursor::pos());
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 默认初始设置
|
||
* Default initial settings
|
||
*/
|
||
void Clock::setupInit()
|
||
{
|
||
countdownSetStartTime();/*倒计时初始化数字转盘
|
||
Countdown initialization digital turntable*/
|
||
|
||
alarmSetStartTime();/*闹钟初始化数字转盘
|
||
Alarm initialization digital turntable*/
|
||
modelSetupSet(); /*设置数据库初始化
|
||
Set database initialization*/
|
||
textTimerupdate();
|
||
clockEditOnClockNew->clockNameLineEdit->setMaxLength(16);/*限制闹钟名字长度为9个字符*/
|
||
|
||
/*设置输入框无视空格,过滤特殊字符*/
|
||
QRegExp rx = QRegExp("^[\u4E00-\u9FA5A-Za-z0-9_]+$");
|
||
QRegExpValidator* validator = new QRegExpValidator(rx);
|
||
clockEditOnClockNew->clockNameLineEdit->setValidator(validator);
|
||
|
||
//倒计时的铃声
|
||
QString bellId = model_setup->index(0, 1).data().toString();
|
||
QString bellName = m_selectBtnUtil->getBellNameById(bellId);
|
||
musicSelectOnCountdownSet->textLabel->setText(bellName);
|
||
musicSelectOnCountdownRun->textLabel->setText(bellName);
|
||
|
||
//重复下拉框
|
||
int moreWidth = 20;
|
||
dialog_repeat = new set_alarm_repeat_Dialog(DIALOG_WIDTH+moreWidth,290,9,ui->editAlarmPage);dialog_repeat->hide();
|
||
//铃声下拉框
|
||
int bellSize = m_selectBtnUtil->getBellListSize();
|
||
dialog_music = new set_alarm_repeat_Dialog(DIALOG_WIDTH+moreWidth,172,bellSize,ui->editAlarmPage);dialog_music->hide();
|
||
//稍后提醒下拉框
|
||
dialog_remind_late = new set_alarm_repeat_Dialog(DIALOG_WIDTH+moreWidth,258,6,ui->editAlarmPage);dialog_remind_late->hide();
|
||
//倒计时铃声选择
|
||
count_music_sellect = new set_alarm_repeat_Dialog(DIALOG_WIDTH+moreWidth,172,bellSize,ui->countdownPage);count_music_sellect->hide();
|
||
|
||
setMusicSelectDialogListById(bellId,count_music_sellect->listWidget);
|
||
//存储重复选择的星期,默认清零
|
||
for (int i = 0; i < 9; i++) {
|
||
repeat_day[i] = 0;
|
||
}
|
||
|
||
|
||
connect(dialog_repeat->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(repeatListclickslot()));
|
||
connect(dialog_music->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(musicListclickslot()));
|
||
connect(dialog_remind_late->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(remindLateListClickSlot()));
|
||
connect(count_music_sellect->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(countMusicListclickslot()));
|
||
connect(dialog_repeat,&set_alarm_repeat_Dialog::dialogClose,this,[=](){
|
||
repeatSelectOnClockNew->updateIconLabel(0);
|
||
});
|
||
connect(dialog_music,&set_alarm_repeat_Dialog::dialogClose,this,[=](){
|
||
musicSelectOnClockNew->updateIconLabel(0);
|
||
});
|
||
connect(dialog_remind_late,&set_alarm_repeat_Dialog::dialogClose,this,[=](){
|
||
remindSelectOnClockNew->updateIconLabel(0);
|
||
});
|
||
connect(count_music_sellect,&set_alarm_repeat_Dialog::dialogClose,this,[=](){
|
||
musicSelectOnCountdownSet->updateIconLabel(0);
|
||
musicSelectOnCountdownRun->updateIconLabel(0);
|
||
});
|
||
indexWeekdayMap = new QHash<int,QString>();
|
||
indexWeekdayMap->insert(0,":monday");
|
||
indexWeekdayMap->insert(1,":tuesday");
|
||
indexWeekdayMap->insert(2,":wednesday");
|
||
indexWeekdayMap->insert(3,":thusday");
|
||
indexWeekdayMap->insert(4,":friday");
|
||
indexWeekdayMap->insert(5,":saturday");
|
||
indexWeekdayMap->insert(6,":sunday");
|
||
}
|
||
|
||
void Clock::bellIni()
|
||
{
|
||
m_selectBtnUtil = new SelectBtnUtil();
|
||
int rowNum = m_bellQueryModel->rowCount();
|
||
if (rowNum < 1) {
|
||
QList<QString> * defaultBell = SelectBtnUtil::getDefaultBellList();
|
||
QList<QString> * defaultBellTr = SelectBtnUtil::getDefaultBellTrList();
|
||
for (int i=0;i<defaultBell->size();i++) {
|
||
m_bellQueryModel->insertRow(i);
|
||
QString temp = defaultBell->at(i);
|
||
QString tempTr = defaultBellTr->at(i);
|
||
m_bellQueryModel->setData(m_bellQueryModel->index(i, 0), Utils::getRandomId());
|
||
m_bellQueryModel->setData(m_bellQueryModel->index(i, 1), tempTr);
|
||
m_bellQueryModel->setData(m_bellQueryModel->index(i, 2), temp);
|
||
QString path = DEFAULT_BELL_SAVE_PATH;
|
||
path = path.append(temp).append(".wav");
|
||
m_bellQueryModel->setData(m_bellQueryModel->index(i, 3), path);
|
||
QDateTime time = QDateTime::currentDateTime(); //获取当前时间
|
||
qint64 timeT = time.toMSecsSinceEpoch();
|
||
m_bellQueryModel->setData(m_bellQueryModel->index(i, 4), timeT);
|
||
m_bellQueryModel->setData(m_bellQueryModel->index(i, 5), 0);
|
||
//排序,暂停1ms
|
||
QThread::msleep(1);
|
||
}
|
||
delete defaultBell;
|
||
m_bellQueryModel->submitAll();
|
||
m_selectBtnUtil->refreshBellData();
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 时间间隔执行
|
||
* Interval calculation execution callback
|
||
*/
|
||
void Clock::stopwatchJg()
|
||
{
|
||
if (stopwatch_hour < 10) {
|
||
QString hours_str = QString::number(stopwatch_hour);
|
||
stopwatch_jg_h = "0"+hours_str;
|
||
} else {
|
||
stopwatch_jg_h = QString::number(stopwatch_hour);
|
||
}
|
||
|
||
if (stopwatch_minute < 10) {
|
||
QString minute_str = QString::number(stopwatch_minute);
|
||
stopwatch_jg_m = "0"+minute_str;
|
||
}else {
|
||
stopwatch_jg_m = QString::number(stopwatch_minute);
|
||
}
|
||
|
||
if (stopwatch_second < 10) {
|
||
QString second_str = QString::number(stopwatch_second);
|
||
stopwatch_jg_s = "0"+second_str;
|
||
} else {
|
||
stopwatch_jg_s = QString::number(stopwatch_second);
|
||
}
|
||
|
||
ui->timeShowSmall->setText(stopwatch_jg_h+TIME_SEPARATOR+stopwatch_jg_m+"."+stopwatch_jg_s);
|
||
|
||
stopwatch_second++;
|
||
if (stopwatch_second==100) {
|
||
stopwatch_minute++; stopwatch_second=0;}
|
||
if (stopwatch_minute==60) {
|
||
stopwatch_hour++; stopwatch_minute=0;}
|
||
}
|
||
|
||
/*
|
||
* 秒表执行
|
||
* Stopwatch execution
|
||
*/
|
||
void Clock::CountDown()
|
||
{
|
||
if (hour < 10) {
|
||
QString hours_str = QString::number(hour);
|
||
stopwatch_h = "0"+hours_str;
|
||
} else {
|
||
stopwatch_h = QString::number(hour);
|
||
}
|
||
|
||
if (minute < 10) {
|
||
QString minute_str = QString::number(minute);
|
||
stopwatch_m = "0"+minute_str;
|
||
} else {
|
||
stopwatch_m = QString::number(minute);
|
||
}
|
||
|
||
if (second < 10) {
|
||
QString second_str = QString::number(second);
|
||
stopwatch_s = "0"+second_str;
|
||
} else {
|
||
stopwatch_s = QString::number(second);
|
||
}
|
||
ui->timeShowBig->setText(stopwatch_h+TIME_SEPARATOR+stopwatch_m+"."+stopwatch_s);
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(38);
|
||
ui->timeShowBig->setFont(f);
|
||
//命名很不友好
|
||
//second单位是10ms
|
||
second++;
|
||
//minute单位是秒
|
||
if (second==100){
|
||
minute++; second=0;
|
||
}
|
||
//hour单位是分钟
|
||
if (minute==60){
|
||
hour++; minute=0;
|
||
}
|
||
|
||
}
|
||
/*
|
||
* 秒表开始暂停继续
|
||
* Stopwatch start pause continue
|
||
*/
|
||
void Clock::onPushbuttonStartClicked()
|
||
{
|
||
if (!isStarted) {
|
||
ui->startStopwatch->setText(tr("suspend"));
|
||
QPalette palette = ui->startStopwatch->palette();
|
||
QColor ColorPlaceholderText(248,163,76,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText);
|
||
//主题框架1.0.6-5kylin2
|
||
palette.setColor(QPalette::Highlight,QColor(248,163,76,255));
|
||
palette.setColor(QPalette::Button,QColor(248,163,76,255));
|
||
palette.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
ui->startStopwatch->setPalette(palette);
|
||
|
||
if (stopwatch_isStarted == 0) {
|
||
timer_2->start();
|
||
stopwatch_isStarted = 1;
|
||
}
|
||
timer->start();
|
||
isStarted=1;
|
||
if (!stopwatch_Animation) {
|
||
stopwatchStartAnimation();
|
||
stopwatch_Animation = 1;
|
||
}
|
||
ui->ringBtn->setText(tr("count"));
|
||
} else {
|
||
timer->stop();
|
||
/*查询间隔计时器是否启动
|
||
Query whether the interval timer starts*/
|
||
if (stopwatch_isStarted == 1) {
|
||
timer_2->stop();
|
||
stopwatch_isStarted = 0;
|
||
}
|
||
isStarted=0;
|
||
ui->startStopwatch->setText(tr("continue"));
|
||
|
||
QPalette palette = ui->startStopwatch->palette();
|
||
QColor ColorPlaceholderText(248,163,76,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText);
|
||
//主题框架1.0.6-5kylin2
|
||
palette.setColor(QPalette::Highlight,QColor(69, 173, 110,255));
|
||
palette.setColor(QPalette::Button,QColor(69, 173, 110,255));
|
||
palette.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
ui->startStopwatch->setPalette(palette);
|
||
ui->ringBtn->setText(tr("reset"));
|
||
}
|
||
return;
|
||
}
|
||
|
||
/*
|
||
*倒计时标签动画移动
|
||
*Countdown start animation move
|
||
*/
|
||
void Clock::stopwatchStartAnimation()
|
||
{
|
||
animation1 = new QPropertyAnimation(ui->timeShowBig, "geometry");
|
||
animation1->setDuration(1000);
|
||
animation1->setKeyValueAt(0, QRect(90, 125, 210, 70));
|
||
animation1->setEndValue(QRect(90, 4, 210, 70));
|
||
animation1->start();
|
||
|
||
animation2 = new QPropertyAnimation(ui->timeShowSmall, "geometry");
|
||
animation2->setDuration(1000);
|
||
animation2->setKeyValueAt(0, QRect(90, 173, 210, 41));
|
||
animation2->setEndValue(QRect(90, 60, 210, 41));
|
||
animation2->start();
|
||
|
||
animation3 = new QPropertyAnimation(ui->timeListWidget, "geometry");
|
||
animation3->setDuration(1000);
|
||
animation3->setKeyValueAt(0, QRect(25 ,230, 340, 270));
|
||
animation3->setEndValue(QRect(25, 109, 340, 270));
|
||
animation3->start();
|
||
}
|
||
/*
|
||
* 倒计时开始动画移动
|
||
* Countdown start animation move
|
||
*/
|
||
void Clock::stopwatchStopAnimation()
|
||
{
|
||
animation1 = new QPropertyAnimation(ui->timeShowBig, "geometry");
|
||
animation1->setDuration(1000);
|
||
animation1->setKeyValueAt(0, QRect(90, 4, 210, 70));
|
||
animation1->setEndValue(QRect(90, 125, 210, 70));
|
||
animation1->start();
|
||
|
||
animation2 = new QPropertyAnimation(ui->timeShowSmall, "geometry");
|
||
animation2->setDuration(1000);
|
||
animation2->setKeyValueAt(0, QRect(90, 55, 210, 41));
|
||
animation2->setEndValue(QRect(90, 183, 210, 41));
|
||
animation2->start();
|
||
|
||
animation3 = new QPropertyAnimation(ui->timeListWidget, "geometry");
|
||
animation3->setDuration(1000);
|
||
animation3->setKeyValueAt(0, QRect(25 ,109, 340, 270));
|
||
animation3->setEndValue(QRect(25, 230, 340, 270));
|
||
animation3->start();
|
||
}
|
||
|
||
/*
|
||
* 计次
|
||
* times count
|
||
*/
|
||
void Clock::onPushbuttonRingClicked()
|
||
{
|
||
if (!isStarted) {
|
||
//复位
|
||
//清空数据
|
||
timeSepOrderIndex->clear();
|
||
hisLongShortIndex->clear();
|
||
if (nullptr != timer) {
|
||
timer->stop();
|
||
timer_2->stop();
|
||
ui->timeShowBig->setText("00:00.00");
|
||
ui->timeShowSmall->setText("00:00.00");
|
||
isStarted = 0;
|
||
stopwatch_isStarted = 0;
|
||
hour = 0; minute = 0;second = 0;
|
||
stopwatch_hour = 0;
|
||
stopwatch_minute = 0;
|
||
stopwatch_second = 0;
|
||
ui->startStopwatch->setText(tr("start"));
|
||
ui->startStopwatch->setPalette(ui->addAlarmBtn->palette());
|
||
for (int i=0; i < stopwatch_item_flag; i++) {
|
||
delete stopwatch_w[i];
|
||
delete stopwatch_aItem[i];
|
||
}
|
||
stopwatch_item_flag = 0;
|
||
if (stopwatch_Animation) {
|
||
stopwatchStopAnimation();
|
||
stopwatch_Animation = 0;
|
||
}
|
||
}
|
||
}else{
|
||
//计次
|
||
if (stopwatch_isStarted == 0) {
|
||
timer_2->start();
|
||
stopwatch_isStarted = 1;
|
||
}
|
||
if (stopwatch_item_flag < 100) {
|
||
stopwatch_aItem[stopwatch_item_flag] =new QListWidgetItem;
|
||
stopwatch_aItem[stopwatch_item_flag]->setSizeHint(QSize(340,58));
|
||
stopwatch_aItem[stopwatch_item_flag]->setTextColor(QColor(255, 0, 0, 255));
|
||
ui->timeListWidget->insertItem(0,stopwatch_aItem[stopwatch_item_flag]);
|
||
|
||
ui->timeListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||
ui->timeListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
stopwatch_w[stopwatch_item_flag] = new stopwatch_item(ui->timeListWidget);
|
||
|
||
stopwatch_w[stopwatch_item_flag]->stopwatch1->setText(tr("count")+QString::number(stopwatch_item_flag+1));
|
||
stopwatch_w[stopwatch_item_flag]->stopwatch2->setText(tr("interval ")+stopwatch_jg_h+TIME_SEPARATOR+stopwatch_jg_m+"."+stopwatch_jg_s);
|
||
//间隔时间存入列表
|
||
long sepTime = stopwatch_hour*3600+stopwatch_minute*60+stopwatch_second;
|
||
timeSepOrderIndex->insert(sepTime,stopwatch_item_flag);
|
||
//添加标签
|
||
updateLongestShortLabel();
|
||
|
||
stopwatch_w[stopwatch_item_flag]->stopwatch3->setText(stopwatch_h+TIME_SEPARATOR+stopwatch_m+"."+stopwatch_s);
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(24);
|
||
stopwatch_w[stopwatch_item_flag]->stopwatch3->setFont(f);
|
||
|
||
ui->timeListWidget->setItemWidget(stopwatch_aItem[stopwatch_item_flag],stopwatch_w[stopwatch_item_flag]);
|
||
|
||
stopwatch_hour = 0;
|
||
stopwatch_minute = 0;
|
||
stopwatch_second = 0;
|
||
|
||
stopwatch_item_flag++;
|
||
|
||
} else if(stopwatch_item_flag >= 100) {
|
||
QToolTip::showText(mapToGlobal(ui->timeListWidget->pos()+QPoint(90,340)),tr("up to 100 times"),this);
|
||
}
|
||
}
|
||
|
||
|
||
//秒表页面子项字体更新
|
||
updateStopwatchItemFront(CURRENT_FONT_SIZE);
|
||
}
|
||
|
||
void Clock::updateLongestShortLabel()
|
||
{
|
||
QListIterator<int> iterator(*hisLongShortIndex);
|
||
while (iterator.hasNext()) {
|
||
int index = iterator.next();
|
||
stopwatch_w[index]->updateTipCommonStyle();
|
||
}
|
||
long shortIndex = timeSepOrderIndex->first();
|
||
stopwatch_w[shortIndex]->updateTipShortestStyle();
|
||
int longIndex = timeSepOrderIndex->last();
|
||
stopwatch_w[longIndex]->updateTipLongestStyle();
|
||
//存储到历史
|
||
hisLongShortIndex->clear();
|
||
hisLongShortIndex->append(shortIndex);
|
||
hisLongShortIndex->append(longIndex);
|
||
|
||
|
||
}
|
||
|
||
/*
|
||
*复位
|
||
*reset
|
||
*/
|
||
void Clock::onPushbuttonTimeselectClicked()
|
||
{
|
||
if (nullptr != timer) {
|
||
if (isStarted)
|
||
return;
|
||
timer->stop();
|
||
timer_2->stop();
|
||
ui->timeShowBig->setText("00:00.00");
|
||
ui->timeShowSmall->setText("00:00.00");
|
||
isStarted = 0;
|
||
stopwatch_isStarted = 0;
|
||
hour = 0; minute = 0;second = 0;
|
||
stopwatch_hour = 0;
|
||
stopwatch_minute = 0;
|
||
stopwatch_second = 0;
|
||
ui->startStopwatch->setText(tr("start"));
|
||
ui->startStopwatch->setPalette(ui->addAlarmBtn->palette());
|
||
|
||
for (int i=0; i < stopwatch_item_flag; i++) {
|
||
delete stopwatch_w[i];
|
||
delete stopwatch_aItem[i];
|
||
}
|
||
stopwatch_item_flag = 0;
|
||
if (stopwatch_Animation) {
|
||
stopwatchStopAnimation();
|
||
stopwatch_Animation = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 窗口关闭
|
||
* window closing
|
||
*/
|
||
void Clock::windowClosingClicked()
|
||
{
|
||
closeHandel();
|
||
|
||
if(close_or_hide_page->close_flag==1){
|
||
// setWindowState(Qt::WindowMinimized);
|
||
this->hide();
|
||
//加入托盘
|
||
enableTrayIcon();
|
||
close_or_hide_page->close_flag = 0;
|
||
}else if(close_or_hide_page->close_flag==2){
|
||
exit(0);
|
||
}
|
||
}
|
||
|
||
/*
|
||
*窗口最小化
|
||
*window minimizing
|
||
*/
|
||
void Clock::windowMinimizingClicked()
|
||
{
|
||
this->showNormal();
|
||
this->showMinimized();
|
||
}
|
||
|
||
void Clock::muteAllBell()
|
||
{
|
||
//静音反转
|
||
m_muteOn = !m_muteOn;
|
||
QPixmap pixmap = QPixmap(":/image/miniIcon/mute-off.png");
|
||
if(m_muteOn){
|
||
pixmap = QPixmap(":/image/miniIcon/mute-on.png");
|
||
}
|
||
ui->muteBtn->setIcon(pixmap);
|
||
if(m_muteOn){
|
||
QPoint position = frameGeometry().center();
|
||
int x = position.x()-m_commonToolTip->geometry().width()/2;
|
||
int y = position.y()-m_commonToolTip->geometry().height()/2;
|
||
m_commonToolTip->move(x,y);
|
||
m_commonToolTip->show();
|
||
m_commonToolTipRemainTime = 2;
|
||
m_commonToolTipCloseTimer->start();
|
||
//存储静音到数据库
|
||
model_setup->setData(model_setup->index(0, 0), 1);//静音 Mute
|
||
}else{
|
||
model_setup->setData(model_setup->index(0, 0), 0);//静音 Mute
|
||
}
|
||
model_setup->submitAll();
|
||
}
|
||
|
||
/*
|
||
* 倒计时切换
|
||
* Countdown switch
|
||
*/
|
||
void Clock:: CountdownPageSwitch ()
|
||
{
|
||
setSwitchHighlightColor(ui->switchCountdown);
|
||
setSwitchDefaultColor(ui->switchClock);
|
||
setSwitchDefaultColor(ui->switchStopwatch);
|
||
ui->mainWidget->setCurrentIndex(0);
|
||
}
|
||
void Clock::setBtnIcon(QPushButton *btn, QString imgUrl, QString localUrl)
|
||
{
|
||
QIcon icon=Utils::getQIcon(imgUrl,localUrl);
|
||
btn->setIcon(QIcon::fromTheme(imgUrl));
|
||
btn->setIconSize(QSize(18, 18));
|
||
QPainter p(btn);
|
||
// 表示引擎应尽可能对图元的边缘进行抗锯齿。
|
||
p.setRenderHint(QPainter::Antialiasing);
|
||
}
|
||
void Clock::setDefaultIcon(QPushButton *btn)
|
||
{
|
||
if(btn==ui->switchClock){
|
||
setBtnIcon(ui->switchClock,"ukui-alarm-symbolic",":/image/alarm.png");
|
||
}else if(btn==ui->switchCountdown){
|
||
setBtnIcon(ui->switchCountdown,"ukui-countselect-symbolic",":/image/count.png");
|
||
}else if(btn==ui->switchStopwatch){
|
||
setBtnIcon(ui->switchStopwatch,"ukui-stopwatch-symbolic",":/image/stopwatch.png");
|
||
}
|
||
if(theme::themetype==1){
|
||
changeIconHeight(btn);
|
||
}
|
||
}
|
||
QColor Clock::getHighlightActive()
|
||
{
|
||
return palette().color(QPalette::Active,QPalette::Highlight);
|
||
}
|
||
|
||
QColor Clock::getButtonActive()
|
||
{
|
||
return palette().color(QPalette::Active,QPalette::Button);
|
||
}
|
||
void Clock::setSwitchDefaultColor(QPushButton * btn)
|
||
{
|
||
auto pa = btn->palette();
|
||
QColor btnAcCol = getButtonActive();
|
||
pa.setColor(QPalette::Active,QPalette::Button,btnAcCol);
|
||
btn->setPalette(pa);
|
||
setDefaultIcon(btn);
|
||
}
|
||
void Clock::setSwitchHighlightColor(QPushButton * btn)
|
||
{
|
||
|
||
auto pa = btn->palette();
|
||
QColor highAcCol = getHighlightActive();
|
||
pa.setColor(QPalette::Active,QPalette::Button,highAcCol);
|
||
btn->setPalette(pa);
|
||
//修改图标颜色
|
||
changeIconHeight(btn);
|
||
|
||
}
|
||
/*
|
||
* 闹钟窗口切换
|
||
* Alarm window switchin
|
||
*/
|
||
void Clock:: AlarmPageSwitch ()
|
||
{
|
||
setSwitchDefaultColor(ui->switchCountdown);
|
||
setSwitchHighlightColor(ui->switchClock);
|
||
setSwitchDefaultColor(ui->switchStopwatch);
|
||
ui->mainWidget->setCurrentIndex(1);
|
||
}
|
||
void Clock::changeIconHeight(QPushButton *btn)
|
||
{
|
||
QPixmap pix = btn->icon().pixmap(btn->iconSize());
|
||
QPixmap tarPix=theme::changeIconColor(pix,palette().highlightedText().color());
|
||
btn->setIcon(QIcon(tarPix));
|
||
}
|
||
/*
|
||
* 秒表窗口切换
|
||
* Stopwatch window switch
|
||
*/
|
||
void Clock:: StopwatchPageSwitch ()
|
||
{
|
||
setSwitchDefaultColor(ui->switchCountdown);
|
||
setSwitchDefaultColor(ui->switchClock);
|
||
setSwitchHighlightColor(ui->switchStopwatch);
|
||
ui->mainWidget->setCurrentIndex(2);
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 闹钟列表项
|
||
*/
|
||
void Clock::textTimerupdate()
|
||
{
|
||
//闹钟表条数
|
||
int rowNum = model->rowCount();
|
||
model_setup->select();
|
||
QTime time = QTime::currentTime();
|
||
int time_H = time.hour();
|
||
int time_M = time.minute();
|
||
int time_S = time.second();
|
||
//Timeformat
|
||
//系统24时
|
||
if (checkSystem24()) {
|
||
set24ClockItem(time_H,time_M,time_S,rowNum);
|
||
} else {
|
||
//系统12时制
|
||
set12ClockItem(time_H,time_M,time_S,rowNum);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief 设置24时制闹钟
|
||
*/
|
||
void Clock::set24ClockItem(int time_H,int time_M,int time_S,int rowNum)
|
||
{
|
||
if(system_time_flag == 0){
|
||
system_time_flag = 1;
|
||
clearClockItem( rowNum);
|
||
} else {
|
||
system_time_flag = 1;
|
||
}
|
||
}
|
||
/**
|
||
* @brief 设置12时制闹钟
|
||
*/
|
||
void Clock::set12ClockItem(int time_H,int time_M,int time_S,int rowNum)
|
||
{
|
||
//原来是24时,则重新构建
|
||
if (system_time_flag == 1) {
|
||
system_time_flag = 0;
|
||
clearClockItem(rowNum);
|
||
} else {
|
||
system_time_flag = 0;
|
||
}
|
||
}
|
||
/**
|
||
* @brief 清理重新构建闹钟列表
|
||
*/
|
||
void Clock::clearClockItem(int rowNum)
|
||
{
|
||
for(int i=0; i<rowNum; i++) {
|
||
delete aItem[i];
|
||
delete w1[i];
|
||
}
|
||
updateAlarmClock();
|
||
}
|
||
/**
|
||
* @brief 初始化系统时间标识
|
||
*/
|
||
void Clock::iniSystemTimeFlag()
|
||
{
|
||
//跟随系统
|
||
if(checkSystem24()){
|
||
system_time_flag = 1;
|
||
}else{
|
||
system_time_flag = 0;
|
||
}
|
||
|
||
}
|
||
/**
|
||
* @brief 判断系统是否是24时制
|
||
*/
|
||
bool Clock::checkSystem24()
|
||
{
|
||
//Qt提供了一个QProcess类用于启动外部程序并与之通信
|
||
QProcess process;
|
||
process.start("gsettings get org.ukui.control-center.panel.plugins hoursystem");
|
||
//阻塞,直到外部程序结束
|
||
process.waitForFinished();
|
||
QByteArray output = process.readAllStandardOutput();
|
||
QString str_output = output;
|
||
return str_output.compare("'24'\n") == 0;
|
||
}
|
||
|
||
void Clock::muteBtnStyle()
|
||
{
|
||
int mute = model_setup->index(0, 0).data().toInt();
|
||
m_muteOn = mute==1?true:false;
|
||
QPixmap pixmap = QPixmap(":/image/miniIcon/mute-off.png");
|
||
if(m_muteOn){
|
||
pixmap = QPixmap(":/image/miniIcon/mute-on.png");
|
||
}
|
||
ui->muteBtn->setIcon(pixmap);
|
||
ui->muteBtn->setIconSize(QSize(32, 32));
|
||
QPainter p(ui->muteBtn);
|
||
//表示引擎应尽可能对图元的边缘进行抗锯齿。
|
||
p.setRenderHint(QPainter::Antialiasing);
|
||
ui->muteBtn->setFlat(true);
|
||
ui->muteBtn->setVisible(true);
|
||
ui->muteBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->muteBtn->setToolTip(tr("mute"));
|
||
//弹窗初始化
|
||
m_commonToolTip = new CommonToolTip(this);
|
||
m_commonToolTip->hide();
|
||
m_commonToolTip->setMsgText(tr("All bells are off"));
|
||
//弹窗定时
|
||
m_commonToolTipCloseTimer = new QTimer(this);
|
||
m_commonToolTipCloseTimer->setInterval(1000);
|
||
connect(m_commonToolTipCloseTimer, &QTimer::timeout, this, [=](){
|
||
m_commonToolTipRemainTime--;
|
||
if(m_commonToolTipRemainTime<=0){
|
||
m_commonToolTipCloseTimer->stop();
|
||
m_commonToolTip->hide();
|
||
}
|
||
});
|
||
connect(ui->muteBtn, SIGNAL(clicked()), this, SLOT(muteAllBell()));
|
||
}
|
||
/**
|
||
* @brief 最小化按钮样式
|
||
*/
|
||
void Clock::minBtnStyle()
|
||
{
|
||
//窗口最小化
|
||
ui->minmizeBtn->setIcon(QIcon::fromTheme("window-minimize-symbolic"));
|
||
ui->minmizeBtn->setFlat(true);
|
||
ui->minmizeBtn->setVisible(true);
|
||
ui->minmizeBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->minmizeBtn->setProperty("useIconHighlightEffect", 0x2);
|
||
ui->minmizeBtn->setProperty("isWindowButton", 0x01);
|
||
ui->minmizeBtn->setToolTip(tr("Minimize"));
|
||
connect(ui->minmizeBtn, SIGNAL(clicked()), this, SLOT(windowMinimizingClicked()));
|
||
}
|
||
/**
|
||
* @brief 关闭按钮样式
|
||
*/
|
||
void Clock::closeBtnStyle()
|
||
{
|
||
|
||
//窗口关闭
|
||
ui->closeTitleBtn->setIcon(QIcon::fromTheme("window-close-symbolic"));
|
||
ui->closeTitleBtn->setFlat(true);
|
||
ui->closeTitleBtn->setVisible(true);
|
||
ui->closeTitleBtn->setFocusPolicy(Qt::NoFocus);
|
||
//主题框架1.0.6-5kylin2
|
||
ui->closeTitleBtn->setProperty("isWindowButton", 0x2);
|
||
ui->closeTitleBtn->setProperty("useIconHighlightEffect", 0x8);
|
||
ui->closeTitleBtn->setToolTip(tr("Quit"));
|
||
connect(ui->closeTitleBtn, SIGNAL(clicked()), this, SLOT(windowClosingClicked()));
|
||
}
|
||
/**
|
||
* @brief 菜单按钮样式
|
||
*/
|
||
void Clock::menuBtnStyle()
|
||
{
|
||
//菜单项
|
||
ui->menuBtn->setIcon(QIcon::fromTheme("open-menu-symbolic"));
|
||
ui->menuBtn->setVisible(true);
|
||
ui->menuBtn->setFocusPolicy(Qt::NoFocus);
|
||
ui->menuBtn->setToolTip(tr("Menu"));
|
||
ui->menuBtn->setProperty("useIconHighlightEffect", 0x2);
|
||
ui->menuBtn->setProperty("useButtonPalette", true);
|
||
/*设置关于页*/
|
||
ui->menuBtn->setPopupMode(QToolButton::InstantPopup);
|
||
m_menu = new QMenu(ui->menuBtn);
|
||
m_menu->setProperty("fillIconSymbolicColor", true);
|
||
// ui->pushButton_12->setProperty("useButtonPalette", true);
|
||
//菜单项的操作
|
||
//帮助
|
||
QAction *m_helpAction = new QAction(m_menu);
|
||
//关于
|
||
QAction *m_aboutAction = new QAction(m_menu);
|
||
//关闭
|
||
QAction *m_closeAction = new QAction(m_menu);
|
||
m_helpAction->setText(tr("Help"));
|
||
m_aboutAction->setText(tr("About"));
|
||
m_closeAction->setText(tr("Close"));
|
||
m_menu->addAction(m_helpAction);
|
||
m_menu->addAction(m_aboutAction);
|
||
m_menu->addAction(m_closeAction);
|
||
ui->menuBtn->setMenu(m_menu);
|
||
connect(m_helpAction, &QAction::triggered, this, [=](){
|
||
qDebug() << "help clicked";
|
||
callUserGuide();
|
||
});
|
||
connect(m_aboutAction, &QAction::triggered, this, [=](){
|
||
About *dialog = new About();
|
||
QPointF position = this->pos();
|
||
XAtomHelper::setStandardWindowHint(dialog->winId());
|
||
dialog->move(position.x()-15,position.y()+130);
|
||
dialog->exec();
|
||
});
|
||
connect(m_closeAction, SIGNAL(triggered()), this, SLOT(windowClosingClicked()));
|
||
|
||
//手动改成透明色
|
||
QPalette pale =ui->menuBtn->palette();
|
||
pale.setColor(QPalette::Active,QPalette::Button,Qt::transparent);
|
||
ui->menuBtn->setPalette(pale);
|
||
}
|
||
/*
|
||
* @brief 检查小窗体是否初始化
|
||
*/
|
||
bool Clock::checkTinyCountdownDia()
|
||
{
|
||
return tinycountdownDia!=nullptr?true:false;
|
||
}
|
||
|
||
void Clock::navigationBtnStyle(QPushButton * btn)
|
||
{
|
||
setDefaultIcon(btn);;
|
||
//不使用主题高亮
|
||
btn->setProperty("useIconHighlightEffect", false);
|
||
//使用灰按钮
|
||
btn->setProperty("useButtonPalette", true);
|
||
}
|
||
|
||
void Clock::updateClockSelectBtnStyle(SelectBtn *temp, int moveHeight)
|
||
{
|
||
temp->move(25,moveHeight);
|
||
}
|
||
|
||
void Clock::updateCountdownSelectBtnStyle(SelectBtn *temp, int moveWidth, int moveHeight)
|
||
{
|
||
temp->move(moveWidth,moveHeight);
|
||
}
|
||
|
||
void Clock::updateClockSelectBtnStyle(Btn_new *temp, int moveHeight)
|
||
{
|
||
temp->move(DIALOG_MOVE_WIDTH,moveHeight);
|
||
}
|
||
|
||
void Clock::updateCountdownSelectBtnStyle(Btn_new *temp, int moveWidth, int moveHeight)
|
||
{
|
||
temp->move(moveWidth,moveHeight);
|
||
}
|
||
|
||
void Clock::updateClockSelectBtnLabel(QLabel *temp, int moveHeight, QString text)
|
||
{
|
||
temp->setText(text);
|
||
temp->setAlignment(Qt::AlignLeft|Qt::AlignVCenter);
|
||
temp->setStyleSheet("font-size:14px;");
|
||
int labelLeftSpace = 20;
|
||
temp->move(labelLeftSpace, moveHeight);
|
||
}
|
||
|
||
void Clock::widgetListWhiteStyle(QListWidget *listWidget)
|
||
{
|
||
QString listBackColor = getDefaultGreyColor();
|
||
QString selectItemRadius = QString::number(SELECT_ITEM_RADIUS);
|
||
listWidget->setStyleSheet("QListWidget{background-color: rgba(0, 0, 0, 0);}\
|
||
QListWidget::Item{background-color:"+listBackColor+";border-radius:"+selectItemRadius+"px;}\
|
||
QListWidget::item::selected{background-color:rgba(233, 233, 233,255);border-radius:"+selectItemRadius+"px;border:1px solid rgba(131, 131, 131,0);}\
|
||
QListWidget::item:hover{background-color:rgba(233, 233, 233,255);border-radius:"+selectItemRadius+"px;}\
|
||
QScrollBar:vertical{width:4px;background:rgba(0, 0, 0, 0);}QScrollBar::handle:vertical{width:4px;background:rgba(186, 193, 201, 1);}\
|
||
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical{background: white;border: 2px solid transparent;}\
|
||
");
|
||
}
|
||
|
||
void Clock::widgetListBlackStyle(QListWidget *listWidget)
|
||
{
|
||
QString selectItemRadius = QString::number(SELECT_ITEM_RADIUS);
|
||
listWidget->setStyleSheet("QListWidget{background-color: rgba(0, 0, 0, 0);}\
|
||
QListWidget::Item{background-color:rgba(41, 41, 41, 255);border-radius:"+selectItemRadius+"px;}\
|
||
QListWidget::item::selected{background-color:rgba(55, 55, 59, 255);border-radius:"+selectItemRadius+"px;border:1px solid rgba(131, 131, 131,0);}\
|
||
QListWidget::item:hover{background-color:rgba(55, 55, 59, 255);border-radius:"+selectItemRadius+"px;}\
|
||
QScrollBar:vertical{width:4px;background:rgba(0, 0, 0, 0);}QScrollBar::handle:vertical{width:4px;background:rgba(186, 193, 201, 1);}\
|
||
QScrollBar::up-arrow:vertical, QScrollBar::down-arrow:vertical{background: white;border: 2px solid transparent;}\
|
||
");
|
||
}
|
||
|
||
/*
|
||
* 动态监控闹钟与本地时间
|
||
* Dynamic monitoring alarm clock and local time
|
||
*/
|
||
void Clock::timerUpdate()
|
||
{
|
||
QTime time = QTime::currentTime();
|
||
int timeH = time.hour();
|
||
int timeM = time.minute();
|
||
int timeS = time.second();
|
||
|
||
model_setup->select();
|
||
//更新闹钟列表项
|
||
textTimerupdate();
|
||
|
||
int rowNum = model->rowCount();
|
||
bool hasNextAlarm = false;
|
||
QString nextAlarmClock = "";
|
||
//记录最近的闹钟时间差
|
||
int spanTime = 0;
|
||
//遍历闹钟
|
||
for (int i = 0; i < rowNum; i++) {
|
||
/*判断星期
|
||
Judgment week*/
|
||
QDateTime current_date_time = QDateTime::currentDateTime();
|
||
//今天没提醒闹钟,则continue
|
||
//缩写的本地化日期名称
|
||
if (current_date_time.toString("ddd").compare("周一")==0 && model->index(i, 6).data().toInt() == 0)
|
||
continue;
|
||
if (current_date_time.toString("ddd").compare("周二")==0 && model->index(i, 7).data().toInt() == 0)
|
||
continue;
|
||
if (current_date_time.toString("ddd").compare("周三")==0 && model->index(i, 8).data().toInt() == 0)
|
||
continue;
|
||
if (current_date_time.toString("ddd").compare("周四")==0 && model->index(i, 9).data().toInt() == 0)
|
||
continue;
|
||
if (current_date_time.toString("ddd").compare("周五")==0 && model->index(i, 10).data().toInt() == 0)
|
||
continue;
|
||
if (current_date_time.toString("ddd").compare("周六")==0 && model->index(i, 11).data().toInt() == 0)
|
||
continue;
|
||
if (current_date_time.toString("ddd").compare("周日")==0 && model->index(i, 12).data().toInt() == 0)
|
||
continue;
|
||
|
||
/*判断开关
|
||
Judgment switch*/
|
||
//闹钟关闭 则 continue
|
||
if ( model->index(i, 3).data().toInt() == 1)
|
||
continue;
|
||
//闹钟时间到
|
||
int alarmH = model->index(i, 0).data().toInt();
|
||
int alarmM = model->index(i, 1).data().toInt();
|
||
if (timeH == alarmH
|
||
&& timeM == alarmM
|
||
&& timeS == 0) {
|
||
double music_time = 30;
|
||
if (model->index(i, 13).data().toString().compare(tr("2min"))==0) {
|
||
music_time = 2*60;
|
||
} else if (model->index(i, 13).data().toString().compare(tr("3min"))==0) {
|
||
music_time = 3*60;
|
||
} else if (model->index(i, 13).data().toString().compare(tr("4min"))==0) {
|
||
music_time = 4*60;
|
||
} else if (model->index(i, 13).data().toString().compare(tr("6min"))==0) {
|
||
music_time = 6*60;
|
||
} else {
|
||
music_time = 60;
|
||
}
|
||
QString id = model->index(i, 14).data().toString();
|
||
noticeDialogShow(music_time, i ,id);
|
||
if(model->index(i, 5).data().toString().compare(tr("No repetition"))==0)
|
||
offAlarm(i);
|
||
}else{
|
||
int tempSpan = (alarmH-timeH)*60+alarmM-timeM;
|
||
if(tempSpan>0){
|
||
hasNextAlarm = true;
|
||
if(spanTime==0){
|
||
spanTime=tempSpan;
|
||
nextAlarmClock = changeNumToStrWithAm(alarmH)+TIME_SEPARATOR+changeNumToStr(alarmM);
|
||
}else{
|
||
if(tempSpan<spanTime){
|
||
spanTime=tempSpan;
|
||
nextAlarmClock = changeNumToStrWithAm(alarmH)+TIME_SEPARATOR+changeNumToStr(alarmM);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if(hasNextAlarm){
|
||
m_trayIconTooltip=tr("recent alarm")+TIME_SEPARATOR_CN+nextAlarmClock;
|
||
}else{
|
||
m_trayIconTooltip="";
|
||
}
|
||
setDefaultTrayIconTooltip();
|
||
//触发一次paintEvent
|
||
update();
|
||
//更新闹钟页面子项字体
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
//刷新倒计时上 时间格式
|
||
getCountdownOverTime();
|
||
}
|
||
|
||
/*
|
||
* 通知弹窗
|
||
* Notification Popup
|
||
*/
|
||
void Clock::noticeDialogShow(int close_time, int alarm_num, QString id)
|
||
{
|
||
model_setup->select();
|
||
QScreen *screen=QGuiApplication::primaryScreen ();
|
||
//闹钟弹窗
|
||
alarmNoticeDialog = new Natice_alarm(close_time,alarm_num,nullptr,id);
|
||
if(countdownNoticeDialog != nullptr) {
|
||
if (countdownNoticeDialog->isVisible() == 0)
|
||
moveUnderMultiScreen(UP_RIGHT,alarmNoticeDialog,1);
|
||
else
|
||
moveUnderMultiScreen(UP_RIGHT,alarmNoticeDialog,0);
|
||
}
|
||
else
|
||
moveUnderMultiScreen(UP_RIGHT,alarmNoticeDialog,1);
|
||
alarmNoticeDialog->playMusic();
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 重绘窗口,更新闹钟 Redraw window, update alarm clock
|
||
*/
|
||
void Clock::updateAlarmClock()
|
||
{
|
||
int rowNum = model->rowCount();
|
||
int hour_now;
|
||
int min_now;
|
||
if(rowNum){
|
||
ui->noAlarm->hide();
|
||
ui->noAlarmIcon->hide();
|
||
}else{
|
||
ui->noAlarm->show();
|
||
ui->noAlarmIcon->show();
|
||
}
|
||
auto sqlQuery = clock_sql::getQSqlQuery();
|
||
sqlQuery.exec("select * from clock order by Hour ASC,Minute ASC");
|
||
int alarmNum = 0;
|
||
//实现id补偿,原表设计没有主键,为实现旧数据兼容
|
||
// QList<int> * needIdNumList = new QList<int>();
|
||
// QHash<int,int> * numToIndex =new QHash<int,int>();
|
||
while (sqlQuery.next()) {
|
||
//窗体
|
||
aItem[alarmNum] =new QListWidgetItem;
|
||
aItem[alarmNum]->setSizeHint(QSize(340,108));
|
||
aItem[alarmNum]->setTextColor(QColor(255, 0, 0, 255));
|
||
ui->alarmListWidget->addItem(aItem[alarmNum]);
|
||
ui->alarmListWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||
ui->alarmListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||
//闹钟信息
|
||
w1[alarmNum] = new item_new(ui->alarmListWidget);
|
||
//信息与展示窗体绑定
|
||
ui->alarmListWidget->setItemWidget(aItem[alarmNum],w1[alarmNum]);
|
||
//绑定Id到闹钟子项
|
||
auto hisId = sqlQuery.value(14).toString();
|
||
w1[alarmNum]->setId(hisId);
|
||
hour_now =sqlQuery.value( 0).toInt();
|
||
min_now =sqlQuery.value( 1).toInt();
|
||
int onOff = sqlQuery.value(3).toInt();
|
||
if(onOff==1){
|
||
w1[alarmNum]->closeStyle(CURRENT_FONT_SIZE);
|
||
}else{
|
||
w1[alarmNum]->openStyle(CURRENT_FONT_SIZE);
|
||
}
|
||
if (system_time_flag) {
|
||
//24时制
|
||
changeTimeNum(hour_now,min_now);//转换int为QString
|
||
// Convert int to qstring
|
||
w1[alarmNum]->alarmLabel0->setText(alarmHour_str+TIME_SEPARATOR+alarmMinute_str);
|
||
QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
QFont f(selfFont);
|
||
f.setPixelSize(38);
|
||
w1[alarmNum]->alarmLabel0->setFont(f);
|
||
|
||
w1[alarmNum]->alarmLabel1->hide();
|
||
} else {
|
||
//12时制
|
||
if (hour_now >= 12) {
|
||
w1[alarmNum]->alarmLabel1->setText(tr("PM"));
|
||
if (hour_now == 12) {
|
||
w1[alarmNum]->alarmLabel0->setText(changeNumToStr(hour_now)+" : "+changeNumToStr(min_now));
|
||
} else {
|
||
w1[alarmNum]->alarmLabel0->setText(changeNumToStr(hour_now-12)+" : "+changeNumToStr(min_now));
|
||
}
|
||
} else {
|
||
w1[alarmNum]->alarmLabel1->setText(tr("AM"));
|
||
if (hour_now == 0) {
|
||
w1[alarmNum]->alarmLabel0->setText(changeNumToStr(12)+" : "+changeNumToStr(min_now));
|
||
} else {
|
||
w1[alarmNum]->alarmLabel0->setText(changeNumToStr(hour_now)+" : "+changeNumToStr(min_now));
|
||
}
|
||
}
|
||
}
|
||
/*闹钟开关
|
||
Alarm switch*/
|
||
//onoroff
|
||
if (sqlQuery.value( 3).toInt() == 1) {
|
||
w1[alarmNum]->alarm_on_off0->setChecked(false);
|
||
} else {
|
||
w1[alarmNum]->alarm_on_off0->setChecked(true);
|
||
}
|
||
//Name 闹钟名
|
||
QString clockName = sqlQuery.value( 13).toString();
|
||
int sizeLimit = 8;
|
||
if(clockName.length()>sizeLimit){
|
||
w1[alarmNum]->alarmLabel_w0->setToolTip(clockName);
|
||
//名字超长
|
||
clockName = clockName.left(sizeLimit);
|
||
clockName = clockName+"..";
|
||
}
|
||
w1[alarmNum]->alarmLabel_w0->setText(clockName);
|
||
//repeat 重复
|
||
QString werk_str = sqlQuery.value( 5).toString();
|
||
QString werk_day ;
|
||
int werk = 0;
|
||
for (int i=0; i<7; i++) {
|
||
//从周一到周日开始判断 为1
|
||
if (sqlQuery.value( 6+i).toInt()) {
|
||
//拼接werk_day
|
||
if(i == 0){
|
||
werk_day = werk_day + tr("Mon")+" ";
|
||
}else if(i == 1){
|
||
werk_day = werk_day + tr("Tue")+" ";
|
||
}else if(i == 2){
|
||
werk_day = werk_day + tr("Wed")+" ";
|
||
}else if(i == 3){
|
||
werk_day = werk_day + tr("Thu")+" ";
|
||
}else if(i == 4){
|
||
werk_day = werk_day + tr("Fri")+" ";
|
||
}else if(i == 5){
|
||
werk_day = werk_day + tr("Sat")+" ";
|
||
}else if(i == 6){
|
||
werk_day = werk_day + tr("Sun")+" ";
|
||
}
|
||
}else{
|
||
//不是全为1
|
||
werk = 1;
|
||
}
|
||
}
|
||
if(werk){
|
||
w1[alarmNum]->alarmLabel_s0->setText(werk_day);
|
||
}else {
|
||
if(werk_str == tr("Every day") || werk_str == "每天"){
|
||
w1[alarmNum]->alarmLabel_s0->setText(tr("Every day"));
|
||
}else if(werk_str == "Workingday" || werk_str == "工作日"){
|
||
w1[alarmNum]->alarmLabel_s0->setText(tr("Workingday"));
|
||
}else if(werk_str == "No repetition" || werk_str == "不重复"){
|
||
w1[alarmNum]->alarmLabel_s0->setText(tr("No repetition"));
|
||
}
|
||
}
|
||
//闹钟开关绑定
|
||
// connect( w1[alarmNum]->alarm_on_off0, SIGNAL(clicked()), this, SLOT(OnOffAlarm()) );
|
||
connect(w1[alarmNum]->alarm_on_off0,SIGNAL(stateChanged()),this, SLOT(OnOffAlarm()));
|
||
alarmNum++;
|
||
}
|
||
// updateClockIdByNum(needIdNumList,numToIndex);
|
||
|
||
}
|
||
|
||
/*
|
||
* 绘制无闹钟提示
|
||
* Draw no alarm prompt
|
||
*/
|
||
void Clock::drawNoAlarmPrompt()
|
||
{
|
||
ui->noAlarmIcon->setPixmap(QPixmap(":/image/noClockWhite.png"));//.pixmap(164,194)
|
||
ui->noAlarm->setAlignment(Qt::AlignHCenter);
|
||
}
|
||
|
||
/*
|
||
* 修改时间单数 为两位数
|
||
* Modify time singular to two digits
|
||
*/
|
||
void Clock::changeTimeNum(int alarmHour, int alarmMinute)
|
||
{
|
||
if (alarmHour < 10) {
|
||
QString hours_str = QString::number(alarmHour);
|
||
alarmHour_str = "0"+hours_str;
|
||
} else {
|
||
alarmHour_str = QString::number(alarmHour);
|
||
}
|
||
if (alarmMinute < 10) {
|
||
QString minute_str = QString::number(alarmMinute);
|
||
alarmMinute_str = "0"+minute_str;
|
||
} else {
|
||
alarmMinute_str = QString::number(alarmMinute);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
/*
|
||
* 新建闹钟按钮回调
|
||
* New alarm button callback
|
||
*/
|
||
void Clock::setAlarmClock()
|
||
{
|
||
onEditPage = false;
|
||
//新建闹钟页
|
||
ui->mainWidget->setCurrentIndex(3);
|
||
//取消
|
||
ui->cancelbtnOnEditAlarm->show();
|
||
repeat_new_or_edit_flag = 0;
|
||
|
||
model_setup->select();/*调用默认设置
|
||
Call default settings*/
|
||
repeat_str_model = tr("Workingday");
|
||
//工作日默认
|
||
repeatSelectOnClockNew->textLabel->setText(repeat_str_model+tr("(default)"));
|
||
//工作日设置的逻辑
|
||
for (int i=0; i<5; i++) {
|
||
repeat_day[i] = 1;
|
||
}
|
||
remind_late_str_model= tr("none");
|
||
//设置新建闹钟默认铃声
|
||
QString defaultBellId = m_selectBtnUtil->getDefaultBellId();
|
||
QString bellName = m_selectBtnUtil->getBellNameById(defaultBellId);
|
||
musicSelectOnClockNew->textLabel->setText(bellName);
|
||
setMusicSelectDialogListById(defaultBellId,dialog_music->listWidget);
|
||
//设置默认稍后提醒
|
||
remindSelectOnClockNew->textLabel->setText(remind_late_str_model);
|
||
setRemindLateSelectDialogListByName(remind_late_str_model,dialog_remind_late->listWidget);
|
||
clock_name = tr(CLOCK_TITLE_NAME);
|
||
clockEditOnClockNew->clockNameLineEdit->setText(clock_name);
|
||
}
|
||
/**
|
||
* @brief 设置新建闹钟的铃声的默认值
|
||
* @param name
|
||
*/
|
||
void Clock::setMusicSelectDialogListById(QString bellId, QListWidget *temp)
|
||
{
|
||
int status = m_selectBtnUtil->getBellIndexById(bellId);
|
||
temp->setCurrentRow(status);
|
||
}
|
||
|
||
void Clock::setRemindLateSelectDialogListByName(QString name, QListWidget *temp)
|
||
{
|
||
|
||
int status = getRemindStatusByName(name);
|
||
temp->setCurrentRow(status);
|
||
}
|
||
|
||
int Clock::getRemindStatusByName(QString name)
|
||
{
|
||
int status = 0;
|
||
if(name.compare("none") == 0 || name.compare("不需要") == 0){
|
||
status = 0;
|
||
}else if(name.compare("five mins late") == 0 || name.compare("5分钟后") == 0){
|
||
status = 1;
|
||
}else if(name.compare("ten mins late") == 0 || name.compare("10分钟后") == 0){
|
||
status = 2;
|
||
}else if(name.compare("twenty mins late") == 0 || name.compare("20分钟后") == 0){
|
||
status = 3;
|
||
}else if(name.compare("thirsty mins late") == 0 || name.compare("30分钟后") == 0){
|
||
status = 4;
|
||
}else if(name.compare("one hour late") == 0 || name.compare("1小时后") == 0){
|
||
status = 5;
|
||
}
|
||
return status;
|
||
}
|
||
|
||
/*
|
||
* 闹钟新建界面保存回调
|
||
* Alarm new interface save callback
|
||
*/
|
||
void Clock::setAlarmSave()
|
||
{
|
||
if(onEditPage){
|
||
//编辑页面保存
|
||
QString clockName = clockEditOnClockNew->clockNameLineEdit->text();
|
||
if(clockName.isEmpty()){
|
||
delete_msg *deletemsg = new delete_msg();
|
||
deletemsg->ui->msgInfo->setText(tr("Please set alarm name!"));
|
||
QPointF position = this->pos();
|
||
deletemsg->move(position.x()+67,position.y()+250);
|
||
deletemsg->exec();
|
||
return ;
|
||
}
|
||
auto curentId = getClockPkByCurrentNum();
|
||
auto sqlQuery = clock_sql::getQSqlQuery();
|
||
sqlQuery.prepare("update clock set hour=:hour,minute=:minute,bell_id=:music,repeat=:repeat,"
|
||
"name=:name,monday=:monday,tuesday=:tuesday,wednesday=:wednesday,thursday=:thusday,"
|
||
"friday=:friday,saturday=:saturday,sunday=:sunday,remind_status=:remind_status where id=:id");
|
||
sqlQuery.bindValue(":id",curentId);
|
||
sqlQuery.bindValue(":hour",timer_alarm_start24->m_currentValue);
|
||
sqlQuery.bindValue(":minute",timer_alarm_start60->m_currentValue);
|
||
QString bellId = getSelectBellId(dialog_music);
|
||
sqlQuery.bindValue(":music",bellId);
|
||
sqlQuery.bindValue(":repeat",repeat_str_model);
|
||
sqlQuery.bindValue(":remind_status",remind_late_str_model);
|
||
sqlQuery.bindValue(":name",clockName);
|
||
for (int i=0; i<7; i++) {
|
||
QString day = indexWeekdayMap->value(i);
|
||
if (repeat_day[i]) {
|
||
sqlQuery.bindValue(day,1);
|
||
} else {
|
||
sqlQuery.bindValue(day,0);
|
||
}
|
||
}
|
||
sqlQuery.exec();
|
||
model->submitAll();
|
||
int m = model->rowCount();
|
||
/*每次updateAlarmClock()之前,删除全部闹钟相关控件
|
||
Delete all alarm related controls before updatealrmclock()*/
|
||
for (int i = 0; i < m; i++) {
|
||
delete aItem[i];
|
||
delete w1[i];
|
||
}
|
||
updateAlarmClock();
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
ui->mainWidget->setCurrentIndex(1);
|
||
ui->mainWidget->raise();/*将页面放置最前方
|
||
Put the page at the front*/
|
||
ui->minmizeBtn->raise();
|
||
ui->closeTitleBtn->raise();
|
||
ui->menuBtn->raise();
|
||
|
||
if (dialog_repeat)
|
||
dialog_repeat->close();
|
||
|
||
if (dialog_music)
|
||
dialog_music->close();
|
||
if(dialog_remind_late)
|
||
dialog_remind_late->close();
|
||
}else{
|
||
//新建页面保存
|
||
clockEditOnClockNew->clockNameLineEdit->setText(clockEditOnClockNew->clockNameLineEdit->text().remove(QRegExp("\\s")));//去除所以空格
|
||
if(clockEditOnClockNew->clockNameLineEdit->text().isEmpty()){
|
||
delete_msg *deletemsg = new delete_msg();
|
||
deletemsg->ui->msgInfo->setText(tr("Please set alarm name!"));
|
||
QPointF position = this->pos();
|
||
deletemsg->move(position.x()+67,position.y()+250);
|
||
deletemsg->exec();
|
||
return ;
|
||
}
|
||
int rowNum;
|
||
rowNum = model->rowCount();
|
||
|
||
qDebug() << rowNum << "闹钟数";
|
||
if (rowNum < 20) {
|
||
saveClockToDatabase(rowNum);
|
||
} else {
|
||
QMessageBox::warning(this, tr("warning"), tr("the number of alarms reaches limit!!"), tr("yes"));
|
||
}
|
||
|
||
ui->mainWidget->setCurrentIndex(1);
|
||
ui->mainWidget->raise();//将页面放置最前方
|
||
// Put the page at the front
|
||
ui->minmizeBtn->raise();
|
||
ui->closeTitleBtn->raise();
|
||
ui->menuBtn->raise();
|
||
|
||
if (dialog_repeat)
|
||
dialog_repeat->close();
|
||
if (dialog_music)
|
||
dialog_music->close();
|
||
}
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
}
|
||
|
||
void Clock::saveClockToDatabase(int rowNum)
|
||
{
|
||
QString clockName = clockEditOnClockNew->clockNameLineEdit->text();
|
||
model->insertRow(rowNum);
|
||
|
||
model->setData(model->index(rowNum, 0), timer_alarm_start24->m_currentValue);
|
||
model->setData(model->index(rowNum, 1), timer_alarm_start60->m_currentValue);
|
||
QString bellId = getSelectBellId(dialog_music);
|
||
model->setData(model->index(rowNum, 2), bellId);
|
||
model->setData(model->index(rowNum, 15), remind_late_str_model);
|
||
model->setData(model->index(rowNum, 3), int(0));
|
||
model->setData(model->index(rowNum, 4), int(model->index(rowNum-1, 4).data().toInt()+1));
|
||
model->setData(model->index(rowNum, 5), repeat_str_model);
|
||
model->setData(model->index(rowNum, 13), clockName);
|
||
//主键
|
||
auto id = Utils::getRandomId();
|
||
model->setData(model->index(rowNum, 14), id);
|
||
for (int i=0; i<7; i++) {
|
||
model->setData(model->index(rowNum, i+6), repeat_day[i]);
|
||
}
|
||
model->submitAll();
|
||
|
||
for (int i=0; i<rowNum; i++) {
|
||
delete aItem[i];
|
||
delete w1[i];
|
||
}
|
||
qDebug() << model->index(rowNum, 0).data().toString()
|
||
<< model->index(rowNum, 1).data().toString()
|
||
<< QFileInfo( model->index(rowNum, 2).data().toString() ).fileName();
|
||
updateAlarmClock();
|
||
}
|
||
|
||
QString Clock::getSelectBellId(set_alarm_repeat_Dialog *tempDialog)
|
||
{
|
||
int num=tempDialog->listWidget->currentRow();
|
||
QString id = m_selectBtnUtil->getBellIdByIndex(num);
|
||
return id;
|
||
}
|
||
|
||
QString Clock::addAlarm(clockInterface::RequestParams param)
|
||
{
|
||
return addAlarm(param.clockName,param.hour,param.minute);
|
||
}
|
||
|
||
QString Clock::addAlarmJosn(QString param)
|
||
{
|
||
neb::CJsonObject oJson(param.toStdString());
|
||
QString clockName = QString::fromStdString(oJson["clockName"].ToString());
|
||
QString hour = QString::fromStdString(oJson["hour"].ToString());
|
||
QString minute = QString::fromStdString(oJson["minute"].ToString());
|
||
if(FieldValidUtil::isNull(hour)){
|
||
return formatReturnMsg(clockInterface::FAIL,"小时为空");
|
||
}
|
||
if(FieldValidUtil::isNull(minute)){
|
||
return formatReturnMsg(clockInterface::FAIL,"分钟为空");
|
||
}
|
||
return addAlarm(clockName, hour.toInt(), minute.toInt());
|
||
}
|
||
|
||
QString Clock::updateClockByIdJosn(QString param)
|
||
{
|
||
neb::CJsonObject oJson(param.toStdString());
|
||
QString id = QString::fromStdString(oJson["id"].ToString());
|
||
if(FieldValidUtil::isNull(id)){
|
||
return formatReturnMsg(clockInterface::FAIL,"主键id为空");
|
||
}
|
||
id = FieldValidUtil::QStringFilter(id);
|
||
QString clockName = QString::fromStdString(oJson["clockName"].ToString());
|
||
QString hour = QString::fromStdString(oJson["hour"].ToString());
|
||
QString minute = QString::fromStdString(oJson["minute"].ToString());
|
||
if(FieldValidUtil::isNull(clockName)&&FieldValidUtil::isNull(hour)&&FieldValidUtil::isNull(minute)){
|
||
return formatReturnMsg(clockInterface::FAIL,"没有需要修改的数据");
|
||
}
|
||
updateClockDatabase(id,clockName,hour,minute,0);
|
||
return formatReturnMsg(clockInterface::SUCCESS,"闹钟修改成功");
|
||
}
|
||
|
||
QString Clock::selectClockByIdJosn(QString param)
|
||
{
|
||
neb::CJsonObject oJson(param.toStdString());
|
||
QString id = QString::fromStdString(oJson["id"].ToString());
|
||
if(FieldValidUtil::isNull(id)){
|
||
return formatReturnMsg(clockInterface::FAIL,"主键id为空");
|
||
}
|
||
id = FieldValidUtil::QStringFilter(id);
|
||
auto sqlQuery = getClockByPK(id);
|
||
QString queryId = sqlQuery.value(14).toString();
|
||
if(FieldValidUtil::isNull(queryId)){
|
||
return formatReturnMsg(clockInterface::FAIL,"查询结果为空");
|
||
}
|
||
oJson.Add("name",sqlQuery.value(13).toString().toStdString());
|
||
oJson.Add("hour",sqlQuery.value( 0).toInt());
|
||
oJson.Add("minute",sqlQuery.value( 1).toInt());
|
||
return formatReturnMsg(oJson,clockInterface::SUCCESS,"闹钟查询成功");
|
||
}
|
||
|
||
QString Clock::deleteClockByIdJosn(QString param)
|
||
{
|
||
neb::CJsonObject oJson(param.toStdString());
|
||
QString id = QString::fromStdString(oJson["id"].ToString());
|
||
if(FieldValidUtil::isNull(id)){
|
||
return formatReturnMsg(clockInterface::FAIL,"主键id为空");
|
||
}
|
||
id = FieldValidUtil::QStringFilter(id);
|
||
deleteAlarmDatabase(id);
|
||
return formatReturnMsg(clockInterface::SUCCESS,"闹钟删除成功");
|
||
}
|
||
|
||
QString Clock::addAlarm(QString clockName, int hour, int minute)
|
||
{
|
||
//表单验证
|
||
if(FieldValidUtil::isNull(clockName)){
|
||
return formatReturnMsg(clockInterface::FAIL,"闹钟名为空");
|
||
}
|
||
QString clockNameQstr = FieldValidUtil::QStringFilter(clockName);
|
||
if(clockNameQstr.length()>16){
|
||
return formatReturnMsg(clockInterface::FAIL,"闹钟名超过16个字");
|
||
}
|
||
if(!FieldValidUtil::isValueBetweenRange(hour,0,23)){
|
||
return formatReturnMsg(clockInterface::FAIL,"小时位不是0-23之间的整数");
|
||
}
|
||
if(!FieldValidUtil::isValueBetweenRange(minute,0,59)){
|
||
return formatReturnMsg(clockInterface::FAIL,"分钟位不是0-59之间的整数");
|
||
}
|
||
int rowNum;
|
||
rowNum = model->rowCount();
|
||
if(rowNum>=20){
|
||
return formatReturnMsg(clockInterface::FAIL,"闹钟数已达上限");
|
||
}
|
||
|
||
//存储到数据库
|
||
model->insertRow(rowNum);
|
||
model->setData(model->index(rowNum, 0), hour);
|
||
model->setData(model->index(rowNum, 1), minute);
|
||
model->setData(model->index(rowNum, 2), tr("glass"));
|
||
model->setData(model->index(rowNum, 3), int(0));
|
||
model->setData(model->index(rowNum, 4), int(model->index(rowNum-1, 4).data().toInt()+1));
|
||
model->setData(model->index(rowNum, 5), tr("No repetition"));
|
||
model->setData(model->index(rowNum, 13), clockNameQstr);
|
||
//主键
|
||
auto id = Utils::getRandomId();
|
||
model->setData(model->index(rowNum, 14), id);
|
||
for (int i=0; i<7; i++) {
|
||
model->setData(model->index(rowNum, i+6), 1);
|
||
}
|
||
model->submitAll();
|
||
for (int i=0; i<rowNum; i++) {
|
||
delete aItem[i];
|
||
delete w1[i];
|
||
}
|
||
updateAlarmClock();
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
neb::CJsonObject oJson;
|
||
oJson.Add("id",id.toStdString());
|
||
return formatReturnMsg(oJson,clockInterface::SUCCESS,"闹钟添加成功");
|
||
}
|
||
|
||
QString Clock::formatReturnMsg(neb::CJsonObject oJson, clockInterface::STATUS_CODE status, std::string msg)
|
||
{
|
||
oJson.Add("status",status);
|
||
oJson.Add("msg",msg);
|
||
return QString::fromStdString(oJson.ToString());
|
||
}
|
||
/**
|
||
* @brief 构造返回值
|
||
* @param status 状态
|
||
* @param msg 返回信息
|
||
* @return
|
||
*/
|
||
QString Clock::formatReturnMsg(STATUS_CODE status, string msg)
|
||
{
|
||
|
||
neb::CJsonObject oJson;
|
||
oJson.Add("status",status);
|
||
oJson.Add("msg",msg);
|
||
return QString::fromStdString(oJson.ToString());
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
/*
|
||
*闹钟新建界面取消回调
|
||
* Cancel callback in alarm new interface
|
||
*/
|
||
void Clock::alarmCancelSave()
|
||
{
|
||
ui->mainWidget->setCurrentIndex(1);
|
||
ui->mainWidget->raise();
|
||
ui->minmizeBtn->raise();
|
||
ui->closeTitleBtn->raise();
|
||
ui->menuBtn->raise();
|
||
}
|
||
|
||
/*
|
||
* 双击闹钟打开重编辑页面
|
||
* Double click the alarm clock to open the re edit page
|
||
*/
|
||
void Clock::listdoubleClickslot()
|
||
{
|
||
onEditPage = true;
|
||
ui->mainWidget->setCurrentIndex(3);
|
||
//以链表序号找寻数据
|
||
auto curentId = getClockPkByCurrentNum();
|
||
//根据id查询数据
|
||
auto sqlQuery = getClockByPK(curentId);
|
||
timer_alarm_start24->m_currentValue=sqlQuery.value( 0).toInt();
|
||
timer_alarm_start60->m_currentValue=sqlQuery.value( 1).toInt();
|
||
repeat_new_or_edit_flag = 1;
|
||
QString werk_day ;
|
||
int werk = 0;
|
||
for (int i=0; i<7; i++) {
|
||
if (sqlQuery.value( 6+i).toInt()) {
|
||
if(i == 0){
|
||
werk_day = werk_day + tr("Mon")+" ";
|
||
}else if(i == 1){
|
||
werk_day = werk_day + tr("Tue")+" ";
|
||
}else if(i == 2){
|
||
werk_day = werk_day + tr("Wed")+" ";
|
||
}else if(i == 3){
|
||
werk_day = werk_day + tr("Thu")+" ";
|
||
}else if(i == 4){
|
||
werk_day = werk_day + tr("Fri")+" ";
|
||
}else if(i == 5){
|
||
werk_day = werk_day + tr("Sat")+" ";
|
||
}else if(i == 6){
|
||
werk_day = werk_day + tr("Sun")+" ";
|
||
}
|
||
}else{
|
||
werk = 1;
|
||
}
|
||
}
|
||
if(werk){
|
||
repeatSelectOnClockNew->textLabel->setText(werk_day);
|
||
}else {
|
||
repeatSelectOnClockNew->textLabel->setText(tr("Every day"));
|
||
}
|
||
if(sqlQuery.value( 5).toString() == tr(" work") || sqlQuery.value( 5).toString() == tr(" 工作日")){
|
||
repeatSelectOnClockNew->textLabel->setText(tr(" work"));
|
||
}
|
||
if(sqlQuery.value( 5).toString() == tr("No repetition") || sqlQuery.value( 5).toString() == tr("不重复")){
|
||
repeatSelectOnClockNew->textLabel->setText(tr("No repetition"));
|
||
}
|
||
repeat_str_model = sqlQuery.value( 5).toString();
|
||
|
||
updateRepeatStr(repeatSelectOnClockNew->textLabel);
|
||
|
||
QString bellId = sqlQuery.value( 2).toString();
|
||
auto name = m_selectBtnUtil->getBellNameById(bellId);
|
||
musicSelectOnClockNew->textLabel->setText(name);
|
||
setMusicSelectDialogListById(bellId,dialog_music->listWidget);
|
||
|
||
//重复
|
||
remind_late_str_model = sqlQuery.value( 15).toString();
|
||
qDebug()<<"从数据库查稍后"<<remind_late_str_model;
|
||
int status = getRemindStatusByName(remind_late_str_model);
|
||
remind_late_str_model = getRemindLateStrFromNum(status);
|
||
remindSelectOnClockNew->textLabel->setText(remind_late_str_model);
|
||
setRemindLateSelectDialogListByName(remind_late_str_model,dialog_remind_late->listWidget);
|
||
|
||
clock_name = sqlQuery.value( 13).toString();
|
||
clockEditOnClockNew->clockNameLineEdit->setText(clock_name);
|
||
for (int i=0; i<7; i++) {
|
||
if (sqlQuery.value( 6+i).toInt()) {
|
||
repeat_day[i] = 1;
|
||
} else {
|
||
repeat_day[i] = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
QString Clock::getClockPkByCurrentNum()
|
||
{
|
||
int num = ui->alarmListWidget->currentRow();
|
||
auto widgetItem = static_cast<item_new *>(ui->alarmListWidget->itemWidget(aItem[num]));
|
||
auto curentId = widgetItem->id();
|
||
return curentId;
|
||
}
|
||
|
||
QSqlQuery Clock::getClockByPK(QString id)
|
||
{
|
||
auto sqlQuery = clock_sql::getQSqlQuery();
|
||
sqlQuery.prepare("select * from clock where id=:id");
|
||
sqlQuery.bindValue(":id",id);
|
||
sqlQuery.exec();
|
||
sqlQuery.next();
|
||
return sqlQuery;
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
* 闹钟重编辑页面删除闹钟回调
|
||
* Alarm re edit page delete alarm callback
|
||
*/
|
||
void Clock::deleteAlarm()
|
||
{
|
||
int rowNum = model->rowCount();
|
||
|
||
|
||
/*
|
||
delete_msg *deletemsg = new delete_msg();
|
||
QPointF position = this->pos();
|
||
deletemsg->move(position.x()+35,position.y()+200);
|
||
deletemsg->exec();
|
||
*/
|
||
|
||
/*
|
||
* 重新适配QMessageBox控件
|
||
* Refit the qmessagebox control
|
||
*/
|
||
int ret;
|
||
QMessageBox msg(this);
|
||
|
||
msg.setIcon(QMessageBox::Question);
|
||
msg.setWindowTitle(QObject::tr("Hint"));
|
||
msg.setText(QObject::tr("Are you sure to delete?"));
|
||
msg.addButton(QObject::tr("sure"), QMessageBox::AcceptRole);
|
||
msg.addButton(QObject::tr("cancel"), QMessageBox::RejectRole);
|
||
|
||
ret = msg.exec();
|
||
|
||
if (ret == QMessageBox::RejectRole) {
|
||
qDebug()<<"dbq-不删除";
|
||
} else {
|
||
//删除数据
|
||
auto curentId = getClockPkByCurrentNum();
|
||
deleteAlarmDatabase(curentId);
|
||
rowNum = model->rowCount();
|
||
qDebug() << rowNum;
|
||
|
||
}
|
||
//闹钟页面子项
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
}
|
||
|
||
void Clock::deleteAlarmDatabase(QString id)
|
||
{
|
||
int rowNum = model->rowCount();
|
||
auto sqlQuery = clock_sql::getQSqlQuery();
|
||
sqlQuery.prepare("delete from clock where id=:id");
|
||
sqlQuery.bindValue(":id",id);
|
||
sqlQuery.exec();
|
||
for (int i=0; i<rowNum; i++) {
|
||
delete w1[i];
|
||
delete aItem[i];
|
||
}
|
||
model->submitAll();
|
||
updateAlarmClock();
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
}
|
||
|
||
void Clock::updateClockDatabase(QString id, QString name, QString hour, QString minute, int onOff)
|
||
{
|
||
QString sql = "update clock set ";
|
||
if(FieldValidUtil::isNotNull(name)){
|
||
sql = sql.append(" Name=:clockName , ");
|
||
}
|
||
if(FieldValidUtil::isNotNull(hour)){
|
||
sql = sql.append(" Hour=:hour , ");
|
||
}
|
||
if(FieldValidUtil::isNotNull(minute)){
|
||
sql = sql.append(" Minute=:minute , ");
|
||
}
|
||
sql = sql.append(" on_or_off=:onOff , ");
|
||
sql = sql.remove(sql.length()-2,2);
|
||
sql = sql.append(" where Id=:id");
|
||
int rowNum = model->rowCount();
|
||
auto sqlQuery = clock_sql::getQSqlQuery();
|
||
sqlQuery.prepare(sql);
|
||
sqlQuery.bindValue(":id",id);
|
||
//绑定数据
|
||
if(FieldValidUtil::isNotNull(name)){
|
||
name = FieldValidUtil::QStringFilter(name);
|
||
sqlQuery.bindValue(":clockName",name);
|
||
}
|
||
if(FieldValidUtil::isNotNull(hour)){
|
||
sqlQuery.bindValue(":hour",hour.toInt());
|
||
}
|
||
if(FieldValidUtil::isNotNull(minute)){
|
||
sqlQuery.bindValue(":minute",minute.toInt());
|
||
}
|
||
sqlQuery.bindValue(":onOff",onOff);
|
||
sqlQuery.exec();
|
||
model->submitAll();
|
||
if(FieldValidUtil::isNotNull(name)||FieldValidUtil::isNotNull(hour)||FieldValidUtil::isNotNull(minute)){
|
||
for (int i=0; i<rowNum; i++) {
|
||
delete w1[i];
|
||
delete aItem[i];
|
||
}
|
||
updateAlarmClock();
|
||
updateAlarmItemFront(CURRENT_FONT_SIZE);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
* 闹钟开关
|
||
* Alarm switch
|
||
*/
|
||
void Clock::OnOffAlarm()
|
||
{
|
||
int i=0 ;
|
||
KSwitchButton *btn = qobject_cast<KSwitchButton*>(QObject::sender());
|
||
while (btn != w1[i]->alarm_on_off0) {
|
||
i++;
|
||
}
|
||
QString id = w1[i]->id();
|
||
auto sqlQuery = getClockByPK(id);
|
||
if (sqlQuery.value(3).toInt() == 0) {
|
||
// btn->closeSlot();
|
||
w1[i]->closeStyle(CURRENT_FONT_SIZE);
|
||
updateClockDatabase(id,nullptr,nullptr,nullptr,1);
|
||
} else {
|
||
// btn->openSlot();
|
||
w1[i]->openStyle(CURRENT_FONT_SIZE);
|
||
updateClockDatabase(id,nullptr,nullptr,nullptr,0);
|
||
}
|
||
}
|
||
/*
|
||
* 不重复时单独关闭闹钟
|
||
* Turn off the alarm separately if it is not repeated
|
||
*/
|
||
void Clock::offAlarm(int i)
|
||
{
|
||
w1[i]->alarm_on_off0->setChecked(false);
|
||
model->setData(model->index(i, 3), int(1));
|
||
model->submitAll();
|
||
|
||
int rowNum = model->rowCount();
|
||
for (int i = 0; i < rowNum; i++) {
|
||
delete aItem[i];
|
||
delete w1[i];
|
||
}
|
||
updateAlarmClock();
|
||
}
|
||
|
||
/*
|
||
* 倒计时音乐选择
|
||
* Countdown music selection
|
||
*/
|
||
void Clock::countdownMusicSellect()
|
||
{
|
||
musicSelectOnCountdownSet->updateIconLabel(1);
|
||
musicSelectOnCountdownRun->updateIconLabel(1);
|
||
QPointF position = this->pos();
|
||
count_music_sellect->move(position.x()+DIALOG_MOVE_WIDTH,position.y()+482);
|
||
count_music_sellect->setWindowFlags(Qt::Popup);
|
||
refreshMusicSelectList(count_music_sellect);
|
||
count_music_sellect->show();
|
||
// connect(count_music_sellect->listWidget,SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(countMusicListclickslot()));
|
||
}
|
||
/*
|
||
* 倒计时音乐选择单机回调
|
||
* Countdown music selection single callback
|
||
*/
|
||
void Clock::countMusicListclickslot()
|
||
{
|
||
int num=count_music_sellect->listWidget->currentRow();
|
||
int size = count_music_sellect->rowNum_all;
|
||
//最后一个自定义铃声
|
||
if(num==(size-1)){
|
||
addDivBell(count_music_sellect,Clock::count_down);
|
||
}else{
|
||
QString id = m_selectBtnUtil->getBellIdByIndex(num);
|
||
QString path = m_selectBtnUtil->getBellPathById(id);
|
||
QString name = m_selectBtnUtil->getBellNameById(id);
|
||
musicSelectOnClockNew->textLabel->setText(name);
|
||
//排除无
|
||
if(num==0){
|
||
path="";
|
||
}
|
||
playMusicFromPath(path);
|
||
model_setup->setData(model_setup->index(0, 1), id);
|
||
musicSelectOnCountdownSet->textLabel->setText(name);
|
||
musicSelectOnCountdownRun->textLabel->setText(name);
|
||
model_setup->submitAll();
|
||
}
|
||
count_music_sellect->close();
|
||
}
|
||
|
||
void Clock::playMusicFromPath(QString path)
|
||
{
|
||
// delete musicSelectPlay;
|
||
// musicSelectPlay = new QMediaPlayer(this);
|
||
//停止上次播放
|
||
// stopHisPlay();
|
||
|
||
// delete music;
|
||
// music = new QMediaPlayer();
|
||
// music->setMedia(QUrl::fromLocalFile(path));
|
||
// music->play();
|
||
|
||
playController::getInstance().playSingleSong(path,0);
|
||
|
||
}
|
||
|
||
void Clock::stopHisPlay()
|
||
{
|
||
if(hisPlayer!=nullptr){
|
||
hisPlayer->stop();
|
||
}
|
||
}
|
||
//TODO 加按钮
|
||
void Clock::addDivBell(set_alarm_repeat_Dialog *tempDialog, btnType type)
|
||
{
|
||
QString filePath = m_selectBtnUtil->openAudioFileDialog(tempDialog);
|
||
if(FieldValidUtil::isNotNull(filePath)){
|
||
qWarning()<<"dbq-开始复制"<<filePath;
|
||
//复制文件
|
||
QString toPatn = m_selectBtnUtil->copyAudioFile(filePath);
|
||
//存储到数据库
|
||
QString bellId = m_selectBtnUtil->saveToBellTable(toPatn);
|
||
QString name = m_selectBtnUtil->getBellNameById(bellId);
|
||
|
||
if(type==Clock::count_down){
|
||
musicSelectOnCountdownSet->textLabel->setText(name);
|
||
musicSelectOnCountdownRun->textLabel->setText(name);
|
||
}else{
|
||
musicSelectOnClockNew->textLabel->setText(name);
|
||
}
|
||
|
||
playMusicFromPath(toPatn);
|
||
//刷新窗体
|
||
// rebuildCountdownMusicDialog();
|
||
//选中新建的铃声
|
||
// setMusicSelectDialogListById(bellId,count_music_sellect->listWidget);
|
||
}
|
||
}
|
||
|
||
//倒计时执行
|
||
// Countdown execution
|
||
void Clock::statCountdown(){
|
||
//减1算法
|
||
if(countdown_second>0){
|
||
countdown_second--;
|
||
}else if(countdown_second==0&&countdown_minute>=1){
|
||
countdown_minute--;
|
||
countdown_second=59;
|
||
}else if(countdown_second==0&&countdown_minute==0&&countdown_hour>=1){
|
||
countdown_hour--;
|
||
countdown_minute=59;
|
||
countdown_second=59;
|
||
}
|
||
|
||
QString h; QString m; QString s;
|
||
if (countdown_hour < 10){
|
||
QString hours_str = QString::number(countdown_hour);
|
||
h = "0"+hours_str;
|
||
} else {
|
||
h = QString::number(countdown_hour);
|
||
}
|
||
if (countdown_minute < 10) {
|
||
QString minute_str = QString::number(countdown_minute);
|
||
m = "0"+minute_str;
|
||
} else {
|
||
m = QString::number(countdown_minute);
|
||
}
|
||
|
||
if (countdown_second < 10) {
|
||
QString second_str = QString::number(countdown_second);
|
||
s = "0"+second_str;
|
||
}else {
|
||
s = QString::number(countdown_second);
|
||
}
|
||
ui->remainTime->setText(h+TIME_SEPARATOR+m+TIME_SEPARATOR+s);
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(40);
|
||
ui->remainTime->setFont(f);
|
||
|
||
//设置倒计时托盘tooltip
|
||
QString tooltip = tr("Count down");
|
||
tooltip +=TIME_SEPARATOR_CN+h+TIME_SEPARATOR+m+TIME_SEPARATOR+s;
|
||
updateTrayIconTooltip(tooltip);
|
||
|
||
//小型倒计时 显示倒计时时间
|
||
if(this->m_selectTinyCountdown){
|
||
if(checkTinyCountdownDia()){
|
||
tinycountdownDia->updateTimeInfo(h+TIME_SEPARATOR+m+TIME_SEPARATOR+s);
|
||
}
|
||
}
|
||
//时间归零
|
||
if (countdown_hour==0 && countdown_minute==0 && (countdown_second)==0) {
|
||
startbtnCountdown();
|
||
countdown_timer->stop();
|
||
//托盘恢复默认
|
||
setDefaultTrayIconTooltip();
|
||
//倒计时通知弹窗
|
||
countdownNoticeDialogShow();
|
||
}
|
||
}
|
||
|
||
void Clock::statCountdownMsec()
|
||
{
|
||
countdown_msec-=10;
|
||
if(countdown_msec<=0){
|
||
//减1算法
|
||
if(countdown_second>0){
|
||
countdown_second--;
|
||
}else if(countdown_second==0&&countdown_minute>=1){
|
||
countdown_minute--;
|
||
countdown_second=59;
|
||
}else if(countdown_second==0&&countdown_minute==0&&countdown_hour>=1){
|
||
countdown_hour--;
|
||
countdown_minute=59;
|
||
countdown_second=59;
|
||
}
|
||
countdown_msec=1000;
|
||
}
|
||
//设置当前时间
|
||
int ringmax = countdown_hour*3600 + countdown_minute*60 + countdown_second;
|
||
ui->countdownRunPage->countdownRunRoundBar->setValue(ringmax);
|
||
|
||
QString h; QString m; QString s;
|
||
if (countdown_hour < 10){
|
||
QString hours_str = QString::number(countdown_hour);
|
||
h = "0"+hours_str;
|
||
} else {
|
||
h = QString::number(countdown_hour);
|
||
}
|
||
if (countdown_minute < 10) {
|
||
QString minute_str = QString::number(countdown_minute);
|
||
m = "0"+minute_str;
|
||
} else {
|
||
m = QString::number(countdown_minute);
|
||
}
|
||
|
||
if (countdown_second < 10) {
|
||
QString second_str = QString::number(countdown_second);
|
||
s = "0"+second_str;
|
||
}else {
|
||
s = QString::number(countdown_second);
|
||
}
|
||
ui->remainTime->setText(h+TIME_SEPARATOR+m+TIME_SEPARATOR+s);
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(40);
|
||
ui->remainTime->setFont(f);
|
||
//设置倒计时托盘tooltip
|
||
QString tooltip = tr("Count down");
|
||
tooltip +=TIME_SEPARATOR_CN+h+TIME_SEPARATOR+m+TIME_SEPARATOR+s;
|
||
updateTrayIconTooltip(tooltip);
|
||
|
||
//小型倒计时 显示倒计时时间
|
||
if(this->m_selectTinyCountdown){
|
||
if(checkTinyCountdownDia()){
|
||
tinycountdownDia->updateTimeInfo(h+TIME_SEPARATOR+m+TIME_SEPARATOR+s);
|
||
}
|
||
}
|
||
//时间归零
|
||
if (countdown_hour==0 && countdown_minute==0 && (countdown_second)==0) {
|
||
startbtnCountdown();
|
||
countdown_timer->stop();
|
||
//托盘恢复默认
|
||
setDefaultTrayIconTooltip();
|
||
//倒计时通知弹窗
|
||
countdownNoticeDialogShow();
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 倒计时通知弹窗
|
||
* Countdown notification pop-up
|
||
*/
|
||
void Clock::countdownNoticeDialogShow()
|
||
{
|
||
//关闭tiny倒计时
|
||
if(checkTinyCountdownDia()){
|
||
tinycountdownDia->set_dialog_close();
|
||
}
|
||
|
||
model_setup->select();
|
||
QScreen *screen=QGuiApplication::primaryScreen ();
|
||
QRect mm=screen->availableGeometry() ;
|
||
int screen_width = mm.width();
|
||
int screen_height = mm.height();
|
||
model_setup->select();
|
||
// countdownNoticeDialog->timer_value = 59;
|
||
//多少秒后自动关闭
|
||
countdownNoticeDialog->ui->autoCloseTime->setText(tr("60 Seconds to close"));
|
||
//左上图标
|
||
// countdownNoticeDialog->ui->titleLabel->setText(tr("Alarm"));
|
||
//时间到
|
||
if (alarmNoticeDialog != nullptr) {
|
||
if (alarmNoticeDialog->isVisible() == 0)
|
||
moveUnderMultiScreen(UP_RIGHT,countdownNoticeDialog,1);
|
||
else
|
||
moveUnderMultiScreen(UP_RIGHT,countdownNoticeDialog,0);
|
||
} else
|
||
moveUnderMultiScreen(UP_RIGHT,countdownNoticeDialog,1);
|
||
countdownNoticeDialog->playMusic();
|
||
}
|
||
|
||
/*
|
||
* 倒计时开始-结束
|
||
* Countdown start end callback
|
||
*/
|
||
void Clock::startbtnCountdown(){
|
||
if (!countdown_isStarted) {
|
||
|
||
//点击了开始
|
||
if (hourTimerRing->m_currentValue==0 && minuteTimeRing->m_currentValue==0 && secondTimeRing->m_currentValue==0) {
|
||
return;
|
||
}
|
||
//当前剩余时间,单位秒
|
||
int ringmax = hourTimerRing->m_currentValue*3600 + minuteTimeRing->m_currentValue*60 + secondTimeRing->m_currentValue;
|
||
//进度圈
|
||
ui->countdownRunPage->countdownRunRoundBar->setRange(0,ringmax);
|
||
//切换进度条颜色
|
||
ui->countdownRunPage->countdownRunRoundBar->switchRunRingColor();
|
||
ui->startCountdownBtn->setStyleSheet("");
|
||
countdown_isStarted=1;
|
||
//结束
|
||
ui->startCountdownBtn->setText(tr("End"));
|
||
//点击开始,刷新数值
|
||
refreshCountdownLabel11Flag = true;
|
||
//设置倒计时初始时间label9 中间数字
|
||
setcoutdownNumber(hourTimerRing->m_currentValue, minuteTimeRing->m_currentValue, secondTimeRing->m_currentValue);//获取转轮当前值
|
||
//倒计时页面
|
||
ui->countdownStackedW->setCurrentIndex(1);
|
||
countdown_timer->start();
|
||
//光圈的进度值修改定时启动
|
||
|
||
} else {
|
||
//点击了结束,或者时间耗尽
|
||
ui->countdownRunPage->countdownRunRoundBar->setRange(0,COUNTDOWN_TIME);
|
||
ui->countdownRunPage->countdownRunRoundBar->setValue(COUNTDOWN_TIME);/*初始化倒计时进度圈
|
||
Initialize countdown progress circle*/
|
||
countdown_timer->stop();
|
||
countdown_isStarted=0;
|
||
countdown_isStarted_2=0;
|
||
hourTimerRing->m_currentValue = 0;
|
||
minuteTimeRing->m_currentValue = 0;
|
||
secondTimeRing->m_currentValue = 0;
|
||
ui->startCountdownBtn->setText(tr("start"));
|
||
ui->remainTime->setText("00:00:00");
|
||
//切换到倒计时滚轮页
|
||
ui->countdownStackedW->setCurrentIndex(0);
|
||
//暂停
|
||
ui->suspendCountdownBtn->setText(tr("suspend"));
|
||
|
||
QPalette palette = ui->suspendCountdownBtn->palette();
|
||
QColor ColorPlaceholderText(248,163,76,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText);
|
||
//主题框架1.0.6-5kylin2
|
||
palette.setColor(QPalette::Highlight,QColor(248,163,76,255));
|
||
palette.setColor(QPalette::Button,QColor(248,163,76,255));
|
||
palette.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
ui->suspendCountdownBtn->setPalette(palette);
|
||
//小窗体清零,隐藏
|
||
if(checkTinyCountdownDia()){
|
||
tinycountdownDia->clearData();
|
||
}
|
||
//恢复默认托盘
|
||
setDefaultTrayIconTooltip();
|
||
}
|
||
return;
|
||
}
|
||
|
||
void Clock::tinyCountdownFinish()
|
||
{
|
||
tinycountdownDia->hide();
|
||
activeWindow();
|
||
startbtnCountdown();
|
||
}
|
||
|
||
/*
|
||
* 设置倒计时初始时间
|
||
* Set the initial countdown time
|
||
*/
|
||
void Clock::setcoutdownNumber(int h1, int m1, int s1){
|
||
countdown_hour=h1; countdown_minute=m1 ; countdown_second=s1;
|
||
|
||
QString h; QString m; QString s;
|
||
|
||
if (countdown_hour < 10){
|
||
QString hours_str = QString::number(countdown_hour);
|
||
h = "0"+hours_str;
|
||
} else {
|
||
h = QString::number(countdown_hour);
|
||
}
|
||
|
||
if (countdown_minute < 10) {
|
||
QString minute_str = QString::number(countdown_minute);
|
||
m = "0"+minute_str;
|
||
} else {
|
||
m = QString::number(countdown_minute);
|
||
}
|
||
|
||
if (countdown_second < 10) {
|
||
QString second_str = QString::number(countdown_second);
|
||
s = "0"+second_str;
|
||
} else {
|
||
s = QString::number(countdown_second);
|
||
}
|
||
|
||
ui->remainTime->setText(h+TIME_SEPARATOR+m+TIME_SEPARATOR+s);
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(40);
|
||
ui->remainTime->setFont(f);
|
||
//获取倒计时结束时间
|
||
getCountdownOverTime();
|
||
}
|
||
|
||
/*
|
||
* 倒计时5分钟
|
||
* Countdown 5 minutes set callback
|
||
*/
|
||
void Clock::onMin_5btnClicked()
|
||
{
|
||
hourTimerRing->m_currentValue = 0;
|
||
minuteTimeRing->m_currentValue = 5;
|
||
secondTimeRing->m_currentValue = 0;
|
||
setcoutdownNumber(0, 5, 0);
|
||
}
|
||
|
||
/*
|
||
* 获取倒计时结束时间
|
||
* Get countdown end time
|
||
*/
|
||
void Clock::getCountdownOverTime()
|
||
{
|
||
QTime time = QTime::currentTime();
|
||
int timeH = time.hour();
|
||
int timeM = time.minute();
|
||
int timeS = time.second();
|
||
if(refreshCountdownLabel11Flag){
|
||
x_h = countdown_hour + timeH;
|
||
x_m = countdown_minute + timeM;
|
||
//分钟位进1
|
||
if(countdown_second+timeS>=60){
|
||
x_m+=1;
|
||
}
|
||
refreshCountdownLabel11Flag = false;
|
||
if (x_m >= 60) {
|
||
x_m = x_m - 60;
|
||
x_h ++;
|
||
}
|
||
}
|
||
if (x_h >= 48) {
|
||
x_h = x_h - 48;
|
||
ui->countdownAlarmTime->setText(tr("after tomorrow")+formatX_h(x_h)+TIME_SEPARATOR+changeNumToStr(x_m));
|
||
} else if (x_h >= 24) {
|
||
x_h = x_h - 24;
|
||
ui->countdownAlarmTime->setText(tr("Tomorrow")+formatX_h(x_h)+TIME_SEPARATOR+changeNumToStr(x_m));
|
||
} else{
|
||
ui->countdownAlarmTime->setText(formatX_h(x_h)+TIME_SEPARATOR+changeNumToStr(x_m));
|
||
}
|
||
}
|
||
//上下午格式
|
||
QString Clock::get12hourStr(int x_h)
|
||
{
|
||
QString str;
|
||
//12时
|
||
if (x_h >= 12) {
|
||
x_h = x_h - 12;
|
||
str=tr("PM")+" "+changeNumToStr(x_h);
|
||
} else {
|
||
str=tr("AM")+" "+changeNumToStr(x_h);
|
||
}
|
||
return str;
|
||
}
|
||
/**
|
||
* @brief 创建用户手册dbus客户端
|
||
*/
|
||
void Clock::createUserGuideDebusClient()
|
||
{
|
||
// 用户手册
|
||
QString serviceName = "com.kylinUserGuide.hotel"
|
||
+ QString("%1%2").arg("_").arg(QString::number(getuid()));
|
||
//创建dbus-client
|
||
userGuideInterface = new QDBusInterface(serviceName,
|
||
"/",
|
||
"com.guide.hotel",
|
||
QDBusConnection::sessionBus());
|
||
qDebug() << "connect to kylinUserGuide" << userGuideInterface->isValid();
|
||
if (!userGuideInterface->isValid()) {
|
||
qDebug() << "fail to connect to kylinUserGuide";
|
||
qDebug() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
||
return;
|
||
}
|
||
}
|
||
|
||
void Clock::onTinyClicked()
|
||
{
|
||
this->m_selectTinyCountdown=true;
|
||
//主窗体最小化
|
||
setWindowState(Qt::WindowMinimized);
|
||
moveUnderMultiScreen(UP_RIGHT,tinycountdownDia,0);
|
||
tinycountdownDia->showTop();
|
||
}
|
||
|
||
void Clock::activeWindow()
|
||
{
|
||
setWindowState(Qt::WindowActive);
|
||
}
|
||
//刷新时间格式
|
||
QString Clock::formatX_h(int x_h)
|
||
{
|
||
QString str;
|
||
//跟随系统时间
|
||
if(m_timeZone == "24"){
|
||
str=changeNumToStr(x_h);
|
||
}else{
|
||
//12时
|
||
str =get12hourStr(x_h);
|
||
}
|
||
return str;
|
||
}
|
||
/*
|
||
* 单位变双位
|
||
* Integer to character
|
||
*/
|
||
QString Clock::changeNumToStr(int alarmHour)
|
||
{
|
||
QString str;
|
||
if (alarmHour < 10) {
|
||
QString hours_str = QString::number(alarmHour);
|
||
str = "0"+hours_str;
|
||
} else {
|
||
str = QString::number(alarmHour);
|
||
}
|
||
return str;
|
||
}
|
||
QString Clock::changeNumToStrWithAm(int alarmHour)
|
||
{
|
||
QString str;
|
||
if (system_time_flag) {
|
||
//24时制
|
||
str = changeNumToStr(alarmHour);//转换int为QString
|
||
} else {
|
||
//12时制
|
||
if (alarmHour >= 12) {
|
||
str+=tr("PM")+" ";
|
||
if (alarmHour == 12) {
|
||
str+=changeNumToStr(alarmHour);
|
||
} else {
|
||
str+=changeNumToStr(alarmHour-12);
|
||
}
|
||
} else {
|
||
str+=tr("AM")+" ";
|
||
if (alarmHour == 0) {
|
||
str+=changeNumToStr(12);
|
||
} else {
|
||
str+=changeNumToStr(alarmHour);
|
||
}
|
||
}
|
||
}
|
||
return str;
|
||
}
|
||
/*
|
||
* 倒计时-暂停继续
|
||
* Countdown - pause resume callback
|
||
*/
|
||
void Clock::onCountPushClicked()
|
||
{
|
||
tinycountdownDia->updateOnRunState(countdown_isStarted_2);
|
||
if (countdown_isStarted_2){
|
||
//点击了继续
|
||
ui->suspendCountdownBtn->setText(tr("suspend"));
|
||
//切换进度条颜色
|
||
ui->countdownRunPage->countdownRunRoundBar->switchRunRingColor();
|
||
|
||
QPalette palette = ui->suspendCountdownBtn->palette();
|
||
QColor ColorPlaceholderText(248,163,76,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText);
|
||
//主题框架1.0.6-5kylin2
|
||
palette.setColor(QPalette::Highlight,QColor(248,163,76,255));
|
||
palette.setColor(QPalette::Button,QColor(248,163,76,255));
|
||
palette.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
ui->suspendCountdownBtn->setPalette(palette);
|
||
|
||
countdown_timer->start();
|
||
countdown_isStarted_2=0;
|
||
refreshCountdownLabel11Flag = true;
|
||
getCountdownOverTime();
|
||
} else {
|
||
//点击了暂停
|
||
ui->suspendCountdownBtn->setText(tr("continue"));
|
||
//切换进度条颜色
|
||
ui->countdownRunPage->countdownRunRoundBar->switchStopRingColor();
|
||
|
||
QPalette palette = ui->suspendCountdownBtn->palette();
|
||
QColor ColorPlaceholderText(SWITCH_BTN_HIGHLIGHT_BACK_COLOR);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText);
|
||
//主题框架1.0.6-5kylin2
|
||
palette.setColor(QPalette::Highlight,QColor(69, 173, 110,255));
|
||
palette.setColor(QPalette::Button,QColor(69, 173, 110,255));
|
||
palette.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
ui->suspendCountdownBtn->setPalette(palette);
|
||
|
||
countdown_timer->stop();
|
||
countdown_isStarted_2=1;
|
||
}
|
||
|
||
return;
|
||
}
|
||
|
||
/*
|
||
* 倒计时初始数字转盘
|
||
* Countdown initial digital dial
|
||
*/
|
||
void Clock::countdownSetStartTime()
|
||
{
|
||
|
||
//倒计时小时滚轮
|
||
hourTimerRing = new VerticalScroll_99(ui->countdownSetPage);
|
||
QLabel * h_in_m = new QLabel (ui->countdownSetPage);
|
||
//倒计时分钟
|
||
minuteTimeRing = new VerticalScroll_60(ui->countdownSetPage);
|
||
QLabel * m_in_s = new QLabel (ui->countdownSetPage);
|
||
//倒计时秒
|
||
secondTimeRing = new VerticalScroll_60(ui->countdownSetPage);
|
||
QLabel * after_s = new QLabel (ui->countdownSetPage);
|
||
|
||
|
||
h_in_m->resize(50,30);
|
||
h_in_m->setText(tr("hour"));
|
||
// h_in_m->setStyleSheet("font: 30pt 'Sans Serif';");
|
||
m_in_s->resize(50,30);
|
||
m_in_s->setText(tr("min"));
|
||
// m_in_s->setStyleSheet("font: 30pt 'Sans Serif';");
|
||
after_s->resize(50,30);
|
||
after_s->setText(tr("sec"));
|
||
// after_s->setStyleSheet("font: 30pt 'Sans Serif';");
|
||
int ringMoveWidth = 73;
|
||
int ringMoveHeight = 45;
|
||
int timeSep = 100;
|
||
int labelSep = 55;
|
||
int timeLabelMoveHeight = 130;
|
||
hourTimerRing->move(ringMoveWidth, ringMoveHeight);
|
||
h_in_m->move(ringMoveWidth+labelSep,timeLabelMoveHeight);
|
||
//hour 要比min长
|
||
if(Utils::checkLocalUs()){
|
||
ringMoveWidth+=timeSep+4;
|
||
}else{
|
||
ringMoveWidth+=timeSep;
|
||
}
|
||
minuteTimeRing->move(ringMoveWidth, ringMoveHeight);
|
||
m_in_s->move(ringMoveWidth+labelSep,timeLabelMoveHeight);
|
||
ringMoveWidth+=timeSep;
|
||
secondTimeRing->move(ringMoveWidth, ringMoveHeight);
|
||
after_s->move(ringMoveWidth+labelSep,timeLabelMoveHeight);
|
||
//配置倒计时页的开始按钮
|
||
startCountSingle = new QPushButton(ui->countdownSetPage);
|
||
startCountSingle->resize(120,34);
|
||
startCountSingle->move(135,401);
|
||
startCountSingle->setText(tr("start"));
|
||
connect(startCountSingle, SIGNAL(clicked()), this, SLOT(startbtnCountdown()) );
|
||
|
||
QPalette palette2 = startCountSingle->palette();
|
||
QColor ColorPlaceholderText2(233,233,233,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText2);
|
||
palette2.setColor(QPalette::Button,QColor(233,233,233,255));
|
||
//palette2.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
startCountSingle->setPalette(palette2);
|
||
|
||
QTimer *timer_count_start;
|
||
timer_count_start = new QTimer();
|
||
connect(timer_count_start, SIGNAL(timeout()), this, SLOT(countStatBtnGray()));
|
||
timer_count_start->setInterval(100);
|
||
timer_count_start->start();
|
||
}
|
||
|
||
/*
|
||
* 倒计时页开始键致灰
|
||
* Start button of countdown page grays out
|
||
*/
|
||
void Clock::countStatBtnGray()
|
||
{
|
||
if(hourTimerRing->m_currentValue==0 && minuteTimeRing->m_currentValue==0 && secondTimeRing->m_currentValue==0) {
|
||
startCountSingle->setEnabled(false);
|
||
QStyleOption opt;
|
||
opt.init(this);
|
||
|
||
if(theme::themetype==0){
|
||
QPalette palette2 = startCountSingle->palette();
|
||
QColor ColorPlaceholderText2(233,233,233,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText2);
|
||
palette2.setColor(QPalette::Button,QColor(233,233,233,255));
|
||
palette2.setBrush(QPalette::ButtonText, QBrush(QColor(158,158,158,255)));
|
||
startCountSingle->setPalette(palette2);
|
||
}else{
|
||
QPalette palette2 = startCountSingle->palette();
|
||
QColor ColorPlaceholderText2(45,45,48,255);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText2);
|
||
palette2.setColor(QPalette::Button,QColor(45,45,48,255));
|
||
palette2.setBrush(QPalette::ButtonText, QBrush(QColor(58,58,58,255)));
|
||
startCountSingle->setPalette(palette2);
|
||
}
|
||
}else{
|
||
startCountSingle->setEnabled(true);
|
||
QPalette palette2 = startCountSingle->palette();
|
||
QColor ColorPlaceholderText2(SWITCH_BTN_HIGHLIGHT_BACK_COLOR);
|
||
QBrush brush2;
|
||
brush2.setColor(ColorPlaceholderText2);
|
||
palette2.setColor(QPalette::Button,QColor(SWITCH_BTN_HIGHLIGHT_BACK_COLOR));
|
||
palette2.setBrush(QPalette::ButtonText, QBrush(Qt::white));
|
||
startCountSingle->setPalette(palette2);
|
||
}
|
||
}
|
||
|
||
|
||
void Clock::updateLabelFront(QLabel *label, int size)
|
||
{
|
||
QString styleSheet = "font-size:";
|
||
styleSheet.append(QString::number(size)).append("px;");
|
||
label->setStyleSheet(styleSheet);
|
||
}
|
||
|
||
void Clock::updateQLineEditFront(QLineEdit *lineEdit, int size)
|
||
{
|
||
QFont font ;
|
||
font.setPixelSize(size);
|
||
lineEdit->setFont(font);
|
||
}
|
||
/**
|
||
* @brief 放大闹钟子项字体
|
||
*/
|
||
void Clock::updateAlarmItemFront(int size)
|
||
{
|
||
QListWidget * alarmList = ui->alarmListWidget;
|
||
for (int i=0;i<alarmList->count() ;i++ ) {
|
||
QListWidgetItem * varItem = alarmList->item(i);
|
||
item_new * varWidget = static_cast<item_new*>(alarmList->itemWidget(varItem)) ;
|
||
varWidget->commonStyle(size);
|
||
}
|
||
}
|
||
|
||
void Clock::updateStopwatchItemFront(int size)
|
||
{
|
||
QListWidget * stopwatchList = ui->timeListWidget;
|
||
for (int i=0;i<stopwatchList->count() ;i++ ) {
|
||
QListWidgetItem * varItem = stopwatchList->item(i);
|
||
stopwatch_item * varWidget = static_cast<stopwatch_item*>(stopwatchList->itemWidget(varItem)) ;
|
||
updateLabelFront(varWidget->stopwatch1,round(1.1*size));
|
||
updateLabelFront(varWidget->stopwatch2,round(1.1*size));
|
||
updateLabelFront(varWidget->stopwatch3,round(2.2*size));
|
||
}
|
||
}
|
||
void Clock::updateFront(const int size)
|
||
{
|
||
|
||
//闹钟页面子项
|
||
updateAlarmItemFront(size);
|
||
//秒表页面 两个时间
|
||
updateLabelFront(ui->timeShowBig,round(3.2*size));
|
||
updateLabelFront(ui->timeShowSmall,round(1.73*size));
|
||
//秒表页面子项
|
||
updateStopwatchItemFront(size);
|
||
double font = 1.15;
|
||
//闹钟编辑页面
|
||
//重复
|
||
updateLabelFront(repeatSelectOnClockNew->nameLabel,round(font*size));
|
||
updateLabelFront(repeatSelectOnClockNew->textLabel,round(font*size));
|
||
//提醒铃声
|
||
updateLabelFront(musicSelectOnClockNew->nameLabel,round(font*size));
|
||
updateLabelFront(musicSelectOnClockNew->textLabel,round(font*size));
|
||
//稍后提醒
|
||
updateLabelFront(remindSelectOnClockNew->nameLabel,round(font*size));
|
||
updateLabelFront(remindSelectOnClockNew->textLabel,round(font*size));
|
||
//倒计时 set 铃声
|
||
updateLabelFront(musicSelectOnCountdownSet->nameLabel,round(font*size));
|
||
updateLabelFront(musicSelectOnCountdownSet->textLabel,round(font*size));
|
||
//倒计时 run 铃声
|
||
updateLabelFront(musicSelectOnCountdownRun->nameLabel,round(font*size));
|
||
updateLabelFront(musicSelectOnCountdownRun->textLabel,round(font*size));
|
||
//闹钟名
|
||
updateLabelFront(clockEditOnClockNew->nameLabel,round(font*size));
|
||
//闹钟编辑
|
||
updateQLineEditFront(clockEditOnClockNew->clockNameLineEdit,round(font*size));
|
||
}
|
||
void Clock::updateRepeatStr(QLabel *label){
|
||
if(Utils::checkLocalChina()){
|
||
updateLabelTextByLength(label,16);
|
||
}
|
||
if(Utils::checkLocalUs()){
|
||
updateLabelTextByLength(label,25);
|
||
}
|
||
}
|
||
void Clock::updateLabelTextByLength(QLabel *label, int limitSize)
|
||
{
|
||
QString str = label->text();
|
||
if(str.length()>limitSize){
|
||
label->setToolTip(str);
|
||
str = Utils::getOmitStr(str,limitSize);
|
||
}
|
||
label->setText(str);
|
||
}
|
||
|
||
|
||
/*
|
||
* 闹钟初始化数字转盘
|
||
* Alarm clock initialization digital turntable drawing
|
||
*/
|
||
void Clock::alarmSetStartTime()
|
||
{
|
||
shadow = new QWidget(ui->editAlarmPage);
|
||
shadow->move(115,58);
|
||
shadow->resize(160,58);
|
||
//闹钟小时滚轮
|
||
timer_alarm_start24 = new VerticalScroll_24(ui->editAlarmPage, this);
|
||
QLabel * h_in_m = new QLabel (ui->editAlarmPage);
|
||
//闹钟分钟滚轮
|
||
timer_alarm_start60 = new VerticalScroll_60(ui->editAlarmPage);
|
||
|
||
timer_alarm_start24->resize(63,220);
|
||
timer_alarm_start60->resize(63,220);
|
||
|
||
QLabel * hour_ring = new QLabel (ui->editAlarmPage);
|
||
QLabel * min_ring = new QLabel (ui->editAlarmPage);
|
||
|
||
hour_ring->hide();
|
||
min_ring->hide();
|
||
|
||
hour_ring->setAlignment(Qt::AlignHCenter);
|
||
min_ring->setAlignment(Qt::AlignHCenter);
|
||
|
||
h_in_m->resize(10,40);
|
||
h_in_m->setText(TIME_SEPARATOR);
|
||
h_in_m->setStyleSheet("font: 25pt;");
|
||
|
||
hour_ring->resize(50,30);
|
||
hour_ring->setText(tr("hour"));
|
||
hour_ring->setStyleSheet("font: 13pt ;color: rgb(148, 148, 148);");
|
||
min_ring->resize(50,30);
|
||
min_ring->setText(tr("min"));
|
||
min_ring->setStyleSheet("font: 13pt ;color: rgb(148, 148, 148);");
|
||
int ringMoveHeight = -30;
|
||
timer_alarm_start24->move(124, ringMoveHeight);
|
||
hour_ring->move(140,7);
|
||
h_in_m->move(187,60);
|
||
timer_alarm_start60->move(196, ringMoveHeight);
|
||
min_ring->move(212,7);
|
||
}
|
||
|
||
/*
|
||
* 闹钟初始化工作日选择界面绘制回调
|
||
* Alarm clock initialization workday selection interface drawing callback
|
||
*/
|
||
void Clock::alarmRepeat()
|
||
{
|
||
repeatSelectOnClockNew->updateIconLabel(1);
|
||
int num;
|
||
//repeat_new_or_edit_flag 编辑是1
|
||
if(repeat_new_or_edit_flag)
|
||
num = ui->alarmListWidget->currentRow();
|
||
else {
|
||
num= model->rowCount();
|
||
}
|
||
QPointF position = this->pos();//446
|
||
dialog_repeat->move(position.x()+DIALOG_MOVE_WIDTH,position.y()+420);
|
||
dialog_repeat->setWindowFlags(Qt::Popup);
|
||
dialog_repeat->widget[0]->alarmLabel0->setText(tr("No repetition"));
|
||
dialog_repeat->widget[1]->alarmLabel0->setText(tr("Workingday"));
|
||
dialog_repeat->widget[2]->alarmLabel0->setText(tr("Mon"));
|
||
dialog_repeat->widget[3]->alarmLabel0->setText(tr("Tue"));
|
||
dialog_repeat->widget[4]->alarmLabel0->setText(tr("Wed"));
|
||
dialog_repeat->widget[5]->alarmLabel0->setText(tr("Thu"));
|
||
dialog_repeat->widget[6]->alarmLabel0->setText(tr("Fri"));
|
||
dialog_repeat->widget[7]->alarmLabel0->setText(tr("Sat"));
|
||
dialog_repeat->widget[8]->alarmLabel0->setText(tr("Sun"));
|
||
for (int i=0; i<7; i++) {
|
||
if (repeat_day[i]) {
|
||
//前两个是不重复和工作日
|
||
dialog_repeat->widget[i+2]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
dialog_repeat->widget[i+2]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
dialog_repeat->show();
|
||
}
|
||
/*
|
||
* 重复选项单击回调
|
||
* Repeat option click callback
|
||
*/
|
||
void Clock::repeatListclickslot()
|
||
{
|
||
int num=dialog_repeat->listWidget->currentRow();
|
||
QString day[7] ;
|
||
day[0]= tr("Mon")+" ";
|
||
day[1] = tr("Tue")+" ";
|
||
day[2] = tr("Wed")+" ";
|
||
day[3] = tr("Thu")+" ";
|
||
day[4] = tr("Fri")+" ";
|
||
day[5] = tr("Sat")+" ";
|
||
day[6] = tr("Sun")+" ";
|
||
//存储"重复"数据
|
||
switch (num)
|
||
{
|
||
case 0:
|
||
repeatSelectOnClockNew->textLabel->setText(tr("No repetition"));
|
||
repeat_str_model = tr("No repetition");
|
||
//不重复
|
||
for (int i=0; i<7; i++) {
|
||
// 周一到周日 全存1
|
||
repeat_day[i] = 1;
|
||
qDebug() << repeat_day[i];
|
||
//周一到周日 设为不选中 但后续会被覆盖?
|
||
dialog_repeat->widget[i+2]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
|
||
dialog_repeat->close();
|
||
return;
|
||
break;
|
||
case 1:
|
||
repeatSelectOnClockNew->textLabel->setText(tr("Workingday"));
|
||
repeat_str_model = tr("Workingday");
|
||
for (int i=0; i<7; i++) {
|
||
if(i<5) {
|
||
repeat_day[i] = 1;
|
||
dialog_repeat->widget[i+2]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
repeat_day[i] = 0;
|
||
dialog_repeat->widget[i+2]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
dialog_repeat->widget[7]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
dialog_repeat->widget[8]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
dialog_repeat->close();
|
||
return;
|
||
break;
|
||
case 2:
|
||
if (repeat_day[0] == 0 ) {
|
||
repeat_day[0] = 1;
|
||
dialog_repeat->widget[2]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[1]== 0 && repeat_day[2]== 0 && repeat_day[3]== 0 && repeat_day[4]== 0 && repeat_day[5]== 0 && repeat_day[6]== 0){
|
||
//防止全部勾选被取消
|
||
}else{
|
||
repeat_day[0] = 0;
|
||
dialog_repeat->widget[2]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
case 3:
|
||
if(repeat_day[1] == 0 ) {
|
||
repeat_day[1] = 1;
|
||
dialog_repeat->widget[3]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[0]== 0 && repeat_day[2]== 0 && repeat_day[3]== 0 && repeat_day[4]== 0 && repeat_day[5]== 0 && repeat_day[6]== 0){
|
||
|
||
}else{
|
||
repeat_day[1] = 0;
|
||
dialog_repeat->widget[3]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
case 4:
|
||
if (repeat_day[2] == 0 ) {
|
||
repeat_day[2] = 1;
|
||
dialog_repeat->widget[4]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[1]== 0 && repeat_day[0]== 0 && repeat_day[3]== 0 && repeat_day[4]== 0 && repeat_day[5]== 0 && repeat_day[6]== 0){
|
||
|
||
}else{
|
||
repeat_day[2] = 0;
|
||
dialog_repeat->widget[4]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
case 5:
|
||
if (repeat_day[3] == 0 ) {
|
||
repeat_day[3] = 1;
|
||
dialog_repeat->widget[5]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[1]== 0 && repeat_day[2]== 0 && repeat_day[0]== 0 && repeat_day[4]== 0 && repeat_day[5]== 0 && repeat_day[6]== 0){
|
||
|
||
}else{
|
||
repeat_day[3] = 0;
|
||
dialog_repeat->widget[5]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
case 6:
|
||
if (repeat_day[4] == 0 ) {
|
||
repeat_day[4] = 1;
|
||
dialog_repeat->widget[6]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[1]== 0 && repeat_day[2]== 0 && repeat_day[3]== 0 && repeat_day[0]== 0 && repeat_day[5]== 0 && repeat_day[6]== 0){
|
||
|
||
}else{
|
||
repeat_day[4] = 0;
|
||
dialog_repeat->widget[6]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
case 7:
|
||
if (repeat_day[5] == 0 ) {
|
||
repeat_day[5] = 1;
|
||
dialog_repeat->widget[7]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[1]== 0 && repeat_day[2]== 0 && repeat_day[3]== 0 && repeat_day[4]== 0 && repeat_day[0]== 0 && repeat_day[6]== 0){
|
||
|
||
}else{
|
||
repeat_day[5] = 0;
|
||
dialog_repeat->widget[7]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
case 8:
|
||
if (repeat_day[6] == 0 ) {
|
||
repeat_day[6] = 1;
|
||
dialog_repeat->widget[8]->alarmLabel1->setPixmap(repeat_on_Pixmap);
|
||
} else {
|
||
if(repeat_day[1]== 0 && repeat_day[2]== 0 && repeat_day[3]== 0 && repeat_day[4]== 0 && repeat_day[5]== 0 && repeat_day[0]== 0){
|
||
|
||
}else{
|
||
repeat_day[6] = 0;
|
||
dialog_repeat->widget[8]->alarmLabel1->setPixmap(repeat_off_Pixmap);
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
//构造重复repeat_str
|
||
for (int i=0; i<7; i++) {
|
||
if (repeat_day[i]) {
|
||
repeat_str=repeat_str+day[i];
|
||
}
|
||
}
|
||
if(repeat_day[0]&&repeat_day[1]&&repeat_day[2]&&repeat_day[3]&&repeat_day[4]&&repeat_day[5]&&repeat_day[6])
|
||
repeat_str = tr("Every day");
|
||
repeatSelectOnClockNew->textLabel->setText(repeat_str);
|
||
repeat_str_model = repeat_str;
|
||
repeat_str="";
|
||
updateRepeatStr(repeatSelectOnClockNew->textLabel);
|
||
}
|
||
|
||
/*
|
||
* 闹钟初始化音乐选择界面回调
|
||
* Alarm clock initialization music selection interface callback
|
||
*/
|
||
void Clock::selectAlarmMusic()
|
||
{
|
||
musicSelectOnClockNew->updateIconLabel(1);
|
||
QPointF position = this->pos();
|
||
dialog_music->move(position.x()+DIALOG_MOVE_WIDTH,position.y()+482);
|
||
dialog_music->setWindowFlags(Qt::Popup);
|
||
refreshMusicSelectList(dialog_music);
|
||
dialog_music->show();
|
||
}
|
||
|
||
void Clock::refreshMusicSelectList(set_alarm_repeat_Dialog *tempDialog)
|
||
{
|
||
// tempDialog = new
|
||
QList<QString> * bellList = m_selectBtnUtil->getAllBellItem();
|
||
int newSize = bellList->size();
|
||
int currentSize = tempDialog->rowNum_all;
|
||
if(currentSize<newSize){
|
||
for (int i=currentSize;i<newSize;i++) {
|
||
tempDialog->set_aItem(i);
|
||
}
|
||
tempDialog->rowNum_all=newSize;
|
||
}
|
||
for (int i=0;i<bellList->size();i++) {
|
||
tempDialog->widget[i]->alarmLabel0->setText(bellList->at(i));
|
||
}
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
void Clock::selectRemindLate()
|
||
{
|
||
remindSelectOnClockNew->updateIconLabel(1);
|
||
QPointF position = this->pos();
|
||
dialog_remind_late->move(position.x()+DIALOG_MOVE_WIDTH,position.y()+510);
|
||
dialog_remind_late->setWindowFlags(Qt::Popup);
|
||
dialog_remind_late->widget[0]->alarmLabel0->setText(tr("none"));
|
||
dialog_remind_late->widget[1]->alarmLabel0->setText(tr("five mins late"));
|
||
dialog_remind_late->widget[2]->alarmLabel0->setText(tr("ten mins late"));
|
||
dialog_remind_late->widget[3]->alarmLabel0->setText(tr("twenty mins late"));
|
||
dialog_remind_late->widget[4]->alarmLabel0->setText(tr("thirsty mins late"));
|
||
dialog_remind_late->widget[5]->alarmLabel0->setText(tr("one hour late"));
|
||
dialog_remind_late->show();
|
||
|
||
}
|
||
|
||
/*
|
||
* 闹钟初始化单击选择音乐
|
||
* Alarm initialization Click to select music
|
||
*/
|
||
void Clock::musicListclickslot()
|
||
{
|
||
int num=dialog_music->listWidget->currentRow();
|
||
int size = dialog_music->rowNum_all;
|
||
//最后一个自定义铃声
|
||
if(num==(size-1)){
|
||
addDivBell(dialog_music,Clock::add_clock);
|
||
}else{
|
||
QString id = m_selectBtnUtil->getBellIdByIndex(num);
|
||
QString path = m_selectBtnUtil->getBellPathById(id);
|
||
QString name = m_selectBtnUtil->getBellNameById(id);
|
||
musicSelectOnClockNew->textLabel->setText(name);
|
||
//排除无
|
||
if(num==0){
|
||
path="";
|
||
}
|
||
playMusicFromPath(path);
|
||
}
|
||
dialog_music->close();
|
||
}
|
||
|
||
void Clock::remindLateListClickSlot()
|
||
{
|
||
int num=dialog_remind_late->listWidget->currentRow();
|
||
remind_late_str_model =getRemindLateStrFromNum(num);
|
||
remindSelectOnClockNew->textLabel->setText(remind_late_str_model);
|
||
dialog_remind_late->close();
|
||
}
|
||
|
||
QString Clock::getRemindLateStrFromNum(int num)
|
||
{
|
||
QString temp=tr("none");
|
||
switch (num)
|
||
{
|
||
case 0:
|
||
temp=tr("none");
|
||
break;
|
||
case 1:
|
||
temp=tr("five mins late");
|
||
break;
|
||
case 2:
|
||
temp=tr("ten mins late");
|
||
break;
|
||
case 3:
|
||
temp=tr("twenty mins late");
|
||
break;
|
||
case 4:
|
||
temp=tr("thirsty mins late");
|
||
break;
|
||
case 5:
|
||
temp=tr("one hour late");
|
||
break;
|
||
default:
|
||
temp=tr("none");
|
||
break;
|
||
}
|
||
return temp;
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
* Default setting database data initialization
|
||
* 默认设置数据库数据初始化
|
||
*/
|
||
void Clock::modelSetupSet()
|
||
{
|
||
int setup_rowNum;
|
||
setup_rowNum = model_setup->rowCount();
|
||
if (setup_rowNum < 1) {
|
||
model_setup->insertRow(setup_rowNum);
|
||
model_setup->setData(model_setup->index(setup_rowNum, 0), int(0));//静音 Mute
|
||
QString id = m_selectBtnUtil->getDefaultBellId();
|
||
model_setup->setData(model_setup->index(setup_rowNum, 1), id);
|
||
}
|
||
model_setup->submitAll();
|
||
}
|
||
|
||
|
||
|
||
void Clock::paintEvent(QPaintEvent *event)
|
||
{
|
||
Q_UNUSED(event);
|
||
QPainter p(this);
|
||
p.setRenderHint(QPainter::Antialiasing); // 反锯齿;
|
||
QPainterPath rectPath;
|
||
rectPath.addRoundedRect(this->rect(), 0, 0); // 左上右下
|
||
|
||
QPainter painter(this);
|
||
QStyleOption opt;
|
||
opt.init(this);
|
||
painter.setBrush(opt.palette.color(QPalette::Base));
|
||
|
||
QColor mainColor;
|
||
mainColor = palette().color(QPalette::Base);
|
||
p.fillPath(rectPath,QBrush(mainColor));
|
||
}
|
||
|
||
|
||
|
||
bool Clock::eventFilter(QObject *watched, QEvent *event)
|
||
{
|
||
if(watched == ui->editAlarmPage && event->type() == QEvent::Paint)
|
||
{
|
||
showPaint(); //响应函数
|
||
}
|
||
|
||
if(watched == shadow && event->type() == QEvent::Paint)
|
||
{
|
||
// showPaint7();
|
||
}
|
||
return QWidget::eventFilter(watched,event);
|
||
}
|
||
|
||
/*
|
||
* 实现响应函数设置页
|
||
*/
|
||
void Clock::showPaint()
|
||
{
|
||
QPainter painter(ui->editAlarmPage);
|
||
painter.setPen(Qt::gray);
|
||
painter.setBrush(Qt::green);
|
||
QStyleOption opt;
|
||
opt.init(this);
|
||
painter.setBrush(opt.palette.color(QPalette::Base));
|
||
painter.setPen(Qt::transparent);
|
||
QRect rect = ui->editAlarmPage->rect();
|
||
rect.setWidth(rect.width() - 0);
|
||
rect.setHeight(rect.height() - 0);
|
||
painter.drawRoundedRect(rect, 7, 7);
|
||
{
|
||
QPainterPath painterPath;
|
||
painterPath.addRoundedRect(rect, 0, 0);
|
||
painter.drawPath(painterPath);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/*
|
||
* 实现响应函数设置页
|
||
*/
|
||
void Clock::showPaint7()
|
||
{
|
||
QPainter painter(shadow);
|
||
painter.setPen(Qt::gray);
|
||
painter.setBrush(Qt::green);
|
||
QStyleOption opt;
|
||
opt.init(this);
|
||
painter.setBrush(opt.palette.color(QPalette::Base));
|
||
|
||
|
||
painter.setBrush(QColor(theme::timeScrollBackColor));
|
||
|
||
painter.setPen(Qt::transparent);
|
||
QRect rect = shadow->rect();
|
||
rect.setWidth(rect.width() - 0);
|
||
rect.setHeight(rect.height() - 0);
|
||
painter.drawRoundedRect(rect, 7, 7);
|
||
{
|
||
QPainterPath painterPath;
|
||
painterPath.addRoundedRect(rect, 8, 8);
|
||
painter.drawPath(painterPath);
|
||
}
|
||
}
|
||
/**
|
||
* @brief 多屏幕下,Natice_alarm移动
|
||
* @param spostion SP_LEFT 左下角 SP_RIGHT 右下角 SP_CENTER 居中
|
||
* @param
|
||
*
|
||
* @return 返回说明
|
||
*/
|
||
void Clock::moveUnderMultiScreen(Clock::ScreenPosition spostion,QWidget * tempDialog,int hiddenFlag)
|
||
{
|
||
QScreen *screen=QGuiApplication::primaryScreen ();
|
||
int screen_width = screen->geometry().width();
|
||
int screen_height = screen->geometry().height();
|
||
int x = primaryManager->getNScreen_x();
|
||
int y = primaryManager->getNScreen_y();
|
||
int heightRadio = 20;
|
||
int widthRadio = 14;
|
||
|
||
switch (spostion) {
|
||
case SP_LEFT:
|
||
{
|
||
int moveWidth = x+round(tempDialog->width()+round(1.0/heightRadio*screen_width));
|
||
int moveHeight = y+round(screen_height-tempDialog->height()-round(1.0/widthRadio*screen_height));
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
}break;
|
||
case SP_RIGHT:
|
||
{
|
||
int moveWidth = x+round(screen_width-tempDialog->width());
|
||
int moveHeight = y+round(screen_height-tempDialog->height()-50);
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
if (hiddenFlag == 1)
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
else
|
||
tempDialog->move(moveWidth,moveHeight-tempDialog->height());
|
||
}break;
|
||
case SP_CENTER:
|
||
{
|
||
int moveWidth = x+round((screen_width-tempDialog->width())*1.0/2);
|
||
int moveHeight = y+round((screen_height-tempDialog->height())*1.0/2);
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
}break;
|
||
case UP_LEFT:
|
||
{
|
||
int moveWidth = x+round(tempDialog->width()+round(1.0/heightRadio*screen_width));
|
||
int moveHeight = y+round(tempDialog->height()+round(1.0/widthRadio*screen_height));
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
}break;
|
||
case UP_RIGHT:
|
||
{
|
||
int moveWidth = x+round(screen_width-tempDialog->width()-round(1.0/heightRadio*screen_width));
|
||
int moveHeight = y+round(1.0/20*screen_height);
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
}break;
|
||
case UP_CENTER:
|
||
{
|
||
int moveWidth = x+round((screen_width-tempDialog->width())*1.0/2);
|
||
int moveHeight = y+round((screen_height-tempDialog->height())*1.0/2);
|
||
tempDialog->move(moveWidth,moveHeight);
|
||
}break;
|
||
default:
|
||
{}
|
||
}
|
||
}
|
||
|
||
|
||
void Clock::updateTinyBtn()
|
||
{
|
||
QPixmap pixmap = QPixmap(":image/switchIconB.png");
|
||
ui->tinyWindowBtn->setProperty("useButtonPalette", true);
|
||
ui->tinyWindowBtn->setIcon(pixmap);
|
||
ui->tinyWindowBtn->setIconSize(QSize(24,24));
|
||
ui->tinyWindowBtn->setToolTip(tr("mini window"));
|
||
// ui->tinyWindowBtn->setFlat(true);
|
||
}
|
||
void Clock::updateSwitchBtnStyle()
|
||
{
|
||
int index=ui->mainWidget->currentIndex();
|
||
if(index==1){
|
||
AlarmPageSwitch();
|
||
}else if(index==0){
|
||
CountdownPageSwitch ();
|
||
}else if(index==2){
|
||
StopwatchPageSwitch ();
|
||
}
|
||
}
|
||
//黑色主题
|
||
void Clock::blackStyle()
|
||
{
|
||
ui->timeShowBig->setStyleSheet("color: rgba(255, 255, 255, 0.9);font-size:38px;");
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(38);
|
||
ui->timeShowBig->setFont(f);
|
||
ui->remainTime->setStyleSheet("color: rgba(255, 255, 255, 0.9)");
|
||
ui->noAlarmIcon->setPixmap(QPixmap(":/image/noClockBlack.png"));
|
||
ui->noAlarm->setStyleSheet("color: rgba(255, 255, 255, 0.6);font-size:16px;");
|
||
|
||
widgetListBlackStyle(ui->alarmListWidget);
|
||
widgetListBlackStyle(ui->timeListWidget);
|
||
QString itemRadius = QString::number(ITEM_RADIUS);
|
||
clockEditOnClockNew->clockNameLineEdit->setStyleSheet("QLineEdit{background-color:rgb(55, 55, 59);border-radius:"+itemRadius+"px;color: rgb(148, 148, 148);}");
|
||
ui->tinyWindowBtn->setIcon(QIcon(":image/switchIconW.png"));
|
||
updateSwitchBtnStyle();
|
||
}
|
||
//白色主题
|
||
void Clock::whiteStyle()
|
||
{
|
||
ui->timeShowBig->setStyleSheet("color: rgba(49, 66, 89, 1);font-size:38px;");
|
||
// QString selfFont = Utils::loadFontFamilyFromTTF();
|
||
// QFont f(selfFont);
|
||
QFont f;
|
||
f.setFamily("NotoSansCJKsc-Regular");
|
||
f.setWeight(400);
|
||
f.setPixelSize(38);
|
||
ui->timeShowBig->setFont(f);
|
||
ui->remainTime->setStyleSheet("color: rgba(49, 66, 89, 1)");
|
||
ui->noAlarmIcon->setPixmap(QPixmap(":/image/noClockWhite.png"));
|
||
ui->noAlarm->setStyleSheet("color: rgba(49, 66, 89, 0.6);font-size:16px;");
|
||
widgetListWhiteStyle(ui->alarmListWidget);
|
||
widgetListWhiteStyle(ui->timeListWidget);
|
||
QString itemRadius = QString::number(ITEM_RADIUS);
|
||
clockEditOnClockNew->clockNameLineEdit->setStyleSheet("QLineEdit{background-color:rgb(240, 240, 240);border-radius:"+itemRadius+"px;color: rgb(148, 148, 148);}");
|
||
ui->tinyWindowBtn->setIcon(QIcon(":image/switchIconB.png"));
|
||
updateSwitchBtnStyle();
|
||
}
|
||
|
||
QString Clock::getDefaultGreyColor()
|
||
{
|
||
QColor color = QColor(COUNTDOWN_RING_BACKCOLOR_WHITE_STYLE);
|
||
QString str = theme::getColorStr(color);
|
||
return str;
|
||
}
|
||
|
||
|
||
|
||
|
||
|