opaque/Icon.qml

78 lines
1.8 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
import "." as Widgets
2020-05-19 20:25:56 +00:00
import "theme"
2020-05-19 19:49:52 +00:00
Rectangle {
id: root
property color backgroundColor: parent.color
property color hilightBackgroundColor: backgroundColor
property bool isHover: false
color: isHover ? hilightBackgroundColor : backgroundColor
2020-05-19 19:49:52 +00:00
property alias iconColor: iconColorOverlay.color
property alias source: srcImg.source
2020-11-25 06:18:11 +00:00
property alias sourceWidth: srcImg.sourceSize.width
property alias sourceHeight: srcImg.sourceSize.height
2020-05-19 19:49:52 +00:00
property real rotationAngle: 0.0
2020-05-19 19:49:52 +00:00
signal clicked()
signal hover(bool hover)
property int size: Math.min(height, width)
2020-05-19 19:49:52 +00:00
Image {
id: srcImg
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
height: size
width: size
2020-05-19 19:49:52 +00:00
antialiasing: true
smooth: true
visible: false
// Apparently qml can now only DOWN-SCALE/SHRINK the SVG, so with this hack it which won't cause blurriness/pixelation
sourceSize.width: size*2
sourceSize.height: size*2
2020-05-19 19:49:52 +00:00
}
ColorOverlay{
id: iconColorOverlay
anchors.fill: srcImg
2020-05-19 19:49:52 +00:00
source: srcImg
antialiasing: true
smooth: true
transform: Rotation { origin.x: width/2; origin.y: height / 2; angle: rotationAngle}
2020-05-19 19:49:52 +00:00
}
MouseArea { // Full row mouse area triggering onClick
id: ma
anchors.fill: parent
hoverEnabled: true
onClicked: { root.clicked() }
onEntered: {
isHover = true
root.hover(true)
2020-05-19 19:49:52 +00:00
}
onExited: {
isHover = false
root.hover(false)
2020-05-19 19:49:52 +00:00
}
}
}