| 1 |
/* Copyright (C) 2014-2016 Dan Chapman <[email protected]> |
| 2 |
|
| 3 |
This file is part of Dekko email client for Ubuntu Devices/ |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License or (at your option) version 3 |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public License |
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
import QtQuick 2.4 |
| 19 |
import QtQuick.Controls.Suru 2.2 |
| 20 |
import Lomiri.Components 1.3 |
| 21 |
import Dekko.Components 1.0 |
| 22 |
|
| 23 |
FocusScope { |
| 24 |
id: titledTextField |
| 25 |
|
| 26 |
height: column.height |
| 27 |
anchors { |
| 28 |
left: parent.left |
| 29 |
right: parent.right |
| 30 |
} |
| 31 |
|
| 32 |
property string title |
| 33 |
property alias text: textfield.text |
| 34 |
property alias inputMethodHints: textfield.inputMethodHints |
| 35 |
property alias echoMode: textfield.echoMode |
| 36 |
// TODO: There must be a more elegant way than this |
| 37 |
property alias font: textfield.font |
| 38 |
property alias textFieldFocusHandle: textfield |
| 39 |
property bool sendTabEventOnEnter |
| 40 |
property bool requiredField: false |
| 41 |
readonly property bool _inputValid: requiredField ? textfield.text : true |
| 42 |
property alias placeholderText: textfield.placeholderText |
| 43 |
property alias secondaryItem: textfield.secondaryItem |
| 44 |
property Action trailingAction |
| 45 |
|
| 46 |
Column { |
| 47 |
id: column |
| 48 |
spacing: units.gu(1) |
| 49 |
anchors { |
| 50 |
left: parent.left |
| 51 |
top: parent.top |
| 52 |
right: parent.right |
| 53 |
} |
| 54 |
|
| 55 |
Label { |
| 56 |
id: titleLabel |
| 57 |
anchors { |
| 58 |
left: parent.left |
| 59 |
leftMargin: units.gu(0.3) |
| 60 |
right: parent.right |
| 61 |
} |
| 62 |
text: !_inputValid ? title + qsTr(" (Required)") : title |
| 63 |
Suru.highlightType: Suru.NegativeHighlight |
| 64 |
color: !_inputValid ? Suru.highlightColor : Suru.secondaryForegroundColor |
| 65 |
wrapMode: TextInput.WordWrap |
| 66 |
} |
| 67 |
StretchRow { |
| 68 |
height: textfield.height |
| 69 |
spacing: units.gu(1) |
| 70 |
anchors { |
| 71 |
left: parent.left |
| 72 |
right: parent.right |
| 73 |
} |
| 74 |
TextField { |
| 75 |
id: textfield |
| 76 |
iconName: "ok" |
| 77 |
implicitWidth: -1 |
| 78 |
onAccepted: { |
| 79 |
if (sendTabEventOnEnter) { |
| 80 |
// TabEventSignaler.sendTabEvent() |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
HeaderButton { |
| 85 |
height: units.gu(6) |
| 86 |
implicitWidth: width |
| 87 |
implicitHeight: height |
| 88 |
iconSize: units.gu(3) |
| 89 |
anchors.verticalCenter: textfield.verticalCenter |
| 90 |
visible: trailingAction |
| 91 |
action: trailingAction |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |