1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-07-14 20:45:23 +02:00
jami-client-qt/src/commoncomponents/MaterialLineEdit.qml
Ming Rui Zhang a811b9666c materialLineEdit: ui simplification
materialLineEdit should be a rather simple component and
any futher changes should be in another component such as
UsernameLineEdit.

Change-Id: I7d284c6fa87653468e64fd42874f8042a58d99cf
2021-08-16 09:20:32 -04:00

86 lines
2.6 KiB
QML

/*
* Copyright (C) 2021 by Savoir-faire Linux
* Author: Sébastien blin <sebastien.blin@savoirfairelinux.com>
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
*
* 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 2.14
import QtQuick.Controls 2.14
import net.jami.Constants 1.0
TextField {
id: root
property int fieldLayoutWidth: 256
property int fieldLayoutHeight: 48
property bool layoutFillwidth: false
property var backgroundColor: JamiTheme.editBackgroundColor
property var borderColor: JamiTheme.greyBorderColor
property bool loseFocusWhenEnterPressed: false
padding: JamiTheme.materialLineEditPadding
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
wrapMode: Text.Wrap
readOnly: false
selectByMouse: true
selectionColor: JamiTheme.placeHolderTextFontColor
font.pointSize: JamiTheme.materialLineEditPointSize
font.kerning: true
color: JamiTheme.textColor
LineEditContextMenu {
id: lineEditContextMenu
lineEditObj: root
selectOnly: readOnly
}
background: Rectangle {
anchors.fill: parent
radius: JamiTheme.primaryRadius
border.color: readOnly? "transparent" : borderColor
color: readOnly? "transparent" : backgroundColor
}
onReleased: {
if (event.button == Qt.RightButton)
lineEditContextMenu.openMenuAt(event)
}
// Enter/Return keys intervention
// Now, both editingFinished and accepted
// signals will be emitted with focus set to false
// Use editingFinished when the info is saved by focus lost
// (since losing focus will also emit editingFinished)
// Use accepted when the info is not saved by focus lost
Keys.onPressed: {
if (event.key === Qt.Key_Enter ||
event.key === Qt.Key_Return) {
if (loseFocusWhenEnterPressed)
root.focus = false
root.accepted()
event.accepted = true;
}
}
}