mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-08-05 23:35:50 +02:00
ModalTextEdit: adapted for general use
- modified UsernameTextEdit - added PasswordTextEdit - changed focus - added echoMode - added second suffix icon Change-Id: I16e0a248757a125bed28aefc375a09cd267f8db2
This commit is contained in:
parent
cf8e4a87e3
commit
c722ddb280
4 changed files with 130 additions and 24 deletions
|
@ -26,7 +26,7 @@ TextField {
|
||||||
|
|
||||||
// We need to remove focus when another widget takes activeFocus,
|
// We need to remove focus when another widget takes activeFocus,
|
||||||
// except the context menu.
|
// except the context menu.
|
||||||
property bool isActive: activeFocus || contextMenu.active
|
property bool isActive: activeFocus || contextMenu.active || root.text.toString() !== ''
|
||||||
onActiveFocusChanged: {
|
onActiveFocusChanged: {
|
||||||
if (!activeFocus && !contextMenu.active) {
|
if (!activeFocus && !contextMenu.active) {
|
||||||
root.focus = false
|
root.focus = false
|
||||||
|
@ -39,7 +39,10 @@ TextField {
|
||||||
property alias prefixIconColor: prefixIcon.color
|
property alias prefixIconColor: prefixIcon.color
|
||||||
property string suffixIconSrc
|
property string suffixIconSrc
|
||||||
property alias suffixIconColor: suffixIcon.color
|
property alias suffixIconColor: suffixIcon.color
|
||||||
property color accent: isActive
|
property string suffixBisIconSrc
|
||||||
|
property alias suffixBisIconColor: suffixBisIcon.color
|
||||||
|
|
||||||
|
property color accent: isActive || hovered
|
||||||
? prefixIconColor
|
? prefixIconColor
|
||||||
: JamiTheme.buttonTintedBlue
|
: JamiTheme.buttonTintedBlue
|
||||||
property color baseColor: JamiTheme.primaryForegroundColor
|
property color baseColor: JamiTheme.primaryForegroundColor
|
||||||
|
@ -50,15 +53,26 @@ TextField {
|
||||||
|
|
||||||
property alias infoTipText: infoTip.text
|
property alias infoTipText: infoTip.text
|
||||||
|
|
||||||
wrapMode: Text.Wrap
|
wrapMode: "NoWrap"
|
||||||
|
|
||||||
font.pointSize: JamiTheme.materialLineEditPointSize
|
font.pointSize: JamiTheme.materialLineEditPointSize
|
||||||
font.kerning: true
|
font.kerning: true
|
||||||
selectByMouse: true
|
selectByMouse: true
|
||||||
mouseSelectionMode: TextInput.SelectCharacters
|
mouseSelectionMode: TextInput.SelectCharacters
|
||||||
|
|
||||||
height: implicitHeight
|
|
||||||
leftPadding: readOnly || prefixIconSrc === '' ? 0 : 32
|
leftPadding: readOnly || prefixIconSrc === '' ? 0 : 32
|
||||||
rightPadding: readOnly || suffixIconSrc === '' ? 0 : 32
|
rightPadding: {
|
||||||
|
var total = 2
|
||||||
|
if (!readOnly) {
|
||||||
|
|
||||||
|
if (suffixIconSrc !== "")
|
||||||
|
total =+ 30
|
||||||
|
if (suffixBisIconSrc !== "")
|
||||||
|
total =+ 30
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
bottomPadding: 20
|
bottomPadding: 20
|
||||||
topPadding: 2
|
topPadding: 2
|
||||||
|
|
||||||
|
@ -116,7 +130,7 @@ TextField {
|
||||||
visible: opacity
|
visible: opacity
|
||||||
HoverHandler { cursorShape: Qt.ArrowCursor }
|
HoverHandler { cursorShape: Qt.ArrowCursor }
|
||||||
Behavior on opacity {
|
Behavior on opacity {
|
||||||
NumberAnimation { duration: JamiTheme.longFadeDuration }
|
NumberAnimation { duration: JamiTheme.longFadeDuration/2 }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +156,8 @@ TextField {
|
||||||
TextFieldIcon {
|
TextFieldIcon {
|
||||||
id: suffixIcon
|
id: suffixIcon
|
||||||
size: 20
|
size: 20
|
||||||
anchors.right: parent.right
|
anchors.right: suffixBisIcon.left
|
||||||
|
anchors.rightMargin: suffixBisIconSrc !== '' ? 5 : 0
|
||||||
color: suffixIconColor
|
color: suffixIconColor
|
||||||
source: suffixIconSrc
|
source: suffixIconSrc
|
||||||
|
|
||||||
|
@ -155,5 +170,20 @@ TextField {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TextFieldIcon {
|
||||||
|
id: suffixBisIcon
|
||||||
|
size: 20
|
||||||
|
anchors.right: parent.right
|
||||||
|
color: suffixBisIconColor
|
||||||
|
source: suffixBisIconSrc
|
||||||
|
|
||||||
|
TapHandler {
|
||||||
|
cursorShape: Qt.ArrowCursor
|
||||||
|
onTapped: {
|
||||||
|
modalTextEditRoot.icoClicked()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
background: null
|
background: null
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,24 +22,27 @@ import net.jami.Constants 1.1
|
||||||
// This component is used to display and edit a value.
|
// This component is used to display and edit a value.
|
||||||
Loader {
|
Loader {
|
||||||
id: root
|
id: root
|
||||||
|
property string prefixIconSrc: JamiResources.round_edit_24dp_svg
|
||||||
property string prefixIconSrc
|
property color prefixIconColor: JamiTheme.editLineColor
|
||||||
property color prefixIconColor
|
property string suffixIconSrc : ""
|
||||||
property string suffixIconSrc
|
property color suffixIconColor: JamiTheme.buttonTintedBlue
|
||||||
property color suffixIconColor
|
property string suffixBisIconSrc : ""
|
||||||
|
property color suffixBisIconColor: JamiTheme.buttonTintedBlue
|
||||||
|
|
||||||
required property string placeholderText
|
required property string placeholderText
|
||||||
required property string staticText
|
property string staticText: ""
|
||||||
property string dynamicText
|
property string dynamicText
|
||||||
property bool inputIsValid: true
|
property bool inputIsValid: true
|
||||||
property string infoTipText
|
property string infoTipText
|
||||||
|
property bool isPersistent: true
|
||||||
property variant validator
|
|
||||||
|
|
||||||
property real fontPointSize: JamiTheme.materialLineEditPointSize
|
property real fontPointSize: JamiTheme.materialLineEditPointSize
|
||||||
|
property bool fontBold: false
|
||||||
|
|
||||||
|
property int echoMode: TextInput.Normal
|
||||||
|
|
||||||
// Always start with the static text component displayed first.
|
// Always start with the static text component displayed first.
|
||||||
property bool editMode: false
|
property bool editMode: true
|
||||||
|
|
||||||
// Emitted when the editor has been accepted.
|
// Emitted when the editor has been accepted.
|
||||||
signal accepted
|
signal accepted
|
||||||
|
@ -47,10 +50,19 @@ Loader {
|
||||||
// Always give up focus when accepted.
|
// Always give up focus when accepted.
|
||||||
onAccepted: focus = false
|
onAccepted: focus = false
|
||||||
|
|
||||||
|
// Needed to give proper focus to loaded item
|
||||||
|
onFocusChanged: {
|
||||||
|
if (root.focus && root.isPersistent) {
|
||||||
|
item.forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This is used when the user is not editing the text.
|
// This is used when the user is not editing the text.
|
||||||
Component {
|
Component {
|
||||||
id: usernameDisplayComp
|
|
||||||
|
id: displayComp
|
||||||
MaterialTextField {
|
MaterialTextField {
|
||||||
|
|
||||||
font.pointSize: root.fontPointSize
|
font.pointSize: root.fontPointSize
|
||||||
readOnly: true
|
readOnly: true
|
||||||
text: staticText
|
text: staticText
|
||||||
|
@ -60,19 +72,27 @@ Loader {
|
||||||
|
|
||||||
// This is used when the user is editing the text.
|
// This is used when the user is editing the text.
|
||||||
Component {
|
Component {
|
||||||
id: usernameEditComp
|
id: editComp
|
||||||
|
|
||||||
MaterialTextField {
|
MaterialTextField {
|
||||||
|
|
||||||
|
id: editCompField
|
||||||
|
|
||||||
focus: true
|
focus: true
|
||||||
infoTipText: root.infoTipText
|
infoTipText: root.infoTipText
|
||||||
prefixIconSrc: root.prefixIconSrc
|
prefixIconSrc: root.prefixIconSrc
|
||||||
prefixIconColor: root.prefixIconColor
|
prefixIconColor: root.prefixIconColor
|
||||||
suffixIconSrc: root.suffixIconSrc
|
suffixIconSrc: root.suffixIconSrc
|
||||||
suffixIconColor: root.suffixIconColor
|
suffixIconColor: root.suffixIconColor
|
||||||
|
suffixBisIconSrc: root.suffixBisIconSrc
|
||||||
|
suffixBisIconColor: root.suffixBisIconColor
|
||||||
font.pointSize: root.fontPointSize
|
font.pointSize: root.fontPointSize
|
||||||
|
font.bold: root.fontBold
|
||||||
|
echoMode: root.echoMode
|
||||||
placeholderText: root.placeholderText
|
placeholderText: root.placeholderText
|
||||||
validator: root.validator
|
|
||||||
onAccepted: root.accepted()
|
onAccepted: root.accepted()
|
||||||
onTextChanged: dynamicText = text
|
onTextChanged: dynamicText = text
|
||||||
|
onVisibleChanged: text = dynamicText
|
||||||
inputIsValid: root.inputIsValid
|
inputIsValid: root.inputIsValid
|
||||||
onFocusChanged: if (!focus) root.editMode = false
|
onFocusChanged: if (!focus) root.editMode = false
|
||||||
}
|
}
|
||||||
|
@ -81,8 +101,10 @@ Loader {
|
||||||
// We use a loader to switch between the two components depending on the
|
// We use a loader to switch between the two components depending on the
|
||||||
// editMode property.
|
// editMode property.
|
||||||
sourceComponent: {
|
sourceComponent: {
|
||||||
editMode
|
|
||||||
? usernameEditComp
|
editMode || isPersistent
|
||||||
: usernameDisplayComp
|
? editComp
|
||||||
|
: displayComp
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
56
src/app/commoncomponents/PasswordTextEdit.qml
Normal file
56
src/app/commoncomponents/PasswordTextEdit.qml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Savoir-faire Linux Inc.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
import net.jami.Adapters 1.1
|
||||||
|
import net.jami.Constants 1.1
|
||||||
|
import net.jami.Models 1.1
|
||||||
|
|
||||||
|
ModalTextEdit {
|
||||||
|
id: modalTextEditRoot
|
||||||
|
|
||||||
|
property bool firstEntry: false
|
||||||
|
|
||||||
|
signal icoClicked
|
||||||
|
|
||||||
|
prefixIconSrc: firstEntry ? JamiResources.lock_svg : JamiResources.round_edit_24dp_svg
|
||||||
|
|
||||||
|
suffixBisIconSrc: JamiResources.eye_cross_svg
|
||||||
|
suffixBisIconColor: JamiTheme.buttonTintedBlue
|
||||||
|
|
||||||
|
placeholderText: JamiStrings.password
|
||||||
|
infoTipText: firstEntry ? JamiStrings.password : ""
|
||||||
|
staticText: ""
|
||||||
|
echoMode: TextInput.Password
|
||||||
|
|
||||||
|
onIcoClicked: {
|
||||||
|
if (echoMode == TextInput.Normal) {
|
||||||
|
echoMode = TextInput.Password
|
||||||
|
suffixBisIconSrc = JamiResources.eye_cross_svg
|
||||||
|
} else {
|
||||||
|
echoMode = TextInput.Normal
|
||||||
|
suffixBisIconSrc = JamiResources.noun_eye_svg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function startEditing() {
|
||||||
|
root.editMode = true
|
||||||
|
forceActiveFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -57,12 +57,10 @@ ModalTextEdit {
|
||||||
|
|
||||||
infoTipText: JamiStrings.usernameToolTip
|
infoTipText: JamiStrings.usernameToolTip
|
||||||
placeholderText: JamiStrings.chooseAUsername
|
placeholderText: JamiStrings.chooseAUsername
|
||||||
staticText: hasRegisteredName ? registeredName : infohash
|
|
||||||
|
|
||||||
enum NameRegistrationState { BLANK, INVALID, TAKEN, FREE, SEARCHING }
|
enum NameRegistrationState { BLANK, INVALID, TAKEN, FREE, SEARCHING }
|
||||||
property int nameRegistrationState: UsernameLineEdit.NameRegistrationState.BLANK
|
property int nameRegistrationState: UsernameLineEdit.NameRegistrationState.BLANK
|
||||||
|
|
||||||
validator: RegularExpressionValidator { regularExpression: /[A-z0-9_]{0,32}/ }
|
|
||||||
inputIsValid: dynamicText.length === 0
|
inputIsValid: dynamicText.length === 0
|
||||||
|| nameRegistrationState === UsernameLineEdit.NameRegistrationState.FREE
|
|| nameRegistrationState === UsernameLineEdit.NameRegistrationState.FREE
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue