opaque/Button.qml

97 lines
2.5 KiB
QML
Raw Permalink Normal View History

2020-05-19 19:49:52 +00:00
import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
2020-05-19 20:25:56 +00:00
import "theme"
import "fonts"
2020-05-19 19:49:52 +00:00
Rectangle {
id: button
2020-12-17 16:10:21 +00:00
width: tm.width + (icon == undefined || icon == "" ? 0 : iconSize) + 2 * Theme.paddingClickTarget + 2 * radius
2020-05-19 19:49:52 +00:00
Layout.minimumWidth: width
Layout.maximumWidth: width
2020-12-17 16:10:21 +00:00
height: 2 * Theme.paddingClickTarget + Math.max(tm.height, (icon == undefined || icon == "" ? 0 : iconSize))
2020-05-19 19:49:52 +00:00
Layout.minimumHeight: height
Layout.maximumHeight: height
property color inactiveColor: Theme.defaultButtonColor
property color activeColor: Theme.defaultButtonActiveColor
2020-08-28 22:08:33 +00:00
property color textColor: Theme.defaultButtonTextColor
color: mousedown ? activeColor : inactiveColor
border.color: mousedown ? activeColor : inactiveColor
2020-05-19 19:49:52 +00:00
border.width: 1
2020-12-17 16:10:21 +00:00
radius: height / 2
2020-05-19 19:49:52 +00:00
antialiasing: true
property bool checked: false
property alias text: buttonText.text
property alias font: buttonText.font.family
property string icon
2020-12-17 16:10:21 +00:00
property int iconSize: Theme.uiIconSizeS
2020-05-19 19:49:52 +00:00
property bool mousedown
property string tooltip
signal clicked
RowLayout {
anchors.centerIn: parent
2020-12-17 16:10:21 +00:00
spacing: Theme.paddingSmall
2020-05-19 19:49:52 +00:00
Image {
id: ico
source: icon!="" ? gcd.assetPath + "core/"+icon+".webp" : "";
visible: icon != ""
2020-12-17 16:10:21 +00:00
height: button.iconSize
sourceSize.height: button.iconSize
ColorOverlay{
id: iconColorOverlay
color: textColor
anchors.fill: ico
source: ico
antialiasing: true
smooth: true
}
2020-05-19 19:49:52 +00:00
}
2020-05-19 19:49:52 +00:00
Label {
id: buttonText
font.family: Fonts.applicationFontRegular.name
font.styleName: "ExtraBold"
2020-12-17 16:10:21 +00:00
font.pointSize: Theme.textMediumPt
2020-08-28 22:08:33 +00:00
color: button.textColor
2020-05-19 19:49:52 +00:00
visible: button.text != "" && button.text != undefined
}
2020-12-17 16:10:21 +00:00
TextMetrics {
id: tm
font: buttonText.font
text: buttonText.text
}
2020-05-19 19:49:52 +00:00
ToolTip.visible: tooltip != "" && mouseArea.containsMouse
ToolTip.text: tooltip
}
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: {
parent.focus = true
parent.clicked()
}
onPressed: mousedown = true
onReleased: mousedown = false
hoverEnabled: true
}
Keys.onSpacePressed: clicked()
}