2020-10-15 12:52:19 +02:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
import QtGraphicalEffects 1.12
|
2020-10-17 03:22:37 +02:00
|
|
|
import QtQuick.Templates 2.12 as T
|
|
|
|
import QtQuick.Controls.impl 2.12
|
|
|
|
import QtQuick.Controls.Material 2.12
|
|
|
|
import QtQuick.Controls.Material.impl 2.12
|
2020-10-15 12:52:19 +02:00
|
|
|
|
|
|
|
Item {
|
|
|
|
id: control
|
|
|
|
|
|
|
|
property bool raised: false
|
|
|
|
property alias mouseArea: mouseArea
|
|
|
|
property string text: ""
|
2020-10-15 13:16:46 +02:00
|
|
|
property string color: ""
|
2020-10-15 12:52:19 +02:00
|
|
|
property bool isDarkColor: control.checkIsDarkColor(color)
|
2020-10-17 21:51:33 +02:00
|
|
|
property double glowRadius: 0.01
|
|
|
|
property double glowSpread: 0.01
|
2020-10-15 12:52:19 +02:00
|
|
|
property bool glowVisible: true
|
2020-10-17 21:51:33 +02:00
|
|
|
property double glowScale: 1
|
2020-10-18 22:42:42 +02:00
|
|
|
property double glowOpacity: Math.pow( control.opacity, 1000 ) * 0.3
|
2020-10-17 03:22:37 +02:00
|
|
|
property bool interactive: true
|
2020-10-18 15:08:12 +02:00
|
|
|
property int horizontalPadding: width * 0.15
|
|
|
|
property int verticalPadding: height * 0.15
|
2020-10-18 22:42:42 +02:00
|
|
|
property int radius: height * 0.5
|
2020-10-15 12:52:19 +02:00
|
|
|
|
|
|
|
signal clicked
|
|
|
|
|
|
|
|
function checkIsDarkColor(color) {
|
2020-10-18 15:08:12 +02:00
|
|
|
|
2020-10-15 12:52:19 +02:00
|
|
|
var c = color.substring(1); // strip #
|
|
|
|
var rgb = parseInt(c, 16); // convert rrggbb to decimal
|
|
|
|
var r = (rgb >> 16) & 0xff; // extract red
|
|
|
|
var g = (rgb >> 8) & 0xff; // extract green
|
|
|
|
var b = (rgb >> 0) & 0xff; // extract blue
|
|
|
|
|
|
|
|
var luma = 0.2126 * r + 0.7152 * g + 0.0722 * b; // per ITU-R BT.709
|
|
|
|
|
|
|
|
return luma < 150
|
|
|
|
}
|
|
|
|
|
|
|
|
RectangularGlow {
|
|
|
|
id: effect
|
|
|
|
glowRadius: control.glowRadius
|
|
|
|
spread: control.glowSpread
|
|
|
|
color: "black"
|
|
|
|
|
|
|
|
visible: control.glowVisible
|
|
|
|
|
|
|
|
cornerRadius: background.radius
|
|
|
|
anchors.fill: background
|
|
|
|
scale: control.glowScale
|
|
|
|
opacity: control.glowOpacity
|
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
id: background
|
|
|
|
anchors.fill: parent
|
|
|
|
color: control.color
|
2020-10-18 22:42:42 +02:00
|
|
|
radius: control.radius
|
2020-10-17 03:22:37 +02:00
|
|
|
clip: true
|
2020-10-15 12:52:19 +02:00
|
|
|
|
|
|
|
Behavior on color {
|
|
|
|
ColorAnimation {}
|
|
|
|
}
|
2020-10-17 03:22:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
Ripple {
|
|
|
|
id: ripple
|
|
|
|
clipRadius: height
|
|
|
|
clip: true
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
|
|
|
pressed: mouseArea.pressed
|
|
|
|
anchor: background
|
|
|
|
active: mouseArea.pressed || mouseArea.visualFocus || mouseArea.containsMouse
|
|
|
|
color: control.Material.rippleColor
|
|
|
|
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: OpacityMask {
|
|
|
|
maskSource: Item {
|
|
|
|
width: ripple.width
|
|
|
|
height: ripple.height
|
|
|
|
Rectangle {
|
|
|
|
anchors.fill: parent
|
2020-10-18 22:42:42 +02:00
|
|
|
radius: control.radius
|
2020-10-17 03:22:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ColorOverlay {
|
|
|
|
source: ripple
|
|
|
|
color: "red"
|
2020-10-15 12:52:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Text {
|
|
|
|
id: contentText
|
2020-10-15 13:16:46 +02:00
|
|
|
anchors.centerIn: background
|
|
|
|
|
2020-10-18 15:08:12 +02:00
|
|
|
width: background.width - 2 * control.horizontalPadding
|
|
|
|
height: background.height - 2 * control.verticalPadding
|
2020-10-15 12:52:19 +02:00
|
|
|
|
|
|
|
font.pixelSize: height
|
|
|
|
fontSizeMode: Text.Fit
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2020-10-15 14:21:34 +02:00
|
|
|
minimumPixelSize: 1
|
2020-10-15 12:52:19 +02:00
|
|
|
|
|
|
|
color: control.isDarkColor ? "white":"black"
|
|
|
|
text: control.text
|
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
id: mouseArea
|
|
|
|
anchors.fill: parent
|
2020-10-17 03:22:37 +02:00
|
|
|
enabled: control.enabled && control.interactive
|
2020-10-15 12:52:19 +02:00
|
|
|
onClicked: control.clicked()
|
|
|
|
}
|
|
|
|
}
|