Warning, /maui/mauikit/src/controls.5/TextFieldPopup.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * Copyright 2023 Camilo Higuita <milo.h@aol.com>
0003 *
0004 * This program is free software; you can redistribute it and/or modify
0005 * it under the terms of the GNU Library General Public License as
0006 * published by the Free Software Foundation; either version 2, or
0007 * (at your option) any later version.
0008 *
0009 * This program is distributed in the hope that it will be useful,
0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012 * GNU General Public License for more details
0013 *
0014 * You should have received a copy of the GNU Library General Public
0015 * License along with this program; if not, write to the
0016 * Free Software Foundation, Inc.,
0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0018 */
0019
0020 import QtQuick 2.15
0021 import QtQuick.Controls 2.15
0022 import QtQuick.Layouts 1.3
0023
0024 import QtGraphicalEffects 1.0
0025 import QtQuick.Window 2.15
0026
0027 import org.mauikit.controls 1.3 as Maui
0028
0029 AbstractButton
0030 {
0031 id: control
0032
0033 Maui.Theme.colorSet: Maui.Theme.Button
0034 Maui.Theme.inherit: false
0035
0036 property int minimumWidth: 400
0037 property int minimumHeight: 500
0038
0039 implicitWidth: 200
0040 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
0041
0042 hoverEnabled: true
0043
0044 default property alias content: _page.content
0045
0046 property alias popup: _popup
0047 property alias textField : _textField
0048
0049 property alias popupVisible: _popup.visible
0050 property alias closePolicy: _popup.closePolicy
0051
0052 property int position: ToolBar.Header
0053
0054 property alias placeholderText: _textField.placeholderText
0055 property alias inputMethodHints: _textField.inputMethodHints
0056 property alias activeFocusOnPress: _textField.activeFocusOnPress
0057 property alias wrapMode :_textField.wrapMode
0058 property alias color: _textField.color
0059 property alias verticalAlignment: _textField.verticalAlignment
0060 property alias preeditText: _textField.preeditText
0061
0062 onClicked:
0063 {
0064 _popup.open()
0065 }
0066
0067 text: _textField.text
0068 icon.name: "edit-find"
0069
0070 Keys.onEscapePressed: control.close()
0071
0072 signal accepted()
0073 signal cleared()
0074 signal opened()
0075 signal closed()
0076
0077 function open()
0078 {
0079 _popup.open()
0080 }
0081
0082 function close()
0083 {
0084 _popup.close()
0085 }
0086
0087 function clear()
0088 {
0089 _textField.clear()
0090 }
0091
0092 padding: Maui.Style.defaultPadding
0093 spacing: Maui.Style.space.small
0094
0095 contentItem: RowLayout
0096 {
0097 id: _layout
0098 spacing: control.spacing
0099
0100 Maui.Icon
0101 {
0102 visible: source ? true : false
0103 source: control.icon.name
0104 implicitHeight: visible ? 16 : 0
0105 implicitWidth: height
0106 color: control.color
0107 }
0108
0109 Item
0110 {
0111 Layout.fillWidth: true
0112 visible: !placeholder.visible
0113 }
0114
0115 Label
0116 {
0117 id: placeholder
0118 Layout.fillWidth: true
0119 text: control.text.length > 0 ? control.text : control.placeholderText
0120 font: control.font
0121 color: control.color
0122 verticalAlignment: control.verticalAlignment
0123 elide: Text.ElideRight
0124 wrapMode: Text.NoWrap
0125
0126 opacity: !_textField.activeFocus ? 1 : 0.5
0127
0128 Behavior on opacity
0129 {
0130 NumberAnimation
0131 {
0132 duration: Maui.Style.units.longDuration
0133 easing.type: Easing.InOutQuad
0134 }
0135 }
0136 }
0137 }
0138
0139 Popup
0140 {
0141 id: _popup
0142
0143 parent: control
0144 anchors.centerIn: undefined
0145
0146 closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
0147 modal: false
0148
0149 y: control.position === ToolBar.Header ? 0 : (control.height - (_popup.height))
0150
0151 x: width === control.width ? 0 : 0 - ((width - control.width)/2)
0152
0153 width: Math.min(Math.max(control.minimumWidth, parent.width), control.Window.window.width - Maui.Style.defaultPadding*2)
0154 height: Math.min(control.Window.window.height- Maui.Style.defaultPadding*2, control.minimumHeight)
0155
0156 margins: 0
0157 padding: 0
0158
0159 onClosed:
0160 {
0161 _textField.clear()
0162 control.closed()
0163 }
0164
0165 onOpened:
0166 {
0167 _textField.forceActiveFocus()
0168 _textField.selectAll()
0169 control.opened()
0170 }
0171
0172 Maui.Page
0173 {
0174 id:_page
0175 anchors.fill: parent
0176 altHeader: control.position === ToolBar.Footer
0177
0178 headBar.visible: false
0179 headerColumn: TextField
0180 {
0181 implicitHeight: control.height
0182 width: parent.width
0183
0184 id: _textField
0185 text: control.text
0186
0187 icon.source: control.icon.name
0188
0189 onTextChanged: control.text = text
0190 onAccepted:
0191 {
0192 control.text = text
0193 control.accepted()
0194 }
0195
0196 onCleared:
0197 {
0198 control.cleared()
0199 }
0200
0201 Keys.enabled: true
0202 Keys.forwardTo: control
0203 Keys.onEscapePressed: control.close()
0204
0205 background: Rectangle
0206 {
0207 color: Maui.Theme.backgroundColor
0208
0209
0210 Maui.Separator
0211 {
0212 id: _border
0213 anchors.left: parent.left
0214 anchors.right: parent.right
0215 weight: Maui.Separator.Weight.Light
0216 opacity: 0.4
0217
0218 Behavior on color
0219 {
0220 Maui.ColorTransition{}
0221 }
0222 }
0223
0224 states: [ State
0225 {
0226 when: control.position === ToolBar.Header
0227
0228 AnchorChanges
0229 {
0230 target: _border
0231 anchors.top: undefined
0232 anchors.bottom: parent.bottom
0233 }
0234 },
0235
0236 State
0237 {
0238 when: control.position === ToolBar.Footer
0239
0240 AnchorChanges
0241 {
0242 target: _border
0243 anchors.top: parent.top
0244 anchors.bottom: undefined
0245 }
0246 }
0247 ]
0248 }
0249 }
0250
0251 }
0252
0253 background: Rectangle
0254 {
0255 color: Maui.Theme.backgroundColor
0256
0257 radius: Maui.Style.radiusV
0258 layer.enabled: true
0259 layer.effect: DropShadow
0260 {
0261 horizontalOffset: 0
0262 verticalOffset: 0
0263 radius: 8
0264 samples: 16
0265 color: "#80000000"
0266 transparentBorder: true
0267 }
0268
0269 Behavior on color
0270 {
0271 Maui.ColorTransition{}
0272 }
0273 }
0274 }
0275
0276 background: Rectangle
0277 {
0278 color: control.enabled ? (control.hovered ? Maui.Theme.hoverColor : Maui.Theme.backgroundColor) : "transparent"
0279
0280 radius: Maui.Style.radiusV
0281
0282 Behavior on color
0283 {
0284 Maui.ColorTransition{}
0285 }
0286 }
0287
0288 function forceActiveFocus()
0289 {
0290 control.open()
0291 }
0292 }