diff options
Diffstat (limited to 'src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp')
-rw-r--r-- | src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp | 73 |
1 files changed, 25 insertions, 48 deletions
diff --git a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp index 7854b597..7c098887 100644 --- a/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp +++ b/src-qt5/core/lumina-desktop-unified/src-screensaver/SSBaseWidget.cpp @@ -7,78 +7,55 @@ #include "SSBaseWidget.h" -#define DEBUG 1 +#define DEBUG 0 -static QStringList validPlugs; // ======== // PUBLIC // ======== -SSBaseWidget::SSBaseWidget(QWidget *parent, QSettings *set) : QWidget(parent){ - if(validPlugs.isEmpty()){ validPlugs << "none"; } //add more later - settings = set; //needed to pass along for plugins to read any special options/settings +SSBaseWidget::SSBaseWidget(QWidget *parent) : QQuickView(parent->windowHandle()){ this->setObjectName("LuminaBaseSSWidget"); - ANIM = 0; - this->setMouseTracking(true); + this->setResizeMode(QQuickView::SizeRootObjectToView); + this->setColor(QColor("black")); //default color for the view + this->setCursor(Qt::BlankCursor); plugType="none"; + restartTimer = new QTimer(this); + restartTimer->setInterval( DesktopSettings::instance()->value(DesktopSettings::ScreenSaver, "globals/plugin_time_seconds", 120).toInt() * 1000); + restartTimer->setSingleShot(true); + connect(restartTimer, SIGNAL(timeout()), this, SLOT(startPainting()) ); } SSBaseWidget::~SSBaseWidget(){ - if(ANIM!=0){ this->stopPainting(); } } void SSBaseWidget::setPlugin(QString plug){ - plug = plug.toLower(); - if(validPlugs.contains(plug) || plug=="random"){ plugType = plug; } - else{ plugType = "none"; } + plugType = plug.toLower(); } // ============= // PUBLIC SLOTS // ============= void SSBaseWidget::startPainting(){ - cplug = plugType; //free up any old animation instance - if(ANIM!=0){ - stopPainting(); - } + stopPainting(); //If a random plugin - grab one of the known plugins - if(cplug=="random"){ - QStringList valid = BaseAnimGroup::KnownAnimations(); - valid.removeAll("none"); //they want a screensaver - remove the "none" option from the valid list - if(valid.isEmpty()){ cplug = "none"; } //no known plugins - else{ cplug = valid[ qrand()%valid.length() ]; } //grab a random plugin - } - if(DEBUG){ qDebug() << " - Screen Saver:" << cplug; } - //Now list all the various plugins and start them appropriately - QString style; - if(cplug=="none"){ - style = "background: black;"; //show the underlying black parent widget - }else{ - style = "background: black;"; + if(plugType=="random"){ + QList<SSPlugin> valid = SSPluginSystem::findAllPlugins(); + if(!valid.isEmpty()){ cplug = valid[ qrand()%valid.length() ]; } //grab a random plugin + }else if(plugType!="none"){ + cplug = SSPluginSystem::findPlugin(plugType); } - this->setStyleSheet("QWidget#LuminaBaseSSWidget{ "+style+"}"); - this->repaint(); - //If not a stylesheet-based plugin - set it here - if(cplug!="none"){ - ANIM = BaseAnimGroup::NewAnimation(cplug, this, settings); - connect(ANIM, SIGNAL(finished()), this, SLOT(startPainting()) ); //repeat the plugin as needed - ANIM->LoadAnimations(); - } - //Now start the animation(s) - if(ANIM!=0){ - if(ANIM->animationCount()>0){ - if(DEBUG){ qDebug() << " - Starting SS Plugin:" << cplug << ANIM->animationCount() << ANIM->duration() << ANIM->loopCount(); } - ANIM->start(); - } + if(DEBUG){ qDebug() << " - Screen Saver:" << plugType << cplug.scriptURL() << cplug.isValid(); } + if(cplug.isValid()){ + this->setSource( cplug.scriptURL() ); + if(plugType=="random"){ restartTimer->start(); } } + } void SSBaseWidget::stopPainting(){ - if(ANIM!=0){ - qDebug() << "Stopping Animation!!"; - ANIM->stop(); - //ANIM->clear(); - ANIM->deleteLater(); - ANIM = 0; + if(!this->source().isEmpty()){ + this->setSource(QUrl()); + cplug = SSPlugin(); //empty structure } + if(restartTimer->isActive()){ restartTimer->stop(); } } |