2019-09-09 15:12:58 +03:00
|
|
|
import QtQuick 2.9
|
|
|
|
import QtQuick.Controls 2.2
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtQuick.Controls.Material 2.2
|
|
|
|
import QtGraphicalEffects 1.0
|
|
|
|
import Qt.labs.platform 1.1
|
|
|
|
|
|
|
|
Item {
|
|
|
|
|
|
|
|
property string label
|
|
|
|
property alias echoMode: textField.echoMode
|
|
|
|
property alias text: textField.text
|
|
|
|
property alias validator: textField.validator
|
|
|
|
property alias horizontalAlignment: textField.horizontalAlignment
|
|
|
|
property bool required: false
|
|
|
|
property string labelText
|
|
|
|
property string validateText
|
|
|
|
property variant validateRegExp
|
|
|
|
property alias textField: textField
|
2019-11-27 16:44:27 +03:00
|
|
|
property bool isValidated: validateInput()
|
2019-09-09 15:12:58 +03:00
|
|
|
property bool validated: {
|
|
|
|
if (validateInput()) {
|
|
|
|
if (required && textField.text.length > 0) {
|
|
|
|
return true
|
|
|
|
} else if (!required) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
signal submit()
|
|
|
|
|
|
|
|
id: textFieldContainer
|
|
|
|
height: 47
|
|
|
|
implicitHeight: 47
|
2019-10-22 11:30:04 +03:00
|
|
|
Layout.bottomMargin: 8
|
2019-09-09 15:12:58 +03:00
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
function validateInput() {
|
|
|
|
if (validateRegExp !== undefined) {
|
|
|
|
if (textField.text.length) {
|
|
|
|
if (!validateRegExp.test(textField.text))
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
function labelTextValue() {
|
|
|
|
if (!validateInput()) {
|
2019-09-09 17:59:30 +03:00
|
|
|
return qsTr("Error")
|
2019-09-09 15:12:58 +03:00
|
|
|
} else if (textField.activeFocus || textField.text.length > 0)
|
|
|
|
return required ? labelText + " *" : labelText
|
|
|
|
else {
|
|
|
|
return " "
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
|
|
|
Label {
|
2019-10-02 15:40:08 +03:00
|
|
|
font.pixelSize: 12
|
2019-11-27 16:44:27 +03:00
|
|
|
color: isValidated ? primaryColor : yubicoRed
|
|
|
|
opacity: isValidated ? lowEmphasis : fullEmphasis
|
2019-09-09 15:12:58 +03:00
|
|
|
text: labelTextValue()
|
|
|
|
}
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
id: textField
|
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
|
|
|
|
selectByMouse: true
|
|
|
|
implicitWidth: textFieldContainer.width
|
|
|
|
font.pixelSize: 13
|
|
|
|
Keys.onEscapePressed: textField.focus = false
|
|
|
|
Keys.onReturnPressed: {
|
|
|
|
textField.focus = false
|
|
|
|
textFieldContainer.submit()
|
|
|
|
}
|
2019-11-27 16:44:27 +03:00
|
|
|
Material.accent: isValidated ? yubicoGreen : yubicoRed
|
2019-10-22 11:30:04 +03:00
|
|
|
Rectangle {
|
|
|
|
color: {
|
|
|
|
if (parent.activeFocus) {
|
2019-11-27 16:44:27 +03:00
|
|
|
return isValidated ? yubicoGreen : yubicoRed
|
2019-10-22 11:30:04 +03:00
|
|
|
} else {
|
|
|
|
return parent.hovered ? formText : formUnderline
|
|
|
|
}
|
|
|
|
}
|
|
|
|
height: parent.hovered ? 2 : 1
|
|
|
|
width: parent.width
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
anchors.bottomMargin: 8
|
|
|
|
}
|
|
|
|
height: 41
|
2019-09-09 15:12:58 +03:00
|
|
|
activeFocusOnTab: true
|
|
|
|
focus: true
|
2019-11-27 16:44:27 +03:00
|
|
|
color: primaryColor
|
|
|
|
opacity: highEmphasis
|
2019-09-09 15:12:58 +03:00
|
|
|
placeholderText: {
|
|
|
|
if (textField.activeFocus) {
|
|
|
|
return ""
|
|
|
|
} else {
|
|
|
|
return required ? labelText + " *" : labelText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
placeholderTextColor: formPlaceholderText
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
hoverEnabled: true
|
|
|
|
cursorShape: Qt.IBeamCursor
|
|
|
|
onClicked: {
|
|
|
|
contextMenu.open();
|
|
|
|
}
|
|
|
|
onPressAndHold: {
|
|
|
|
if (mouse.source === Qt.MouseEventNotSynthesized) {
|
|
|
|
contextMenu.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Menu {
|
|
|
|
id: contextMenu
|
|
|
|
|
|
|
|
MenuItem {
|
2019-09-09 17:59:30 +03:00
|
|
|
text: qsTr("Cut")
|
2019-09-09 15:12:58 +03:00
|
|
|
onTriggered: {
|
|
|
|
textField.cut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MenuItem {
|
2019-09-09 17:59:30 +03:00
|
|
|
text: qsTr("Copy")
|
2019-09-09 15:12:58 +03:00
|
|
|
onTriggered: {
|
|
|
|
textField.copy()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MenuItem {
|
2019-09-09 17:59:30 +03:00
|
|
|
text: qsTr("Paste")
|
2019-09-09 15:12:58 +03:00
|
|
|
onTriggered: {
|
|
|
|
textField.paste()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
font.pixelSize: 10
|
|
|
|
color: yubicoRed
|
|
|
|
text: validateText
|
2019-11-27 16:44:27 +03:00
|
|
|
visible: !isValidated
|
2019-09-09 15:12:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|