forked from Shinonome/dots-hyprland
group button & ripple button: fix non-left btn release, add more actions
This commit is contained in:
@@ -18,8 +18,10 @@ Button {
|
|||||||
property string buttonText
|
property string buttonText
|
||||||
property real buttonRadius: Appearance?.rounding?.small ?? 4
|
property real buttonRadius: Appearance?.rounding?.small ?? 4
|
||||||
property real buttonRadiusPressed: buttonRadius
|
property real buttonRadiusPressed: buttonRadius
|
||||||
property var altAction
|
property var downAction // When left clicking (down)
|
||||||
property var middleClickAction
|
property var releaseAction // When left clicking (release)
|
||||||
|
property var altAction // When right clicking
|
||||||
|
property var middleClickAction // When middle clicking
|
||||||
property bool bounce: true
|
property bool bounce: true
|
||||||
property real baseWidth: contentItem.implicitWidth + padding * 2
|
property real baseWidth: contentItem.implicitWidth + padding * 2
|
||||||
property real baseHeight: contentItem.implicitHeight + padding * 2
|
property real baseHeight: contentItem.implicitHeight + padding * 2
|
||||||
@@ -37,6 +39,10 @@ Button {
|
|||||||
animation: Appearance.animation.clickBounce.numberAnimation.createObject(this)
|
animation: Appearance.animation.clickBounce.numberAnimation.createObject(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Behavior on implicitHeight {
|
||||||
|
animation: Appearance.animation.clickBounce.numberAnimation.createObject(this)
|
||||||
|
}
|
||||||
|
|
||||||
Behavior on radius {
|
Behavior on radius {
|
||||||
animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this)
|
animation: Appearance.animation.elementMoveFast.numberAnimation.createObject(this)
|
||||||
}
|
}
|
||||||
@@ -70,18 +76,21 @@ Button {
|
|||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
acceptedButtons: Qt.LeftButton | Qt.RightButton | Qt.MiddleButton
|
||||||
onPressed: (event) => {
|
onPressed: (event) => {
|
||||||
if (event.button === Qt.MiddleButton) {
|
if(event.button === Qt.RightButton) {
|
||||||
if (root.middleClickAction) root.middleClickAction();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (event.button === Qt.RightButton) {
|
|
||||||
if (root.altAction) root.altAction();
|
if (root.altAction) root.altAction();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(event.button === Qt.MiddleButton) {
|
||||||
|
if (root.middleClickAction) root.middleClickAction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
root.down = true
|
root.down = true
|
||||||
|
if (root.downAction) root.downAction();
|
||||||
}
|
}
|
||||||
onReleased: (event) => {
|
onReleased: (event) => {
|
||||||
root.down = false
|
root.down = false
|
||||||
|
if (event.button != Qt.LeftButton) return;
|
||||||
|
if (root.releaseAction) root.releaseAction();
|
||||||
root.click() // Because the MouseArea already consumed the event
|
root.click() // Because the MouseArea already consumed the event
|
||||||
}
|
}
|
||||||
onCanceled: (event) => {
|
onCanceled: (event) => {
|
||||||
|
|||||||
@@ -20,8 +20,10 @@ Button {
|
|||||||
property real buttonEffectiveRadius: root.down ? root.buttonRadiusPressed : root.buttonRadius
|
property real buttonEffectiveRadius: root.down ? root.buttonRadiusPressed : root.buttonRadius
|
||||||
property int rippleDuration: 1200
|
property int rippleDuration: 1200
|
||||||
property bool rippleEnabled: true
|
property bool rippleEnabled: true
|
||||||
property var altAction
|
property var downAction // When left clicking (down)
|
||||||
property var middleClickAction
|
property var releaseAction // When left clicking (release)
|
||||||
|
property var altAction // When right clicking
|
||||||
|
property var middleClickAction // When middle clicking
|
||||||
|
|
||||||
property color colBackground: ColorUtils.transparentize(Appearance?.colors.colLayer1Hover, 1) || "transparent"
|
property color colBackground: ColorUtils.transparentize(Appearance?.colors.colLayer1Hover, 1) || "transparent"
|
||||||
property color colBackgroundHover: Appearance?.colors.colLayer1Hover ?? "#E5DFED"
|
property color colBackgroundHover: Appearance?.colors.colLayer1Hover ?? "#E5DFED"
|
||||||
@@ -70,12 +72,15 @@ Button {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
root.down = true
|
root.down = true
|
||||||
|
if (root.downAction) root.downAction();
|
||||||
if (!root.rippleEnabled) return;
|
if (!root.rippleEnabled) return;
|
||||||
const {x,y} = event
|
const {x,y} = event
|
||||||
startRipple(x, y)
|
startRipple(x, y)
|
||||||
}
|
}
|
||||||
onReleased: (event) => {
|
onReleased: (event) => {
|
||||||
root.down = false
|
root.down = false
|
||||||
|
if (event.button != Qt.LeftButton) return;
|
||||||
|
if (root.releaseAction) root.releaseAction();
|
||||||
root.click() // Because the MouseArea already consumed the event
|
root.click() // Because the MouseArea already consumed the event
|
||||||
if (!root.rippleEnabled) return;
|
if (!root.rippleEnabled) return;
|
||||||
rippleFadeAnim.restart();
|
rippleFadeAnim.restart();
|
||||||
|
|||||||
Reference in New Issue
Block a user