forked from qt-creator/qt-creator
QmlDesigner.propertyEditor: adding translation support
Adding support for qsTr() Change-Id: Ib678820c40e910f744d9722e7958225dcc115d70 Reviewed-on: http://codereview.qt.nokia.com/565 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
@@ -11,8 +11,12 @@ AnimatedToolButton {
|
|||||||
function setIcon() {
|
function setIcon() {
|
||||||
if (backendValue == null)
|
if (backendValue == null)
|
||||||
extendedFunctionButton.iconFromFile = "images/placeholder.png"
|
extendedFunctionButton.iconFromFile = "images/placeholder.png"
|
||||||
else if (backendValue.isBound) {
|
else if (backendValue.isBound ) {
|
||||||
extendedFunctionButton.iconFromFile = "images/expression.png"
|
if (backendValue.isTranslated) { //translations are a special case
|
||||||
|
extendedFunctionButton.iconFromFile = "images/placeholder.png"
|
||||||
|
} else {
|
||||||
|
extendedFunctionButton.iconFromFile = "images/expression.png"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (backendValue.complexNode != null && backendValue.complexNode.exists) {
|
if (backendValue.complexNode != null && backendValue.complexNode.exists) {
|
||||||
extendedFunctionButton.iconFromFile = "images/behaivour.png"
|
extendedFunctionButton.iconFromFile = "images/behaivour.png"
|
||||||
@@ -26,11 +30,16 @@ AnimatedToolButton {
|
|||||||
setIcon();
|
setIcon();
|
||||||
}
|
}
|
||||||
property bool isBoundBackend: backendValue.isBound;
|
property bool isBoundBackend: backendValue.isBound;
|
||||||
|
property string backendExpression: backendValue.expression;
|
||||||
|
|
||||||
onIsBoundBackendChanged: {
|
onIsBoundBackendChanged: {
|
||||||
setIcon();
|
setIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBackendExpressionChanged: {
|
||||||
|
setIcon();
|
||||||
|
}
|
||||||
|
|
||||||
toolButtonStyle: "Qt::ToolButtonIconOnly"
|
toolButtonStyle: "Qt::ToolButtonIconOnly"
|
||||||
popupMode: "QToolButton::InstantPopup";
|
popupMode: "QToolButton::InstantPopup";
|
||||||
property bool active: false;
|
property bool active: false;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ QWidget {
|
|||||||
property variant baseStateFlag
|
property variant baseStateFlag
|
||||||
property alias text: lineEditWidget.text
|
property alias text: lineEditWidget.text
|
||||||
property alias readOnly: lineEditWidget.readOnly
|
property alias readOnly: lineEditWidget.readOnly
|
||||||
|
property alias translation: trCheckbox.visible
|
||||||
|
|
||||||
minimumHeight: 24;
|
minimumHeight: 24;
|
||||||
|
|
||||||
@@ -68,7 +69,11 @@ QWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onEditingFinished: {
|
onEditingFinished: {
|
||||||
backendValue.value = text
|
if (backendValue.isTranslated) {
|
||||||
|
backendValue.expression = "qsTr(\"" + text + "\")"
|
||||||
|
} else {
|
||||||
|
backendValue.value = text
|
||||||
|
}
|
||||||
evaluate();
|
evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,4 +92,30 @@ QWidget {
|
|||||||
x: 0
|
x: 0
|
||||||
visible: lineEdit.enabled
|
visible: lineEdit.enabled
|
||||||
}
|
}
|
||||||
|
QCheckBox {
|
||||||
|
id: trCheckbox
|
||||||
|
y: 2
|
||||||
|
styleSheetFile: "checkbox_tr.css";
|
||||||
|
toolTip: qsTr("Translate this string")
|
||||||
|
x: lineEditWidget.width - 22
|
||||||
|
height: lineEdit.height - 2;
|
||||||
|
width: 24
|
||||||
|
visible: false
|
||||||
|
checked: backendValue.isTranslated
|
||||||
|
onToggled: {
|
||||||
|
if (trCheckbox.checked) {
|
||||||
|
backendValue.expression = "qsTr(\"" + lineEditWidget.text + "\")"
|
||||||
|
} else {
|
||||||
|
backendValue.value = lineEditWidget.text
|
||||||
|
}
|
||||||
|
evaluate();
|
||||||
|
}
|
||||||
|
|
||||||
|
onVisibleChanged: {
|
||||||
|
if (trCheckbox.visible) {
|
||||||
|
trCheckbox.raise();
|
||||||
|
lineEditWidget.styleSheet = "QLineEdit { padding-left: 32; padding-right: 62;}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ GroupBox {
|
|||||||
LineEdit {
|
LineEdit {
|
||||||
backendValue: backendValues.text
|
backendValue: backendValues.text
|
||||||
baseStateFlag: isBaseState;
|
baseStateFlag: isBaseState;
|
||||||
|
translation: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_checked.png
Normal file
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_checked.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 449 B |
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_checked_hover.png
Normal file
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_checked_hover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 449 B |
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_checked_pressed.png
Normal file
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_checked_pressed.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 449 B |
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_unchecked.png
Normal file
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_unchecked.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 354 B |
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_unchecked_hover.png
Normal file
BIN
src/libs/qmleditorwidgets/images/checkbox_tr_unchecked_hover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 354 B |
Binary file not shown.
|
After Width: | Height: | Size: 354 B |
@@ -6,6 +6,12 @@
|
|||||||
<file>images/checkbox_unchecked.png</file>
|
<file>images/checkbox_unchecked.png</file>
|
||||||
<file>images/checkbox_unchecked_hover.png</file>
|
<file>images/checkbox_unchecked_hover.png</file>
|
||||||
<file>images/checkbox_unchecked_pressed.png</file>
|
<file>images/checkbox_unchecked_pressed.png</file>
|
||||||
|
<file>images/checkbox_tr_checked.png</file>
|
||||||
|
<file>images/checkbox_tr_checked_hover.png</file>
|
||||||
|
<file>images/checkbox_tr_checked_pressed.png</file>
|
||||||
|
<file>images/checkbox_tr_unchecked.png</file>
|
||||||
|
<file>images/checkbox_tr_unchecked_hover.png</file>
|
||||||
|
<file>images/checkbox_tr_unchecked_pressed.png</file>
|
||||||
<file>images/eye_open.png</file>
|
<file>images/eye_open.png</file>
|
||||||
<file>images/eye_crossed.png</file>
|
<file>images/eye_crossed.png</file>
|
||||||
<file>images/lock.png</file>
|
<file>images/lock.png</file>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "propertyeditorvalue.h"
|
#include "propertyeditorvalue.h"
|
||||||
|
#include <QRegExp>
|
||||||
#include <abstractview.h>
|
#include <abstractview.h>
|
||||||
#include <nodeabstractproperty.h>
|
#include <nodeabstractproperty.h>
|
||||||
#include <nodeproperty.h>
|
#include <nodeproperty.h>
|
||||||
@@ -97,7 +98,7 @@ static bool cleverColorCompare(QVariant value1, QVariant value2)
|
|||||||
|
|
||||||
void PropertyEditorValue::setValueWithEmit(const QVariant &value)
|
void PropertyEditorValue::setValueWithEmit(const QVariant &value)
|
||||||
{
|
{
|
||||||
if (m_value != value) {
|
if (m_value != value || isBound()) {
|
||||||
QVariant newValue = value;
|
QVariant newValue = value;
|
||||||
if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name()))
|
if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name()))
|
||||||
if (modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("QUrl")) {
|
if (modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("QUrl")) {
|
||||||
@@ -190,6 +191,22 @@ void PropertyEditorValue::setIsValid(bool valid)
|
|||||||
m_isValid = valid;
|
m_isValid = valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PropertyEditorValue::isTranslated() const
|
||||||
|
{
|
||||||
|
if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name()))
|
||||||
|
if (modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("QString") || modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("string")) {
|
||||||
|
const QmlDesigner::QmlObjectNode objectNode(modelNode());
|
||||||
|
if (objectNode.isValid() && objectNode.hasBindingProperty(name())) {
|
||||||
|
//qsTr()
|
||||||
|
QRegExp rx("qsTr(\"*\")");
|
||||||
|
rx.setPatternSyntax(QRegExp::Wildcard);
|
||||||
|
return rx.exactMatch(expression());
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QmlDesigner::ModelNode PropertyEditorValue::modelNode() const
|
QmlDesigner::ModelNode PropertyEditorValue::modelNode() const
|
||||||
{
|
{
|
||||||
return m_modelNode;
|
return m_modelNode;
|
||||||
|
|||||||
@@ -86,6 +86,8 @@ class PropertyEditorValue : public QObject
|
|||||||
Q_PROPERTY(bool isInSubState READ isInSubState NOTIFY valueChangedQml FINAL)
|
Q_PROPERTY(bool isInSubState READ isInSubState NOTIFY valueChangedQml FINAL)
|
||||||
Q_PROPERTY(bool isBound READ isBound NOTIFY isBoundChanged FINAL)
|
Q_PROPERTY(bool isBound READ isBound NOTIFY isBoundChanged FINAL)
|
||||||
Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL)
|
Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged FINAL)
|
||||||
|
Q_PROPERTY(bool isTranslated READ isTranslated NOTIFY valueChangedQml FINAL)
|
||||||
|
|
||||||
Q_PROPERTY(QString name READ name FINAL)
|
Q_PROPERTY(QString name READ name FINAL)
|
||||||
Q_PROPERTY(PropertyEditorNodeWrapper* complexNode READ complexNode NOTIFY complexNodeChanged FINAL)
|
Q_PROPERTY(PropertyEditorNodeWrapper* complexNode READ complexNode NOTIFY complexNodeChanged FINAL)
|
||||||
|
|
||||||
@@ -109,6 +111,8 @@ public:
|
|||||||
|
|
||||||
void setIsValid(bool valid);
|
void setIsValid(bool valid);
|
||||||
|
|
||||||
|
bool isTranslated() const;
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user