From ee494111f41ed0c5ab7b43d30f76bdb44cadfa5e Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Fri, 4 Aug 2017 17:00:14 -0400 Subject: Added an experimental VideoSlideshow screensaver plus fixes --- .../src-screensaver/animations/BaseAnimGroup.cpp | 8 +- .../src-screensaver/animations/Grav.h | 69 +++++----- .../src-screensaver/animations/ImageSlideshow.h | 140 +++++++++++++++++++++ .../src-screensaver/animations/Text.h | 9 +- .../src-screensaver/animations/VideoSlideshow.h | 102 +++++++++++++++ .../src-screensaver/animations/animations.pri | 2 + 6 files changed, 290 insertions(+), 40 deletions(-) create mode 100644 src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h create mode 100644 src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h (limited to 'src-qt5/core/lumina-desktop-unified/src-screensaver') diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp index aaae8b41..7fc4eb50 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp @@ -12,6 +12,8 @@ #include "Grav.h" #include "SampleAnimation.h" #include "Text.h" +#include "ImageSlideshow.h" +#include "VideoSlideshow.h" //============================== // PLUGIN LOADING/LISTING @@ -24,6 +26,10 @@ BaseAnimGroup* BaseAnimGroup::NewAnimation(QString type, QWidget *parent, QSetti return (new GravAnimation(parent, set)); }else if(type == "text") { return (new TextAnimation(parent, set)); + }else if(type == "imageSlideshow") { + return (new ImageAnimation(parent, set)); + }else if(type == "videoSlideshow") { + return (new VideoAnimation(parent, set)); }else { //Unknown screensaver, return a blank animation group return (new BaseAnimGroup(parent, set)); @@ -31,5 +37,5 @@ BaseAnimGroup* BaseAnimGroup::NewAnimation(QString type, QWidget *parent, QSetti } QStringList BaseAnimGroup::KnownAnimations(){ - return (QStringList() << "grav"); + return (QStringList() << "videoSlideshow" /*<< "grav" << "text" << "imageSlideshow" << "fireflies"*/); } diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Grav.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Grav.h index ec1de914..50d733e9 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Grav.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Grav.h @@ -9,10 +9,8 @@ //PI is equal to 2*pi #define PI 6.2832 - #include "global-includes.h" #include "BaseAnimGroup.h" -#include #include #include @@ -32,44 +30,53 @@ private: radius = qSqrt( (qPow(start.x()-ref->x(),2) + qPow(start.y()-ref->y(),2) )); //Number of frames in animation. Increase for smother motion - double step = 1000.0; + double step = 300.0; //Random values that give the eliptical pattern to the orbit. Between 0.4 and 2.3 - double xrand = (qrand()%20+4)/10.0; - double yrand = (qrand()%20+4)/10.0; - - QPoint firstP = QPoint(ref->x() + xrand*start.x()*(qCos(0/step) -qSin(0/step)), ref->y() + yrand*start.y()*(qCos(0/step) -qSin(0/step))); - QPoint lastP = QPoint(ref->x() + xrand*start.x()*(qCos(PI/step) -qSin(PI/step)), ref->y() + yrand*start.y()*(qCos(PI/step) -qSin(PI/step))); - orbit->setKeyValueAt(0, firstP); - orbit->setKeyValueAt(1, lastP); + double xrand = 0.4; //(qrand()%10+4)/10.0; + double yrand = 0.4; //(qrand()%10+4)/10.0; + + double theta = 1.5707963; + //double theta = aTan((start.x() - ref->x())/(start.y() - ref->y())); + QMatrix rotation = QMatrix(qCos(theta), qSin(theta), -qSin(theta), qCos(theta), -ref->x(), -ref->y()); + qDebug() << rotation; + //qDebug() << "Starting Point" << start; + //qDebug() << "Angle" << theta; + //qDebug() << "Distance" << radius; + //qDebug() << "Center" << *ref; + + QPoint firstP = (QPoint(ref->x() + xrand*start.x()*(qCos(0/step) -qSin(0/step)), ref->y() + yrand*start.y()*(qCos(0/step) -qSin(0/step)))); + QPoint rotFP = rotation.map(firstP); + qDebug() << "First Point" << firstP; + qDebug() << "Rotation by Matrix" << rotFP; + QPoint lastP = (QPoint(ref->x() + xrand*start.x()*(qCos(PI/step) -qSin(PI/step)), ref->y() + yrand*start.y()*(qCos(PI/step) -qSin(PI/step)))); + orbit->setKeyValueAt(0, firstP); + orbit->setKeyValueAt(1, lastP); //path.push_back(firstP); //Loops through all steps and creates all the points of the orbit for(int i=1; ix() + xrand*start.x()*(qCos((PI*i)/step) -qSin((PI*i)/step)); - double newY = ref->y() + yrand*start.y()*(qSin((PI*i)/step) + qCos((PI*i)/step)); - - //Calculates the radius from the sun as the distance between the points - radius = (qSqrt( (qPow(newX-ref->x(),2) + qPow(newY-ref->y(),2) ))); + double newX = ref->x() + xrand*start.x()*(qCos((PI*i)/step) - qSin((PI*i)/step)); + double newY = ref->y() + yrand*start.y()*(qSin((PI*i)/step) + qCos((PI*i)/step)); //Creates a new point and creates a key as part of the animation - QPoint newLoc = QPoint(newX, newY); - orbit->setKeyValueAt(i/step, newLoc); + QPoint newLoc = (QPoint(newX, newY)); + orbit->setKeyValueAt(i/step, newLoc); //path.push_back(newLoc); } //Sets the time for a full orbit. Increasing makes the orbit slower. //path.push_back(lastP); } private slots: - void LoopChanged(int loop){ + /*void LoopChanged(int loop){ //Adjust the orbit animation a bit - /*if(loop >= 0) { + if(loop >= 0) { orbit->setStartValue(orbit->endValue()); //start at the previous end point orbit->setEndValue(path.at(loop%1000)); orbit->setDuration(10); - }*/ - } + } + }*/ void stopped(){ qDebug() << "Planet stopped"; planet->hide();} public: @@ -96,22 +103,18 @@ public: QRect invalid = QRect(center+QPoint(-50,-50), center+QPoint(50,50)); QPoint tmp = center; while(invalid.contains(tmp)){ - int randwidth = qrand()%(range.width() - 2*planet_radius) + planet_radius; - int randheight= qrand()%(range.height()- 2*planet_radius) + planet_radius; + int randwidth = qrand()%(range.width() - 2*planet_radius) + planet_radius; + int randheight = qrand()%(range.height()- 2*planet_radius) + planet_radius; tmp = QPoint(randwidth, randheight); } - /*double tmpDistance = qSqrt((qPow((tmp.x()-center.x()), 2) + qPow((tmp.y()-center.y()), 2))); - double theta = qAsin(qAbs(tmp.y()-center.y())/tmpDistance); - QMatrix rotation = QMatrix(qCos(theta), qSin(theta), -qSin(theta), qCos(theta), -center.x(), -center.y());*/ - //Creates all frames for the animation setupLoop(tmp, ¢er); this->addAnimation(orbit); planet->show(); //Ensures the screensaver will not stop until the user wishes to login or it times out - this->setLoopCount(5); //number of orbits + this->setLoopCount(1); //number of orbits orbit->setDuration( qrand() %1000 + 19000); //20 second orbits //orbit->setEndValue(path.at(0)); //LoopChanged(0); //load initial values @@ -138,13 +141,14 @@ private slots: for(int i=0; ianimationCount(); i++){ if(this->animationAt(i)->state()==QAbstractAnimation::Running){ running++; } } - if(running<=1){ wobble->stop(); emit wobble->finished();} + if(running<=1){ wobble->stop(); emit wobble->finished();} } public: GravAnimation(QWidget *parent, QSettings *set) : BaseAnimGroup(parent, set){} ~GravAnimation(){ - //this->stop(); + sun->deleteLater(); + while(planets.length()>0){ planets.takeAt(0)->deleteLater(); } } void LoadAnimations(){ @@ -152,8 +156,8 @@ public: sun = new QWidget(canvas); QPoint center = canvas->geometry().center(); QString sunstyle = QStringLiteral("background-color:qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, ") + - QStringLiteral("stop:0 rgba(0, 0, 0, 0), stop:0.38 rgba(0, 0, 0, 0), stop:0.4 rgba(82, 121, 76, 33), stop:0.5 rgba(159, 235, 148, 64), ") + - QStringLiteral("stop:0.6 rgba(255, 238, 150, 129), stop:0.7 rgba(0, 0, 0, 0));"); + QStringLiteral("stop:0 rgba(0, 0, 0, 0), stop:0.38 rgba(0, 0, 0, 0), stop:0.4 rgba(82, 121, 76, 33), stop:0.5 rgba(159, 235, 148, 64), ") + + QStringLiteral("stop:0.6 rgba(255, 238, 150, 129), stop:0.7 rgba(0, 0, 0, 0));"); sun->setStyleSheet(sunstyle); //Creates the sun's pulsing animation @@ -170,7 +174,6 @@ public: this->addAnimation(wobble); sun->show(); sun->setGeometry(initgeom); - while(planets.length()>0){ planets.takeAt(0)->deleteLater(); } //Gives the screensaver a black background canvas->setStyleSheet("background: black;"); diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h new file mode 100644 index 00000000..4abc3ae7 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h @@ -0,0 +1,140 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_SCREEN_SAVER_IMAGESLIDESHOW_ANIMATION_H +#define _LUMINA_DESKTOP_SCREEN_SAVER_IMAGESLIDESHOW_ANIMATION_H + +#include "global-includes.h" +#include "BaseAnimGroup.h" + +class ImageSlideshow: public QParallelAnimationGroup{ + Q_OBJECT +private: + QLabel *image; + QPropertyAnimation *bounce, *fading; + QPixmap pixmap; + QStringList imageFiles; + QString imagePath; + QSize screenSize; + bool animate; + +private: + void setupAnimation() { + //Choose between starting from top or bottom at random + if(qrand() % 2) { + bounce->setKeyValueAt(0, QPoint(0,screenSize.height()-image->height())); + bounce->setKeyValueAt(0.25, QPoint((screenSize.width()-image->width())/2,0)); + bounce->setKeyValueAt(0.5, QPoint(screenSize.width()-image->width(),screenSize.height()-image->height())); + bounce->setKeyValueAt(0.75, QPoint((screenSize.width()-image->width())/2,0)); + bounce->setKeyValueAt(1, QPoint(0,screenSize.height()-image->height())); + }else{ + bounce->setKeyValueAt(0, QPoint(0,0)); + bounce->setKeyValueAt(0.25, QPoint((screenSize.width()-image->width())/2,screenSize.height()-image->height())); + bounce->setKeyValueAt(0.5, QPoint(screenSize.width()-image->width(),0)); + bounce->setKeyValueAt(0.75, QPoint((screenSize.width()-image->width())/2,screenSize.height()-image->height())); + bounce->setKeyValueAt(1, QPoint(0,0)); + } + } + + void chooseImage() { + QString randomFile = imagePath+imageFiles[qrand() % imageFiles.size()]; + + //Choose a new file if the chosen one is not an image + while(QImageReader::imageFormat(randomFile).isEmpty()) + randomFile = imagePath+imageFiles[qrand() % imageFiles.size()]; + pixmap.load(imagePath+imageFiles[qrand() % imageFiles.size()]); + + //If the image is larger than the screen, then shrink the image down to 3/4 it's size (so there's still some bounce) + //Scale the pixmap to keep the aspect ratio instead of resizing the label itself + if(pixmap.width() > screenSize.width() or pixmap.height() > screenSize.height()) + pixmap = pixmap.scaled(screenSize*(3.0/4.0), Qt::KeepAspectRatio); + + //Set pixmap to the image label + image->setPixmap(pixmap); + image->resize(pixmap.size()); + } + +private slots: + void LoopChanged(){ + //Load a new random image. Resize the label based on the image's size + chooseImage(); + setupAnimation(); + } + void stopped(){ qDebug() << "Image Stopped"; image->hide();} + +public: + ImageSlideshow(QWidget *parent, QString path, bool animate) : QParallelAnimationGroup(parent){ + imagePath = path; + image = new QLabel(parent); + screenSize = parent->size(); + this->animate = animate; + + //Generate the list of files in the directory + imageFiles = QDir(imagePath).entryList(QDir::Files); + if(imageFiles.empty()) + qDebug() << "Current image file path has no files."; + + //Change some default settings for the image. If scaledContents is false, the image will be cut off if resized + image->setScaledContents(true); + image->setAlignment(Qt::AlignHCenter); + + //Load a random initial image + chooseImage(); + + //Create the animation that moves the image across the screen + bounce = new QPropertyAnimation(image, "pos", parent); + + //Add the animation that fades the image in and out + QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(parent); + image->setGraphicsEffect(eff); + fading = new QPropertyAnimation(eff,"opacity"); + fading->setKeyValueAt(0, 0); + fading->setKeyValueAt(0.20, 1); + fading->setKeyValueAt(0.80, 1); + fading->setKeyValueAt(1, 0); + this->addAnimation(fading); + + setupAnimation(); + image->show(); + //Only add the animation if set in the configuration file + if(animate) + this->addAnimation(bounce); + else + //If no animation, center the image in the middle of the screen + image->move(QPoint((parent->width()-image->width())/2,(parent->height()-image->height())/2)); + + //Loop through 30 times for a total for 4 minutes + this->setLoopCount(30); + bounce->setDuration(8000); + fading->setDuration(8000); + + connect(this, SIGNAL(currentLoopChanged(int)), this, SLOT(LoopChanged()) ); + connect(this, SIGNAL(finished()), this, SLOT(stopped()) ); + } + ~ImageSlideshow(){} + +}; + +class ImageAnimation: public BaseAnimGroup{ + Q_OBJECT +public: + ImageAnimation(QWidget *parent, QSettings *set) : BaseAnimGroup(parent, set){} + ~ImageAnimation(){ + this->stop(); + } + + void LoadAnimations(){ + canvas->setStyleSheet("background: black;"); + //Load the path of the images from the configuration file (default /usr/local/backgrounds/) + QString imagePath = settings->value("imageSlideshow/path","/usr/local/backgrounds/").toString(); + //Load whether to animate the image (default true) + bool animate = settings->value("imageSlideshow/animate", true).toBool(); + ImageSlideshow *tmp = new ImageSlideshow(canvas, imagePath, animate); + this->addAnimation(tmp); + } + +}; +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Text.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Text.h index a4c49692..3ec0af82 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Text.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/Text.h @@ -4,11 +4,8 @@ // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== -#ifndef _LUMINA_DESKTOP_SCREEN_SAVER_Text_ANIMATION_H -#define _LUMINA_DESKTOP_SCREEN_SAVER_Text_ANIMATION_H - -//PI is equal to 2*pi -#define PI 6.2832 +#ifndef _LUMINA_DESKTOP_SCREEN_SAVER_TEXT_ANIMATION_H +#define _LUMINA_DESKTOP_SCREEN_SAVER_TEXT_ANIMATION_H #include "global-includes.h" #include "BaseAnimGroup.h" @@ -38,7 +35,7 @@ private slots: currLoc.setY(currLoc.y() + v.y()); movement->setEndValue(currLoc); } - void stopped(){ qDebug() << "text stopped"; text->hide();} + void stopped(){ qDebug() << "Text Stopped"; text->hide();} public: Text(QWidget *parent) : QParallelAnimationGroup(parent){ diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h new file mode 100644 index 00000000..fdddaf93 --- /dev/null +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h @@ -0,0 +1,102 @@ +//=========================================== +// Lumina-DE source code +// Copyright (c) 2015, Ken Moore +// Available under the 3-clause BSD license +// See the LICENSE file for full details +//=========================================== +#ifndef _LUMINA_DESKTOP_SCREEN_SAVER_VIDEOSLIDESHOW_ANIMATION_H +#define _LUMINA_DESKTOP_SCREEN_SAVER_VIDEOSLIDESHOW_ANIMATION_H + +#include "global-includes.h" +#include "BaseAnimGroup.h" + +class VideoSlideshow: public QPropertyAnimation{ + Q_OBJECT +public: + VideoSlideshow(QWidget *parent, QVideoWidget *videoWidget) : QPropertyAnimation(videoWidget, "pos", parent){ + this->setKeyValueAt(0,QPoint(0,0)); + this->setKeyValueAt(1,QPoint(0,0)); + } + ~VideoSlideshow(){} + +}; + +class VideoAnimation: public BaseAnimGroup{ + Q_OBJECT +private: + QString videoPath; + VideoSlideshow *tmp; + QVideoWidget *videoWidget; + QMediaPlayer *video; + QStringList videoFiles; + QMediaPlaylist *playlist; + bool multimonitor, random; + +private slots: + void startVideo() { + this->addAnimation(tmp); + tmp->setDuration(video->duration()); + qDebug() << "Status: " << video->mediaStatus(); + video->setPlaylist(playlist); + video->setVolume(100); + video->play(); + } + + void LoopChanged(){ + qDebug() << "New Video"; + if(random) + playlist->setCurrentIndex(qrand() % videoFiles.size()); + else + playlist->setCurrentIndex(playlist->currentIndex()+1); + } + + void stopped(){qDebug() << "Video Stopped"; videoWidget->hide();} + +public: + VideoAnimation(QWidget *parent, QSettings *set) : BaseAnimGroup(parent, set){} + + ~VideoAnimation(){ + this->stop(); + } + + void LoadAnimations(){ + canvas->setStyleSheet("background: black;"); + + //Load the path of the videos from the configuration file (default /usr/local/videos/) + videoPath = settings->value("videoSlideshow/path","/usr/local/videos/").toString(); + + //Set whether to copy videos on two monitors or play different videos + multimonitor = settings->value("videoSlideshow/multimonitor",true).toBool(); + + //Set whether to play random videos or in order + random = settings->value("videoSlideshow/random",false).toBool(); + + video = new QMediaPlayer(canvas, QMediaPlayer::VideoSurface); + videoWidget = new QVideoWidget(canvas); + + tmp = new VideoSlideshow(canvas, videoWidget); + + //Generate the list of files in the directory + videoFiles = QDir(videoPath).entryList(QDir::Files); + if(videoFiles.empty()) + qDebug() << "Current video file path has no files."; + + this->setLoopCount(videoFiles.size()); + + //Load a random initial video + playlist = new QMediaPlaylist(); + for(int i = 0; i < videoFiles.size(); i++) + playlist->addMedia(QUrl::fromLocalFile(videoFiles[i])); + if(random) + playlist->setCurrentIndex(qrand() % videoFiles.size()); + + video->setVideoOutput(videoWidget); + videoWidget->show(); + qDebug() << "VideoWidget Displayed"; + connect(video, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(startVideo())); + connect(this, SIGNAL(currentLoopChanged(int)), this, SLOT(LoopChanged()) ); + connect(this, SIGNAL(finished()), this, SLOT(stopped()) ); + } + +}; +#endif diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/animations.pri b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/animations.pri index 35141a0e..fdc75717 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/animations.pri +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/animations.pri @@ -4,5 +4,7 @@ HEADERS += $$PWD/BaseAnimGroup.h \ $$PWD/SampleAnimation.h \ $${PWD}/Fireflies.h \ $${PWD}/Grav.h \ + $${PWD}/ImageSlideshow.h \ + $${PWD}/VideoSlideshow.h \ $${PWD}/Text.h #FORMS += -- cgit From 0079e45a9bd78c2ebbef5abe641e268571ade45b Mon Sep 17 00:00:00 2001 From: ZackaryWelch Date: Tue, 15 Aug 2017 09:30:58 -0400 Subject: Added fixes for the experimental video screensaver --- .../src-screensaver/LScreenSaver.cpp | 4 +- .../src-screensaver/animations/BaseAnimGroup.cpp | 2 +- .../src-screensaver/animations/ImageSlideshow.h | 25 ++++++-- .../src-screensaver/animations/VideoSlideshow.h | 68 +++++++++++----------- 4 files changed, 59 insertions(+), 40 deletions(-) (limited to 'src-qt5/core/lumina-desktop-unified/src-screensaver') diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/LScreenSaver.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/LScreenSaver.cpp index 2c36af80..39a7b596 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/LScreenSaver.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/LScreenSaver.cpp @@ -151,10 +151,12 @@ void LScreenSaver::HideScreenSaver(){ emit ClosingScreenSaver(); emit LockStatusChanged(false); } + qDebug() << "Stop ScreenSavers"; for(int i=0; istopPainting(); BASES[i]->hide(); + BASES.takeAt(i)->deleteLater(); + i--; } UpdateTimers(); } diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp index 7fc4eb50..c8a248c0 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/BaseAnimGroup.cpp @@ -37,5 +37,5 @@ BaseAnimGroup* BaseAnimGroup::NewAnimation(QString type, QWidget *parent, QSetti } QStringList BaseAnimGroup::KnownAnimations(){ - return (QStringList() << "videoSlideshow" /*<< "grav" << "text" << "imageSlideshow" << "fireflies"*/); + return (QStringList() << "imageSlideshow" /*<< "grav" << "text" << "imageSlideshow" << "fireflies"*/); } diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h index 4abc3ae7..a64144ac 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h @@ -17,9 +17,9 @@ private: QPropertyAnimation *bounce, *fading; QPixmap pixmap; QStringList imageFiles; - QString imagePath; + QString imagePath, scriptPath; QSize screenSize; - bool animate; + bool animate, scriptLoad; private: void setupAnimation() { @@ -45,7 +45,16 @@ private: //Choose a new file if the chosen one is not an image while(QImageReader::imageFormat(randomFile).isEmpty()) randomFile = imagePath+imageFiles[qrand() % imageFiles.size()]; - pixmap.load(imagePath+imageFiles[qrand() % imageFiles.size()]); + if(scriptLoad){ + QProcess process; + process.start("/home/zwelch/test.sh"); + process.waitForFinished(1000); + QByteArray output = process.readAllStandardOutput(); + qDebug() << output; + pixmap.load(imagePath+imageFiles[qrand() % imageFiles.size()]); + }else{ + pixmap.load(imagePath+imageFiles[qrand() % imageFiles.size()]); + } //If the image is larger than the screen, then shrink the image down to 3/4 it's size (so there's still some bounce) //Scale the pixmap to keep the aspect ratio instead of resizing the label itself @@ -66,11 +75,13 @@ private slots: void stopped(){ qDebug() << "Image Stopped"; image->hide();} public: - ImageSlideshow(QWidget *parent, QString path, bool animate) : QParallelAnimationGroup(parent){ + ImageSlideshow(QWidget *parent, QString path, bool animate, bool scriptLoad, QString scriptPath) : QParallelAnimationGroup(parent){ imagePath = path; image = new QLabel(parent); screenSize = parent->size(); this->animate = animate; + this->scriptLoad = scriptLoad; + this->scriptPath = scriptPath; //Generate the list of files in the directory imageFiles = QDir(imagePath).entryList(QDir::Files); @@ -132,7 +143,11 @@ public: QString imagePath = settings->value("imageSlideshow/path","/usr/local/backgrounds/").toString(); //Load whether to animate the image (default true) bool animate = settings->value("imageSlideshow/animate", true).toBool(); - ImageSlideshow *tmp = new ImageSlideshow(canvas, imagePath, animate); + bool scriptLoad = settings->value("imageSlideshow/scriptLoad", true).toBool(); + QString scriptPath; + if(scriptLoad) + scriptPath = settings->value("imageSlideshow/scriptPath", "/usr/local/backgrounds/script.sh").toString(); + ImageSlideshow *tmp = new ImageSlideshow(canvas, imagePath, animate, scriptLoad, scriptPath); this->addAnimation(tmp); } diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h index fdddaf93..cc3c1b83 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/animations/VideoSlideshow.h @@ -16,6 +16,8 @@ public: VideoSlideshow(QWidget *parent, QVideoWidget *videoWidget) : QPropertyAnimation(videoWidget, "pos", parent){ this->setKeyValueAt(0,QPoint(0,0)); this->setKeyValueAt(1,QPoint(0,0)); + this->setDuration(1000000); + this->setLoopCount(-1); } ~VideoSlideshow(){} @@ -29,29 +31,32 @@ private: QVideoWidget *videoWidget; QMediaPlayer *video; QStringList videoFiles; - QMediaPlaylist *playlist; - bool multimonitor, random; + bool multimonitor; private slots: - void startVideo() { - this->addAnimation(tmp); - tmp->setDuration(video->duration()); - qDebug() << "Status: " << video->mediaStatus(); - video->setPlaylist(playlist); - video->setVolume(100); - video->play(); + void startVideo(QAbstractAnimation::State state) { + qDebug() << "Status: " << video->mediaStatus() << "New Animation State:" << state; + if(state==QAbstractAnimation::Running){ + video->setVolume(100); + video->play(); + } + if(state==QAbstractAnimation::Stopped && video->state()!=QMediaPlayer::StoppedState){ + video->stop(); + } } - void LoopChanged(){ - qDebug() << "New Video"; - if(random) - playlist->setCurrentIndex(qrand() % videoFiles.size()); - else - playlist->setCurrentIndex(playlist->currentIndex()+1); + void stopVideo() { + if(video->state() == QMediaPlayer::StoppedState) { + qDebug() << "Stopping Animation"; + //this->deleteLater(); + videoWidget->hide(); + tmp->stop(); + //tmp->deleteLater(); + videoWidget->deleteLater(); + video->deleteLater(); + } } - void stopped(){qDebug() << "Video Stopped"; videoWidget->hide();} - public: VideoAnimation(QWidget *parent, QSettings *set) : BaseAnimGroup(parent, set){} @@ -63,39 +68,36 @@ public: canvas->setStyleSheet("background: black;"); //Load the path of the videos from the configuration file (default /usr/local/videos/) - videoPath = settings->value("videoSlideshow/path","/usr/local/videos/").toString(); + videoPath = settings->value("videoSlideshow/path","/usr/local/videos").toString(); + if(!videoPath.endsWith("/")){ videoPath.append("/"); } //Set whether to copy videos on two monitors or play different videos multimonitor = settings->value("videoSlideshow/multimonitor",true).toBool(); - //Set whether to play random videos or in order - random = settings->value("videoSlideshow/random",false).toBool(); - video = new QMediaPlayer(canvas, QMediaPlayer::VideoSurface); videoWidget = new QVideoWidget(canvas); + videoWidget->setGeometry(QRect(QPoint(0,0), canvas->size())); tmp = new VideoSlideshow(canvas, videoWidget); - + this->addAnimation(tmp); + //Generate the list of files in the directory videoFiles = QDir(videoPath).entryList(QDir::Files); if(videoFiles.empty()) qDebug() << "Current video file path has no files."; - this->setLoopCount(videoFiles.size()); - - //Load a random initial video - playlist = new QMediaPlaylist(); - for(int i = 0; i < videoFiles.size(); i++) - playlist->addMedia(QUrl::fromLocalFile(videoFiles[i])); - if(random) - playlist->setCurrentIndex(qrand() % videoFiles.size()); + this->setLoopCount(1); + QUrl url = QUrl::fromLocalFile(videoPath+videoFiles[qrand() % videoFiles.size()]); + video->setMedia(url); + qDebug() << url; video->setVideoOutput(videoWidget); videoWidget->show(); + qDebug() << "VideoWidget Displayed"; - connect(video, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(startVideo())); - connect(this, SIGNAL(currentLoopChanged(int)), this, SLOT(LoopChanged()) ); - connect(this, SIGNAL(finished()), this, SLOT(stopped()) ); + connect(tmp, SIGNAL(stateChanged(QAbstractAnimation::State, QAbstractAnimation::State)), this, SLOT(startVideo(QAbstractAnimation::State)) ); + //connect(video, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), this, SLOT(startVideo()) ); + connect(video, SIGNAL(stateChanged(QMediaPlayer::State)), this, SLOT(stopVideo()) ); } }; -- cgit