嵌入式linux--电子相册

2019-07-12 20:39发布

实验内容与要求:采用QT开发技术,在物联网实验箱上实现一个电子相框,系统上电启动后自动启动此电子相框程序。程序自动读取U盘中的所有图片,并自动按照5秒一张的时间间隔播放。图片自动在显示屏全屏显示(不能变形)。所有图片自动循环播放。如果没有插入U盘或U盘中没有图片,则界面上提示没有可播放的图片。要求支持jpg、jpeg、gif、png、bmp等常见格式的图片。可以加入图片切换时的特效功能。
特 {MOD}功能:点击屏幕显示暂停按钮和关闭按钮 再次点击即可隐藏
PS:自动启动需要改系统脚本 //formphoto.cpp #include "formphoto.h" #include "ui_formphoto.h" #include #include #include #include //#include <QGraphicsOpacityEffect> FormPhoto::FormPhoto(QWidget *parent) : QWidget(parent), ui(new Ui::FormPhoto) { ui->setupUi(this); this->Init(); } FormPhoto::~FormPhoto() { delete ui; } void FormPhoto::Init() { width = QApplication::desktop()->width(); height = QApplication::desktop()->height(); ui->scrollArea -> setFrameShape(QFrame::NoFrame); ui->scrollArea -> resize(width,height); ui->scrollArea -> setAlignment(Qt::AlignCenter); ui->imageLabel -> resize(width,height); ui->imageLabel -> setAlignment(Qt::AlignCenter); ui->showbutton -> setStyleSheet("QToolButton{background: transparent;}"); ui->showbutton -> resize(width,height); ui->playorstop -> setGeometry(QRect(QPoint(width/2-25, height/2-25), QSize(50, 50))); ui->playorstop -> setStyleSheet("QToolButton{background: transparent;}"); ui->playorstop -> setVisible(false); ui->close-> setGeometry(QRect(QPoint(width-70,5), QSize(30, 30))); ui->close -> setStyleSheet("QToolButton{background: transparent;}"); ui->close -> setVisible(false); currentNo = 0; imageNum = 0; isplaying = true; imagePixmap.load(":/image/MainPage.jpg"); imagePixmap = imagePixmap.scaled(width,height,Qt::IgnoreAspectRatio); ui->imageLabel->setPixmap(imagePixmap); timerfordelay=new QTimer; connect(timerfordelay,SIGNAL(timeout()),this,SLOT(hasImages())); timerfordelay->start(2000); timer=new QTimer; connect(timer,SIGNAL(timeout()),this,SLOT(playImageSlot())); timer->start(5000); //timerforfade = new QTimer; } void FormPhoto::hasImages() { timerfordelay->stop(); this -> getImages("/udisk/image"); if(!imageNum) { QMessageBox message(QMessageBox::Warning,NULL,"U盘中无图片", QMessageBox::Retry | QMessageBox::Cancel, NULL); message.setButtonText (QMessageBox::Retry,QString("重试")); message.setButtonText (QMessageBox::Cancel,QString("退出")); switch(message.exec()){ case QMessageBox::Retry: this->hasImages();break; case QMessageBox::Cancel: app->quit();break; } } else this -> playImageSlot(); } void FormPhoto::playImageSlot() { if(currentNo>=imageNum) currentNo=0; QString fileName=imageArrary[currentNo++]; if(isgif[currentNo-1] == true){ QMovie *movie = new QMovie(fileName); ui->imageLabel->setMovie(movie); movie->start(); } else{ imagePixmap.load(fileName); imagePixmap = imagePixmap.scaled(width,height,Qt::KeepAspectRatio); ui->imageLabel->setPixmap(imagePixmap); } // opacity=0; // this->fade_on_fade_in(); // connect(timerforfade,SIGNAL(timeout()),this,SLOT(fade_on_fade_in())); // timerforfade->start(50); } void FormPhoto::getImages(QString _dir) { QFileInfo dir(_dir); if(!dir.isDir()){ QMessageBox message(QMessageBox::Warning,NULL,"请插入U盘", QMessageBox::Retry | QMessageBox::Cancel, NULL); message.setButtonText (QMessageBox::Retry,QString("重试")); message.setButtonText (QMessageBox::Cancel,QString("退出")); switch(message.exec()){ case QMessageBox::Retry: this->getImages(_dir);break; case QMessageBox::Cancel: app->quit();break; } } else{ QDirIterator it(_dir,QDir::Files|QDir::Dirs|QDir::NoDotAndDotDot); while (it.hasNext())//存在 { QString name = it.next();//读取 QFileInfo info(name); if (info.isDir())//判断是目录 { this->getImages(name);//递归 } else { if (info.suffix() == "jpg" || info.suffix() == "bmp" || info.suffix() == "png" || info.suffix() == "gif" || info.suffix() == "jpeg") { if(info.suffix()=="gif") isgif[imageNum] = true; else isgif[imageNum] = false; imageArrary[imageNum++]=name;//符合添加 } } } } } void FormPhoto::on_showbutton_clicked() { if(ui->playorstop->isHidden()){ ui->playorstop->setVisible(true); ui->close->setVisible(true); } else{ ui->playorstop->setVisible(false); ui->close->setVisible(false); } } void FormPhoto::on_playorstop_clicked() { if(isplaying){ this->timer->stop(); isplaying = false; ui->playorstop->setIcon(QPixmap(":/image/play.png")); } else{ this->timer->start(5000); isplaying = true; ui->playorstop->setIcon(QPixmap(":/image/stop.png")); } } void FormPhoto::on_close_clicked() { app->quit(); } //void FormPhoto::fade_on_fade_in() //{ if(opacity==1.0) // { // this->timerforfade->stop();//定时器停止 // } // else // { // QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect;; // effect->setOpacity(opacity); // ui->imageLabel->setGraphicsEffect(effect); // } // opacity+=0.01;//透明度累加 //} 这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
完整工程下载:http://download.csdn.net/detail/qq_29777421/9892855