some new icons, Icon is now a qml class

This commit is contained in:
Blue 2024-04-03 20:51:08 -03:00
parent abc3ebf80a
commit 9a5a0b27a2
Signed by: blue
GPG key ID: 9B203B252A63EE38
13 changed files with 328 additions and 37 deletions

View file

@ -29,13 +29,10 @@ Item {
height: parent.iconSize
color: line.color
IconLabel {
Icon {
anchors.fill: parent
icon {
name: line.icon
width: width
height: height
}
iconName: line.icon
color: pickColor(line.color)
}
}

View file

@ -12,6 +12,7 @@ qt_add_qml_module(magpieComponents
Modal.qml
AssetLine.qml
IconPicker.qml
Icon.qml
)
target_link_libraries(magpie PRIVATE magpieComponents)

52
qml/Components/Icon.qml Normal file
View file

@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick
import QtQuick.Controls
IconImage {
required property string iconName
property int iconSize: 20
id: image
source: "qrc:/icons/" + iconName + ".svg"
height: iconSize
width: iconSize
sourceSize.width: iconSize
sourceSize.height: iconSize
IconImage {
id: fallback
anchors.fill: parent
source: "qrc:/icons/unknown.svg"
visible: parent.status == Image.Error
color: image.color
sourceSize.width: iconSize
sourceSize.height: iconSize
}
function pickColor (color: color) {
const text = palette.text;
const base = palette.base;
const t = brightness(text)
const b = brightness(base)
let l = text, r = base;
if (t > b) {
l = base;
r = text;
}
const s = (t + b) / 2;
if (brightness(color) - s > 0)
return l;
else
return r;
}
function brightness (color: color) {
return Math.sqrt(0.2126 * color.r * color.r + 0.7152 * color.g * color.g + 0.0722 * color.b * color.b);
}
}

View file

@ -8,7 +8,7 @@ ComboBox {
property string icon: ""
id: box
model: ["wallet", "whatever"]
model: ["wallet", "coin", "paper"]
delegate: MenuItem {
required property string modelData
required property int index
@ -26,24 +26,12 @@ ComboBox {
component View: Row {
required property string icon
property int iconSize: 20
spacing: 5
IconImage {
id: image
Icon {
anchors.verticalCenter: parent.verticalCenter
iconName: icon
color: palette.text
source: "qrc:/icons/" + icon + ".svg"
height: parent.iconSize
width: parent.iconSize
IconImage {
id: fallback
anchors.fill: parent
source: "qrc:/icons/wallet.svg"
visible: parent.status == Image.Error
color: palette.text
}
}
Label {