moment/harmonyqml/components/base/HButton.qml

77 lines
2.0 KiB
QML
Raw Normal View History

2019-04-22 00:44:04 +10:00
import QtQuick 2.7
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.4
Button {
2019-04-27 06:02:20 +10:00
property alias fontSize: buttonLabel.font.pixelSize
property color backgroundColor: "lightgray"
property alias overlayOpacity: buttonBackgroundOverlay.opacity
2019-04-22 00:44:04 +10:00
property string iconName: ""
2019-04-27 06:02:20 +10:00
property bool circle: false
2019-04-22 00:44:04 +10:00
id: button
display: Button.TextBesideIcon
2019-04-27 06:02:20 +10:00
background: Rectangle {
id: buttonBackground
color: Qt.lighter(backgroundColor, checked ? 1.3 : 1.0)
radius: circle ? height : 0
Rectangle {
id: buttonBackgroundOverlay
anchors.fill: parent
radius: parent.radius
color: "black"
opacity: 0
}
}
contentItem: HRowLayout {
spacing: button.text && iconName ? 5 : 0
Component {
id: buttonIcon
Image {
cache: true
mipmap: true
source: "../../icons/" + iconName + ".svg"
fillMode: Image.PreserveAspectFit
width: button.text ? 20 : 24
height: width
}
}
Loader {
sourceComponent: iconName ? buttonIcon : undefined
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
HLabel {
id: buttonLabel
text: button.text
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
maximumLineCount: 1
Layout.maximumWidth: button.width - buttonIcon.width
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
}
}
MouseArea {
2019-04-27 06:52:26 +10:00
z: 101
2019-04-27 06:02:20 +10:00
anchors.fill: parent
hoverEnabled: true
propagateComposedEvents: true
onEntered: overlayOpacity = checked ? 0 : 0.3
onExited: overlayOpacity = 0
onPressed: overlayOpacity += 0.3
onReleased: {
if (checkable) { checked = ! checked }
overlayOpacity = checked ? 0 : 0.3
}
}
2019-04-22 00:44:04 +10:00
}