linux.x86.linphone/Linphone/view/Item/TextInput.qml
Gaelle Braud 82b5d6a008 contact list
fixes:
generic VariantList
FriendModel resetAddresses
check null default account
address list update on save
generic item for white background lists
ui
fix set photo friend
protect friendmodel setters
remove main splitview to stick to the mock-up (keeping it commented cause it may be useful to be able to resize the panels)
default image avatar
fix crash when address not set
2024-02-01 15:19:29 +01:00

136 lines
3.6 KiB
QML

import QtQuick
import QtQuick.Controls as Control
import QtQuick.Layouts 1.0
import Linphone
ColumnLayout {
id: mainItem
property string label: ""
property string errorMessage: ""
property string placeholderText: ""
property bool mandatory: false
property bool hidden: false
property int textInputWidth: 346 * DefaultStyle.dp
property var validator: RegularExpressionValidator{}
property bool fillWidth: false
property bool enableBackgroundColors: true
property color backgroundColor: DefaultStyle.grey_100
property color backgroundBorderColor: DefaultStyle.grey_200
property string initialText
property bool enableErrorText: false
property bool errorTextVisible: errorText.opacity > 0
property alias textField: textField
property alias background: input
readonly property string text: textField.text
readonly property bool hasActiveFocus: textField.activeFocus
signal editingFinished()
Component.onCompleted: {
setText(initialText)
}
function setText(text) {
textField.text = text
}
function resetText() {
setText(initialText)
}
Text {
visible: mainItem.label.length > 0
verticalAlignment: Text.AlignVCenter
text: mainItem.label + (mainItem.mandatory ? "*" : "")
color: textField.activeFocus ? DefaultStyle.main1_500_main : DefaultStyle.main2_600
elide: Text.ElideRight
wrapMode: Text.Wrap
maximumLineCount: 1
font {
pixelSize: 13 * DefaultStyle.dp
family: DefaultStyle.defaultFont
weight: 700 * DefaultStyle.dp
}
Layout.preferredWidth: mainItem.textInputWidth
}
Rectangle {
id: input
Component.onCompleted: {
if (mainItem.fillWidth)
Layout.fillWidth = true
}
Layout.preferredWidth: mainItem.textInputWidth
Layout.preferredHeight: 49 * DefaultStyle.dp
radius: 79 * DefaultStyle.dp
color: mainItem.backgroundColor
border.color: mainItem.errorTextVisible
? DefaultStyle.danger_500main
: textField.activeFocus
? DefaultStyle.main1_500_main
: mainItem.backgroundBorderColor
Control.TextField {
id: textField
anchors.left: parent.left
anchors.leftMargin: 10 * DefaultStyle.dp
anchors.right: eyeButton.visible ? eyeButton.left : parent.right
anchors.rightMargin: eyeButton.visible ? 0 : 10 * DefaultStyle.dp
anchors.verticalCenter: parent.verticalCenter
placeholderText: mainItem.placeholderText
echoMode: (mainItem.hidden && !eyeButton.checked) ? TextInput.Password : TextInput.Normal
font.family: DefaultStyle.defaultFont
font {
pixelSize: 14 * DefaultStyle.dp
weight: 400 * DefaultStyle.dp
}
color: mainItem.errorTextVisible ? DefaultStyle.danger_500main : DefaultStyle.main2_600
selectByMouse: true
validator: mainItem.validator
background: Item {
opacity: 0.
}
cursorDelegate: Rectangle {
visible: textField.activeFocus
color: DefaultStyle.main1_500_main
width: 2 * DefaultStyle.dp
}
onEditingFinished: {
mainItem.editingFinished()
}
Keys.onPressed: (event)=> {
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
textField.focus = false
}
}
}
Control.Button {
id: eyeButton
visible: mainItem.hidden
checkable: true
background: Rectangle {
color: "transparent"
}
contentItem: Image {
fillMode: Image.PreserveAspectFit
source: eyeButton.checked ? AppIcons.eyeShow : AppIcons.eyeHide
width: 20 * DefaultStyle.dp
height: 20 * DefaultStyle.dp
}
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
anchors.rightMargin: 5 * DefaultStyle.dp
}
}
ErrorText {
id: errorText
visible: mainItem.enableErrorText
text: mainItem.errorMessage
Layout.preferredWidth: implicitWidth
}
}