Add hover animation

pull/7/head
reionwong 5 years ago
parent 65f601e7fe
commit b1a514027b

@ -28,8 +28,13 @@ import Cutefish.StatusBar 1.0
Item { Item {
id: control id: control
property real moveX: 0
property real moveY: 0
property string popupText: "" property string popupText: ""
property bool checked: false property bool checked: false
property bool animationEnabled: false
signal clicked signal clicked
signal rightClicked signal rightClicked
@ -40,6 +45,18 @@ Item {
acceptedButtons: Qt.LeftButton | Qt.RightButton acceptedButtons: Qt.LeftButton | Qt.RightButton
hoverEnabled: true hoverEnabled: true
onEntered: {
_bgRect.x = mouseX
_bgRect.y = mouseY
_bgRect.state = "shown"
}
onExited: {
control.moveX = mouseX
control.moveY = mouseY
_bgRect.state = "hidden"
}
onClicked: { onClicked: {
if (mouse.button == Qt.LeftButton) if (mouse.button == Qt.LeftButton)
control.clicked() control.clicked()
@ -64,24 +81,85 @@ Item {
} }
Rectangle { Rectangle {
anchors.fill: parent id: _bgRect
anchors.topMargin: 1
anchors.bottomMargin: 1
radius: FishUI.Theme.smallRadius radius: FishUI.Theme.smallRadius
state: "hidden"
states: [
State {
name: "shown"
PropertyChanges {
target: _bgRect
x: 0
y: 1
width: control.width
height: control.height - 2
visible: true
}
},
State {
name: "hidden"
PropertyChanges {
target: _bgRect
x: control.moveX
y: control.moveY
width: 0
height: 0
visible: false
}
}
]
transitions:[
Transition {
from: "hidden"
to: "shown"
SequentialAnimation{
PropertyAnimation {
target: _bgRect
properties: "visible"
duration: 0
easing.type: Easing.OutQuart
}
PropertyAnimation {
target: _bgRect
properties: "x, y, width, height"
duration: control.animationEnabled ? 400 : 0
easing.type: Easing.OutQuart
}
}
},
Transition {
from: "shown"
to: "hidden"
SequentialAnimation{
PropertyAnimation {
target: _bgRect
properties: "x, y, width, height"
duration: control.animationEnabled ? 200 : 0
easing.type: Easing.OutQuart
}
PropertyAnimation {
target: _bgRect
properties: "visible"
duration: 0
easing.type: Easing.OutQuart
}
}
}
]
color: { color: {
if (control.checked) { if (control.checked) {
return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1) return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1)
} }
if (_mouseArea.containsMouse) { if (_mouseArea.containsPress)
if (_mouseArea.containsPress) return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.3) : Qt.rgba(0, 0, 0, 0.2)
return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.3) : Qt.rgba(0, 0, 0, 0.2) else
else return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1)
return (rootItem.darkMode) ? Qt.rgba(255, 255, 255, 0.2) : Qt.rgba(0, 0, 0, 0.1)
}
return "transparent"
} }
} }
} }

@ -233,10 +233,12 @@ Item {
} }
delegate: StandardItem { delegate: StandardItem {
property bool darkMode: rootItem.darkMode
width: trayView.itemWidth width: trayView.itemWidth
height: ListView.view.height height: ListView.view.height
animationEnabled: true
property bool darkMode: rootItem.darkMode
onDarkModeChanged: updateTimer.restart() onDarkModeChanged: updateTimer.restart()
Timer { Timer {
@ -262,6 +264,7 @@ Item {
StandardItem { StandardItem {
id: controler id: controler
animationEnabled: true
Layout.fillHeight: true Layout.fillHeight: true
Layout.preferredWidth: _controlerLayout.implicitWidth + FishUI.Units.largeSpacing Layout.preferredWidth: _controlerLayout.implicitWidth + FishUI.Units.largeSpacing
@ -339,6 +342,7 @@ Item {
StandardItem { StandardItem {
id: datetimeItem id: datetimeItem
animationEnabled: true
Layout.fillHeight: true Layout.fillHeight: true
Layout.preferredWidth: _dateTimeLayout.implicitWidth + FishUI.Units.smallSpacing Layout.preferredWidth: _dateTimeLayout.implicitWidth + FishUI.Units.smallSpacing

Loading…
Cancel
Save