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
|
|
|
|
|
|
|
|
AppControls2.StyleBackground {
|
|
|
|
readonly property string text: textInput.text;
|
|
|
|
function clear() {
|
|
|
|
textInput.clear();
|
|
|
|
}
|
2023-03-02 13:57:13 +08:00
|
|
|
alpha: 0.04
|
|
|
|
useStyleTransparent: false
|
|
|
|
paletteRole: Palette.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
|
|
|
|
borderColor: textInput.activeFocus ? Palette.Highlight : Palette.Base
|
2023-02-27 09:29:19 +08:00
|
|
|
|
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
|
|
|
|
|
|
|
|
ThemeIcon {
|
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-02-27 09:29:19 +08:00
|
|
|
source: "image://appicon/search-symbolic"
|
2023-03-24 17:47:17 +08:00
|
|
|
highLight: mainWindow.isFullScreen
|
2023-04-08 18:42:31 +08:00
|
|
|
autoHighLight: !mainWindow.isFullScreen
|
2023-02-27 09:29:19 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-02 13:57:13 +08:00
|
|
|
|
2023-03-24 17:47:17 +08:00
|
|
|
|
|
|
|
AppControls2.StyleText {
|
|
|
|
id: defaultText
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: searchIcon.right
|
|
|
|
text: qsTr("Search App")
|
|
|
|
visible: textInput.contentWidth === 0
|
|
|
|
font.pixelSize: 14
|
|
|
|
paletteRole: mainWindow.isFullScreen ? Palette.HighlightedText : Palette.Text
|
|
|
|
verticalAlignment: TextInput.AlignVCenter
|
|
|
|
alpha: 0.25
|
|
|
|
}
|
|
|
|
|
|
|
|
states: State {
|
|
|
|
when: textInput.activeFocus || !mainWindow.isFullScreen
|
|
|
|
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
|
|
|
|
font.pixelSize: 14
|
|
|
|
focus: parent.visible || mainWindow.isFullScreen
|
|
|
|
onActiveFocusChanged: clear()
|
|
|
|
|
|
|
|
property int textColor: mainWindow.isFullScreen ? Palette.HighlightedText : Palette.Text
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
AppControls2.RoundButton {
|
|
|
|
id: clearButton
|
|
|
|
width: 18; height: width
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: (parent.height - height) / 2
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
visible: mainWindow.isFullScreen && textInput.activeFocus
|
|
|
|
buttonIcon: "image://appicon/edit-clear-symbolic"
|
|
|
|
highlight: true
|
2023-04-08 18:42:31 +08:00
|
|
|
autoHighLight: false
|
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
|
|
|
}
|
|
|
|
}
|