Commit 723a2048 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.propertyEditor: adding translation support

Adding support for qsTr()

Change-Id: Ib678820c40e910f744d9722e7958225dcc115d70
Reviewed-on: http://codereview.qt.nokia.com/565

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@nokia.com>
parent cf98df93
......@@ -11,8 +11,12 @@ AnimatedToolButton {
function setIcon() {
if (backendValue == null)
extendedFunctionButton.iconFromFile = "images/placeholder.png"
else if (backendValue.isBound) {
extendedFunctionButton.iconFromFile = "images/expression.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: {
backendValue.value = text
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
}
}
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment