main
zhuzihcu 2023-03-30 18:23:33 +08:00
parent 7720208d17
commit cbd4c229aa
3 changed files with 129 additions and 38 deletions

View File

@ -11,6 +11,10 @@ TextField{
property bool disabled: false property bool disabled: false
signal itemClicked(var data) signal itemClicked(var data)
signal handleClicked signal handleClicked
QtObject{
id:d
property bool flagVisible: true
}
id:input id:input
width: 300 width: 300
enabled: !disabled enabled: !disabled
@ -20,13 +24,7 @@ TextField{
} }
return FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1) return FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1)
} }
selectionColor: { selectionColor: FluTheme.primaryColor.lightest
if(FluTheme.dark){
return FluTheme.primaryColor.lighter
}else{
return FluTheme.primaryColor.dark
}
}
renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
placeholderTextColor: { placeholderTextColor: {
if(disabled){ if(disabled){
@ -39,11 +37,9 @@ TextField{
} }
rightPadding: icon_right.visible ? 50 : 30 rightPadding: icon_right.visible ? 50 : 30
selectByMouse: true selectByMouse: true
Keys.onUpPressed: { Keys.onUpPressed: {
list_view.currentIndex = Math.max(list_view.currentIndex-1,0) list_view.currentIndex = Math.max(list_view.currentIndex-1,0)
} }
Keys.onDownPressed: { Keys.onDownPressed: {
list_view.currentIndex = Math.min(list_view.currentIndex+1,list_view.count-1) list_view.currentIndex = Math.min(list_view.currentIndex+1,list_view.count-1)
} }
@ -129,10 +125,8 @@ TextField{
Popup{ Popup{
id:input_popup id:input_popup
visible: input.focus
y:input.height y:input.height
modal: true focus: false
dim:false
enter: Transition { enter: Transition {
NumberAnimation { NumberAnimation {
property: "y" property: "y"
@ -147,9 +141,6 @@ TextField{
duration: 150 duration: 150
} }
} }
onClosed: {
input.focus = false
}
onVisibleChanged: { onVisibleChanged: {
if(visible){ if(visible){
list_view.currentIndex = -1 list_view.currentIndex = -1
@ -165,7 +156,6 @@ TextField{
height: 38*Math.min(Math.max(list_view.count,1),8) height: 38*Math.min(Math.max(list_view.count,1),8)
ListView{ ListView{
id:list_view id:list_view
signal closePopup
anchors.fill: parent anchors.fill: parent
clip: true clip: true
currentIndex: -1 currentIndex: -1
@ -207,12 +197,7 @@ TextField{
} }
} }
} }
onClicked: handleClick() onClicked: handleClick(modelData)
function handleClick(){
input_popup.close()
input.itemClicked(modelData)
input.text = modelData.title
}
} }
Rectangle{ Rectangle{
width: 3 width: 3
@ -237,8 +222,56 @@ TextField{
} }
} }
function handleClick(modelData){
input_popup.visible = false
input.itemClicked(modelData)
d.flagVisible = false
input.text = modelData.title
d.flagVisible = true
}
onTextChanged: { onTextChanged: {
searchData() searchData()
if(d.flagVisible){
input_popup.visible = true
}
}
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: menu.popup()
}
FluMenu{
id:menu
focus: false
FluMenuItem{
text: "剪切"
visible: input.text !== ""
onClicked: {
input.cut()
}
}
FluMenuItem{
text: "复制"
visible: input.selectedText !== ""
onClicked: {
input.copy()
}
}
FluMenuItem{
text: "粘贴"
visible: input.canPaste
onClicked: {
input.paste()
}
}
FluMenuItem{
text: "全选"
visible: input.text !== ""
onClicked: {
input.selectAll()
}
}
} }
function searchData(){ function searchData(){

View File

@ -20,13 +20,7 @@ TextArea{
wrapMode: Text.WrapAnywhere wrapMode: Text.WrapAnywhere
renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
selectByMouse: true selectByMouse: true
selectionColor: { selectionColor: FluTheme.primaryColor.lightest
if(FluTheme.dark){
return FluTheme.primaryColor.lighter
}else{
return FluTheme.primaryColor.dark
}
}
background: FluTextBoxBackground{ background: FluTextBoxBackground{
inputItem: input inputItem: input
} }
@ -79,6 +73,40 @@ TextArea{
return text.pixelSize * 1.0 return text.pixelSize * 1.0
} }
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: menu.popup()
}
FluMenu{
id:menu
focus: false
FluMenuItem{
text: "剪切"
visible: input.text !== ""
onClicked: {
input.cut()
}
}
FluMenuItem{
text: "复制"
visible: input.selectedText !== ""
onClicked: {
input.copy()
}
}
FluMenuItem{
text: "粘贴"
visible: input.canPaste
onClicked: {
input.paste()
}
}
FluMenuItem{
text: "全选"
visible: input.text !== ""
onClicked: {
input.selectAll()
}
}
}
} }

View File

@ -18,13 +18,7 @@ TextField{
return FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1) return FluTheme.dark ? Qt.rgba(255/255,255/255,255/255,1) : Qt.rgba(27/255,27/255,27/255,1)
} }
renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering renderType: FluTheme.nativeText ? Text.NativeRendering : Text.QtRendering
selectionColor: { selectionColor: FluTheme.primaryColor.lightest
if(FluTheme.dark){
return FluTheme.primaryColor.lighter
}else{
return FluTheme.primaryColor.dark
}
}
placeholderTextColor: { placeholderTextColor: {
if(disabled){ if(disabled){
return FluTheme.dark ? Qt.rgba(131/255,131/255,131/255,1) : Qt.rgba(160/255,160/255,160/255,1) return FluTheme.dark ? Qt.rgba(131/255,131/255,131/255,1) : Qt.rgba(160/255,160/255,160/255,1)
@ -78,6 +72,42 @@ TextField{
background: FluTextBoxBackground{ background: FluTextBoxBackground{
inputItem: input inputItem: input
} }
TapHandler {
acceptedButtons: Qt.RightButton
onTapped: menu.popup()
}
FluMenu{
id:menu
focus: false
FluMenuItem{
text: "剪切"
visible: input.text !== ""
onClicked: {
input.cut()
}
}
FluMenuItem{
text: "复制"
visible: input.selectedText !== ""
onClicked: {
input.copy()
}
}
FluMenuItem{
text: "粘贴"
visible: input.canPaste
onClicked: {
input.paste()
}
}
FluMenuItem{
text: "全选"
visible: input.text !== ""
onClicked: {
input.selectAll()
}
}
}
} }