summaryrefslogtreecommitdiff
path: root/popups/launcher/components
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2026-09-02 18:26:45 +0800
committerlittleblack111 <littleblack11111@gmail.com>2026-09-02 18:26:45 +0800
commitf7a43077fe4e139dd7e3f46f448e0951740ec148 (patch)
treef6a68248fe42bd899e99049bab7fdb7e5d26ea60 /popups/launcher/components
parent2f7576faf493b4667b02dcb60ddbf3aa0a9f654b (diff)
fix: qmlfmt
IListView: animation
Diffstat (limited to 'popups/launcher/components')
-rw-r--r--popups/launcher/components/App.qml359
-rw-r--r--popups/launcher/components/Calc.qml250
-rw-r--r--popups/launcher/components/Clip.qml420
-rw-r--r--popups/launcher/components/DuckDuckGo.qml300
-rw-r--r--popups/launcher/components/Emoji.qml354
-rw-r--r--popups/launcher/components/IComponent.qml291
-rw-r--r--popups/launcher/components/IInnerComponent.qml50
-rw-r--r--popups/launcher/components/ISmartCalc.qml146
-rw-r--r--popups/launcher/components/SelectionState.qml84
-rw-r--r--popups/launcher/components/Spell.qml456
10 files changed, 1356 insertions, 1354 deletions
diff --git a/popups/launcher/components/App.qml b/popups/launcher/components/App.qml
index aa278f1..1fa27a7 100644
--- a/popups/launcher/components/App.qml
+++ b/popups/launcher/components/App.qml
@@ -8,183 +8,184 @@ import qs.services
import qs.config
IComponent {
- id: root
-
- property list<DesktopEntry> entries: AppSearch.query(inputCleaned)
- property int selectedIndex: -1
-
- name: "Applications"
-
- implicitHeight: valid ? layout.height : 0
-
- preview: Component {
- IconImage {
- source: Quickshell.iconPath(answer, "image-missing")
- implicitWidth: General.appIconSize
- implicitHeight: General.appIconSize
- }
- }
-
- property string predictiveCompletion: entries[selectedIndex]?.name.slice(input.length) || ""
-
- process: function () {
- const valid = entries.length > 0;
- // TODO: consider removing the valid check
- const selected = valid ? entries[selectedIndex] : "";
- return {
- valid,
- priority: valid,
- answer: selected?.icon || ""
- };
- }
-
- exec: function () {
- SelectionState.selected?.modelData?.execute();
- }
-
- up: function () {
- if (selectedIndex <= 0)
- return true;
- selectedIndex--;
- }
- down: function () {
- if (selectedIndex + 1 > listView.count - 1)
- return true;
- selectedIndex++;
- }
-
- home: function () {
- if (selectedIndex <= 0)
- return true;
- selectedIndex = 0;
- }
- end: function () {
- if (selectedIndex + 1 > listView.count - 1)
- return true;
- selectedIndex = listView.count - 1;
- }
-
- pgup: function () {
- if (selectedIndex <= 0)
- return true;
-
- const pageSize = Math.floor(listView.height / (General.appIconSize + Launcher.innerMargin * 2));
-
- if (selectedIndex - pageSize < 0)
- selectedIndex = 0;
- else
- selectedIndex -= pageSize;
- }
-
- pgdn: function () {
- if (selectedIndex === entries.length - 1)
- return true;
-
- const pageSize = Math.floor(listView.height / (General.appIconSize + Launcher.innerMargin * 2));
- if (selectedIndex + pageSize >= listView.count) {
- selectedIndex = listView.count - 1;
- } else {
- selectedIndex += pageSize;
- }
- }
-
- onEntriesChanged: {
- if (selectedIndex !== -1) {
- if (selectedIndex > entries.length - 1)
- selectedIndex = entries.length - 1;
-
- syncSelectionState();
- return;
- }
-
- selectedIndex = 0;
- syncSelectionState();
- }
-
- onSelectedIndexChanged: {
- Qt.callLater(() => {
- // so at least it exist
- listView.positionViewAtIndex(selectedIndex, ListView.Visible);
- syncSelectionState();
- listView.positionViewAtIndex(selectedIndex, ListView.Contain);
- });
- }
-
- syncSelectionState: function () {
- Qt.callLater(() => {
- if (selectedIndex < 0 || selectedIndex >= listView.count || !root.visible)
- return;
-
- state.selected = listView.itemAtIndex(selectedIndex);
- });
- }
-
- IInnerComponent {
- id: layout
- fromParent: false
- width: parent.width
- height: Math.min(listView.contentHeight + titleBar.height, Launcher.widgetHeight * 1.5)
-
- ListView {
- id: listView
- Layout.fillWidth: true
- Layout.fillHeight: true
- clip: true
- model: entries
- spacing: 0
-
- delegate: Item {
- required property DesktopEntry modelData
- required property int index
- visible: modelData !== null
- width: item.implicitWidth + Launcher.innerMargin * 4
- height: item.height + Launcher.innerMargin * 4
-
- RowLayout {
- id: item
- scale: root.isSelectedPriority() && index === selectedIndex ? 1.01 : 0.99
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.margins: Launcher.innerMargin * 2
- spacing: Launcher.innerMargin * 2
-
- IconImage {
- source: modelData ? Quickshell.iconPath(modelData.icon, "image-missing") : ""
- implicitWidth: General.appIconSize
- implicitHeight: General.appIconSize
- }
- IText {
- text: modelData ? modelData.name : ""
- renderType: Text.QtRendering
- font.bold: root.isSelectedPriority() && index === selectedIndex
- color: root.isSelectedPriority() && index === selectedIndex ? Colors.foreground1 : Colors.foreground2
- Behavior on color {
- ColorAnimation {
- duration: General.animationDuration
- easing.type: Easing.InOutQuad
- }
- }
- }
-
- Behavior on scale {
- ISpringAnimation {}
- }
- }
-
- IMouseArea {
- anchors.fill: parent
- hoverEnabled: true
- onEntered_: {
- root.selectedIndex = index;
- }
- onPressed: {
- root._exec();
- }
- }
- }
- onContentYChanged: {
- SelectionState.syncSelectionState();
- }
- }
- }
+ id: root
+
+ property list<DesktopEntry> entries: AppSearch.query(inputCleaned)
+ property int selectedIndex: -1
+
+ name: "Applications"
+
+ implicitHeight: valid ? layout.height : 0
+
+ preview: Component {
+ IconImage {
+ source: Quickshell.iconPath(answer, "image-missing")
+ implicitWidth: General.appIconSize
+ implicitHeight: General.appIconSize
+ }
+ }
+
+ property string predictiveCompletion: entries[selectedIndex]?.name.slice(input.length) || ""
+
+ process: function () {
+ const valid = entries.length > 0;
+ // TODO: consider removing the valid check
+ const selected = valid ? entries[selectedIndex] : "";
+ return {
+ valid,
+ priority: valid,
+ answer: selected?.icon || ""
+ };
+ }
+
+ exec: function () {
+ SelectionState.selected?.modelData?.execute();
+ }
+
+ up: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex--;
+ }
+ down: function () {
+ if (selectedIndex + 1 > listView.count - 1)
+ return true;
+ selectedIndex++;
+ }
+
+ home: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex = 0;
+ }
+ end: function () {
+ if (selectedIndex + 1 > listView.count - 1)
+ return true;
+ selectedIndex = listView.count - 1;
+ }
+
+ pgup: function () {
+ if (selectedIndex <= 0)
+ return true;
+
+ const pageSize = Math.floor(listView.height / (General.appIconSize + Launcher.innerMargin * 2));
+
+ if (selectedIndex - pageSize < 0)
+ selectedIndex = 0;
+ else
+ selectedIndex -= pageSize;
+ }
+
+ pgdn: function () {
+ if (selectedIndex === entries.length - 1)
+ return true;
+
+ const pageSize = Math.floor(listView.height / (General.appIconSize + Launcher.innerMargin * 2));
+ if (selectedIndex + pageSize >= listView.count) {
+ selectedIndex = listView.count - 1;
+ } else {
+ selectedIndex += pageSize;
+ }
+ }
+
+ onEntriesChanged: {
+ if (selectedIndex !== -1) {
+ if (selectedIndex > entries.length - 1)
+ selectedIndex = entries.length - 1;
+
+ syncSelectionState();
+ return;
+ }
+
+ selectedIndex = 0;
+ syncSelectionState();
+ }
+
+ onSelectedIndexChanged: {
+ Qt.callLater(() => {
+ // so at least it exist
+ listView.scrollToIndex(selectedIndex, ListView.Visible);
+ syncSelectionState();
+ listView.scrollToIndex(selectedIndex, ListView.Contain);
+ });
+ }
+
+ syncSelectionState: function () {
+ Qt.callLater(() => {
+ if (selectedIndex < 0 || selectedIndex >= listView.count || !root.visible)
+ return;
+
+ state.selected = listView.itemAtIndex(selectedIndex);
+ });
+ }
+
+ IInnerComponent {
+ id: layout
+ fromParent: false
+ width: parent.width
+ height: Math.min(listView.contentHeight + titleBar.height, Launcher.widgetHeight * 1.5)
+
+ IListView {
+ id: listView
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ clip: true
+ model: entries
+ spacing: 0
+
+ highlightMoveDuration: 500
+ delegate: Item {
+ required property DesktopEntry modelData
+ required property int index
+ visible: modelData !== null
+ width: item.implicitWidth + Launcher.innerMargin * 4
+ height: item.height + Launcher.innerMargin * 4
+
+ RowLayout {
+ id: item
+ scale: root.isSelectedPriority() && index === selectedIndex ? 1.01 : 0.99
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.margins: Launcher.innerMargin * 2
+ spacing: Launcher.innerMargin * 2
+
+ IconImage {
+ source: modelData ? Quickshell.iconPath(modelData.icon, "image-missing") : ""
+ implicitWidth: General.appIconSize
+ implicitHeight: General.appIconSize
+ }
+ IText {
+ text: modelData ? modelData.name : ""
+ renderType: Text.QtRendering
+ font.bold: root.isSelectedPriority() && index === selectedIndex
+ color: root.isSelectedPriority() && index === selectedIndex ? Colors.foreground1 : Colors.foreground2
+ Behavior on color {
+ ColorAnimation {
+ duration: General.animationDuration
+ easing.type: Easing.InOutQuad
+ }
+ }
+ }
+
+ Behavior on scale {
+ ISpringAnimation {}
+ }
+ }
+
+ IMouseArea {
+ anchors.fill: parent
+ hoverEnabled: true
+ onEntered_: {
+ root.selectedIndex = index;
+ }
+ onPressed: {
+ root._exec();
+ }
+ }
+ }
+ onContentYChanged: {
+ SelectionState.syncSelectionState();
+ }
+ }
+ }
}
diff --git a/popups/launcher/components/Calc.qml b/popups/launcher/components/Calc.qml
index 4daae66..d3b5043 100644
--- a/popups/launcher/components/Calc.qml
+++ b/popups/launcher/components/Calc.qml
@@ -9,129 +9,129 @@ import qs.config
import core
IComponent {
- id: root
-
- property int cursorPosition: SelectionState.cursorPosition
-
- name: "Calculator"
- preview: Component {
- Icon {
- text: ""
- }
- }
-
- onInputChanged: {
- MathCalc.reset_result();
- }
-
- process: function () {
- MathCalc.query(input);
- const valid = MathCalc.result && MathCalc.result.length > 0;
- const answer = MathCalc.result ? MathCalc.result
- // 1. Calculus & Summations (Case insensitive)
- .replace(/\bint(?:egral)?\b/gi, "∫").replace(/\bsum\b/gi, "∑")
-
- // 2. Constants & Symbols (Case insensitive)
- .replace(/\bpi\b/gi, "π").replace(/\btau\b/gi, "τ").replace(/\binf(?:inity)?\b/gi, "∞").replace(/\bdeg\b/gi, "°")
-
- // 3. Roots & Exponentials (Case insensitive)
- .replace(/\bsqrt\b/gi, "√").replace(/\bcbrt\b/gi, "∛")
-
- // 4. Rounding & Absolute Value (Case insensitive)
- .replace(/\bceil\(([^\)]+)\)/gi, "⌈$1⌉").replace(/\bfloor\(([^\)]+)\)/gi, "⌊$1⌋").replace(/\bround\b/gi, " ≈ ")
-
- // 5. Comparison & Equality
- .replace(/\s*<=\s*/g, " ≤ ").replace(/\s*>=\s*/g, " ≥ ").replace(/\s*!=\s*/g, " ≠ ").replace(/\s*==\s*/g, " = ")
-
- // 6. Exponents to Unicode Superscripts FIRST (Case insensitive for ^n, ^x, ^y)
- .replace(/\^0/g, "⁰").replace(/\^1/g, "¹").replace(/\^2/g, "²").replace(/\^3/g, "³").replace(/\^4/g, "⁴").replace(/\^5/g, "⁵").replace(/\^6/g, "⁶").replace(/\^7/g, "⁷").replace(/\^8/g, "⁸").replace(/\^9/g, "⁹").replace(/\^\+/g, "⁺").replace(/\^-/g, "⁻").replace(/\^n/gi, "ⁿ").replace(/\^x/gi, "ˣ").replace(/\^y/gi, "ʸ")
-
- // 7. Kalk Number Bases
- .replace(/_0/g, "₀").replace(/_10/g, "₁₀").replace(/_16/g, "₁₆").replace(/_1/g, "₁").replace(/_2/g, "₂").replace(/_3/g, "₃").replace(/_4/g, "₄").replace(/_5/g, "₅").replace(/_6/g, "₆").replace(/_7/g, "₇").replace(/_8/g, "₈").replace(/_9/g, "₉")
-
- // 8. Arithmetic Operators
- .replace(/\s*\*\s*/g, " × ").replace(/\s*\/\s*/g, " ÷ ").replace(/\s*-\s*/g, " − ").replace(/\s*\+\s*/g, " + ") : "";
- return {
- valid,
- priority: valid,
- answer,
- predictiveCompletion: valid ? ' = ' + answer : ''
- };
- }
- exec: function () {
- Clip.copy(answer);
- MathCalc.reset_ctx();
- }
-
- 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
- // 1. Calculus & Summations (Case insensitive)
- .replace(/\bint(?:egral)?\b/gi, "∫").replace(/\bsum\b/gi, "∑")
-
- // 2. Constants & Symbols (Case insensitive)
- .replace(/\bpi\b/gi, "π").replace(/\btau\b/gi, "τ").replace(/\binf(?:inity)?\b/gi, "∞").replace(/\bdeg\b/gi, "°")
-
- // 3. Roots & Exponentials (Case insensitive)
- .replace(/\bsqrt\b/gi, "√").replace(/\bcbrt\b/gi, "∛")
-
- // 4. Rounding & Absolute Value (Case insensitive)
- .replace(/\bceil\(([^\)]+)\)/gi, "⌈$1⌉").replace(/\bfloor\(([^\)]+)\)/gi, "⌊$1⌋").replace(/\bround\b/gi, " ≈ ")
-
- // 5. Comparison & Equality
- .replace(/\s*<=\s*/g, " ≤ ").replace(/\s*>=\s*/g, " ≥ ").replace(/\s*!=\s*/g, " ≠ ").replace(/\s*==\s*/g, " = ")
-
- // 6. Exponents to Unicode Superscripts FIRST (Case insensitive for ^n, ^x, ^y)
- .replace(/\^0/g, "⁰").replace(/\^1/g, "¹").replace(/\^2/g, "²").replace(/\^3/g, "³").replace(/\^4/g, "⁴").replace(/\^5/g, "⁵").replace(/\^6/g, "⁶").replace(/\^7/g, "⁷").replace(/\^8/g, "⁸").replace(/\^9/g, "⁹").replace(/\^\+/g, "⁺").replace(/\^-/g, "⁻").replace(/\^n/gi, "ⁿ").replace(/\^x/gi, "ˣ").replace(/\^y/gi, "ʸ")
-
- // 7. Kalk Number Bases
- .replace(/_0/g, "₀").replace(/_10/g, "₁₀").replace(/_16/g, "₁₆").replace(/_1/g, "₁").replace(/_2/g, "₂").replace(/_3/g, "₃").replace(/_4/g, "₄").replace(/_5/g, "₅").replace(/_6/g, "₆").replace(/_7/g, "₇").replace(/_8/g, "₈").replace(/_9/g, "₉")
-
- // 8. Arithmetic Operators
- .replace(/\s*\*\s*/g, " × ").replace(/\s*\/\s*/g, " ÷ ").replace(/\s*-\s*/g, " − ").replace(/\s*\+\s*/g, " + ")
- 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()
- }
- }
- }
- }
- }
+ id: root
+
+ property int cursorPosition: SelectionState.cursorPosition
+
+ name: "Calculator"
+ preview: Component {
+ Icon {
+ text: ""
+ }
+ }
+
+ onInputChanged: {
+ MathCalc.reset_result();
+ }
+
+ process: function () {
+ MathCalc.query(input);
+ const valid = MathCalc.result && MathCalc.result.length > 0;
+ const answer = MathCalc.result ? MathCalc.result
+ // 1. Calculus & Summations (Case insensitive)
+ .replace(/\bint(?:egral)?\b/gi, "∫").replace(/\bsum\b/gi, "∑")
+
+ // 2. Constants & Symbols (Case insensitive)
+ .replace(/\bpi\b/gi, "π").replace(/\btau\b/gi, "τ").replace(/\binf(?:inity)?\b/gi, "∞").replace(/\bdeg\b/gi, "°")
+
+ // 3. Roots & Exponentials (Case insensitive)
+ .replace(/\bsqrt\b/gi, "√").replace(/\bcbrt\b/gi, "∛")
+
+ // 4. Rounding & Absolute Value (Case insensitive)
+ .replace(/\bceil\(([^\)]+)\)/gi, "⌈$1⌉").replace(/\bfloor\(([^\)]+)\)/gi, "⌊$1⌋").replace(/\bround\b/gi, " ≈ ")
+
+ // 5. Comparison & Equality
+ .replace(/\s*<=\s*/g, " ≤ ").replace(/\s*>=\s*/g, " ≥ ").replace(/\s*!=\s*/g, " ≠ ").replace(/\s*==\s*/g, " = ")
+
+ // 6. Exponents to Unicode Superscripts FIRST (Case insensitive for ^n, ^x, ^y)
+ .replace(/\^0/g, "⁰").replace(/\^1/g, "¹").replace(/\^2/g, "²").replace(/\^3/g, "³").replace(/\^4/g, "⁴").replace(/\^5/g, "⁵").replace(/\^6/g, "⁶").replace(/\^7/g, "⁷").replace(/\^8/g, "⁸").replace(/\^9/g, "⁹").replace(/\^\+/g, "⁺").replace(/\^-/g, "⁻").replace(/\^n/gi, "ⁿ").replace(/\^x/gi, "ˣ").replace(/\^y/gi, "ʸ")
+
+ // 7. Kalk Number Bases
+ .replace(/_0/g, "₀").replace(/_10/g, "₁₀").replace(/_16/g, "₁₆").replace(/_1/g, "₁").replace(/_2/g, "₂").replace(/_3/g, "₃").replace(/_4/g, "₄").replace(/_5/g, "₅").replace(/_6/g, "₆").replace(/_7/g, "₇").replace(/_8/g, "₈").replace(/_9/g, "₉")
+
+ // 8. Arithmetic Operators
+ .replace(/\s*\*\s*/g, " × ").replace(/\s*\/\s*/g, " ÷ ").replace(/\s*-\s*/g, " − ").replace(/\s*\+\s*/g, " + ") : "";
+ return {
+ valid,
+ priority: valid,
+ answer,
+ predictiveCompletion: valid ? ' = ' + answer : ''
+ };
+ }
+ exec: function () {
+ Clip.copy(answer);
+ MathCalc.reset_ctx();
+ }
+
+ 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
+ // 1. Calculus & Summations (Case insensitive)
+ .replace(/\bint(?:egral)?\b/gi, "∫").replace(/\bsum\b/gi, "∑")
+
+ // 2. Constants & Symbols (Case insensitive)
+ .replace(/\bpi\b/gi, "π").replace(/\btau\b/gi, "τ").replace(/\binf(?:inity)?\b/gi, "∞").replace(/\bdeg\b/gi, "°")
+
+ // 3. Roots & Exponentials (Case insensitive)
+ .replace(/\bsqrt\b/gi, "√").replace(/\bcbrt\b/gi, "∛")
+
+ // 4. Rounding & Absolute Value (Case insensitive)
+ .replace(/\bceil\(([^\)]+)\)/gi, "⌈$1⌉").replace(/\bfloor\(([^\)]+)\)/gi, "⌊$1⌋").replace(/\bround\b/gi, " ≈ ")
+
+ // 5. Comparison & Equality
+ .replace(/\s*<=\s*/g, " ≤ ").replace(/\s*>=\s*/g, " ≥ ").replace(/\s*!=\s*/g, " ≠ ").replace(/\s*==\s*/g, " = ")
+
+ // 6. Exponents to Unicode Superscripts FIRST (Case insensitive for ^n, ^x, ^y)
+ .replace(/\^0/g, "⁰").replace(/\^1/g, "¹").replace(/\^2/g, "²").replace(/\^3/g, "³").replace(/\^4/g, "⁴").replace(/\^5/g, "⁵").replace(/\^6/g, "⁶").replace(/\^7/g, "⁷").replace(/\^8/g, "⁸").replace(/\^9/g, "⁹").replace(/\^\+/g, "⁺").replace(/\^-/g, "⁻").replace(/\^n/gi, "ⁿ").replace(/\^x/gi, "ˣ").replace(/\^y/gi, "ʸ")
+
+ // 7. Kalk Number Bases
+ .replace(/_0/g, "₀").replace(/_10/g, "₁₀").replace(/_16/g, "₁₆").replace(/_1/g, "₁").replace(/_2/g, "₂").replace(/_3/g, "₃").replace(/_4/g, "₄").replace(/_5/g, "₅").replace(/_6/g, "₆").replace(/_7/g, "₇").replace(/_8/g, "₈").replace(/_9/g, "₉")
+
+ // 8. Arithmetic Operators
+ .replace(/\s*\*\s*/g, " × ").replace(/\s*\/\s*/g, " ÷ ").replace(/\s*-\s*/g, " − ").replace(/\s*\+\s*/g, " + ")
+ 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()
+ }
+ }
+ }
+ }
+ }
}
diff --git a/popups/launcher/components/Clip.qml b/popups/launcher/components/Clip.qml
index 9b7a0a9..a830483 100644
--- a/popups/launcher/components/Clip.qml
+++ b/popups/launcher/components/Clip.qml
@@ -8,214 +8,214 @@ import qs.services
import qs.config
IComponent {
- id: root
-
- property var clipHist: active ? Clip.query(inputCleaned) : []
- property int selectedIndex: -1
-
- name: "Clipboard"
-
- prefix: "clip"
-
- implicitHeight: valid ? layout.height : 0
-
- process: function () {
- const isValid = clipHist.length > 0;
- return {
- valid: isValid,
- priority: isValid
- };
- }
-
- exec: function () {
- Clip.decodeAndCopy(clipHist[selectedIndex].raw);
- }
-
- up: function () {
- if (selectedIndex <= 0)
- return true;
- selectedIndex--;
- }
- down: function () {
- if (selectedIndex + 1 > listView.count - 1)
- return true;
- selectedIndex++;
- }
- home: function () {
- if (selectedIndex <= 0)
- return true;
- selectedIndex = 0;
- }
- end: function () {
- if (selectedIndex + 1 > listView.count - 1)
- return true;
- selectedIndex = listView.count - 1;
- }
- // TODO: impl pgup pgdn
-
- onClipHistChanged: {
- if (selectedIndex !== -1) {
- syncSelectionState();
- return;
- }
-
- selectedIndex = 0;
- syncSelectionState();
- }
-
- onSelectedIndexChanged: {
- if (selectedIndex >= 0 && selectedIndex < listView.count)
- Qt.callLater(() => {
- listView.positionViewAtIndex(selectedIndex, ListView.Visible);
- syncSelectionState();
- listView.positionViewAtIndex(selectedIndex, ListView.Contain);
- });
- }
-
- syncSelectionState: function () {
- Qt.callLater(() => {
- if (!root.visible || selectedIndex < 0 || selectedIndex >= listView.count)
- return;
-
- trySetSelfPriority();
- state.selected = listView.itemAtIndex(selectedIndex);
- });
- }
-
- IInnerComponent {
- id: layout
- fromParent: false
- width: parent.width
- height: Math.min(listView.contentHeight + titleBar.height, Launcher.widgetHeight * 1.5)
-
- RowLayout {
- Layout.fillWidth: true
- Layout.fillHeight: true
-
- ListView {
- id: listView
- Layout.fillWidth: true
- Layout.fillHeight: true
- clip: true
- model: clipHist
- spacing: 0
-
- delegate: Item {
- required property var modelData
- required property int index
- width: Math.min(item.implicitWidth + Launcher.innerMargin * 4, listView.width)
- height: item.height + Launcher.innerMargin * 4
-
- Row {
- id: item
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.margins: Launcher.innerMargin * 2
- spacing: Launcher.innerMargin * 2
- clip: true
-
- IconImage {
- scale: root.isSelectedPriority() && index === root.selectedIndex ? 1.01 : 0.9
- source: modelData?.appIcon
- implicitSize: parent.height
-
- Behavior on scale {
- ISpringAnimation {}
- }
- }
-
- Column {
- Loader {
- sourceComponent: modelData?.type === "image" ? img : text
- readonly property Component text: IText {
- text: String(modelData?.data || "").substring(0, General.maxClipPreviewChar).replace(/\n/g, " ")
- color: root.isSelectedPriority() && index === selectedIndex ? Colors.foreground1 : Colors.foreground2
- font.pixelSize: Launcher.widgetFontSize
- font.bold: root.isSelectedPriority() && index === selectedIndex
- }
- readonly property Component img: Image {
- source: modelData?.data || ""
- height: Launcher.widgetFontSize * 1.3
- fillMode: Image.PreserveAspectFit
- scale: root.isSelectedPriority() && index === root.selectedIndex ? 1.01 : 0.9
-
- MouseArea {
- anchors.fill: parent
- onClicked: {
- Quickshell.execDetached(["xdg-open", modelData?.data]);
- }
- }
-
- Behavior on scale {
- ISpringAnimation {}
- }
- }
- }
- Row {
- spacing: Launcher.innerMargin
- property string sinceWhen: TimeDate.sinceWhen(modelData?.timestamp) || ""
- IText {
- text: modelData.type
- color: isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
- font.pixelSize: Launcher.widgetFontSize / 1.35
- }
- IText {
- visible: parent.sinceWhen
- text: '·'
- color: isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
- font.pixelSize: Launcher.widgetFontSize / 1.35
- }
- IText {
- text: parent.sinceWhen || ""
- color: root.isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
- font.pixelSize: Launcher.widgetFontSize / 1.35
- }
- }
- }
- }
- }
- }
-
- Flickable {
- id: preview
- clip: true
- Layout.fillWidth: true
- Layout.fillHeight: true
-
- contentWidth: loader.item.width
- contentHeight: loader.item.height
- flickableDirection: Flickable.VerticalFlick
- boundsBehavior: Flickable.StopAtBounds
-
- Loader {
- id: loader
- asynchronous: true
- sourceComponent: clipHist[selectedIndex]?.type === "image" ? img : text
- property Component text: ITextEdit {
- id: textEdit
- animate: true
- readOnly: true
- wrapMode: TextEdit.Wrap
- width: preview.width
- color: Colors.foreground1
- selectionColor: Colors.background3
- text: clipHist[selectedIndex]?.decoded || ""
- }
- property Component img: Image {
- id: image
- asynchronous: true
- width: preview.width
- height: preview.height
- source: clipHist[selectedIndex]?.image || ""
- fillMode: Image.PreserveAspectFit
- TapHandler {
- onTapped: {
- Quickshell.execDetached(["xdg-open", clipHist[selectedIndex]?.image]);
- }
- }
- }
- }
- }
- }
- }
+ id: root
+
+ property var clipHist: active ? Clip.query(inputCleaned) : []
+ property int selectedIndex: -1
+
+ name: "Clipboard"
+
+ prefix: "clip"
+
+ implicitHeight: valid ? layout.height : 0
+
+ process: function () {
+ const isValid = clipHist.length > 0;
+ return {
+ valid: isValid,
+ priority: isValid
+ };
+ }
+
+ exec: function () {
+ Clip.decodeAndCopy(clipHist[selectedIndex].raw);
+ }
+
+ up: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex--;
+ }
+ down: function () {
+ if (selectedIndex + 1 > listView.count - 1)
+ return true;
+ selectedIndex++;
+ }
+ home: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex = 0;
+ }
+ end: function () {
+ if (selectedIndex + 1 > listView.count - 1)
+ return true;
+ selectedIndex = listView.count - 1;
+ }
+ // TODO: impl pgup pgdn
+
+ onClipHistChanged: {
+ if (selectedIndex !== -1) {
+ syncSelectionState();
+ return;
+ }
+
+ selectedIndex = 0;
+ syncSelectionState();
+ }
+
+ onSelectedIndexChanged: {
+ if (selectedIndex >= 0 && selectedIndex < listView.count)
+ Qt.callLater(() => {
+ listView.scrollToIndex(selectedIndex, ListView.Visible);
+ syncSelectionState();
+ listView.scrollToIndex(selectedIndex, ListView.Contain);
+ });
+ }
+
+ syncSelectionState: function () {
+ Qt.callLater(() => {
+ if (!root.visible || selectedIndex < 0 || selectedIndex >= listView.count)
+ return;
+
+ trySetSelfPriority();
+ state.selected = listView.itemAtIndex(selectedIndex);
+ });
+ }
+
+ IInnerComponent {
+ id: layout
+ fromParent: false
+ width: parent.width
+ height: Math.min(listView.contentHeight + titleBar.height, Launcher.widgetHeight * 1.5)
+
+ RowLayout {
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+
+ IListView {
+ id: listView
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ clip: true
+ model: clipHist
+ spacing: 0
+
+ delegate: Item {
+ required property var modelData
+ required property int index
+ width: Math.min(item.implicitWidth + Launcher.innerMargin * 4, listView.width)
+ height: item.height + Launcher.innerMargin * 4
+
+ Row {
+ id: item
+ anchors.left: parent.left
+ anchors.top: parent.top
+ anchors.margins: Launcher.innerMargin * 2
+ spacing: Launcher.innerMargin * 2
+ clip: true
+
+ IconImage {
+ scale: root.isSelectedPriority() && index === root.selectedIndex ? 1.01 : 0.9
+ source: modelData?.appIcon
+ implicitSize: parent.height
+
+ Behavior on scale {
+ ISpringAnimation {}
+ }
+ }
+
+ Column {
+ Loader {
+ sourceComponent: modelData?.type === "image" ? img : text
+ readonly property Component text: IText {
+ text: String(modelData?.data || "").substring(0, General.maxClipPreviewChar).replace(/\n/g, " ")
+ color: root.isSelectedPriority() && index === selectedIndex ? Colors.foreground1 : Colors.foreground2
+ font.pixelSize: Launcher.widgetFontSize
+ font.bold: root.isSelectedPriority() && index === selectedIndex
+ }
+ readonly property Component img: Image {
+ source: modelData?.data || ""
+ height: Launcher.widgetFontSize * 1.3
+ fillMode: Image.PreserveAspectFit
+ scale: root.isSelectedPriority() && index === root.selectedIndex ? 1.01 : 0.9
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ Quickshell.execDetached(["xdg-open", modelData?.data]);
+ }
+ }
+
+ Behavior on scale {
+ ISpringAnimation {}
+ }
+ }
+ }
+ Row {
+ spacing: Launcher.innerMargin
+ property string sinceWhen: TimeDate.sinceWhen(modelData?.timestamp) || ""
+ IText {
+ text: modelData.type
+ color: isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
+ font.pixelSize: Launcher.widgetFontSize / 1.35
+ }
+ IText {
+ visible: parent.sinceWhen
+ text: '·'
+ color: isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
+ font.pixelSize: Launcher.widgetFontSize / 1.35
+ }
+ IText {
+ text: parent.sinceWhen || ""
+ color: root.isSelectedPriority() && index === root.selectedIndex ? Colors.foreground2 : Colors.foreground3
+ font.pixelSize: Launcher.widgetFontSize / 1.35
+ }
+ }
+ }
+ }
+ }
+ }
+
+ Flickable {
+ id: preview
+ clip: true
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+
+ contentWidth: loader.item.width
+ contentHeight: loader.item.height
+ flickableDirection: Flickable.VerticalFlick
+ boundsBehavior: Flickable.StopAtBounds
+
+ Loader {
+ id: loader
+ asynchronous: true
+ sourceComponent: clipHist[selectedIndex]?.type === "image" ? img : text
+ property Component text: ITextEdit {
+ id: textEdit
+ animate: true
+ readOnly: true
+ wrapMode: TextEdit.Wrap
+ width: preview.width
+ color: Colors.foreground1
+ selectionColor: Colors.background3
+ text: clipHist[selectedIndex]?.decoded || ""
+ }
+ property Component img: Image {
+ id: image
+ asynchronous: true
+ width: preview.width
+ height: preview.height
+ source: clipHist[selectedIndex]?.image || ""
+ fillMode: Image.PreserveAspectFit
+ TapHandler {
+ onTapped: {
+ Quickshell.execDetached(["xdg-open", clipHist[selectedIndex]?.image]);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
diff --git a/popups/launcher/components/DuckDuckGo.qml b/popups/launcher/components/DuckDuckGo.qml
index 379f56b..ee5b752 100644
--- a/popups/launcher/components/DuckDuckGo.qml
+++ b/popups/launcher/components/DuckDuckGo.qml
@@ -10,154 +10,154 @@ import qs.config
import core
IComponent {
- id: root
-
- property int cursorPosition: SelectionState.cursorPosition
- property bool expand: false
-
- implicitHeight: valid ? expand ? layout.implicitHeight + (Launcher.duckduckgoSpacing * 2) : Launcher.widgetHeight : 0
-
- name: "DuckDuckGo" // subclass of WebSearch in the future
- preview: Component {
- Icon {
- text: "🌐"
- }
- }
-
- onInputChanged: {
- // TODO: think of this should be part of rs backend .query fn
- DuckDuckGo.reset();
- }
-
- // TODO: decouple all query logic from process -> onInputCleanedChanged and resetting / temp state on speciifc input -> onInputChanged
- onInputCleanedChanged: {
- if (inputCleaned)
- DuckDuckGo.query(inputCleaned);
- }
-
- process: function () {
- const valid = DuckDuckGo.ok;
- const answer = DuckDuckGo.title || DuckDuckGo.description_html;
- return {
- valid,
- priority: valid,
- answer,
- predictiveCompletion: valid && inputCleaned.toLowerCase() != answer.toLowerCase().trim() ? ' is ' + answer : ''
- };
- }
- exec: function () {
- // FIXME: doesn't work as enter closes the launcher
- // if (!expand) {
- // expand = true;
- // return false;
- // } else
- Clip.copy(`${DuckDuckGo.title}\n${DuckDuckGo.description_html}`);
- }
-
- IInnerComponent {
- anchors.margins: Launcher.duckduckgoSpacing
- RowLayout {
- id: layout
- spacing: Launcher.duckduckgoSpacing
- Layout.fillWidth: true
- Layout.fillHeight: true
-
- Item {
- Layout.fillWidth: true
- Layout.fillHeight: true
- Layout.preferredWidth: 0
- Layout.maximumWidth: image.maxWidth
- Layout.minimumWidth: 0
-
- visible: image.status === Image.Ready
-
- Image {
- id: image
- property real maxWidth: status === Image.Ready ? implicitWidth : 0
- anchors.fill: parent
- scale: root.isSelectedPriority() ? 1.01 : 0.99
-
- fillMode: Image.PreserveAspectCrop
-
- opacity: status === Image.Ready ? 1 : 0
-
- source: DuckDuckGo.image
- asynchronous: true
-
- Behavior on opacity {
- NumberAnimation {
- duration: General.animationDuration / 4
- }
- }
-
- Behavior on maxWidth {
- ISpringAnimation {}
- }
-
- Behavior on scale {
- ISpringAnimation {}
- }
- }
- }
-
- ColumnLayout {
- Layout.preferredWidth: 3
- Layout.minimumWidth: 0
- Layout.fillHeight: true
- Layout.fillWidth: true
-
- spacing: Launcher.duckduckgoImageSpacing / 4
-
- ITextEdit {
- animate: true
-
- Layout.alignment: Qt.AlignTop
- Layout.fillWidth: true
-
- readOnly: true
- renderType: Text.CurveRendering
- visible: valid
- text: answer
- font {
- pixelSize: Launcher.widgetFontSize * 1.1
- bold: root.isSelectedPriority()
- }
- }
-
- ScrollView {
- id: scroll
- Layout.fillWidth: true
- Layout.fillHeight: true
- contentWidth: availableWidth
- clip: true
-
- ITextEdit {
- id: text
-
- animate: true
-
- height: scroll.contentHeight
- width: scroll.contentWidth
-
- readOnly: true
- renderType: Text.CurveRendering
- visible: valid && DuckDuckGo.title
- text: DuckDuckGo.title ? DuckDuckGo.description_html : ''
- font {
- pixelSize: Launcher.widgetFontSize
- }
-
- TapHandler {
- gesturePolicy: TapHandler.DragThreshold
- onTapped: expand = !expand
- }
- }
- }
- }
- }
- }
-
- Behavior on implicitHeight {
- ISpringAnimation {}
- }
+ id: root
+
+ property int cursorPosition: SelectionState.cursorPosition
+ property bool expand: false
+
+ implicitHeight: valid ? expand ? layout.implicitHeight + (Launcher.duckduckgoSpacing * 2) : Launcher.widgetHeight : 0
+
+ name: "DuckDuckGo" // subclass of WebSearch in the future
+ preview: Component {
+ Icon {
+ text: "🌐"
+ }
+ }
+
+ onInputChanged: {
+ // TODO: think of this should be part of rs backend .query fn
+ DuckDuckGo.reset();
+ }
+
+ // TODO: decouple all query logic from process -> onInputCleanedChanged and resetting / temp state on speciifc input -> onInputChanged
+ onInputCleanedChanged: {
+ if (inputCleaned)
+ DuckDuckGo.query(inputCleaned);
+ }
+
+ process: function () {
+ const valid = DuckDuckGo.ok;
+ const answer = DuckDuckGo.title || DuckDuckGo.description_html;
+ return {
+ valid,
+ priority: valid,
+ answer,
+ predictiveCompletion: valid && inputCleaned.toLowerCase() != answer.toLowerCase().trim() ? ' is ' + answer : ''
+ };
+ }
+ exec: function () {
+ // FIXME: doesn't work as enter closes the launcher
+ // if (!expand) {
+ // expand = true;
+ // return false;
+ // } else
+ Clip.copy(`${DuckDuckGo.title}\n${DuckDuckGo.description_html}`);
+ }
+
+ IInnerComponent {
+ anchors.margins: Launcher.duckduckgoSpacing
+ RowLayout {
+ id: layout
+ spacing: Launcher.duckduckgoSpacing
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+
+ Item {
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Layout.preferredWidth: 0
+ Layout.maximumWidth: image.maxWidth
+ Layout.minimumWidth: 0
+
+ visible: image.status === Image.Ready
+
+ Image {
+ id: image
+ property real maxWidth: status === Image.Ready ? implicitWidth : 0
+ anchors.fill: parent
+ scale: root.isSelectedPriority() ? 1.01 : 0.99
+
+ fillMode: Image.PreserveAspectCrop
+
+ opacity: status === Image.Ready ? 1 : 0
+
+ source: DuckDuckGo.image
+ asynchronous: true
+
+ Behavior on opacity {
+ NumberAnimation {
+ duration: General.animationDuration / 4
+ }
+ }
+
+ Behavior on maxWidth {
+ ISpringAnimation {}
+ }
+
+ Behavior on scale {
+ ISpringAnimation {}
+ }
+ }
+ }
+
+ ColumnLayout {
+ Layout.preferredWidth: 3
+ Layout.minimumWidth: 0
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+
+ spacing: Launcher.duckduckgoImageSpacing / 4
+
+ ITextEdit {
+ animate: true
+
+ Layout.alignment: Qt.AlignTop
+ Layout.fillWidth: true
+
+ readOnly: true
+ renderType: Text.CurveRendering
+ visible: valid
+ text: answer
+ font {
+ pixelSize: Launcher.widgetFontSize * 1.1
+ bold: root.isSelectedPriority()
+ }
+ }
+
+ ScrollView {
+ id: scroll
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ contentWidth: availableWidth
+ clip: true
+
+ ITextEdit {
+ id: text
+
+ animate: true
+
+ height: scroll.contentHeight
+ width: scroll.contentWidth
+
+ readOnly: true
+ renderType: Text.CurveRendering
+ visible: valid && DuckDuckGo.title
+ text: DuckDuckGo.title ? DuckDuckGo.description_html : ''
+ font {
+ pixelSize: Launcher.widgetFontSize
+ }
+
+ TapHandler {
+ gesturePolicy: TapHandler.DragThreshold
+ onTapped: expand = !expand
+ }
+ }
+ }
+ }
+ }
+ }
+
+ Behavior on implicitHeight {
+ ISpringAnimation {}
+ }
}
diff --git a/popups/launcher/components/Emoji.qml b/popups/launcher/components/Emoji.qml
index ecb1cd4..a74f693 100644
--- a/popups/launcher/components/Emoji.qml
+++ b/popups/launcher/components/Emoji.qml
@@ -8,181 +8,181 @@ import qs.services
import qs.config
IComponent {
- id: root
-
- property var emojis: active ? Emoji.query(input) : []
- property int selectedIndex: -1
-
- property int cols: Math.max(1, Math.floor(innerLoader.width / Math.max(1, Math.round(Launcher.widgetFontSize * 4))))
- property int cellWidth: Math.floor(innerLoader.width / cols)
- property int cellHeight: Math.ceil(Launcher.widgetFontSize * 2) + Launcher.innerMargin * 2
-
- name: "Emoji"
- prefix: name.toLowerCase() + " "
-
- onEmojisChanged: {
- Qt.callLater(() => {
- if (selectedIndex !== -1) {
- syncSelectionState();
- return;
- }
-
- selectedIndex = 0;
- if (loader.item && loader.item.flickable)
- loader.item.flickable.contentY = 0;
- });
- }
-
- onSelectedIndexChanged: {
- Qt.callLater(() => {
- if (!loader?.view || selectedIndex < 0 || selectedIndex >= loader.view.count)
- return;
-
- if (!isSelectedPriority() && state.selected === loader.view.itemAtIndex(selectedIndex)) {
- state.selected = null;
- return;
- }
-
- loader.view.currentIndex = selectedIndex;
- loader.view.positionViewAtIndex(selectedIndex, GridView.Contain);
- syncSelectionState();
- });
- }
-
- process: function () {
- const isValid = selectedIndex >= 0 && emojis.length > 0;
- const select = isValid ? emojis[selectedIndex] : null;
- return {
- valid: isValid,
- priority: isValid,
- answer: isValid ? select.emoji : ""
- };
- }
-
- home: function () {
- if (!loader.view.count)
- return true;
- selectedIndex = 0;
- }
- end: function () {
- if (!loader.view.count)
- return true;
- selectedIndex = loader.view.count - 1;
- }
- prev: function () {
- if (selectedIndex <= 0)
- return true;
- selectedIndex--;
- }
- next: function () {
- if (selectedIndex + 1 >= emojis.length)
- return true;
- selectedIndex++;
- }
- up: function () {
- if (selectedIndex - cols < 0)
- return true;
- selectedIndex -= cols;
- }
- down: function () {
- if (selectedIndex + cols >= emojis.length)
- return true;
- selectedIndex += cols;
- }
-
- exec: function () {
- if (selectedIndex >= 0 && emojis.length > 0)
- Emoji.copy(emojis[selectedIndex].emoji);
- }
-
- syncSelectionState: function () {
- Qt.callLater(() => {
- if (!loader.view || selectedIndex < 0 || selectedIndex >= loader.view.count || !root.visible)
- return;
-
- state.selected = loader.view.itemAtIndex(selectedIndex);
- });
- }
-
- IInnerComponent {
- id: innerLoader
-
- Loader {
- id: loader
- Layout.fillWidth: true
- Layout.fillHeight: true
- Layout.preferredHeight: parent.height
- sourceComponent: show
- property var view: null
-
- readonly property Component show: Component {
- Item {
- property alias flickable: grid
-
- GridView {
- id: grid
- anchors.fill: parent
- clip: true
- boundsBehavior: Flickable.StopAtBounds
- cacheBuffer: cellHeight * 2
- model: emojis
- interactive: true
- flow: GridView.FlowLeftToRight
- snapMode: GridView.NoSnap
-
- cellWidth: root.cellWidth
- cellHeight: root.cellHeight
-
- delegate: Item {
- required property var modelData
- required property int index
- width: grid.cellWidth
- height: chipContent.implicitHeight + Launcher.innerMargin * 2
- scale: isSelectedPriority() && index === root.selectedIndex ? 1.03 : 0.97
-
- IRect {
- anchors.fill: parent
- color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency)
- radius: Launcher.widgetRadius
-
- Column {
- id: chipContent
- anchors.centerIn: parent
- spacing: 2
-
- Icon {
- anchors.horizontalCenter: parent.horizontalCenter
- text: modelData.emoji
- font.pixelSize: Launcher.widgetFontSize * 1.2
- }
- IText {
- anchors.horizontalCenter: parent.horizontalCenter
- text: modelData.name
- font.pixelSize: Launcher.widgetFontSize * 0.7
- font.bold: isSelectedPriority() && index === selectedIndex
- color: index === selectedIndex ? Colors.foreground1 : Colors.foreground2
- elide: Text.ElideRight
- width: parent.parent.width - Launcher.innerMargin * 2
- }
- }
-
- MouseArea {
- anchors.fill: parent
- hoverEnabled: true
- onEntered: root.selectedIndex = index
- onPressed: root._exec()
- }
- }
-
- Behavior on scale {
- ISpringAnimation {}
- }
- }
-
- Component.onCompleted: loader.view = grid
- }
- }
- }
- }
- }
+ id: root
+
+ property var emojis: active ? Emoji.query(input) : []
+ property int selectedIndex: -1
+
+ property int cols: Math.max(1, Math.floor(innerLoader.width / Math.max(1, Math.round(Launcher.widgetFontSize * 4))))
+ property int cellWidth: Math.floor(innerLoader.width / cols)
+ property int cellHeight: Math.ceil(Launcher.widgetFontSize * 2) + Launcher.innerMargin * 2
+
+ name: "Emoji"
+ prefix: name.toLowerCase() + " "
+
+ onEmojisChanged: {
+ Qt.callLater(() => {
+ if (selectedIndex !== -1) {
+ syncSelectionState();
+ return;
+ }
+
+ selectedIndex = 0;
+ if (loader.item && loader.item.flickable)
+ loader.item.flickable.contentY = 0;
+ });
+ }
+
+ onSelectedIndexChanged: {
+ Qt.callLater(() => {
+ if (!loader?.view || selectedIndex < 0 || selectedIndex >= loader.view.count)
+ return;
+
+ if (!isSelectedPriority() && state.selected === loader.view.itemAtIndex(selectedIndex)) {
+ state.selected = null;
+ return;
+ }
+
+ loader.view.currentIndex = selectedIndex;
+ loader.view.scrollToIndex(selectedIndex, GridView.Contain);
+ syncSelectionState();
+ });
+ }
+
+ process: function () {
+ const isValid = selectedIndex >= 0 && emojis.length > 0;
+ const select = isValid ? emojis[selectedIndex] : null;
+ return {
+ valid: isValid,
+ priority: isValid,
+ answer: isValid ? select.emoji : ""
+ };
+ }
+
+ home: function () {
+ if (!loader.view.count)
+ return true;
+ selectedIndex = 0;
+ }
+ end: function () {
+ if (!loader.view.count)
+ return true;
+ selectedIndex = loader.view.count - 1;
+ }
+ prev: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex--;
+ }
+ next: function () {
+ if (selectedIndex + 1 >= emojis.length)
+ return true;
+ selectedIndex++;
+ }
+ up: function () {
+ if (selectedIndex - cols < 0)
+ return true;
+ selectedIndex -= cols;
+ }
+ down: function () {
+ if (selectedIndex + cols >= emojis.length)
+ return true;
+ selectedIndex += cols;
+ }
+
+ exec: function () {
+ if (selectedIndex >= 0 && emojis.length > 0)
+ Emoji.copy(emojis[selectedIndex].emoji);
+ }
+
+ syncSelectionState: function () {
+ Qt.callLater(() => {
+ if (!loader.view || selectedIndex < 0 || selectedIndex >= loader.view.count || !root.visible)
+ return;
+
+ state.selected = loader.view.itemAtIndex(selectedIndex);
+ });
+ }
+
+ IInnerComponent {
+ id: innerLoader
+
+ Loader {
+ id: loader
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Layout.preferredHeight: parent.height
+ sourceComponent: show
+ property var view: null
+
+ readonly property Component show: Component {
+ Item {
+ property alias flickable: grid
+
+ GridView {
+ id: grid
+ anchors.fill: parent
+ clip: true
+ boundsBehavior: Flickable.StopAtBounds
+ cacheBuffer: cellHeight * 2
+ model: emojis
+ interactive: true
+ flow: GridView.FlowLeftToRight
+ snapMode: GridView.NoSnap
+
+ cellWidth: root.cellWidth
+ cellHeight: root.cellHeight
+
+ delegate: Item {
+ required property var modelData
+ required property int index
+ width: grid.cellWidth
+ height: chipContent.implicitHeight + Launcher.innerMargin * 2
+ scale: isSelectedPriority() && index === root.selectedIndex ? 1.03 : 0.97
+
+ IRect {
+ anchors.fill: parent
+ color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency)
+ radius: Launcher.widgetRadius
+
+ Column {
+ id: chipContent
+ anchors.centerIn: parent
+ spacing: 2
+
+ Icon {
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: modelData.emoji
+ font.pixelSize: Launcher.widgetFontSize * 1.2
+ }
+ IText {
+ anchors.horizontalCenter: parent.horizontalCenter
+ text: modelData.name
+ font.pixelSize: Launcher.widgetFontSize * 0.7
+ font.bold: isSelectedPriority() && index === selectedIndex
+ color: index === selectedIndex ? Colors.foreground1 : Colors.foreground2
+ elide: Text.ElideRight
+ width: parent.parent.width - Launcher.innerMargin * 2
+ }
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ hoverEnabled: true
+ onEntered: root.selectedIndex = index
+ onPressed: root._exec()
+ }
+ }
+
+ Behavior on scale {
+ ISpringAnimation {}
+ }
+ }
+
+ Component.onCompleted: loader.view = grid
+ }
+ }
+ }
+ }
+ }
}
diff --git a/popups/launcher/components/IComponent.qml b/popups/launcher/components/IComponent.qml
index e48a0a1..a237f49 100644
--- a/popups/launcher/components/IComponent.qml
+++ b/popups/launcher/components/IComponent.qml
@@ -5,149 +5,150 @@ import qs.components
import qs.config
IRect {
- id: root
- // virtual properties
- property bool standalone: false
- property var state: SelectionState
- property string name // Component/File name
- readonly property string _input: state.input
- readonly property string input: !standalone ? _input.slice(prefix.length) : _input
- readonly property string inputCleaned: input.toLowerCase().trim()
- property string prefix
- property bool active: !standalone ? input && _input.startsWith(prefix) : true
- property bool valid: !standalone ? processed?.valid || false : true
- property bool priority: !standalone ? valid && processed?.priority || false : true // please set priority to false if it's invalid
- property string answer: processed?.answer || ""
- property Component preview: Component {
- IText {
- // TODO: use proper active: false via Loader
- visible: answer.length <= Launcher.maxPreviewLen
- animate: true
- text: answer
- }
- }
- property string predictiveCompletion: processed?.predictiveCompletion || "" // would technically work with just from answer, but stuff like calc's answer wouldnt have anything to do with the input
- property var processed: active ? process() : {} // cached process, thought qml would do that automatically :/
- property var process: () => ({
- valid: valid,
- priority: priority,
- answer: answer,
- preview: preview,
- predictiveCompletion: predictiveCompletion
- })
- // use the current IRect if valid is set
- property var syncSelectionState: () => {}
- // actions
- property var up: () => ({
- top: true
- })
- property var down: () => ({
- bottom: true
- })
- property var prev: () => ({
- left: true
- })
- property var next: () => ({
- right: true
- })
- // true if not closed
- property var exec: () => {}
- property var home: () => ({
- top: true
- })
- property var end: () => ({
- bottom: true
- })
- property var pgup: () => ({
- top: true
- })
- property var pgdn: () => ({
- bottom: true
- })
-
- function enter() {
- trySetSelfPriority();
- // root or null hmm
- state.selected = root;
- }
-
- signal close
-
- function _exec() {
- if (!exec())
- close();
- }
-
- function getSelfPriority() {
- return state.priorities.indexOf(root);
- }
-
- function isSelectedPriority() {
- return state.selectedPriority === getSelfPriority();
- }
-
- function trySetSelfPriority() {
- let self = getSelfPriority();
- // ??? why tf is it -1 not null or undefined this is why rust is better
- if (self !== -1)
- state.selectedPriority = self;
- }
-
- function syncPriority() {
- if (!standalone) {
- if (state.priorities.includes(root) && !priority)
- state.priorities = state.priorities.filter(x => x !== root);
- else if (priority)
- state.priorities = [...new Set(state.priorities), root];
- } else
- state.priorities = [root];
- }
-
- // this doesn't change launcher size but only hides the actual content but the outside still think the content is there
- visible: active
- opacity: valid ? 1 : 0
- y: valid ? 0 : -Launcher.widgetHeight
-
- implicitWidth: valid ? Launcher.widgetWidth : 0
- implicitHeight: valid ? Launcher.widgetHeight : 0
-
- radius: Launcher.widgetRadius
- color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.widgetBgTransparency) // TODO when prioritized, highlight
-
- onPriorityChanged: {
- // sync with state.priorities
- Qt.callLater(() => {
- syncPriority();
- });
- }
-
- Behavior on y {
- NumberAnimation {
- duration: General.animationDuration / 4
- easing.type: Easing.InOutQuad
- }
- }
-
- HoverHandler {
- onHoveredChanged: {
- if (hovered) {
- root.enter();
- root.syncSelectionState();
- }
- }
- }
-
- Component.onCompleted: {
- Qt.callLater(() => {
- syncPriority();
- });
-
- // Qt.callLater(() => {
- // syncSelectionState();
- // });
- }
-
- Component.onDestruction: {
- state.priorities = state.priorities.filter(x => x !== root);
- }
+ id: root
+ // virtual properties
+ property bool standalone: false
+ property var state: SelectionState
+ property string name // Component/File name
+ readonly property string _input: state.input
+ readonly property string input: !standalone ? _input.slice(prefix.length) : _input
+ readonly property string inputCleaned: input.toLowerCase().trim()
+ property string prefix
+ property bool active: !standalone ? input && _input.startsWith(prefix) : true
+ property bool valid: !standalone ? processed?.valid || false : true
+ property bool priority: !standalone ? valid && processed?.priority || false : true // please set priority to false if it's invalid
+ property string answer: processed?.answer || ""
+ property Component preview: Component {
+ IText {
+ // TODO: use proper active: false via Loader
+ visible: answer.length <= Launcher.maxPreviewLen
+ animate: true
+ text: answer
+ }
+ }
+ property string predictiveCompletion: processed?.predictiveCompletion || "" // would technically work with just from answer, but stuff like calc's answer wouldnt have anything to do with the input
+ property var processed: active ? process() : {} // cached process, thought qml would do that automatically :/
+ // todo: change all to function
+ property var process: () => ({
+ valid: valid,
+ priority: priority,
+ answer: answer,
+ preview: preview,
+ predictiveCompletion: predictiveCompletion
+ })
+ // use the current IRect if valid is set
+ property var syncSelectionState: () => {}
+ // actions
+ property var up: () => ({
+ top: true
+ })
+ property var down: () => ({
+ bottom: true
+ })
+ property var prev: () => ({
+ left: true
+ })
+ property var next: () => ({
+ right: true
+ })
+ // true if not closed
+ property var exec: () => {}
+ property var home: () => ({
+ top: true
+ })
+ property var end: () => ({
+ bottom: true
+ })
+ property var pgup: () => ({
+ top: true
+ })
+ property var pgdn: () => ({
+ bottom: true
+ })
+
+ function enter() {
+ trySetSelfPriority();
+ // root or null hmm
+ state.selected = root;
+ }
+
+ signal close
+
+ function _exec() {
+ if (!exec())
+ close();
+ }
+
+ function getSelfPriority() {
+ return state.priorities.indexOf(root);
+ }
+
+ function isSelectedPriority() {
+ return state.selectedPriority === getSelfPriority();
+ }
+
+ function trySetSelfPriority() {
+ let self = getSelfPriority();
+ // ??? why tf is it -1 not null or undefined this is why rust is better
+ if (self !== -1)
+ state.selectedPriority = self;
+ }
+
+ function syncPriority() {
+ if (!standalone) {
+ if (state.priorities.includes(root) && !priority)
+ state.priorities = state.priorities.filter(x => x !== root);
+ else if (priority)
+ state.priorities = [...new Set(state.priorities), root];
+ } else
+ state.priorities = [root];
+ }
+
+ // this doesn't change launcher size but only hides the actual content but the outside still think the content is there
+ visible: active
+ opacity: valid ? 1 : 0
+ y: valid ? 0 : -Launcher.widgetHeight
+
+ implicitWidth: valid ? Launcher.widgetWidth : 0
+ implicitHeight: valid ? Launcher.widgetHeight : 0
+
+ radius: Launcher.widgetRadius
+ color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.widgetBgTransparency) // TODO when prioritized, highlight
+
+ onPriorityChanged: {
+ // sync with state.priorities
+ Qt.callLater(() => {
+ syncPriority();
+ });
+ }
+
+ Behavior on y {
+ NumberAnimation {
+ duration: General.animationDuration / 4
+ easing.type: Easing.InOutQuad
+ }
+ }
+
+ HoverHandler {
+ onHoveredChanged: {
+ if (hovered) {
+ root.enter();
+ root.syncSelectionState();
+ }
+ }
+ }
+
+ Component.onCompleted: {
+ Qt.callLater(() => {
+ syncPriority();
+ });
+
+ // Qt.callLater(() => {
+ // syncSelectionState();
+ // });
+ }
+
+ Component.onDestruction: {
+ state.priorities = state.priorities.filter(x => x !== root);
+ }
}
diff --git a/popups/launcher/components/IInnerComponent.qml b/popups/launcher/components/IInnerComponent.qml
index 7bbc9f0..9f95592 100644
--- a/popups/launcher/components/IInnerComponent.qml
+++ b/popups/launcher/components/IInnerComponent.qml
@@ -5,30 +5,30 @@ import qs.components
import qs.config
ColumnLayout {
- property bool fromParent: true
- property alias titleBar: titleBar
- anchors.fill: fromParent ? parent : undefined
- spacing: 0
- IRect {
- id: titleBar
- Layout.fillWidth: true
- Layout.fillHeight: false
- visible: Launcher.showWidgetTitle && valid
- height: childrenRect.height
- width: parent.width
- topLeftRadius: Launcher.widgetRadius
- topRightRadius: Launcher.widgetRadius
- color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.widgetTitleBgTransparency)
+ property bool fromParent: true
+ property alias titleBar: titleBar
+ anchors.fill: fromParent ? parent : undefined
+ spacing: 0
+ IRect {
+ id: titleBar
+ Layout.fillWidth: true
+ Layout.fillHeight: false
+ visible: Launcher.showWidgetTitle && valid
+ height: childrenRect.height
+ width: parent.width
+ topLeftRadius: Launcher.widgetRadius
+ topRightRadius: Launcher.widgetRadius
+ color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.widgetTitleBgTransparency)
- IText {
- anchors {
- top: parent.top
- left: parent.left
- leftMargin: Launcher.innerMargin
- }
- visible: valid
- font.pixelSize: Launcher.widgetFontSize
- text: name
- }
- }
+ IText {
+ anchors {
+ top: parent.top
+ left: parent.left
+ leftMargin: Launcher.innerMargin
+ }
+ visible: valid
+ font.pixelSize: Launcher.widgetFontSize
+ text: name
+ }
+ }
}
diff --git a/popups/launcher/components/ISmartCalc.qml b/popups/launcher/components/ISmartCalc.qml
index 679bd5f..7f4302a 100644
--- a/popups/launcher/components/ISmartCalc.qml
+++ b/popups/launcher/components/ISmartCalc.qml
@@ -9,86 +9,86 @@ import qs.config
import core
IComponent {
- id: root
+ id: root
- property string symbol
- required property bool category
- required property string predictiveText
+ property string symbol
+ required property bool category
+ required property string predictiveText
- property int cursorPosition: SelectionState.cursorPosition
+ property int cursorPosition: SelectionState.cursorPosition
- preview: Component {
- Icon {
- text: symbol
- }
- }
+ preview: Component {
+ Icon {
+ text: symbol
+ }
+ }
- onInputChanged: {
- SmartCalc.reset_result();
- }
+ 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);
- }
+ 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
+ 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()
- }
- }
- }
+ 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()
- }
+ 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()
- }
- }
- }
- }
- }
+ 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()
+ }
+ }
+ }
+ }
+ }
}
diff --git a/popups/launcher/components/SelectionState.qml b/popups/launcher/components/SelectionState.qml
index 5b80b2e..3fc1f79 100644
--- a/popups/launcher/components/SelectionState.qml
+++ b/popups/launcher/components/SelectionState.qml
@@ -5,46 +5,46 @@ import QtQuick
// FIXME: fix some selection not show/updated when deselected i.e. "pi" from app back to calc wont visually show deselection of last app
// FIXME: icon/answer not updated when changed to non first priority
Singleton {
- id: root
-
- PersistentProperties {
- id: persist
- reloadableId: "launcherSelectionState"
-
- property string input: ""
- property int cursorPosition: 0
- property int selectedPriority: 0
- }
-
- property Item selected: null
- property alias input: persist.input
- property alias cursorPosition: persist.cursorPosition
- property var priorities: []
- property alias selectedPriority: persist.selectedPriority
- property var widgets: []
- signal syncSelectionState
-
- onSelectedPriorityChanged: {
- priorities[selectedPriority]?.enter();
- priorities[selectedPriority]?.syncSelectionState();
- }
-
- // order them based on widgets(which came from order from config)
- onPrioritiesChanged: {
- for (let i = priorities.length - 1; i >= 0; i--)
- if (!priorities[i] || priorities[i].priority !== true)
- priorities.splice(i, 1);
-
- priorities.sort((a, b) => (widgets.indexOf(a) - widgets.indexOf(b)) || 0);
-
- Qt.callLater(function step() {
- if (!priorities[selectedPriority] && selectedPriority > 0) {
- selectedPriority--;
- Qt.callLater(step);
- } else {
- priorities[selectedPriority]?.enter();
- priorities[selectedPriority]?.syncSelectionState();
- }
- });
- }
+ id: root
+
+ PersistentProperties {
+ id: persist
+ reloadableId: "launcherSelectionState"
+
+ property string input: ""
+ property int cursorPosition: 0
+ property int selectedPriority: 0
+ }
+
+ property Item selected: null
+ property alias input: persist.input
+ property alias cursorPosition: persist.cursorPosition
+ property var priorities: []
+ property alias selectedPriority: persist.selectedPriority
+ property var widgets: []
+ signal syncSelectionState
+
+ onSelectedPriorityChanged: {
+ priorities[selectedPriority]?.enter();
+ priorities[selectedPriority]?.syncSelectionState();
+ }
+
+ // order them based on widgets(which came from order from config)
+ onPrioritiesChanged: {
+ for (let i = priorities.length - 1; i >= 0; i--)
+ if (!priorities[i] || priorities[i].priority !== true)
+ priorities.splice(i, 1);
+
+ priorities.sort((a, b) => (widgets.indexOf(a) - widgets.indexOf(b)) || 0);
+
+ Qt.callLater(function step() {
+ if (!priorities[selectedPriority] && selectedPriority > 0) {
+ selectedPriority--;
+ Qt.callLater(step);
+ } else {
+ priorities[selectedPriority]?.enter();
+ priorities[selectedPriority]?.syncSelectionState();
+ }
+ });
+ }
}
diff --git a/popups/launcher/components/Spell.qml b/popups/launcher/components/Spell.qml
index c09a705..b7c1aa6 100644
--- a/popups/launcher/components/Spell.qml
+++ b/popups/launcher/components/Spell.qml
@@ -8,232 +8,232 @@ import qs.services
import qs.config
IComponent {
- id: root
-
- property list<string> aspell
- property int selectedIndex: -1
-
- name: "Spell"
- prefix: name.toLowerCase() + ' '
-
- onValidChanged: {
- if (valid)
- return;
-
- aspell = [];
- proc.running = false;
- selectedIndex = -1;
- return;
- }
-
- onAspellChanged: {
- Qt.callLater(() => {
- if (selectedIndex !== -1) {
- syncSelectionState();
- return;
- }
- selectedIndex = aspell.length > 0 ? 0 : -1;
- if (loader.item && loader.item.flickable)
- loader.item.flickable.contentY = 0;
- });
- }
-
- onSelectedIndexChanged: {
- Qt.callLater(() => {
- if (!loader.view || selectedIndex < 0 || selectedIndex >= loader.view.count)
- return;
-
- syncSelectionState();
- loader.view.currentIndex = selectedIndex;
- loader.view.positionViewAtIndex(selectedIndex, GridView.Contain);
- });
- }
-
- process: function () {
- Qt.callLater(() => {
- proc.running = true;
- });
-
- const isValid = selectedIndex >= 0 && aspell.length > 0;
- const selected = isValid ? aspell[selectedIndex] : "";
- const answer = selected === "*" ? input : selected;
-
- return {
- valid: isValid,
- priority: isValid,
- answer: answer || "",
- predictiveCompletion: answer?.slice(input.length) || ""
- };
- }
-
- home: function () {
- if (loader.view.count === 0)
- return true;
- selectedIndex = -1;
- selectedIndex = 0;
- }
- end: function () {
- if (loader.view.count === 0)
- return true;
- selectedIndex = loader.view.count;
- selectedIndex = loader.view.count - 1;
- }
-
- prev: function () {
- if (selectedIndex <= 0)
- return true;
- selectedIndex--;
- }
-
- next: function () {
- if (selectedIndex + 1 >= aspell.length)
- return true;
- selectedIndex++;
- }
-
- up: function () {
- const cols = Math.max(1, Math.floor(innerLoader.width / Math.max(1, Math.round(Launcher.widgetFontSize * 6))));
- if (selectedIndex - cols < 0)
- return true;
- selectedIndex -= cols;
- }
-
- down: function () {
- const cols = Math.max(1, Math.floor(innerLoader.width / Math.max(1, Math.round(Launcher.widgetFontSize * 6))));
- if (selectedIndex + cols >= aspell.length)
- return true;
- selectedIndex += cols;
- }
-
- exec: function () {
- if (selectedIndex >= 0)
- if (aspell[selectedIndex] !== "*")
- Clip.copy(aspell[selectedIndex]);
- else
- Clip.copy(input);
- }
-
- syncSelectionState: function () {
- Qt.callLater(() => {
- if (!loader.view || selectedIndex < 0 || selectedIndex >= loader.view.count || !root.visible)
- return;
-
- trySetSelfPriority();
- state.selected = loader.view.itemAtIndex(selectedIndex);
- });
- }
-
- IInnerComponent {
- id: innerLoader
- Loader {
- id: loader
- Layout.fillWidth: true
- Layout.fillHeight: true
- Layout.preferredHeight: parent.height
- sourceComponent: aspell[0] === "*" ? correct : show
- property var view: null
-
- readonly property Component show: Component {
- Item {
- property alias flickable: grid
-
- GridView {
- id: grid
- anchors.fill: parent
- clip: true
- boundsBehavior: Flickable.StopAtBounds
- cacheBuffer: 0
- model: aspell
- interactive: true
- flow: GridView.FlowLeftToRight
- snapMode: GridView.NoSnap
-
- cellWidth: Math.floor(width / Math.max(1, Math.floor(width / Math.max(1, Math.round(Launcher.widgetFontSize * 6)))))
- cellHeight: Math.ceil(Launcher.widgetFontSize * 1.6) + Launcher.innerMargin * 2
-
- delegate: Item {
- required property var modelData
- required property int index
-
- width: grid.cellWidth
- height: chipContent.implicitHeight + Launcher.innerMargin * 2
- scale: index === selectedIndex ? 1.03 : 0.97
-
- IRect {
- anchors.fill: parent
- color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency)
- radius: Launcher.widgetRadius
-
- IText {
- id: chipContent
- anchors.centerIn: parent
- text: modelData
- font.pixelSize: Launcher.widgetFontSize
- elide: Text.ElideRight
- color: index === selectedIndex ? Colors.foreground1 : Colors.foreground2
- }
-
- MouseArea {
- anchors.fill: parent
- hoverEnabled: true
- onEntered: {
- root.selectedIndex = index;
- }
- onPressed: {
- root._exec();
- }
- }
- }
-
- Behavior on scale {
- ISpringAnimation {}
- }
- }
-
- Component.onCompleted: {
- loader.view = grid;
- }
- }
- }
- }
-
- readonly property Component correct: Component {
- IRect {
- Layout.fillWidth: true
- color: Qt.rgba(Colors.background1.r, Colors.background1.g, Colors.background1.b, Launcher.widgetBgTransparency / 4)
- radius: Launcher.widgetRadius
- IText {
- anchors.centerIn: parent
- text: "Correct"
- font.pixelSize: Launcher.widgetFontSize
- anchors.horizontalCenter: parent.horizontalCenter
- }
- }
- }
- }
- }
-
- Process {
- id: proc
- command: ["sh", "-c", "echo " + input + " | aspell -a"]
- property bool found: false
- stdout: SplitParser {
- onRead: data => {
- if (data.startsWith("&")) {
- proc.found = true;
- aspell = data.split(/\W+/).filter(input => /^[A-Za-z]+$/.test(input)).slice(1);
- } else if (data.startsWith("*")) {
- proc.found = true;
- aspell = ["*"];
- }
- }
- }
- onStarted: {
- found = false;
- }
- onExited: {
- if (!found)
- aspell = [];
- }
- }
+ id: root
+
+ property list<string> aspell
+ property int selectedIndex: -1
+
+ name: "Spell"
+ prefix: name.toLowerCase() + ' '
+
+ onValidChanged: {
+ if (valid)
+ return;
+
+ aspell = [];
+ proc.running = false;
+ selectedIndex = -1;
+ return;
+ }
+
+ onAspellChanged: {
+ Qt.callLater(() => {
+ if (selectedIndex !== -1) {
+ syncSelectionState();
+ return;
+ }
+ selectedIndex = aspell.length > 0 ? 0 : -1;
+ if (loader.item && loader.item.flickable)
+ loader.item.flickable.contentY = 0;
+ });
+ }
+
+ onSelectedIndexChanged: {
+ Qt.callLater(() => {
+ if (!loader.view || selectedIndex < 0 || selectedIndex >= loader.view.count)
+ return;
+
+ syncSelectionState();
+ loader.view.currentIndex = selectedIndex;
+ loader.view.scrollToIndex(selectedIndex, GridView.Contain);
+ });
+ }
+
+ process: function () {
+ Qt.callLater(() => {
+ proc.running = true;
+ });
+
+ const isValid = selectedIndex >= 0 && aspell.length > 0;
+ const selected = isValid ? aspell[selectedIndex] : "";
+ const answer = selected === "*" ? input : selected;
+
+ return {
+ valid: isValid,
+ priority: isValid,
+ answer: answer || "",
+ predictiveCompletion: answer?.slice(input.length) || ""
+ };
+ }
+
+ home: function () {
+ if (loader.view.count === 0)
+ return true;
+ selectedIndex = -1;
+ selectedIndex = 0;
+ }
+ end: function () {
+ if (loader.view.count === 0)
+ return true;
+ selectedIndex = loader.view.count;
+ selectedIndex = loader.view.count - 1;
+ }
+
+ prev: function () {
+ if (selectedIndex <= 0)
+ return true;
+ selectedIndex--;
+ }
+
+ next: function () {
+ if (selectedIndex + 1 >= aspell.length)
+ return true;
+ selectedIndex++;
+ }
+
+ up: function () {
+ const cols = Math.max(1, Math.floor(innerLoader.width / Math.max(1, Math.round(Launcher.widgetFontSize * 6))));
+ if (selectedIndex - cols < 0)
+ return true;
+ selectedIndex -= cols;
+ }
+
+ down: function () {
+ const cols = Math.max(1, Math.floor(innerLoader.width / Math.max(1, Math.round(Launcher.widgetFontSize * 6))));
+ if (selectedIndex + cols >= aspell.length)
+ return true;
+ selectedIndex += cols;
+ }
+
+ exec: function () {
+ if (selectedIndex >= 0)
+ if (aspell[selectedIndex] !== "*")
+ Clip.copy(aspell[selectedIndex]);
+ else
+ Clip.copy(input);
+ }
+
+ syncSelectionState: function () {
+ Qt.callLater(() => {
+ if (!loader.view || selectedIndex < 0 || selectedIndex >= loader.view.count || !root.visible)
+ return;
+
+ trySetSelfPriority();
+ state.selected = loader.view.itemAtIndex(selectedIndex);
+ });
+ }
+
+ IInnerComponent {
+ id: innerLoader
+ Loader {
+ id: loader
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ Layout.preferredHeight: parent.height
+ sourceComponent: aspell[0] === "*" ? correct : show
+ property var view: null
+
+ readonly property Component show: Component {
+ Item {
+ property alias flickable: grid
+
+ GridView {
+ id: grid
+ anchors.fill: parent
+ clip: true
+ boundsBehavior: Flickable.StopAtBounds
+ cacheBuffer: 0
+ model: aspell
+ interactive: true
+ flow: GridView.FlowLeftToRight
+ snapMode: GridView.NoSnap
+
+ cellWidth: Math.floor(width / Math.max(1, Math.floor(width / Math.max(1, Math.round(Launcher.widgetFontSize * 6)))))
+ cellHeight: Math.ceil(Launcher.widgetFontSize * 1.6) + Launcher.innerMargin * 2
+
+ delegate: Item {
+ required property var modelData
+ required property int index
+
+ width: grid.cellWidth
+ height: chipContent.implicitHeight + Launcher.innerMargin * 2
+ scale: index === selectedIndex ? 1.03 : 0.97
+
+ IRect {
+ anchors.fill: parent
+ color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency)
+ radius: Launcher.widgetRadius
+
+ IText {
+ id: chipContent
+ anchors.centerIn: parent
+ text: modelData
+ font.pixelSize: Launcher.widgetFontSize
+ elide: Text.ElideRight
+ color: index === selectedIndex ? Colors.foreground1 : Colors.foreground2
+ }
+
+ MouseArea {
+ anchors.fill: parent
+ hoverEnabled: true
+ onEntered: {
+ root.selectedIndex = index;
+ }
+ onPressed: {
+ root._exec();
+ }
+ }
+ }
+
+ Behavior on scale {
+ ISpringAnimation {}
+ }
+ }
+
+ Component.onCompleted: {
+ loader.view = grid;
+ }
+ }
+ }
+ }
+
+ readonly property Component correct: Component {
+ IRect {
+ Layout.fillWidth: true
+ color: Qt.rgba(Colors.background1.r, Colors.background1.g, Colors.background1.b, Launcher.widgetBgTransparency / 4)
+ radius: Launcher.widgetRadius
+ IText {
+ anchors.centerIn: parent
+ text: "Correct"
+ font.pixelSize: Launcher.widgetFontSize
+ anchors.horizontalCenter: parent.horizontalCenter
+ }
+ }
+ }
+ }
+ }
+
+ Process {
+ id: proc
+ command: ["sh", "-c", "echo " + input + " | aspell -a"]
+ property bool found: false
+ stdout: SplitParser {
+ onRead: data => {
+ if (data.startsWith("&")) {
+ proc.found = true;
+ aspell = data.split(/\W+/).filter(input => /^[A-Za-z]+$/.test(input)).slice(1);
+ } else if (data.startsWith("*")) {
+ proc.found = true;
+ aspell = ["*"];
+ }
+ }
+ }
+ onStarted: {
+ found = false;
+ }
+ onExited: {
+ if (!found)
+ aspell = [];
+ }
+ }
}