EffectComposer: Clean up tr()

Use Tr::tr, clean up translatable strings.

Change-Id: Ie88a3407f5127307d06057529cad1b7db004a8f0
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Eike Ziller
2025-02-11 14:19:45 +01:00
parent 7d4a39ce4f
commit 256c3b3c99
11 changed files with 90 additions and 57 deletions

View File

@@ -10,6 +10,7 @@ add_qtc_plugin(EffectComposer
effectcomposereditablenodesmodel.cpp effectcomposereditablenodesmodel.h effectcomposereditablenodesmodel.cpp effectcomposereditablenodesmodel.h
effectcodeeditorwidget.cpp effectcodeeditorwidget.h effectcodeeditorwidget.cpp effectcodeeditorwidget.h
effectcomposerplugin.cpp effectcomposerplugin.cpp
effectcomposertr.h
effectcomposerwidget.cpp effectcomposerwidget.h effectcomposerwidget.cpp effectcomposerwidget.h
effectcomposerview.cpp effectcomposerview.h effectcomposerview.cpp effectcomposerview.h
effectcomposermodel.cpp effectcomposermodel.h effectcomposermodel.cpp effectcomposermodel.h

View File

@@ -3,6 +3,7 @@
#include "effectcodeeditorwidget.h" #include "effectcodeeditorwidget.h"
#include "effectcomposertr.h"
#include "effectsautocomplete.h" #include "effectsautocomplete.h"
#include "syntaxhighlighter.h" #include "syntaxhighlighter.h"
@@ -49,14 +50,12 @@ EffectCodeEditorWidget::EffectCodeEditorWidget()
* We have to register our own active auto completion shortcut, because the original shortcut will * We have to register our own active auto completion shortcut, because the original shortcut will
* use the cursor position of the original editor in the editor manager. * use the cursor position of the original editor in the editor manager.
*/ */
m_completionAction = new QAction(tr("Trigger Completion"), this); m_completionAction = new QAction(Tr::tr("Trigger Completion"), this);
Core::Command *command = Core::ActionManager::registerAction( Core::Command *command = Core::ActionManager::registerAction(
m_completionAction, TextEditor::Constants::COMPLETE_THIS, context); m_completionAction, TextEditor::Constants::COMPLETE_THIS, context);
command->setDefaultKeySequence(QKeySequence( command->setDefaultKeySequence(
Core::useMacShortcuts QKeySequence(Core::useMacShortcuts ? Tr::tr("Meta+Space") : Tr::tr("Ctrl+Space")));
? tr("Meta+Space")
: tr("Ctrl+Space")));
connect(m_completionAction, &QAction::triggered, this, [this] { connect(m_completionAction, &QAction::triggered, this, [this] {
invokeAssist(TextEditor::Completion); invokeAssist(TextEditor::Completion);
@@ -149,7 +148,7 @@ void EffectDocument::triggerPendingUpdates()
EffectCodeEditorFactory::EffectCodeEditorFactory() EffectCodeEditorFactory::EffectCodeEditorFactory()
{ {
setId(EFFECTEDITOR_CONTEXT_ID); setId(EFFECTEDITOR_CONTEXT_ID);
setDisplayName(::Core::Tr::tr("Effect Code Editor")); setDisplayName(Tr::tr("Effect Code Editor"));
addMimeType(EFFECTEDITOR_CONTEXT_ID); addMimeType(EFFECTEDITOR_CONTEXT_ID);
addMimeType(Utils::Constants::QML_MIMETYPE); addMimeType(Utils::Constants::QML_MIMETYPE);
addMimeType(Utils::Constants::QMLTYPES_MIMETYPE); addMimeType(Utils::Constants::QMLTYPES_MIMETYPE);

View File

@@ -4,6 +4,7 @@
#include "effectcomposereditablenodesmodel.h" #include "effectcomposereditablenodesmodel.h"
#include "effectcomposermodel.h" #include "effectcomposermodel.h"
#include "effectcomposertr.h"
namespace EffectComposer { namespace EffectComposer {
@@ -140,7 +141,7 @@ void EffectComposerEditableNodesModel::reload()
const int mainIdx = m_sourceModel->mainCodeEditorIndex(); const int mainIdx = m_sourceModel->mainCodeEditorIndex();
m_data.append(Item{tr("Main"), mainIdx}); m_data.append(Item{Tr::tr("Main"), mainIdx});
m_sourceToItemMap.insert(mainIdx, 0); m_sourceToItemMap.insert(mainIdx, 0);
const int sourceSize = m_sourceModel->rowCount(); const int sourceSize = m_sourceModel->rowCount();
for (int i = 0; i < sourceSize; ++i) { for (int i = 0; i < sourceSize; ++i) {

View File

@@ -4,6 +4,7 @@
#include "effectcomposermodel.h" #include "effectcomposermodel.h"
#include "compositionnode.h" #include "compositionnode.h"
#include "effectcomposertr.h"
#include "effectshaderscodeeditor.h" #include "effectshaderscodeeditor.h"
#include "effectutils.h" #include "effectutils.h"
#include "propertyhandler.h" #include "propertyhandler.h"
@@ -292,9 +293,9 @@ QString EffectComposerModel::getUniqueEffectName() const
QString EffectComposerModel::getUniqueDisplayName(const QStringList reservedNames) const QString EffectComposerModel::getUniqueDisplayName(const QStringList reservedNames) const
{ {
return QmlDesigner::UniqueName::generate(tr("New Property"), [&reservedNames] (const QString &name) { return QmlDesigner::UniqueName::generate(
return reservedNames.contains(name); Tr::tr("New Property"),
}); [&reservedNames](const QString &name) { return reservedNames.contains(name); });
} }
bool EffectComposerModel::nameExists(const QString &name) const bool EffectComposerModel::nameExists(const QString &name) const
@@ -315,10 +316,11 @@ void EffectComposerModel::chooseCustomPreviewImage()
QmlDesigner::DesignDocument *document = QmlDesigner::QmlDesignerPlugin::instance()->currentDesignDocument(); QmlDesigner::DesignDocument *document = QmlDesigner::QmlDesignerPlugin::instance()->currentDesignDocument();
const FilePath currentDir = lastDir.isEmpty() ? document->fileName().parentDir() const FilePath currentDir = lastDir.isEmpty() ? document->fileName().parentDir()
: lastDir; : lastDir;
const QStringList fileNames = QFileDialog::getOpenFileNames(Core::ICore::dialogParent(), const QStringList fileNames = QFileDialog::getOpenFileNames(
tr("Select custom effect background image"), Core::ICore::dialogParent(),
Tr::tr("Select Custom Effect Background Image"),
currentDir.toFSPathString(), currentDir.toFSPathString(),
tr("Image Files (%1)").arg(suffixes.join(" "))); Tr::tr("Image Files (%1)").arg(suffixes.join(" ")));
if (!fileNames.isEmpty()) { if (!fileNames.isEmpty()) {
FilePath imageFile = FilePath::fromString(fileNames.first()); FilePath imageFile = FilePath::fromString(fileNames.first());
@@ -618,22 +620,20 @@ void EffectComposerModel::setEffectError(const QString &errorMessage, int type,
QString EffectComposerModel::effectErrors() const QString EffectComposerModel::effectErrors() const
{ {
static const QStringList errorTypeStrings { static const QStringList errorTypeStrings{
"Common", Tr::tr("Common error: %1"),
"QML parsing", Tr::tr("QML parsing error: %1"),
"Shader", Tr::tr("Shader error: %1"),
"Preprocessor" Tr::tr("Preprocessor error: %1")};
};
static const QString messageTemplate = tr("%1 error: %2\n");
QString retval;
QString retval;
for (const QList<EffectError> &errors : std::as_const(m_effectErrors)) { for (const QList<EffectError> &errors : std::as_const(m_effectErrors)) {
for (const EffectError &e : errors) { for (const EffectError &e : errors) {
if (!e.m_message.isEmpty()) { if (!e.m_message.isEmpty()) {
int index = e.m_type; int index = e.m_type;
if (index < 0 || index >= errorTypeStrings.size()) if (index < 0 || index >= errorTypeStrings.size())
index = 0; index = 0;
retval.append(messageTemplate.arg(errorTypeStrings[index], e.m_message)); retval.append(errorTypeStrings[index].arg(e.m_message) + "\n");
} }
} }
} }
@@ -860,7 +860,10 @@ R"(
ExpandingSpacer {} ExpandingSpacer {}
} }
)"; )";
s += animSec.arg(tr("Animation"), tr("Running"), tr("Set this property to animate the effect.")); s += animSec.arg(
Tr::tr("Animation"),
Tr::tr("Running"),
Tr::tr("Set this property to animate the effect."));
if (m_shaderFeatures.enabled(ShaderFeatures::Time)) { if (m_shaderFeatures.enabled(ShaderFeatures::Time)) {
QString timeProp = QString timeProp =
@@ -884,7 +887,10 @@ R"(
ExpandingSpacer {} ExpandingSpacer {}
} }
)"; )";
s += timeProp.arg(tr("Time"), tr("This property allows explicit control of current animation time when Running property is false.")); s += timeProp.arg(
Tr::tr("Time"),
Tr::tr("This property allows explicit control of current animation time when "
"Running property is false."));
} }
if (m_shaderFeatures.enabled(ShaderFeatures::Frame)) { if (m_shaderFeatures.enabled(ShaderFeatures::Frame)) {
@@ -909,7 +915,10 @@ R"(
ExpandingSpacer {} ExpandingSpacer {}
} }
)"; )";
s += frameProp.arg(tr("Frame"), tr("This property allows explicit control of current animation frame when Running property is false.")); s += frameProp.arg(
Tr::tr("Frame"),
Tr::tr("This property allows explicit control of current animation frame when "
"Running property is false."));
} }
s += " }\n"; s += " }\n";
@@ -945,8 +954,11 @@ R"(
} }
} }
)"; )";
s += generalSection.arg(tr("General"), tr("Extra Margin"), s += generalSection.arg(
tr("This property specifies how much of extra space is reserved for the effect outside the parent geometry.")); Tr::tr("General"),
Tr::tr("Extra Margin"),
Tr::tr("This property specifies how much of extra space is reserved for the effect "
"outside the parent geometry."));
} }
for (const auto &node : std::as_const(m_nodes)) { for (const auto &node : std::as_const(m_nodes)) {

View File

@@ -0,0 +1,15 @@
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#pragma once
#include <QCoreApplication>
namespace EffectComposer {
struct Tr
{
Q_DECLARE_TR_FUNCTIONS(QtC::EffectComposer)
};
} // namespace EffectComposee

View File

@@ -3,6 +3,7 @@
#include "effectcomposeruniformstablemodel.h" #include "effectcomposeruniformstablemodel.h"
#include "effectcomposertr.h"
#include "uniform.h" #include "uniform.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -15,14 +16,6 @@ namespace EffectComposer {
namespace { namespace {
struct Tr
{
static inline QString tr(const auto &text)
{
return EffectComposerUniformsTableModel::tr(text);
}
};
struct RoleColMap struct RoleColMap
{ {
using UniformRole = EffectComposerUniformsModel::Roles; using UniformRole = EffectComposerUniformsModel::Roles;

View File

@@ -5,6 +5,7 @@
#include "effectcomposermodel.h" #include "effectcomposermodel.h"
#include "effectcomposernodesmodel.h" #include "effectcomposernodesmodel.h"
#include "effectcomposertr.h"
#include "effectcomposerwidget.h" #include "effectcomposerwidget.h"
#include "listmodelwidthcalculator.h" #include "listmodelwidthcalculator.h"
#include "studioquickwidget.h" #include "studioquickwidget.h"
@@ -120,10 +121,11 @@ QmlDesigner::WidgetInfo EffectComposerView::widgetInfo()
}); });
} }
return createWidgetInfo(m_widget.data(), return createWidgetInfo(
m_widget.data(),
"EffectComposer", "EffectComposer",
QmlDesigner::WidgetInfo::LeftPane, QmlDesigner::WidgetInfo::LeftPane,
tr("Effect Composer [beta]")); Tr::tr("Effect Composer [beta]"));
} }
void EffectComposerView::customNotification([[maybe_unused]] const AbstractView *view, void EffectComposerView::customNotification([[maybe_unused]] const AbstractView *view,

View File

@@ -6,6 +6,7 @@
#include "effectcomposercontextobject.h" #include "effectcomposercontextobject.h"
#include "effectcomposermodel.h" #include "effectcomposermodel.h"
#include "effectcomposernodesmodel.h" #include "effectcomposernodesmodel.h"
#include "effectcomposertr.h"
#include "effectcomposerview.h" #include "effectcomposerview.h"
#include "effectutils.h" #include "effectutils.h"
#include "propertyhandler.h" #include "propertyhandler.h"
@@ -78,7 +79,7 @@ EffectComposerWidget::EffectComposerWidget(EffectComposerView *view)
, m_effectComposerView(view) , m_effectComposerView(view)
, m_quickWidget{new StudioQuickWidget(this)} , m_quickWidget{new StudioQuickWidget(this)}
{ {
setWindowTitle(tr("Effect Composer", "Title of effect composer widget")); setWindowTitle(Tr::tr("Effect Composer", "Title of effect composer widget"));
setMinimumWidth(400); setMinimumWidth(400);
// create the inner widget // create the inner widget

View File

@@ -5,6 +5,7 @@
#include "effectcomposereditablenodesmodel.h" #include "effectcomposereditablenodesmodel.h"
#include "effectcomposermodel.h" #include "effectcomposermodel.h"
#include "effectcomposertr.h"
#include "effectcomposeruniformsmodel.h" #include "effectcomposeruniformsmodel.h"
#include "effectcomposeruniformstablemodel.h" #include "effectcomposeruniformstablemodel.h"
#include "effectcomposerwidget.h" #include "effectcomposerwidget.h"
@@ -271,7 +272,7 @@ void EffectShadersCodeEditor::insertTextToCursorPosition(const QString &text)
EffectShadersCodeEditor *EffectShadersCodeEditor::instance() EffectShadersCodeEditor *EffectShadersCodeEditor::instance()
{ {
static EffectShadersCodeEditor *editorInstance static EffectShadersCodeEditor *editorInstance
= new EffectShadersCodeEditor(tr("Shaders Code Editor"), Core::ICore::dialogParent()); = new EffectShadersCodeEditor(Tr::tr("Shaders Code Editor"), Core::ICore::dialogParent());
return editorInstance; return editorInstance;
} }

View File

@@ -4,6 +4,7 @@
#pragma once #pragma once
#include "effectcodeeditorwidget.h" #include "effectcodeeditorwidget.h"
#include "effectcomposertr.h"
#include <texteditor/texteditor.h> #include <texteditor/texteditor.h>
@@ -50,7 +51,8 @@ class EffectShadersCodeEditor : public QWidget
NOTIFY selectedShaderChanged) NOTIFY selectedShaderChanged)
public: public:
EffectShadersCodeEditor(const QString &title = tr("Untitled Editor"), QWidget *parent = nullptr); EffectShadersCodeEditor(
const QString &title = Tr::tr("Untitled Editor"), QWidget *parent = nullptr);
~EffectShadersCodeEditor() override; ~EffectShadersCodeEditor() override;
void showWidget(); void showWidget();

View File

@@ -2,6 +2,9 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "uniform.h" #include "uniform.h"
#include "effectcomposertr.h"
#include <qmldesignerplugin.h> #include <qmldesignerplugin.h>
#include "propertyhandler.h" #include "propertyhandler.h"
@@ -328,27 +331,27 @@ R"(
case Type::Vec2: { case Type::Vec2: {
QVector2D minVal = m_minValue.value<QVector2D>(); QVector2D minVal = m_minValue.value<QVector2D>();
QVector2D maxVal = m_maxValue.value<QVector2D>(); QVector2D maxVal = m_maxValue.value<QVector2D>();
appendVectorSpinbox("x", tr("X"), minVal.x(), maxVal.x(), true); appendVectorSpinbox("x", Tr::tr("X"), minVal.x(), maxVal.x(), true);
appendVectorSpinbox("y", tr("Y"), minVal.y(), maxVal.y(), false); appendVectorSpinbox("y", Tr::tr("Y"), minVal.y(), maxVal.y(), false);
break; break;
} }
case Type::Vec3: { case Type::Vec3: {
QVector3D minVal = m_minValue.value<QVector3D>(); QVector3D minVal = m_minValue.value<QVector3D>();
QVector3D maxVal = m_maxValue.value<QVector3D>(); QVector3D maxVal = m_maxValue.value<QVector3D>();
appendVectorSpinbox("x", tr("X"), minVal.x(), maxVal.x(), true); appendVectorSpinbox("x", Tr::tr("X"), minVal.x(), maxVal.x(), true);
appendVectorSpinbox("y", tr("Y"), minVal.y(), maxVal.y(), false); appendVectorSpinbox("y", Tr::tr("Y"), minVal.y(), maxVal.y(), false);
appendVectorSeparator(); appendVectorSeparator();
appendVectorSpinbox("z", tr("Z"), minVal.z(), maxVal.z(), true); appendVectorSpinbox("z", Tr::tr("Z"), minVal.z(), maxVal.z(), true);
break; break;
} }
case Type::Vec4: { case Type::Vec4: {
QVector4D minVal = m_minValue.value<QVector4D>(); QVector4D minVal = m_minValue.value<QVector4D>();
QVector4D maxVal = m_maxValue.value<QVector4D>(); QVector4D maxVal = m_maxValue.value<QVector4D>();
appendVectorSpinbox("x", tr("X"), minVal.x(), maxVal.x(), true); appendVectorSpinbox("x", Tr::tr("X"), minVal.x(), maxVal.x(), true);
appendVectorSpinbox("y", tr("Y"), minVal.y(), maxVal.y(), false); appendVectorSpinbox("y", Tr::tr("Y"), minVal.y(), maxVal.y(), false);
appendVectorSeparator(); appendVectorSeparator();
appendVectorSpinbox("z", tr("Z"), minVal.z(), maxVal.z(), true); appendVectorSpinbox("z", Tr::tr("Z"), minVal.z(), maxVal.z(), true);
appendVectorSpinbox("w", tr("W"), minVal.w(), maxVal.w(), false); appendVectorSpinbox("w", Tr::tr("W"), minVal.w(), maxVal.w(), false);
break; break;
} }
case Type::Color: { case Type::Color: {
@@ -383,10 +386,13 @@ R"(
backendValue: backendValues.%2 backendValue: backendValues.%2
} }
)"; )";
specs += typeSpec.arg(m_name + "Url") specs
+= typeSpec.arg(m_name + "Url")
.arg(m_name) .arg(m_name)
.arg(m_displayName + tr(" Item")) .arg(Tr::tr("%1 Item").arg(m_displayName))
.arg(tr("Set this to use an item in the scene as %1 instead of the above image.") .arg(
Tr::tr(
"Set this to use an item in the scene as %1 instead of the above image.")
.arg(m_displayName)); .arg(m_displayName));
break; break;
} }