| 
									
										
										
										
											2017-04-27 20:30:36 +02:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | import QtQuick 2.6 | 
					
						
							|  |  |  | import QtQuick.Controls 2.0 | 
					
						
							|  |  |  | import QtGraphicalEffects 1.0 | 
					
						
							|  |  |  | import QtQuick.Layouts 1.2 | 
					
						
							|  |  |  | import org.kde.kirigami 2.0 as Kirigami | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TextField { | 
					
						
							|  |  |  | 	id: root | 
					
						
							|  |  |  | 	z: focus ? 999 : 0 | 
					
						
							|  |  |  | 	property alias model: hintsView.model | 
					
						
							|  |  |  | 	property alias currentIndex: hintsView.currentIndex | 
					
						
							|  |  |  | 	inputMethodHints: Qt.ImhNoPredictiveText | 
					
						
							|  |  |  | 	onTextChanged: { | 
					
						
							|  |  |  | 		textUpdateTimer.restart(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-04-14 14:03:51 -07:00
										 |  |  | 	onFocusChanged: frame.shouldShow = focus | 
					
						
							|  |  |  | 	onVisibleChanged: { | 
					
						
							|  |  |  | 		if (visible) { | 
					
						
							|  |  |  | 			focus = false | 
					
						
							|  |  |  | 			frame.shouldShow = false | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 	Keys.onUpPressed: { | 
					
						
							|  |  |  | 		hintsView.currentIndex--; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Keys.onDownPressed: { | 
					
						
							|  |  |  | 		hintsView.currentIndex++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Timer { | 
					
						
							|  |  |  | 		id: textUpdateTimer | 
					
						
							|  |  |  | 		interval: 300 | 
					
						
							|  |  |  | 		onTriggered: { | 
					
						
							|  |  |  | 			if (root.text.length == 0) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			for (var i = 0; i < hintsView.count; ++i) { | 
					
						
							|  |  |  | 				var m = model[i].match(root.text); | 
					
						
							|  |  |  | 				if (m !== null && model[i].startsWith(root.text)) { | 
					
						
							|  |  |  | 					hintsView.currentIndex = i; | 
					
						
							|  |  |  | 					root.text = model[i]; | 
					
						
							|  |  |  | 					root.select(m[0].length, model[i].length); | 
					
						
							|  |  |  | 					textUpdateTimer.running = false; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Frame { | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 		id: frame | 
					
						
							|  |  |  | 		property bool shouldShow | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 		z: 9000 | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 		y: -height - Kirigami.Units.gridUnit | 
					
						
							|  |  |  | 		opacity: root.focus && shouldShow ? 1 : 0 | 
					
						
							|  |  |  | 		visible: opacity > 0 | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 		width: root.width | 
					
						
							|  |  |  | 		leftPadding: 0 | 
					
						
							|  |  |  | 		rightPadding: 0 | 
					
						
							|  |  |  | 		topPadding: 2 | 
					
						
							|  |  |  | 		bottomPadding: 2 | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 		height: Math.min(Kirigami.Units.gridUnit * 14, Math.max(Kirigami.Units.gridUnit*4, hintsView.contentHeight + topPadding + bottomPadding)) | 
					
						
							|  |  |  | 		Behavior on opacity { | 
					
						
							|  |  |  | 			NumberAnimation { | 
					
						
							|  |  |  | 				duration: 200 | 
					
						
							|  |  |  | 				easing.type: Easing.OutQuad | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 		background: Rectangle { | 
					
						
							| 
									
										
										
										
											2017-06-21 15:47:29 -07:00
										 |  |  | 			color: subsurfaceTheme.backgroundColor | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 			radius: 2 | 
					
						
							|  |  |  | 			layer.enabled: true | 
					
						
							|  |  |  | 			layer.effect: DropShadow { | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 				anchors.fill: parent | 
					
						
							|  |  |  | 				anchors.bottomMargin: -Kirigami.Units.gridUnit * 2 | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 				horizontalOffset: 0 | 
					
						
							|  |  |  | 				verticalOffset: 1 | 
					
						
							|  |  |  | 				radius: Kirigami.Units.gridUnit | 
					
						
							|  |  |  | 				samples: 32 | 
					
						
							|  |  |  | 				color: Qt.rgba(0, 0, 0, 0.5) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 			Rectangle { | 
					
						
							| 
									
										
										
										
											2017-06-21 15:47:29 -07:00
										 |  |  | 				color: subsurfaceTheme.backgroundColor | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 				width: Kirigami.Units.gridUnit | 
					
						
							|  |  |  | 				height: width | 
					
						
							|  |  |  | 				rotation: 45 | 
					
						
							|  |  |  | 				anchors { | 
					
						
							|  |  |  | 					verticalCenter: parent.bottom | 
					
						
							|  |  |  | 					left: parent.left | 
					
						
							|  |  |  | 					leftMargin: width | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		ListView { | 
					
						
							|  |  |  | 			id: hintsView | 
					
						
							|  |  |  | 			anchors.fill: parent | 
					
						
							|  |  |  | 			clip: true | 
					
						
							| 
									
										
										
										
											2017-04-14 13:43:48 -07:00
										 |  |  | 			onCurrentIndexChanged: root.text = currentIndex === -1 ? "" : model[currentIndex]; | 
					
						
							| 
									
										
										
										
											2017-04-14 09:22:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 			delegate: Kirigami.BasicListItem { | 
					
						
							|  |  |  | 				label: modelData | 
					
						
							|  |  |  | 				topPadding: 0 | 
					
						
							|  |  |  | 				bottomPadding: 0 | 
					
						
							|  |  |  | 				leftPadding: 0 | 
					
						
							|  |  |  | 				rightPadding: 0 | 
					
						
							|  |  |  | 				implicitHeight: Kirigami.Units.gridUnit*2 | 
					
						
							|  |  |  | 				checked: hintsView.currentIndex == index | 
					
						
							|  |  |  | 				onClicked: { | 
					
						
							|  |  |  | 					hintsView.currentIndex = index | 
					
						
							|  |  |  | 					root.text = modelData | 
					
						
							| 
									
										
										
										
											2017-04-04 21:49:02 +02:00
										 |  |  | 					frame.shouldShow = false; | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-04-04 21:42:27 +02:00
										 |  |  | 			ScrollBar.vertical: ScrollBar { } | 
					
						
							| 
									
										
										
										
											2017-03-31 17:41:43 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |