ESP32_upper/QML/components/LeftMenu.qml
impressionyang 8ef0a05b73 file📦: 添加SVG图标文件
style💄: 更新左边菜单样式
2024-11-28 17:02:42 +08:00

128 lines
4.7 KiB
QML

import QtQuick 2.15
import QtQuick.Controls
import QtQuick.Layouts
import Qt5Compat.GraphicalEffects
import ESP32_upper 1.0
Item {
GlobalProperties {
id: global_properties
}
Component {
id: contactDelegate
// property int my_index: index
Rectangle {
width: 60; height: 60
anchors.left: parent.left // 靠父组件左边
anchors.leftMargin: 10 // 左边距20像素
radius: 5
color: global_properties.left_menu_non_lighlight_color
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: {
// id_view.view.currentIndex = index
global_properties.left_menu_index_last = global_properties.left_menu_index_now
global_properties.left_menu_index_now = index
id_view.currentIndex = index
// console.log("left_menu_index", global_properties.left_menu_index_now)
}
onEntered: {
if (index != global_properties.left_menu_index_now) {
id_view.itemAtIndex(index).color = global_properties.left_menu_focus_color
}
id_lm_tooltip_text.text = name;
id_lm_tooltip.visible = true;
}
onExited: {
if (index != global_properties.left_menu_index_now) {
id_view.itemAtIndex(index).color = global_properties.left_menu_non_lighlight_color
}
id_lm_tooltip.visible = false;
}
Rectangle {
color: "transparent" // 设置背景为透明
width:50 ; height:50
anchors.centerIn : parent
Image {
id:svgIMG
source: qrc_path
width: parent.width
height: parent.height
smooth: true // 使图片平滑缩放
asynchronous: true // 异步加载图片
}
// 使用 ColorOverlay 修改 SVG 颜色
ColorOverlay {
anchors.fill: svgIMG
source: svgIMG
color: global_properties.left_menu_icon_color // 修改后的 SVG 图片颜色
}
}
ToolTip {
id: id_lm_tooltip
delay: 1000
timeout: 5000
width: 60
height: 30
// text: "" // 初始文本为空
opacity: 0.7
background: Rectangle {
color: "#e70e0e"
anchors.fill: parent
border.color: "#e70e0e"
radius: 10
Text {
anchors.centerIn: parent
id: id_lm_tooltip_text
text: ""
font.pixelSize: 20
color: "#0e0606"
}
}
}
}
}
}
MouseArea {
anchors.fill: parent
onWheel: (wheel) => {
wheel.accepted = true; // 处理滚轮事件并阻止事件传递
id_view.contentY += wheel.angleDelta.y / 120 * 10; // 根据滚轮的滚动方向和量来滚动 ListView
}
ListView {
id: id_view
spacing: 10
topMargin: 10
anchors.fill: parent
model: TestModels {}
delegate: contactDelegate
flickDeceleration: 0 // 禁止滚动时的伸缩效果
clip : true
snapMode: ListView.SnapToItem
onCurrentIndexChanged: {
// console.log("2 left_menu_index", global_properties.left_menu_index_now)
itemAtIndex(global_properties.left_menu_index_now).color = global_properties.left_menu_lighlight_color
itemAtIndex(global_properties.left_menu_index_last).color = global_properties.left_menu_non_lighlight_color
}
Component.onCompleted: {
id_view.currentIndex = id_view.count
global_properties.left_menu_index_last = id_view.count
global_properties.left_menu_index_now = 0
id_view.currentIndex = 0
console.log("complete at ", global_properties.left_menu_index_now)
}
}
}
}