#include "mainwindow.h"
#include "ui_mainwindow.h"
int i=0,k=0,image_open=0; //定义图像的全局变量
int soundList_i=0,j=0,sound_open=0;//定义音乐的全局变量
int first=0;
QString imagelist[100]; //存放打开的图片
QStringList::iterator it; //连接器
QString soundList[10]; //存放加载的声音资源
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
/*关联定时器溢出信号和相应的槽函数 */
timer1 = new QTimer(this);//新建定时器
timer2 = new QTimer(this);
timer3 = new QTimer(this);
timer3->start(1000);
connect(timer1,SIGNAL(timeout()),this,SLOT(fun_autotime()));
connect(timer2, SIGNAL(timeout()), this, SLOT(fun_rapidtime()));
connect(timer3, SIGNAL(timeout()), this, SLOT(timerUpdate()));
qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
/*界面美化*/
QPalette palette;
palette.setBrush(QPalette::Background,QBrush(QPixmap("../Images/Background2.jpg").scaled(this->size())));
this->setPalette(palette);
/*下面的函数实现鼠标移到按钮前是白色,移到按钮后是蓝色,按下后是红色*/
setStyleSheet(tr("QRadioButton{background-color:white;}QRadioButton:hover{background-color:cyan;}QRadioButton:pressed{background-color:red;}"));
setWindowTitle(tr("Electronic Album")); //程序名
//初始化音频Mean
sound2 = new QSound("../Images/Mean.wav");//加载声音文件
sound1 = new QSound("../Images/1.wav",this);
}
MainWindow::~MainWindow()
{
delete timer1;
delete timer2;
delete timer3;
delete sound1;
delete sound2;
delete ui;
}
void MainWindow::timerUpdate()
{
/*获取系统现在的时间 */
QDateTime time = QDateTime::currentDateTime(); //设置系统时间显示格式
QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd"); //在标签上显示时间
ui->lineEdit->setText(str);
}
void MainWindow::on_autobtn_clicked()
{ sound2->stop();//停止音频的播放
if(image_open==0)//获取图片资源
{ image_open=1;
/*可以通过快捷键"CTRL+A"全选*/
QStringList list = QFileDialog::getOpenFileNames(this,tr("Select File"),"..",tr("Image Files (*.png *.bmp )"));
for(it = list.begin();it<list.end();it++)
{
imagelist[k] = *it;
qDebug()<<imagelist[k];
k++;
}
k-=1;
if(k<0)
{
k=0;
}
}
if(sound_open==0) //加载声音资源
{ sound_open=1;
/*可以通过快捷键"CTRL+A"全选*/
QStringList list = QFileDialog::getOpenFileNames(this,tr("Select File"),"..",tr("Music Files (*.wav)"));
for(it = list.begin();it<list.end();it++)
{
soundList[j] = *it;
qDebug()<<soundList[j];
j++;
}
j-=1;
if(j<0)
{
j=0;
}
}
//timer1->start(10000);//timer1定时10秒
timer1->start(5000);//timer1定时5秒
timer2->stop(); //timer2停止定时
timer3->start(1000);//timer3定时1秒
sound1->stop();//停止上一段的音频
if(first==0)
{
first=1;
soundList_i=i;
pix.load(imagelist[i]); //下载图片
pix = pix.scaled(ui->Image->width(),ui->Image->height(),Qt::IgnoreAspectRatio);
ui->Image->setPixmap(pix);
i++;
if(i>k)
{
i=0;
}
sound1=new QSound(soundList[soundList_i++]);
sound1->play();
}
}
void MainWindow::on_rapidbtn_clicked()
{ first=0;
timer1->stop();
timer2->start(1000);
timer3->start(1000);
sound1->stop();//停止上一段的音频
sound2->play();//播放音频
sound2->setLoops(-1);//设置死循环
}
void MainWindow::on_stopbtn_clicked()
{
first=0;
timer1->stop();
timer2->stop();
timer3->stop();
sound1->stop();//停止上一段的音频
sound2->stop();//停止音频的播放
}
void MainWindow::fun_autotime()
{
if(sound1->isFinished()==false)
{
sound1->stop();//停止上一段的音频
}
pix.load(imagelist[i]); //下载图片
pix = pix.scaled(ui->Image->width(),ui->Image->height(),Qt::IgnoreAspectRatio);
ui->Image->setPixmap(pix);
i++;
if(i>k)
{
i=0;
}
if(soundList_i>=10)
{
soundList_i=0;
}
//sound1->play(soundList[soundList_i++]);//静态函数,不能停止播放
sound1=new QSound(soundList[soundList_i++]);
sound1->play();
}
void MainWindow::fun_rapidtime()
{
int rand = qrand() % 10+1; // 产生10以内随机整数:1-10
ui->Image->setPixmap(QString("../Images/%1.png").arg(rand));
}
基于Qt的电子相册设计(x64系统)
需积分: 47 187 浏览量
2018-06-15
12:35:18
上传
评论 5
收藏 24.61MB RAR 举报
漫9612
- 粉丝: 1
- 资源: 1
最新资源
- 徐州市区shp边界文件
- 简易数字频率计设计(原理图、PCB、源码、分析报告)
- 20225207038罗丽文财管专2201班.rar
- Golang:通过Gin框架+Redis+责任链,实现一个简单的钉钉机器人,进行消息处理 ps:多应用版
- 基于cnn和AlexNet的铝材缺陷检测内含数据集和demo原型2种方法
- 2023年各城市PM2.5, PM10, SO2, NO2等环境空气质量数据
- go 语言 实现的 使用modbus 协议 通过DTU tcp 链接 采集数据
- SHELL脚本(全是干货)
- Windows屏幕录屏软件
- 2022年各城市PM2.5, PM10, SO2, NO2等环境空气质量数据
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