2023-02-27 09:29:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023, KylinSoft Co., Ltd.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-03-24 17:47:17 +08:00
|
|
|
import QtQuick 2.12
|
2023-02-27 09:29:19 +08:00
|
|
|
import QtQuick.Controls 2.5
|
|
|
|
import QtQuick.Layouts 1.12
|
2023-03-02 13:57:13 +08:00
|
|
|
import org.ukui.menu.core 1.0
|
2023-02-27 09:29:19 +08:00
|
|
|
import AppControls2 1.0 as AppControls2
|
2024-01-04 11:13:41 +08:00
|
|
|
import org.ukui.quick.platform 1.0 as Platform
|
2023-11-29 16:13:50 +08:00
|
|
|
import org.ukui.quick.items 1.0 as UkuiItems
|
2023-02-27 09:29:19 +08:00
|
|
|
|
2023-11-29 16:13:50 +08:00
|
|
|
UkuiItems.StyleBackground {
|
2023-05-23 11:54:17 +08:00
|
|
|
property Item changeFocusTarget
|
|
|
|
property alias text: textInput.text;
|
2023-04-26 17:04:22 +08:00
|
|
|
|
2023-03-02 13:57:13 +08:00
|
|
|
alpha: 0.04
|
2023-11-29 16:13:50 +08:00
|
|
|
useStyleTransparency: false
|
2024-01-04 11:13:41 +08:00
|
|
|
paletteRole: Platform.Theme.Text
|
2023-03-24 17:47:17 +08:00
|
|
|
border.width: 1
|
2023-03-30 16:44:53 +08:00
|
|
|
borderAlpha: textInput.activeFocus ? 1 : 0.1
|
2024-01-04 11:13:41 +08:00
|
|
|
borderColor: textInput.activeFocus ? Platform.Theme.Highlight : Platform.Theme.Base
|
2023-08-15 10:10:13 +08:00
|
|
|
Component.onCompleted: mainWindow.visibleChanged.connect(clear)
|
|
|
|
Component.onDestruction: mainWindow.visibleChanged.disconnect(clear)
|
2023-04-12 15:22:57 +08:00
|
|
|
function textInputFocus() {
|
|
|
|
textInput.forceActiveFocus();
|
|
|
|
}
|
2023-04-26 17:04:22 +08:00
|
|
|
function clear() {
|
|
|
|
textInput.clear();
|
|
|
|
}
|
2023-03-24 17:47:17 +08:00
|
|
|
Item {
|
|
|
|
id: defaultSearch
|
|
|
|
width: searchIcon.width + defaultText.contentWidth; height: parent.height
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2024-02-23 18:19:22 +08:00
|
|
|
anchors.left: parent.left
|
2023-02-27 09:29:19 +08:00
|
|
|
|
|
|
|
Item {
|
2023-03-24 17:47:17 +08:00
|
|
|
id: searchIcon
|
|
|
|
width: 32; height: 32
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: (parent.height - height) / 2
|
|
|
|
|
2024-01-09 10:08:53 +08:00
|
|
|
UkuiItems.Icon {
|
2023-02-27 09:29:19 +08:00
|
|
|
anchors.centerIn: parent
|
2023-03-24 17:47:17 +08:00
|
|
|
width: parent.height / 2; height: width
|
2023-11-29 16:13:50 +08:00
|
|
|
source: "search-symbolic"
|
2024-02-02 15:42:23 +08:00
|
|
|
mode: UkuiItems.Icon.AutoHighlight
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-02 13:57:13 +08:00
|
|
|
|
2023-03-24 17:47:17 +08:00
|
|
|
|
2023-11-29 16:13:50 +08:00
|
|
|
UkuiItems.StyleText {
|
2023-03-24 17:47:17 +08:00
|
|
|
id: defaultText
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: searchIcon.right
|
|
|
|
text: qsTr("Search App")
|
|
|
|
visible: textInput.contentWidth === 0
|
2024-02-02 15:42:23 +08:00
|
|
|
paletteRole: Platform.Theme.Text
|
2023-03-24 17:47:17 +08:00
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
|
|
|
alpha: 0.25
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextInput {
|
|
|
|
id: textInput
|
|
|
|
clip: true
|
2024-05-14 11:45:59 +08:00
|
|
|
anchors.right: clearButton.left
|
2024-10-22 16:50:37 +08:00
|
|
|
width: parent.width - searchIcon.width - clearButton.width -
|
|
|
|
searchIcon.anchors.leftMargin - clearButton.anchors.rightMargin
|
2023-03-24 17:47:17 +08:00
|
|
|
height: parent.height
|
|
|
|
selectByMouse: true
|
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
2023-05-15 17:28:48 +08:00
|
|
|
font.pointSize: defaultText.font.pointSize
|
2024-07-08 14:00:11 +08:00
|
|
|
font.family: defaultText.font.family
|
2024-02-23 18:19:22 +08:00
|
|
|
focus: true
|
2023-05-23 11:54:17 +08:00
|
|
|
activeFocusOnTab: true
|
2024-02-23 18:19:22 +08:00
|
|
|
|
2023-05-23 11:54:17 +08:00
|
|
|
function changeFocusToListView() {
|
|
|
|
if (!mainWindow.isFullScreen) {
|
2023-05-24 13:46:29 +08:00
|
|
|
normalUI.focus = true;
|
|
|
|
changeFocusTarget.focus = true;
|
|
|
|
appPage.content.resetFocus();
|
2023-05-23 11:54:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Keys.onDownPressed: changeFocusToListView()
|
2023-06-06 09:22:29 +08:00
|
|
|
Keys.onReturnPressed: changeFocusToListView()
|
2023-03-24 17:47:17 +08:00
|
|
|
|
|
|
|
function updateTextInputColor() {
|
2024-02-23 18:19:22 +08:00
|
|
|
color = Platform.Theme.text();
|
2024-01-18 03:24:01 +08:00
|
|
|
selectionColor = Platform.Theme.highlight();
|
2023-03-24 17:47:17 +08:00
|
|
|
}
|
2024-01-18 03:24:01 +08:00
|
|
|
|
|
|
|
Platform.Theme.onPaletteChanged: {
|
|
|
|
updateTextInputColor();
|
|
|
|
}
|
|
|
|
|
2023-03-24 17:47:17 +08:00
|
|
|
Component.onCompleted: {
|
|
|
|
updateTextInputColor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 10:08:53 +08:00
|
|
|
UkuiItems.Button {
|
2024-05-14 11:45:59 +08:00
|
|
|
id: clearButton
|
2023-03-24 17:47:17 +08:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: (parent.height - height) / 2
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2024-02-23 18:19:22 +08:00
|
|
|
width: 32; height: width
|
|
|
|
background.radius: width / 2
|
|
|
|
visible: textInput.length !== 0
|
2024-01-09 10:08:53 +08:00
|
|
|
activeFocusOnTab: false
|
|
|
|
|
|
|
|
icon.source: "edit-clear-symbolic"
|
2024-02-02 15:42:23 +08:00
|
|
|
icon.mode: UkuiItems.Icon.AutoHighlight
|
2023-03-24 17:47:17 +08:00
|
|
|
|
2023-04-08 18:42:31 +08:00
|
|
|
onClicked: {
|
|
|
|
textInput.clear();
|
|
|
|
}
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|
2024-07-08 17:10:33 +08:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.left: textInput.left
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
width: clearButton.visible ? textInput.width : textInput.width + clearButton.width
|
|
|
|
height: parent.height
|
|
|
|
cursorShape: Qt.IBeamCursor
|
|
|
|
enabled: false
|
|
|
|
}
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|