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-02-27 09:29:19 +08:00
|
|
|
|
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.horizontalCenter: mainWindow.isFullScreen ? parent.horizontalCenter : undefined
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
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-01-09 10:08:53 +08:00
|
|
|
mode: mainWindow.isFullScreen ? UkuiItems.Icon.Highlight : 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-01-04 11:13:41 +08:00
|
|
|
paletteRole: mainWindow.isFullScreen ? Platform.Theme.HighlightedText : Platform.Theme.Text
|
2023-03-24 17:47:17 +08:00
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
|
|
|
alpha: 0.25
|
|
|
|
}
|
|
|
|
|
|
|
|
states: State {
|
2023-08-15 10:10:13 +08:00
|
|
|
when: !mainWindow.isFullScreen || textInput.text !== "" || textInput.activeFocus
|
2023-03-24 17:47:17 +08:00
|
|
|
AnchorChanges {
|
|
|
|
target: defaultSearch
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.horizontalCenter: undefined
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-24 17:47:17 +08:00
|
|
|
|
|
|
|
transitions: Transition {
|
|
|
|
AnchorAnimation { duration: 300; easing.type: Easing.InOutCubic }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TextInput {
|
|
|
|
id: textInput
|
|
|
|
clip: true
|
|
|
|
anchors.right: parent.right
|
|
|
|
width: parent.width - searchIcon.width
|
|
|
|
height: parent.height
|
|
|
|
selectByMouse: true
|
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
2023-05-15 17:28:48 +08:00
|
|
|
font.pointSize: defaultText.font.pointSize
|
2023-04-26 17:04:22 +08:00
|
|
|
focus: parent.visible || mainWindow.isFullScreen
|
2023-03-24 17:47:17 +08:00
|
|
|
|
2023-05-23 11:54:17 +08:00
|
|
|
activeFocusOnTab: true
|
|
|
|
function changeFocusToListView() {
|
|
|
|
if (!mainWindow.isFullScreen) {
|
2023-05-24 13:46:29 +08:00
|
|
|
normalUI.focus = true;
|
|
|
|
changeFocusTarget.focus = true;
|
|
|
|
appPage.content.resetFocus();
|
2023-08-15 10:10:13 +08:00
|
|
|
} else {
|
|
|
|
if (text !== "") {
|
|
|
|
fullScreenContent.viewFocusEnable();
|
|
|
|
}
|
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
|
|
|
|
2023-04-26 17:04:22 +08:00
|
|
|
//字体选中跟随主题高亮
|
|
|
|
property int textColor: mainWindow.isFullScreen ? Palette.HighlightedText : Palette.Text
|
2023-03-24 17:47:17 +08:00
|
|
|
function updateTextInputColor() {
|
|
|
|
color = themePalette.paletteColor(textColor)
|
|
|
|
selectionColor = themePalette.paletteColor(Palette.Highlight)
|
|
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
|
|
updateTextInputColor();
|
|
|
|
themePalette.styleColorChanged.connect(updateTextInputColor);
|
|
|
|
}
|
|
|
|
onTextColorChanged: updateTextInputColor()
|
|
|
|
Component.onDestruction: themePalette.styleColorChanged.disconnect(updateTextInputColor)
|
|
|
|
}
|
|
|
|
|
2024-01-09 10:08:53 +08:00
|
|
|
UkuiItems.Button {
|
2023-03-24 17:47:17 +08:00
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: (parent.height - height) / 2
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
2024-01-09 10:08:53 +08:00
|
|
|
width: 18; height: width
|
2023-11-29 16:13:50 +08:00
|
|
|
visible: textInput.activeFocus
|
2024-01-09 10:08:53 +08:00
|
|
|
activeFocusOnTab: false
|
|
|
|
|
|
|
|
background.radius: width/2
|
|
|
|
background.border.width: 1
|
|
|
|
icon.source: "edit-clear-symbolic"
|
|
|
|
icon.mode: mainWindow.isFullScreen ? UkuiItems.Icon.Highlight : UkuiItems.Icon.AutoHighlight
|
2023-03-24 17:47:17 +08:00
|
|
|
|
2023-04-08 18:42:31 +08:00
|
|
|
onClicked: {
|
|
|
|
textInput.clear();
|
|
|
|
textInput.focus = false;
|
|
|
|
}
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|
|
|
|
}
|