diff options
author | ZackaryWelch <welch.zackary@gmail.com> | 2017-08-04 17:00:14 -0400 |
---|---|---|
committer | ZackaryWelch <welch.zackary@gmail.com> | 2017-08-04 17:00:14 -0400 |
commit | ee494111f41ed0c5ab7b43d30f76bdb44cadfa5e (patch) | |
tree | ee54b9d089448ff593628caa342e11fb2282976c | |
parent | Merge branch 'master' of http://github.com/trueos/lumina (diff) | |
download | lumina-ee494111f41ed0c5ab7b43d30f76bdb44cadfa5e.tar.gz lumina-ee494111f41ed0c5ab7b43d30f76bdb44cadfa5e.tar.bz2 lumina-ee494111f41ed0c5ab7b43d30f76bdb44cadfa5e.zip |
Added an experimental VideoSlideshow screensaver plus fixes
6 files changed, 290 insertions, 40 deletions
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 <QParallelAnimationGroup> #include <QtMath> #include <QMatrix> @@ -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; i<step; i++) { //Calculates the new point, including gravitational pull and eccentricity. Goes from 0 to 2PI in steps. - 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)); - - //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; i<this->animationCount(); 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 += |