1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-07 19:42:45 +01:00

Fix replacing wallpaper from different types

This commit is contained in:
Elias Steurer 2020-08-11 20:18:34 +02:00
parent 02042f060f
commit 1fe1fb2c4b
4 changed files with 36 additions and 15 deletions

View File

@ -38,11 +38,28 @@ Rectangle {
newObject.destroy(10000) newObject.destroy(10000)
} }
function onReloadQML() { // Replace wallpaper with QML Scene
function onReloadQML(oldType) {
loader.sourceComponent = undefined loader.sourceComponent = undefined
loader.source = "" loader.source = ""
Wallpaper.clearComponentCache() if (oldType === Wallpaper.WallpaperType.QML)
root.init() Wallpaper.clearComponentCache()
loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath)
}
// This function only gets called here (the same function
// is inside the WebView.qml) when the previous Wallpaper type
// was not a video
function onReloadVideo(oldType) {
// We need to check if the old type
// was also Video not get called twice
if (oldType === Wallpaper.WallpaperType.Video)
return
imgCover.state = "in"
loader.source = "qrc:/WebView.qml"
} }
} }
@ -54,12 +71,12 @@ Rectangle {
case Wallpaper.WallpaperType.Html: case Wallpaper.WallpaperType.Html:
loader.webViewUrl = Qt.resolvedUrl(Wallpaper.fullContentPath) loader.webViewUrl = Qt.resolvedUrl(Wallpaper.fullContentPath)
loader.source = "qrc:/WebView.qml" loader.source = "qrc:/WebView.qml"
fadeIn() fadeIn()
break break
case Wallpaper.WallpaperType.Qml: case Wallpaper.WallpaperType.Qml:
loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath) loader.source = Qt.resolvedUrl(Wallpaper.fullContentPath)
imgCover.state = "out" imgCover.state = "out"
fadeIn() fadeIn()
break break
} }
} }

View File

@ -98,7 +98,8 @@ Item {
Connections { Connections {
target: Wallpaper target: Wallpaper
function onReloadVideo() { function onReloadVideo(oldType) {
webView.runJavaScript(root.getSetVideoCommand()) webView.runJavaScript(root.getSetVideoCommand())
} }

View File

@ -13,6 +13,7 @@ BaseWindow::BaseWindow(QString projectFilePath, const QVector<int> activeScreens
QApplication::instance()->installEventFilter(this); QApplication::instance()->installEventFilter(this);
qRegisterMetaType<BaseWindow::WallpaperType>(); qRegisterMetaType<BaseWindow::WallpaperType>();
qmlRegisterType<BaseWindow>("ScreenPlay.Wallpaper", 1, 0, "Wallpaper"); qmlRegisterType<BaseWindow>("ScreenPlay.Wallpaper", 1, 0, "Wallpaper");
setOSVersion(QSysInfo::productVersion()); setOSVersion(QSysInfo::productVersion());
@ -66,8 +67,9 @@ BaseWindow::BaseWindow(QString projectFilePath, const QVector<int> activeScreens
setBasePath(projectFilePath); setBasePath(projectFilePath);
setFullContentPath("file:///" + projectFilePath + "/" + projectObject.value("file").toString()); setFullContentPath("file:///" + projectFilePath + "/" + projectObject.value("file").toString());
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, &BaseWindow::reloadQML); auto reloadQMLLambda = [this]() { emit reloadQML(type()); };
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, &BaseWindow::reloadQML); QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::directoryChanged, this, reloadQMLLambda);
QObject::connect(&m_fileSystemWatcher, &QFileSystemWatcher::fileChanged, this, reloadQMLLambda);
m_fileSystemWatcher.addPaths({ projectFilePath, projectFilePath + "/" + projectObject.value("file").toString() }); m_fileSystemWatcher.addPaths({ projectFilePath, projectFilePath + "/" + projectObject.value("file").toString() });
QString type = projectObject.value("type").toString().toLower(); QString type = projectObject.value("type").toString().toLower();
@ -143,6 +145,7 @@ void BaseWindow::replaceWallpaper(
const QString type, const QString type,
const bool checkWallpaperVisible) const bool checkWallpaperVisible)
{ {
const WallpaperType oldType = this->type();
setCheckWallpaperVisible(checkWallpaperVisible); setCheckWallpaperVisible(checkWallpaperVisible);
setVolume(volume); setVolume(volume);
setFillMode(fillMode); setFillMode(fillMode);
@ -151,10 +154,10 @@ void BaseWindow::replaceWallpaper(
qInfo() << file; qInfo() << file;
if (m_type == WallpaperType::Qml || m_type == WallpaperType::Html) if (m_type == WallpaperType::Qml || m_type == WallpaperType::Html)
emit reloadQML(); emit reloadQML(oldType);
if (m_type == WallpaperType::Video) if (m_type == WallpaperType::Video)
emit reloadVideo(); emit reloadVideo(oldType);
} }
// Used for loading shader // Used for loading shader

View File

@ -106,7 +106,7 @@ public:
return m_playbackRate; return m_playbackRate;
} }
WallpaperType type() const BaseWindow::WallpaperType type() const
{ {
return m_type; return m_type;
} }
@ -178,14 +178,14 @@ public:
signals: signals:
void qmlExit(); void qmlExit();
void reloadQML(); void reloadQML(const BaseWindow::WallpaperType oldType);
void reloadVideo(); void reloadVideo(const BaseWindow::WallpaperType oldType);
void loopsChanged(bool loops); void loopsChanged(bool loops);
void volumeChanged(float volume); void volumeChanged(float volume);
void isPlayingChanged(bool isPlaying); void isPlayingChanged(bool isPlaying);
void playbackRateChanged(float playbackRate); void playbackRateChanged(float playbackRate);
void typeChanged(WallpaperType type); void typeChanged(BaseWindow::WallpaperType type);
void fullContentPathChanged(QString fullContentPath); void fullContentPathChanged(QString fullContentPath);
void appIDChanged(QString appID); void appIDChanged(QString appID);
void qmlSceneValueReceived(QString key, QString value); void qmlSceneValueReceived(QString key, QString value);
@ -259,7 +259,7 @@ public slots:
emit playbackRateChanged(m_playbackRate); emit playbackRateChanged(m_playbackRate);
} }
void setType(WallpaperType type) void setType(BaseWindow::WallpaperType type)
{ {
if (m_type == type) if (m_type == type)
return; return;