This commit is contained in:
Yzzi 2020-08-14 20:27:22 +08:00
parent 2fed1bbb57
commit 3304a410c9
12 changed files with 1036 additions and 845 deletions

1348
LICENSE

File diff suppressed because it is too large Load Diff

0
build.sh Executable file → Normal file
View File

43
countdown.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "countdown.h"
countDown::countDown(QObject *parent) : QObject(parent)
{
timer=new QTimer(this);
connect(timer,&QTimer::timeout,this,&countDown::refresh);
}
void countDown::refresh()
{
if(ms)
{
ms--;
if(!ms) emit ended();//计时结束,触发结束信号,写在这里是为了让声音和画面同步
}
else
{
if(timer->isActive())timer->stop();
}
emit refreshed();
}
void countDown::setTime(int t)//弃坑,写不来
{
mem=ms=t;
emit setted();
}
void countDown::reset()
{
ms=mem;
refresh();
emit setted();
}
void countDown::start()
{
emit refreshed();
timer->start(1000);
}
void countDown::stop()
{
emit refreshed();
if(timer->isActive())timer->stop();
}

30
countdown.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef COUNTDOWN_H
#define COUNTDOWN_H
#include <QObject>
#include <QTimer>
class countDown : public QObject
{
Q_OBJECT
public:
explicit countDown(QObject *parent = nullptr);
int ms;//供Widget访问
bool end=true;//控制是否响应timeout信号
int mem=ms=1500;
QTimer *timer;
signals:
void refreshed();//刷新完成信号
void ended();//计时结束信号
void setted();//设置时间完成信号(会和refresh形成死循环废弃)
public slots:
void refresh();//刷新
void setTime(int t);//设置时间(菜是原罪,写不来,暂时废弃)
void reset();//重置时间
void start();//开始响应timeout信号
void stop();//停止响应timeout信号
};
#endif // COUNTDOWN_H

0
dabao/dabao.sh Executable file → Normal file
View File

View File

View File

@ -26,10 +26,14 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += main.cpp\
widget.cpp
widget.cpp \
countdown.cpp \
toptime.cpp
HEADERS += \
widget.h
widget.h \
countdown.h \
toptime.h
CONFIG += link_pkgconfig
PKGCONFIG += dtkwidget

18
toptime.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "toptime.h"
#include <QDateTime>
topTime::topTime(QObject *parent) : QObject(parent)
{
current_time = QDateTime::currentDateTime();
str=current_time.toString("hh:mm");
timer=new QTimer(this);
connect(timer,&QTimer::timeout,this,&topTime::refresh);
timer->start(1000);
}
void topTime::refresh()
{
current_time = QDateTime::currentDateTime();
str=current_time.toString("hh:mm");
emit refreshed();
}

23
toptime.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef TOPTIME_H
#define TOPTIME_H
#include <QObject>
#include <QDateTime>
#include <QTimer>
class topTime : public QObject
{
Q_OBJECT
public:
explicit topTime(QObject *parent = nullptr);
QString str;//供Widget访问
QDateTime current_time;
QTimer *timer;
signals:
void refreshed();//刷新完成信号
public slots:
void refresh();//刷新槽函数
};
#endif // TOPTIME_H

View File

