summaryrefslogtreecommitdiff
path: root/popups/launcher/components/ISmartCalc.qml
blob: 7f4302af9eafd264c9d6612805fe15f271f5f713 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import Quickshell
import QtQuick
import QtQuick.Layouts

import qs.components
import qs.services
import qs.config

import core

IComponent {
	id: root

	property string symbol
	required property bool category
	required property string predictiveText

	property int cursorPosition: SelectionState.cursorPosition

	preview: Component {
		Icon {
			text: symbol
		}
	}

	onInputChanged: {
		SmartCalc.reset_result();
	}

	process: function () {
		SmartCalc.query(input);
		const answer = SmartCalc.result;
		// TODO: use answer property rn its circular dependent since it has to be valid which is the line below
		const valid = SmartCalc.result && SmartCalc.result.length > 0 && category;
		return {
			valid,
			priority: valid,
			answer,
			predictiveCompletion: ` ${predictiveText} ` + answer
		};
	}
	exec: function () {
		Clip.copy(answer);
	}

	IInnerComponent {
		RowLayout {
			spacing: 0
			Layout.fillWidth: true
			Layout.fillHeight: true
			Layout.preferredHeight: parent.height

			Item {
				Layout.fillWidth: true
				IText {
					anchors.centerIn: parent
					elide: cursorPosition > input.length / 2 ? Text.ElideLeft : Text.ElideRight
					width: Math.min(implicitWidth, parent.width - Launcher.innerMargin * 2)
					clip: true
					renderType: Text.CurveRendering
					visible: valid
					text: input
					font {
						pixelSize: Launcher.widgetFontSize
						bold: root.isSelectedPriority()
					}
				}
			}

			IText {
				visible: valid
				text: "→"
				font.pixelSize: Launcher.widgetFontSize
				font.bold: root.isSelectedPriority()
			}

			Item {
				Layout.fillWidth: true
				IText {
					animate: true
					anchors.centerIn: parent
					width: Math.min(implicitWidth, parent.width - Launcher.innerMargin * 2)
					renderType: Text.CurveRendering
					visible: valid
					text: valid ? answer : ''
					font {
						pixelSize: Launcher.widgetFontSize
						bold: root.isSelectedPriority()
					}
				}
			}
		}
	}
}