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 /src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h | |
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
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h')
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-screensaver/animations/ImageSlideshow.h | 140 |
1 files changed, 140 insertions, 0 deletions
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 |