@ -9,10 +9,8 @@
#include <DApplication>
#include <QDialog>
#include <DInputDialog>
#include "countdown.h"
using namespace std;
QTimer *timer = new QTimer();
int a;
bool timerswitch;
Widget::Widget(DBlurEffectWidget *parent) :
DBlurEffectWidget(parent),
m_menu(new QMenu),
@ -27,14 +25,13 @@ Widget::Widget(DBlurEffectWidget *parent) :
ui(new Ui::Widget)
{
ui->setupUi(this);
ui->gridLayout->setContentsMargins(0, 0, 0, 0);
ui->titlebar->setFixedHeight(50);//初始化标题栏
ui->titlebar->setBackgroundTransparent(true);//设置标题栏透明
ui->titlebar->setIcon(QIcon::fromTheme(":/icon/icon/top.yzzi.tomato.svg"));
ui->titlebar->setTitle("");
setMaskAlpha(190);
ui->titlebar->setMenu(m_menu);
mem=ms = 1500+1;//设置初始时间
m_menu->addMenu(menu_times);//设置菜单
menu_times->setTitle(tr("时间"));
menu_times->addAction(m_5);
@ -44,7 +41,6 @@ Widget::Widget(DBlurEffectWidget *parent) :
menu_times->addAction(m_45);
menu_times->addAction(m_set);
timesGroup = new QActionGroup(this);//设置按钮互斥
timesGroup->addAction(m_5);
timesGroup->addAction(m_15);
@ -62,52 +58,61 @@ Widget::Widget(DBlurEffectWidget *parent) :
m_25->setChecked(true);
//in->setParent(this);
//设置按钮响应
connect(m_5,&QAction::triggered,[=](){mem=ms = 300+1;timer->start(1000);refresh();});
connect(m_15,&QAction::triggered,[=](){mem=ms = 900+1;timer->start(1000);refresh();});
connect(m_25,&QAction::triggered,[=](){mem=ms = 1500+1;timer->start(1000);refresh();});
connect(m_35,&QAction::triggered,[=](){mem=ms = 2100+1;timer->start(1000);refresh();});
connect(m_45,&QAction::triggered,[=](){mem=ms = 2700+1;timer->start(1000);refresh();});
connect(m_set,&QAction::triggered,[=](){input();});
connect(m_5,&QAction::triggered,[=](){count->mem=count->ms = 300;refresh();});
connect(m_15,&QAction::triggered,[=](){count->mem=count->ms = 900;refresh();});
connect(m_25,&QAction::triggered,[=](){count->mem=count->ms = 1500;refresh();});
connect(m_35,&QAction::triggered,[=](){count->mem=count->ms = 2100;refresh();});
connect(m_45,&QAction::triggered,[=](){count->mem=count->ms = 2700;refresh();});
connect(m_set,&QAction::triggered,[=](){input();refresh();});
//实例化对象
count=new countDown(this);
toptime=new topTime(this);
switchbutton = new DSwitchButton (this);
ui->horizontalLayout_2->addWidget(switchbutton);
switchbutton->setChecked(false);
timerswitch=false;
setWindowFlags(windowFlags()&~Qt::WindowMaximizeButtonHint);// 禁止最大化按钮
setFixedSize(this->width(),this->height());// 禁止拖动窗口大小
connect(switchbutton, SIGNAL(checkedChanged(bool)), this, SLOT(onSBtnSwitchButtonCheckedChanged(bool)));
//时间更新
//结束时音频播放(待修改!)
player = new QMediaPlayer(this);
player->setVolume(100);
player->setMedia(QUrl("qrc:/audio/ding.wav"));
//设置界面刷新和对象响应
connect(count,&countDown::refreshed,this,&Widget::refreshCount);
connect(toptime,&topTime::refreshed,this,&Widget::refreshTime);
connect(count,&countDown::ended,player,&QMediaPlayer::play);
//时间控制
timer->start(1000); //每隔1000ms发送timeout的信号
connect(timer, SIGNAL(timeout()), this,SLOT(refresh()));
refresh();
//音频播放
player = new QMediaPlayer;
player->setVolume(100);
player->setMedia(QUrl("qrc:/audio/ding.wav"));
refreshCount();
refreshTime();
}
void Widget::refresh()
void Widget::refresh()//刷新count的开始结束动作
{
ostringstream timeshow;
if(timerswitch==true)
if(btSwitch)
{
if(ms==0) ms=mem;
ms-=1;
QDateTime tomato_time = QDateTime::fromTime_t(ms);
QString textout=tomato_time.toString("mm:ss");
ui->time->setText(textout);
if(ms==0)
{
player->play();
timer->stop();
}
}else {
QDateTime current_time = QDateTime::currentDateTime();
QString str=current_time.toString("hh:mm");
ui->time->setText(str);
if(!count->ms) count->reset();
count->start();
}
else
{
count->stop();
}
}
void Widget::refreshTime()//用toptime的信息刷新时间显示
{
ui->titlebar->setTitle(toptime->str);
}
void Widget::refreshCount()//用count的信息刷新倒计时显示
{
QDateTime tomato_time = QDateTime::fromTime_t(count->ms);
QString textout=tomato_time.toString("mm:ss");
ui->time->setText(textout);
}
DTitlebar* Widget::getTitlebar()
{
@ -151,22 +156,37 @@ void Widget::input()
timer->start(1000);
refresh();
}
void Widget::input()//输入时间
{
bool isOK;
int i = DInputDialog::getInt(this, "输入时间",
"请输入时间分钟小于60",
count->mem/60,0,100,1,&isOK);
if(isOK)
{
count->ms=count->mem=60*i;
}
switch (count->mem) {
case 300+1:
m_5->setChecked(true);
break;
case 900+1:
m_15->setChecked(true);
break;
case 1500+1:
m_25->setChecked(true);
break;
case 2100+1:
m_35->setChecked(true);
break;
case 2700+1:
m_45->setChecked(true);
break;
}
}
void Widget::onSBtnSwitchButtonCheckedChanged(bool ck)
{
if(ck==true)
{
timerswitch=true;
timer->start(1000);
/*Widget::player->play();*/
}
else
{
timerswitch=false;
timer->start(1000);
/*Widget::player->stop();*/
}
player->stop();
btSwitch=ck;
refresh();
}

View File

@ -7,7 +7,8 @@
#include <QMediaPlayer>
#include <DBlurEffectWidget>
#include <DTitlebar>
#include "countdown.h"
#include "toptime.h"
DWIDGET_USE_NAMESPACE
namespace Ui {
@ -24,35 +25,35 @@ public:
QMediaPlayer *player;
QMediaPlaylist *playlist;
DTitlebar* getTitlebar();
bool btSwitch;
private slots:
void onSBtnSwitchButtonCheckedChanged(bool);
void refresh();
void refreshTime();
void refreshCount();
void input();
private:
Ui::Widget *ui;
DSwitchButton * switchbutton;
QTimer *timer = new QTimer();
int a;
bool timerswitch;
int ms;
int mem;
DTitlebar *titlebar;
QMenu *m_menu;
QActionGroup *timesGroup;
QAction *m_full;
QAction *m_5;
QAction *m_15;
QAction *m_25;
QAction *m_35;
QAction *m_45;
QAction *m_set;
countDown *count;
topTime *toptime;
QMenu *menu_times=new QMenu;
};
#endif // WIDGET_H

268
widget.ui
View File

@ -7,119 +7,166 @@
<x>0</x>
<y>0</y>
<width>470</width>
<height>254</height>
<height>265</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>470</width>
<height>265</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>471</width>
<height>182</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="DTitlebar" name="titlebar" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="time">
<property name="maximumSize">
<size>
<width>431</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>72</pointsize>
</font>
</property>
<property name="text">
<string>24:33</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>180</y>
<width>471</width>
<height>54</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2"/>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="DTitlebar" name="titlebar" native="true">
<property name="minimumSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="time">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>431</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<pointsize>72</pointsize>
</font>
</property>
<property name="text">
<string>25:00</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="DSwitchButton" name="switchbutton" native="true"/>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>50</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
@ -128,6 +175,11 @@
<header location="global">dtitlebar.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>DSwitchButton</class>
<extends>QWidget</extends>
<header>dswitchbutton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>