linphone-desktop/ui/modules/Common/Form/Fields/HexField.qml
2017-06-14 18:05:18 +02:00

52 lines
1.2 KiB
QML

import QtQuick 2.7
import Common.Styles 1.0
// =============================================================================
Item {
id: wrapper
// ---------------------------------------------------------------------------
property alias readOnly: textField.readOnly
property string text
// ---------------------------------------------------------------------------
signal editingFinished (int value)
// ---------------------------------------------------------------------------
function _computeText (text) {
return (+text).toString(16).toUpperCase()
}
// ---------------------------------------------------------------------------
implicitHeight: textField.height
width: TextFieldStyle.background.width
// ---------------------------------------------------------------------------
Binding {
property: 'text'
target: textField
value: _computeText(wrapper.text)
}
TextField {
id: textField
validator: RegExpValidator {
regExp: /[0-9A-Fa-f]*/
}
width: parent.width
onEditingFinished: {
text = _computeText('0x' + text)
wrapper.editingFinished(parseInt(text, 16))
}
}
}