Files
z-bar-qt/Modules/Launcher/Items/CalcItem.qml
T
zach 7d6f3cc275
C++ / fmt (pull_request) Successful in 4s
JS/TS / fmt (pull_request) Successful in 20s
JS/TS / lint (pull_request) Successful in 22s
Python / static (pull_request) Successful in 57s
Rust / fmt (pull_request) Successful in 1m2s
C++ / build (pull_request) Successful in 2m10s
Rust / build (pull_request) Successful in 1m50s
Rust / clippy (pull_request) Successful in 1m25s
Python / verify (pull_request) Successful in 2m58s
C++ / clang-tidy (pull_request) Successful in 7m8s
initial commit for media widget update + anim tokens restructure
2026-08-18 16:14:41 +02:00

118 lines
2.8 KiB
QML

import ZShell
import Quickshell
import QtQuick
import QtQuick.Layouts
import qs.Components
import qs.Modules
import qs.Helpers
import ZShell.Config
import qs.Services
Item {
id: root
required property var list
readonly property string math: list.search.text.slice(`${Config.launcher.actionPrefix}calc `.length)
function onClicked(): void {
Quickshell.execDetached(["wl-copy", Qalculator.eval(math, false)]);
root.list.visibilities.launcher = false;
}
anchors.left: parent?.left
anchors.right: parent?.right
implicitHeight: Config.launcher.sizes.itemHeight
StateLayer {
radius: Tokens.rounding.small
onClicked: {
root.onClicked();
}
}
RowLayout {
anchors.left: parent.left
anchors.margins: Tokens.padding.small
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: Tokens.spacing.medium
MaterialIcon {
Layout.alignment: Qt.AlignVCenter
font.pointSize: Tokens.font.size.extraLarge
text: "function"
}
CustomText {
id: result
Layout.alignment: Qt.AlignVCenter
Layout.fillWidth: true
color: {
if (text.includes("error: ") || text.includes("warning: "))
return Colors.palette.m3error;
if (!root.math)
return Colors.palette.m3onSurfaceVariant;
return Colors.palette.m3onSurface;
}
elide: Text.ElideLeft
text: root.math.length > 0 ? Qalculator.eval(root.math) : qsTr("Type an expression to calculate")
}
CustomRect {
Layout.alignment: Qt.AlignVCenter
clip: true
color: Colors.palette.m3tertiary
implicitHeight: Math.max(label.implicitHeight, icon.implicitHeight) + Tokens.padding.extraSmall * 2
implicitWidth: (stateLayer.containsMouse ? label.implicitWidth + label.anchors.rightMargin : 0) + icon.implicitWidth + Tokens.padding.small * 2
radius: Tokens.rounding.medium
Behavior on implicitWidth {
Anim {
easing: Tokens.anim.expressiveDefaultEffects
}
}
StateLayer {
id: stateLayer
color: Colors.palette.m3onTertiary
onClicked: {
Quickshell.execDetached(["app2unit", "--", ...Config.general.apps.terminal, "fish", "-C", `exec qalc -i '${root.math}'`]);
root.list.visibilities.launcher = false;
}
}
CustomText {
id: label
anchors.right: icon.left
anchors.rightMargin: Tokens.spacing.small
anchors.verticalCenter: parent.verticalCenter
color: Colors.palette.m3onTertiary
font.pointSize: Tokens.font.size.normal
opacity: stateLayer.containsMouse ? 1 : 0
text: qsTr("Open in calculator")
Behavior on opacity {
Anim {
}
}
}
MaterialIcon {
id: icon
anchors.right: parent.right
anchors.rightMargin: Tokens.padding.small
anchors.verticalCenter: parent.verticalCenter
color: Colors.palette.m3onTertiary
font.pointSize: Tokens.font.size.large
text: "open_in_new"
}
}
}
}