EffectComposer: Fix custom preview issues

- Custom preview saving and loading fixed when file is deleted
- Custom preview not shown in combo when it's opened after file deletion
- Fixed selected highlight on custom preview

Fixes: QDS-13880
Change-Id: I8ef3fed5cfc220e3b37007b302f54fe3bf01899d
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2024-10-25 14:32:24 +03:00
parent 20c8e51d99
commit 2ea6b555e5
3 changed files with 33 additions and 12 deletions

View File

@@ -69,6 +69,7 @@ StudioControls.ComboBox {
target: root.popup target: root.popup
function onAboutToShow() { function onAboutToShow() {
EffectComposerBackend.effectComposerModel.previewComboAboutToOpen()
root.calculateWindowGeometry() root.calculateWindowGeometry()
window.show() window.show()
@@ -170,7 +171,9 @@ StudioControls.ComboBox {
required property var modelData required property var modelData
color: "transparent" color: "transparent"
border.color: root.selectedImage === modelData ? StudioTheme.Values.themeInteraction border.color: root.selectedImage === modelData
|| index == 0 && root.selectedImage == EffectComposerBackend.effectComposerModel.customPreviewImage
? StudioTheme.Values.themeInteraction
: "transparent" : "transparent"
width: 200 width: 200

View File

@@ -294,6 +294,17 @@ void EffectComposerModel::chooseCustomPreviewImage()
}); });
} }
void EffectComposerModel::previewComboAboutToOpen()
{
if (!m_customPreviewImage.isEmpty() && !Utils::FilePath::fromUrl(m_customPreviewImage).exists()) {
if (m_currentPreviewImage == m_customPreviewImage) {
m_customPreviewImage.clear();
emit customPreviewImageChanged();
setCurrentPreviewImage({});
}
}
}
QString EffectComposerModel::fragmentShader() const QString EffectComposerModel::fragmentShader() const
{ {
return m_fragmentShader; return m_fragmentShader;
@@ -1067,8 +1078,12 @@ void EffectComposerModel::saveComposition(const QString &name)
json.insert("tool", "EffectComposer"); json.insert("tool", "EffectComposer");
Utils::FilePath customPreviewPath = Utils::FilePath::fromUrl(m_customPreviewImage); Utils::FilePath customPreviewPath = Utils::FilePath::fromUrl(m_customPreviewImage);
if (m_customPreviewImage.isLocalFile()) if (m_customPreviewImage.isLocalFile()) {
if (customPreviewPath.exists())
customPreviewPath = customPreviewPath.relativePathFrom(compositionDir); customPreviewPath = customPreviewPath.relativePathFrom(compositionDir);
else
customPreviewPath = {};
}
json.insert("customPreviewImage", customPreviewPath.toUrl().toString()); json.insert("customPreviewImage", customPreviewPath.toUrl().toString());
QUrl previewUrl = m_currentPreviewImage; QUrl previewUrl = m_currentPreviewImage;
@@ -1259,6 +1274,7 @@ void EffectComposerModel::openComposition(const QString &path)
m_customPreviewImage.clear(); m_customPreviewImage.clear();
if (json.contains("customPreviewImage")) { if (json.contains("customPreviewImage")) {
QUrl imageUrl{json["customPreviewImage"].toString()}; QUrl imageUrl{json["customPreviewImage"].toString()};
if (!imageUrl.isEmpty()) {
Utils::FilePath imagePath = Utils::FilePath::fromUrl(imageUrl); Utils::FilePath imagePath = Utils::FilePath::fromUrl(imageUrl);
if (imagePath.isAbsolutePath()) { if (imagePath.isAbsolutePath()) {
if (imagePath.exists()) if (imagePath.exists())
@@ -1269,6 +1285,7 @@ void EffectComposerModel::openComposition(const QString &path)
m_customPreviewImage = imagePath.toUrl(); m_customPreviewImage = imagePath.toUrl();
} }
} }
}
if (json.contains("nodes") && json["nodes"].isArray()) { if (json.contains("nodes") && json["nodes"].isArray()) {
beginResetModel(); beginResetModel();

View File

@@ -81,6 +81,7 @@ public:
Q_INVOKABLE QString getUniqueEffectName() const; Q_INVOKABLE QString getUniqueEffectName() const;
Q_INVOKABLE bool nameExists(const QString &name) const; Q_INVOKABLE bool nameExists(const QString &name) const;
Q_INVOKABLE void chooseCustomPreviewImage(); Q_INVOKABLE void chooseCustomPreviewImage();
Q_INVOKABLE void previewComboAboutToOpen();
bool shadersUpToDate() const; bool shadersUpToDate() const;
void setShadersUpToDate(bool newShadersUpToDate); void setShadersUpToDate(bool newShadersUpToDate);