NButton: added support for right click and middle click, removed rippled effect.
This commit is contained in:
parent
2bd30947fc
commit
8ad2bef2f5
1 changed files with 20 additions and 54 deletions
|
|
@ -22,6 +22,8 @@ Rectangle {
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
signal clicked
|
signal clicked
|
||||||
|
signal rightClicked
|
||||||
|
signal middleClicked
|
||||||
|
|
||||||
// Internal properties
|
// Internal properties
|
||||||
property bool hovered: false
|
property bool hovered: false
|
||||||
|
|
@ -125,56 +127,13 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ripple effect
|
|
||||||
Rectangle {
|
|
||||||
id: ripple
|
|
||||||
anchors.centerIn: parent
|
|
||||||
width: 0
|
|
||||||
height: width
|
|
||||||
radius: width / 2
|
|
||||||
color: root.outlined ? root.backgroundColor : root.textColor
|
|
||||||
opacity: 0
|
|
||||||
|
|
||||||
ParallelAnimation {
|
|
||||||
id: rippleAnimation
|
|
||||||
|
|
||||||
NumberAnimation {
|
|
||||||
target: ripple
|
|
||||||
property: "width"
|
|
||||||
from: 0
|
|
||||||
to: Math.max(root.width, root.height) * 2
|
|
||||||
duration: Style.animationFast
|
|
||||||
easing.type: Easing.OutCubic
|
|
||||||
}
|
|
||||||
|
|
||||||
SequentialAnimation {
|
|
||||||
NumberAnimation {
|
|
||||||
target: ripple
|
|
||||||
property: "opacity"
|
|
||||||
from: 0
|
|
||||||
to: 0.05
|
|
||||||
duration: 100
|
|
||||||
easing.type: Easing.OutCubic
|
|
||||||
}
|
|
||||||
|
|
||||||
NumberAnimation {
|
|
||||||
target: ripple
|
|
||||||
property: "opacity"
|
|
||||||
from: 0.05
|
|
||||||
to: 0
|
|
||||||
duration: 300
|
|
||||||
easing.type: Easing.InCubic
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mouse interaction
|
// Mouse interaction
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
enabled: root.enabled
|
enabled: root.enabled
|
||||||
hoverEnabled: true
|
hoverEnabled: true
|
||||||
|
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
||||||
cursorShape: root.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
cursorShape: root.enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
|
||||||
|
|
||||||
onEntered: root.hovered = true
|
onEntered: root.hovered = true
|
||||||
|
|
@ -182,15 +141,22 @@ Rectangle {
|
||||||
root.hovered = false
|
root.hovered = false
|
||||||
root.pressed = false
|
root.pressed = false
|
||||||
}
|
}
|
||||||
onPressed: {
|
onPressed: mouse => {
|
||||||
root.pressed = true
|
root.pressed = true
|
||||||
rippleAnimation.restart()
|
|
||||||
}
|
|
||||||
onReleased: {
|
|
||||||
if (containsMouse) {
|
|
||||||
root.clicked()
|
|
||||||
}
|
}
|
||||||
|
onReleased: mouse => {
|
||||||
root.pressed = false
|
root.pressed = false
|
||||||
|
if (!root.hovered) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mouse.button === Qt.LeftButton) {
|
||||||
|
root.clicked()
|
||||||
|
} else if (mouse.button == Qt.RightButton) {
|
||||||
|
root.rightClicked()
|
||||||
|
} else if (mouse.button == Qt.MiddleButton) {
|
||||||
|
root.middleClicked
|
||||||
|
}
|
||||||
}
|
}
|
||||||
onCanceled: {
|
onCanceled: {
|
||||||
root.pressed = false
|
root.pressed = false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue