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:
@@ -12,7 +12,11 @@ AnimatedToolButton {
|
||||
if (backendValue == null)
|
||||
extendedFunctionButton.iconFromFile = "images/placeholder.png"
|
||||
else if (backendValue.isBound ) {
|
||||
if (backendValue.isTranslated) { //translations are a special case
|
||||
extendedFunctionButton.iconFromFile = "images/placeholder.png"
|
||||
} else {
|
||||
extendedFunctionButton.iconFromFile = "images/expression.png"
|
||||
}
|
||||
} else {
|
||||
if (backendValue.complexNode != null && backendValue.complexNode.exists) {
|
||||
extendedFunctionButton.iconFromFile = "images/behaivour.png"
|
||||
@@ -26,11 +30,16 @@ AnimatedToolButton {
|
||||
setIcon();
|
||||
}
|
||||
property bool isBoundBackend: backendValue.isBound;
|
||||
property string backendExpression: backendValue.expression;
|
||||
|
||||
onIsBoundBackendChanged: {
|
||||
setIcon();
|
||||
}
|
||||
|
||||
onBackendExpressionChanged: {
|
||||
setIcon();
|
||||
}
|
||||
|
||||
toolButtonStyle: "Qt::ToolButtonIconOnly"
|
||||
popupMode: "QToolButton::InstantPopup";
|
||||
property bool active: false;
|
||||
|
||||
@@ -9,6 +9,7 @@ QWidget {
|
||||
property variant baseStateFlag
|
||||
property alias text: lineEditWidget.text
|
||||
property alias readOnly: lineEditWidget.readOnly
|
||||
property alias translation: trCheckbox.visible
|
||||
|
||||
minimumHeight: 24;
|
||||
|
||||
@@ -68,7 +69,11 @@ QWidget {
|
||||
}
|
||||
|
||||
onEditingFinished: {
|
||||
if (backendValue.isTranslated) {
|
||||
backendValue.expression = "qsTr(\"" + text + "\")"
|
||||
} else {
|
||||
backendValue.value = text
|
||||
}
|
||||
evaluate();
|
||||
}
|
||||
|
||||
@@ -87,4 +92,30 @@ QWidget {
|
||||
x: 0
|
||||
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 {
|
||||
backendValue: backendValues.text
|
||||
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_hover.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_crossed.png</file>
|
||||
<file>images/lock.png</file>
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "propertyeditorvalue.h"
|
||||
#include <QRegExp>
|
||||
#include <abstractview.h>
|
||||
#include <nodeabstractproperty.h>
|
||||
#include <nodeproperty.h>
|
||||
@@ -97,7 +98,7 @@ static bool cleverColorCompare(QVariant value1, QVariant value2)
|
||||
|
||||
void PropertyEditorValue::setValueWithEmit(const QVariant &value)
|
||||
{
|
||||
if (m_value != value) {
|
||||
if (m_value != value || isBound()) {
|
||||
QVariant newValue = value;
|
||||
if (modelNode().isValid() && modelNode().metaInfo().isValid() && modelNode().metaInfo().hasProperty(name()))
|
||||
if (modelNode().metaInfo().propertyTypeName(name()) == QLatin1String("QUrl")) {
|
||||
@@ -190,6 +191,22 @@ void PropertyEditorValue::setIsValid(bool 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
|
||||
{
|
||||
return m_modelNode;
|
||||
|
||||
@@ -86,6 +86,8 @@ class PropertyEditorValue : public QObject
|
||||
Q_PROPERTY(bool isInSubState READ isInSubState NOTIFY valueChangedQml FINAL)
|
||||
Q_PROPERTY(bool isBound READ isBound NOTIFY isBoundChanged 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(PropertyEditorNodeWrapper* complexNode READ complexNode NOTIFY complexNodeChanged FINAL)
|
||||
|
||||
@@ -109,6 +111,8 @@ public:
|
||||
|
||||
void setIsValid(bool valid);
|
||||
|
||||
bool isTranslated() const;
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user