2019-07-11 05:00:57 +10:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
2019-07-11 05:00:57 +10:00
|
|
|
|
|
|
|
Button {
|
|
|
|
property bool circle: false
|
|
|
|
|
|
|
|
property color backgroundColor: theme.controls.button.background
|
|
|
|
property alias overlayOpacity: buttonBackgroundOverlay.opacity
|
|
|
|
property bool checkedLightens: false
|
|
|
|
|
|
|
|
signal canceled
|
|
|
|
signal clicked
|
|
|
|
signal doubleClicked
|
|
|
|
signal entered
|
|
|
|
signal exited
|
|
|
|
signal pressAndHold
|
|
|
|
signal pressed
|
|
|
|
signal released
|
|
|
|
|
|
|
|
id: button
|
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
id: buttonBackground
|
|
|
|
color: Qt.lighter(
|
2019-07-14 10:15:20 +10:00
|
|
|
backgroundColor,
|
|
|
|
! enabled ? 0.7 :
|
|
|
|
checked ? (checkedLightens ? 1.3 : 0.7) :
|
|
|
|
1.0
|
2019-07-11 05:00:57 +10:00
|
|
|
)
|
|
|
|
radius: circle ? height : 0
|
|
|
|
|
2019-07-18 15:53:28 +10:00
|
|
|
Behavior on color { HColorAnimation { factor: 0.5 } }
|
2019-07-11 05:00:57 +10:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: buttonBackgroundOverlay
|
|
|
|
anchors.fill: parent
|
|
|
|
radius: parent.radius
|
|
|
|
color: "black"
|
|
|
|
opacity: 0
|
|
|
|
|
2019-07-18 15:53:28 +10:00
|
|
|
Behavior on opacity { HNumberAnimation { factor: 0.5 } }
|
2019-07-11 05:00:57 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
|
|
onCanceled: button.canceled()
|
|
|
|
onClicked: button.clicked()
|
|
|
|
onDoubleClicked: button.doubleClicked()
|
|
|
|
onEntered: {
|
|
|
|
overlayOpacity = checked ? 0 : 0.15
|
|
|
|
button.entered()
|
|
|
|
}
|
|
|
|
onExited: {
|
|
|
|
overlayOpacity = 0
|
|
|
|
button.exited()
|
|
|
|
}
|
|
|
|
onPressAndHold: button.pressAndHold()
|
|
|
|
onPressed: {
|
|
|
|
overlayOpacity += 0.15
|
|
|
|
button.pressed()
|
|
|
|
}
|
|
|
|
onReleased: {
|
|
|
|
if (checkable) { checked = ! checked }
|
|
|
|
overlayOpacity = checked ? 0 : 0.15
|
|
|
|
button.released()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|