#include "HeartWidget.h"
HeartWidget::HeartWidget(QWidget *parent) :
QWidget(parent)
{
initMusic();
initWindow();
initTimer();
}
HeartWidget::~HeartWidget()
{
}
void HeartWidget::initWindow()
{
// 设置程序不在任务栏显示且窗体无边框 ^_^
this->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);
// 窗口整体透明,但窗口控件不透明
this->setAttribute(Qt::WA_TranslucentBackground, true);
// 全屏显示
this->showFullScreen();
// 设置分别率
QRect screenRect = QApplication::desktop()->screenGeometry();
w = screenRect.width();
h = screenRect.height();
if (w == 1920)
resolution = 0;
else if (w <= 1400 && w >= 1280)
resolution = 1;
else
resolution = 1;
}
void HeartWidget::initTimer()
{
timer = new QTimer(this);
//timer->setInterval(100);
timer->start(8);
connect(timer, SIGNAL(timeout()), this, SLOT(update()));
}
void HeartWidget::initMusic()
{
player = new QMediaPlayer(this);
player->setMedia(QMediaContent(QUrl("qrc:/new/prefix2/mp3/vae.mp3")));
//player->setMedia(QMediaContent(QUrl("../flowers/images/like.mp3")));
player->play();
// 单曲循环
connect(player, &QMediaPlayer::stateChanged, [=]{player->play();});
}
void HeartWidget::paintEvent(QPaintEvent *)
{
painter = new QPainter(this);
QPixmap pix;
#if 1
// 限定画爱心的取点
static int count = 0;
// 参数方程中的角度
static double angle = 10.0;
// 用于绘制I❤Y
// -1 -2 -> 大爱心
// 0 1 2 -> I
// 3 4 5 -> Y
// 6 -> ❤
// 7 -> 文字
static int state = -2;
static int i = 0;
double a = 1.15, b = 1.15;
switch(resolution)
{
case 0:
a = 1.4;
b = 1.4;
break;
case 1:
a = 1.15;
b = 1.15;
break;
}
if (angle < 30 && state == -2)
{
switch (resolution)
{
case 0:
pix.load(":/new/prefix1/images/hh.gif");
break;
case 1:
pix.load(":/new/prefix1/images/hh1.gif");
break;
}
float t = (float) (angle / 3.14159);
int x = (int) (19.5 * a * (16 * pow(sin(t), 3)));
int y = (int) (-20.0 * b * (13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)));
// 隔15个点取一次绘制
if (count % 15 == 0)
{
//painter->drawPixmap(550 + x, 400 + y, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 3.491 + x, h / 2.7 + y, pix.width(), pix.height(), pix);
}
count++;
angle += 0.02;
if (angle >= 30)
{
angle = 10.0;
state = -1;
}
}
else if (angle < 30 && state == -1)
{
float t = (float) (angle / 3.14159);
int x = (int) (19.5 * a * (16 * pow(sin(t), 3)));
int y = (int) (-20.0 * b * (13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t)));
switch (resolution)
{
case 0:
pix.load(":/new/prefix1/images/ff.png");
break;
case 1:
pix.load(":/new/prefix1/images/ff1.png");
break;
}
// 隔15个点取一次绘制
if (count % 15 == 0)
{
int d = 0;
if (resolution == 1)
{
d = 30;
}
//painter->drawPixmap(1250 + x, 400 + y, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 1.536 + d + x, h / 2.7 + y, pix.width(), pix.height(), pix);
}
count++;
angle += 0.02;
if (angle >= 30)
{
timer->stop();
timer->start(100);
state = 0;
}
}
else
{
//timer->stop();
QPen pen;
switch(resolution)
{
case 0:
painter->setFont(QFont("Microsoft YaHei", 28, QFont::DemiBold));
break;
case 1:
painter->setFont(QFont("Microsoft YaHei", 20, QFont::DemiBold));
break;
}
pix.load(":/new/prefix1/images/rr1.png");
if (state == 0)
{
int d = 0;
if (resolution == 1)
{
d = -50;
}
//painter->drawPixmap(300 + i, 325, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 6.4 + i, h / 3.323, pix.width(), pix.height(), pix);
i += 25;
if (i >= (175 + d))
{
state = 1;
i = 0;
}
}
else if (state == 1)
{
int d = 0;
if (resolution == 1)
{
d = -50;
}
//painter->drawPixmap(375, 325 + i, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 5.12 + d / 8, h / 3.323 + i, pix.width(), pix.height(), pix);
i += 25;
if (i >= (200 + d))
{
state = 2;
i = 0;
}
}
else if (state == 2)
{
int d = 0;
if (resolution == 1)
{
d = -50;
}
//painter->drawPixmap(300 + i, 525, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 6.4 + i, h / 2.057, pix.width(), pix.height(), pix);
i += 25;
if (i >= (175 + d))
{
state = 3;
i = 0;
}
}
else if (state == 3)
{
int d = 0;
if (resolution == 1)
{
d = -50;
}
//pix.load("../flowers/images/love.png");
//painter->drawPixmap(700 + i, 325 + tan(3.141592 / 3.0) * i, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 2.743 + i, h / 3.323 + tan(3.141592 / 3.0) * i, pix.width(), pix.height(), pix);
i += 10;
if (i >= 50)
{
state = 4;
i = 0;
}
}
else if (state == 4)
{
//painter->drawPixmap(755 + i, 411 - tan(3.141592 / 3) * i, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 2.543 + i, h / 2.628 - tan(3.141592 / 3) * i, pix.width(), pix.height(), pix);
i += 10;
if (i >= 60)
{
state = 5;
i = 0;
}
}
else if (state == 5)
{
//painter->drawPixmap(755, 411 + i, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 2.543, h / 2.628 + i, pix.width(), pix.height(), pix);
i += 25;
if (i >= 125)
{
state = 6;
i = 0;
}
}
else if (state == 6)
{
switch (resolution)
{
case 0:
//pix.load(":/new/prefix1/images/love.png");
pix.load(":/new/prefix1/images/ll.png");
break;
case 1:
pix.load(":/new/prefix1/images/ll1.png");
break;
}
//painter->drawPixmap(500, 350, pix.width(), pix.height(), pix);
painter->drawPixmap(w / 3.84, h / 3.086, pix.width(), pix.height(), pix);
state = 7;
timer->stop();
timer->start(1000);
}
else if (state == 7)
{
int d = 0;
if (resolution == 1)
d = 60;
pen.setBrush(QColor("pink"));
painter->setPen(pen);
//painter->drawText(1100, 400, "眼角眉梢都充满着暖�
没有合适的资源?快使用搜索试试~ 我知道了~
基于Qt widget (cpp)的一个表白动画程序.zip
共32个文件
png:12个
gif:6个
mp3:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 199 浏览量
2024-04-26
16:32:07
上传
评论
收藏 47.55MB ZIP 举报
温馨提示
基于QT的系统
资源推荐
资源详情
资源评论
收起资源包目录
基于Qt widget (cpp)的一个表白动画程序.zip (32个子文件)
flowers-master
widget.ui 441B
HeartWidget.cpp 11KB
screenshot
screen_recording.gif 9.54MB
screenshot.png 695KB
screen_recording.mp4 12.88MB
FireWidget.h 985B
exe
flowers.exe 21.86MB
main.cpp 275B
mp3
vae.mp3 439KB
fire.mp3 300KB
images.qrc 531B
images
hh1.gif 5KB
aa.png 15KB
ll.gif 52KB
like.mp3 244KB
hh.gif 8KB
ff1.png 11KB
Thumbs.db 347KB
ff.png 17KB
ll.png 50KB
face.png 15KB
love.png 38KB
fire.gif 933KB
fire1.gif 1.23MB
rr.png 19KB
ll1.png 32KB
zz.png 13KB
rr1.png 8KB
love1.png 27KB
FireWidget.cpp 3KB
HeartWidget.h 804B
flowers.pro 1KB
共 32 条
- 1
资源评论
我慢慢地也过来了
- 粉丝: 6486
- 资源: 3993
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功