import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
640
height: 480
title: qsTr("Hello World")
Rectangle {
height: 40
parent.width
color: "red"
anchors.top: parent.top
}
MouseArea {
id: mouseArea
// 滑屏动画
/*! 第一次点击y坐标 */
property int pressY: 0
/*! 拖动总距离 */
property int dragTotalChangedY: 0
/*! 每次拖动启始y坐标 */
property int dragStartY: 0
/*! 每次拖动距离 */
property int dragChangedY: 0
property int distance: 40
anchors.fill: parent
enabled: true
onPressed: {
dragStartY = mouseY
pressY = mouseY
console.info("pressY = ", pressY, "Screen.height * 0.01 = ", Screen.height * 0.01)
}
onMouseYChanged: {
// 边缘划入才拉起下拉面板,锁定及关机界面不唤起下拉面板
if (pressY - distance > 0)
return
dragChangedY = mouseY - dragStartY // 每次拖动距离
dragStartY = mouseY // 每次拖动启始坐标
dragTotalChangedY = mouseY - pressY // 拖动总距离
console.info("onMouseYChanged dragChangedY = ", dragChangedY)
console.info("onMouseYChanged dragTotalChangedY = ", dragTotalChangedY)
}
onReleased: {
if (pressY - distance > 0)
return
console.info("onReleased dragChangedY = ", dragChangedY)
console.info("onReleased dragTotalChangedY = ", dragTotalChangedY)
if (dragChangedY > Screen.height * 0.01) {
// 显示界面
console.info("111111111")
dragTotalChangedY = 0
} else if (dragChangedY < -Screen.height * 0.01) {
// 隐藏界面
console.info("2222222")
dragTotalChangedY = -Screen.height
} else {
// 超过屏幕一半显示,否则隐藏界面
dragTotalChangedY = (mouseY > (Screen.height / 2)) ? 0 : -Screen.height
}
if (0 === dragTotalChangedY) {
console.info("down")
} else {
console.info("invalid")
}
// 清除历史数据
dragChangedY = dragTotalChangedY = dragStartY = pressY = 0
}
}
}