2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-07-06 15:48:52 +00:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-07-06 15:48:52 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-06 15:48:52 +00:00
|
|
|
|
2012-09-27 10:50:54 +02:00
|
|
|
import QtQuick 1.0
|
2010-01-27 18:38:09 +01:00
|
|
|
import Bauhaus 1.0
|
|
|
|
|
|
|
|
|
|
QWidget {
|
2010-02-05 15:42:31 +10:00
|
|
|
id: lineEdit
|
2010-01-27 18:38:09 +01:00
|
|
|
|
2011-07-22 11:48:42 +02:00
|
|
|
function escapeString(string) {
|
|
|
|
|
var str = string;
|
|
|
|
|
str = str.replace(/\\/g, "\\\\");
|
|
|
|
|
str.replace(/\"/g, "\\\"");
|
|
|
|
|
str = str.replace(/\t/g, "\\t");
|
|
|
|
|
str = str.replace(/\r/g, "\\r");
|
|
|
|
|
str = str.replace(/\n/g, '\\n');
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-13 11:20:39 +02:00
|
|
|
property variant backendValue
|
2010-02-05 15:42:31 +10:00
|
|
|
property alias enabled: lineEdit.enabled
|
2010-04-13 11:20:39 +02:00
|
|
|
property variant baseStateFlag
|
2010-02-26 15:20:34 +01:00
|
|
|
property alias text: lineEditWidget.text
|
2010-02-26 17:24:36 +01:00
|
|
|
property alias readOnly: lineEditWidget.readOnly
|
2011-06-21 16:11:55 +02:00
|
|
|
property alias translation: trCheckbox.visible
|
2011-07-12 15:52:51 +02:00
|
|
|
property alias inputMask: lineEditWidget.inputMask
|
2010-01-27 18:38:09 +01:00
|
|
|
|
|
|
|
|
minimumHeight: 24;
|
|
|
|
|
|
2010-02-26 15:20:34 +01:00
|
|
|
onBaseStateFlagChanged: {
|
|
|
|
|
evaluate();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-13 11:20:39 +02:00
|
|
|
property variant isEnabled: lineEdit.enabled
|
2010-02-26 15:20:34 +01:00
|
|
|
onIsEnabledChanged: {
|
|
|
|
|
evaluate();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-16 11:28:37 +02:00
|
|
|
|
|
|
|
|
property bool isInModel: backendValue.isInModel;
|
|
|
|
|
onIsInModelChanged: {
|
|
|
|
|
evaluate();
|
|
|
|
|
}
|
|
|
|
|
property bool isInSubState: backendValue.isInSubState;
|
|
|
|
|
onIsInSubStateChanged: {
|
|
|
|
|
evaluate();
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 10:02:49 +01:00
|
|
|
function evaluate() {
|
|
|
|
|
if (!enabled) {
|
|
|
|
|
lineEditWidget.setStyleSheet("color: "+scheme.disabledColor);
|
|
|
|
|
} else {
|
|
|
|
|
if (baseStateFlag) {
|
|
|
|
|
if (backendValue != null && backendValue.isInModel)
|
|
|
|
|
lineEditWidget.setStyleSheet("color: "+scheme.changedBaseColor);
|
|
|
|
|
else
|
|
|
|
|
lineEditWidget.setStyleSheet("color: "+scheme.defaultColor);
|
|
|
|
|
} else {
|
|
|
|
|
if (backendValue != null && backendValue.isInSubState)
|
|
|
|
|
lineEditWidget.setStyleSheet("color: "+scheme.changedStateColor);
|
|
|
|
|
else
|
|
|
|
|
lineEditWidget.setStyleSheet("color: "+scheme.defaultColor);
|
|
|
|
|
}
|
2010-02-25 16:48:20 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColorScheme { id:scheme; }
|
|
|
|
|
|
2010-01-27 18:38:09 +01:00
|
|
|
QLineEdit {
|
2010-04-16 11:28:37 +02:00
|
|
|
y: 2
|
2010-01-27 18:38:09 +01:00
|
|
|
id: lineEditWidget
|
2010-04-09 17:23:11 +02:00
|
|
|
styleSheet: "QLineEdit { padding-left: 32; }"
|
2010-02-05 15:42:31 +10:00
|
|
|
width: lineEdit.width
|
|
|
|
|
height: lineEdit.height
|
2010-04-29 09:51:24 +02:00
|
|
|
toolTip: backendValue.isBound ? backendValue.expression : ""
|
2010-04-21 11:28:17 +02:00
|
|
|
|
|
|
|
|
property string valueFromBackend: (backendValue === undefined || backendValue.value === undefined) ? "" : backendValue.value;
|
2010-01-27 18:38:09 +01:00
|
|
|
|
2010-04-21 11:28:17 +02:00
|
|
|
onValueFromBackendChanged: {
|
|
|
|
|
if (backendValue.value === undefined)
|
|
|
|
|
return;
|
|
|
|
|
text = backendValue.value;
|
|
|
|
|
}
|
2010-01-27 18:38:09 +01:00
|
|
|
|
2010-02-26 17:09:32 +01:00
|
|
|
onEditingFinished: {
|
2011-06-21 16:11:55 +02:00
|
|
|
if (backendValue.isTranslated) {
|
2011-07-22 11:48:42 +02:00
|
|
|
backendValue.expression = "qsTr(\"" + escapeString(text) + "\")"
|
2011-06-21 16:11:55 +02:00
|
|
|
} else {
|
|
|
|
|
backendValue.value = text
|
|
|
|
|
}
|
2010-02-26 15:20:34 +01:00
|
|
|
evaluate();
|
2010-01-27 18:38:09 +01:00
|
|
|
}
|
2010-02-25 16:48:20 +01:00
|
|
|
|
|
|
|
|
onFocusChanged: {
|
|
|
|
|
if (focus)
|
2010-04-16 11:28:37 +02:00
|
|
|
backendValue.lock();
|
2010-02-25 16:48:20 +01:00
|
|
|
else
|
2010-04-16 11:28:37 +02:00
|
|
|
backendValue.unlock();
|
2010-02-25 16:48:20 +01:00
|
|
|
}
|
2010-01-27 18:38:09 +01:00
|
|
|
|
|
|
|
|
|
2010-02-26 15:36:27 +01:00
|
|
|
}
|
2010-01-27 18:38:09 +01:00
|
|
|
ExtendedFunctionButton {
|
2010-02-05 15:42:31 +10:00
|
|
|
backendValue: lineEdit.backendValue
|
2010-04-16 11:28:37 +02:00
|
|
|
y: 6
|
2010-03-24 17:11:17 +01:00
|
|
|
x: 0
|
2010-02-05 15:42:31 +10:00
|
|
|
visible: lineEdit.enabled
|
2010-01-27 18:38:09 +01:00
|
|
|
}
|
2011-06-21 16:11:55 +02:00
|
|
|
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) {
|
2011-07-22 11:48:42 +02:00
|
|
|
backendValue.expression = "qsTr(\"" + escapeString(lineEditWidget.text) + "\")"
|
2011-06-21 16:11:55 +02:00
|
|
|
} else {
|
|
|
|
|
backendValue.value = lineEditWidget.text
|
|
|
|
|
}
|
|
|
|
|
evaluate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onVisibleChanged: {
|
|
|
|
|
if (trCheckbox.visible) {
|
|
|
|
|
trCheckbox.raise();
|
|
|
|
|
lineEditWidget.styleSheet = "QLineEdit { padding-left: 32; padding-right: 62;}"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-27 18:38:09 +01:00
|
|
|
}
|