summaryrefslogtreecommitdiff
path: root/popups
diff options
context:
space:
mode:
Diffstat (limited to 'popups')
-rw-r--r--popups/IPopup.qml21
-rw-r--r--popups/launcher/ILauncher.qml16
-rw-r--r--popups/launcher/Launcher.qml900
-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
13 files changed, 1824 insertions, 1823 deletions
diff --git a/popups/IPopup.qml b/popups/IPopup.qml
index 59d569d..84b8fd7 100644
--- a/popups/IPopup.qml
+++ b/popups/IPopup.qml
@@ -1,18 +1,17 @@
import Quickshell.Wayland
-
import qs.components
IWindow {
- required property var parentLoader
- // TODO: optional only display on focused screen
- focusable: true
+ required property var parentLoader
- layer: WlrLayer.Overlay
+ // TODO: optional only display on focused screen
+ focusable: true
+ layer: WlrLayer.Overlay
- anchors {
- top: false
- bottom: false
- left: false
- right: false
- }
+ anchors {
+ top: false
+ bottom: false
+ left: false
+ right: false
+ }
}
diff --git a/popups/launcher/ILauncher.qml b/popups/launcher/ILauncher.qml
index 325ab2c..e268b26 100644
--- a/popups/launcher/ILauncher.qml
+++ b/popups/launcher/ILauncher.qml
@@ -3,13 +3,13 @@ import Quickshell.Hyprland
import ".."
IPopup {
- id: root
+ id: root
- HyprlandFocusGrab {
- active: true
- windows: [root]
- onCleared: {
- parentLoader.active = false; // or active = true again
- }
- }
+ HyprlandFocusGrab {
+ active: true
+ windows: [root]
+ onCleared: {
+ parentLoader.active = false; // or active = true again
+ }
+ }
}
diff --git a/popups/launcher/Launcher.qml b/popups/launcher/Launcher.qml
index fd6b851..c198603 100644
--- a/popups/launcher/Launcher.qml
+++ b/popups/launcher/Launcher.qml
@@ -8,454 +8,454 @@ import qs.config
// TODO: currently, we're relying on the compositor to provide the animation which ig is fine, but we should use our own in the future, however it might look weird combined with the compositors's
ILauncher {
- id: launcher
-
- property list<Component> widgetItems: Launcher.widgets
- property var state: SelectionState
-
- name: "quickshell::launcher::launcher"
-
- anchors.top: true
- margins.top: Launcher.topMargin
- aboveWindows: true
- exclusionMode: ExclusionMode.Ignore
-
- IRect {
- id: container
- property var selection: launcher.state?.selected
- property var mappedSelection: selection?.mapToItem(null, 0, 0)
-
- onMappedSelectionChanged: {
- // launcher.state?.selected may be slow.. smh qt
- // my guess is mapToItem is called when its not finished doing whatever it needs to do,
- // so it doesnt get the right vars, but it doesn't update after since it already triggered it
- selectionSync.running = true;
- }
-
- // for some reason selection changing doesnt call onMappedSelectionChanged, so we manually trigger it
- onSelectionChanged: {
- selectionSync.running = true;
- }
-
- Timer {
- id: selectionSync
- // TODO: evaluate weather i just leave it running repeat, might be costy though
- running: false
- repeat: false
- // sync w/ IComponent y animation duration
- interval: General.animationDuration / 4
- onTriggered: {
- parent.mappedSelection = launcher.state?.selected?.mapToItem(null, 0, 0);
- }
- }
-
- IRect {
- id: activeRect
- visible: parent.mappedSelection || false
- y: parent.mappedSelection?.y || 0
- x: parent.mappedSelection?.x || 0
- implicitWidth: launcher.state?.selected?.width || 0
- implicitHeight: launcher.state?.selected?.height || 0
- radius: Launcher.borderRadius
- color: Qt.rgba(Colors.background1.r, Colors.background1.g, Colors.background1.b, Launcher.bgTransparency)
- Behavior on x {
- ISpringAnimation {
- id: springAnim
- speed: 1.5
- }
- }
- Behavior on y {
- ISpringAnimation {
- speed: 1.5
- }
- }
- Behavior on implicitWidth {
- NumberAnimation {
- duration: springAnim.duration
- easing.type: Easing.BezierSpline
- // fast slow
- easing.bezierCurve: [0.33, 0.8, 0, 1]
- }
- }
- Behavior on implicitHeight {
- NumberAnimation {
- duration: springAnim.duration
- easing.type: Easing.BezierSpline
- // fast slow
- easing.bezierCurve: [0.33, 0.8, 0, 1]
- }
- }
- }
- color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.bgTransparency)
- radius: Launcher.borderRadius
-
- width: Math.max(root.width, Launcher.defaultWidth) + Launcher.innerMargin
- height: root.height
-
- IRect {
- id: root
- property alias input: textInput.text
-
- height: searchBar.height + widgets.height + textInput.height / 2 // * 1.5
- width: Math.max(widgets.implicitWidth, Launcher.defaultWidth)
-
- anchors.centerIn: parent
-
- color: "transparent"
-
- RowLayout {
- id: searchBar
- anchors {
- top: parent.top
- left: parent.left
- right: parent.right
- leftMargin: Launcher.innerMargin
- rightMargin: Launcher.innerMargin
- // try to center it when no widgets are present
- topMargin: widgets.height === Launcher.widgets.length * 5 - 5 ? parent.height / 2 - textInput.height / 2 : Launcher.innerMargin // textInput or Icon is the height of this
-
- Behavior on topMargin {
- ISpringAnimation {}
- }
- }
-
- spacing: Launcher.innerMargin * 2
-
- Icon {
- text: ""
- }
-
- RowLayout {
- spacing: 0
- TextInput {
- id: textInput
- property bool pendingUpdate: false
- Keys.onPressed: event => {
- if (event.key === Qt.Key_End || event.key === Qt.Key_Home) {
- if (event.key === Qt.Key_End) {
- endShortcut.activated();
- } else if (event.key === Qt.Key_Home) {
- homeShortcut.activated();
- }
- event.accepted = true;
- }
- }
-
- Layout.fillHeight: true
- Layout.fillWidth: true
- Layout.maximumWidth: implicitWidth
-
- color: Colors.foreground1
- selectionColor: Colors.background3
-
- text: launcher.state?.input || ""
- clip: true
- focus: true
-
- antialiasing: true
- smooth: true
- font {
- pixelSize: Style.font.size.large
- family: Style.font.family.sans
- wordSpacing: 5
- }
- // move to different file if we have more textinput
- cursorDelegate: IRect {
- id: cursor
- color: Colors.cursor
- // width: 1.5
- width: 2
- height: 1
- // blinking animation
- SequentialAnimation {
- running: true
- loops: Animation.Infinite
- PauseAnimation {
- duration: 500
- }
- ParallelAnimation {
- PropertyAnimation {
- target: cursor
- property: "opacity"
- to: 0
- duration: General.animationDuration / 5
- }
- PropertyAnimation {
- target: cursor
- property: "scale"
- to: 0
- duration: General.animationDuration / 5
- }
- }
- PauseAnimation {
- duration: 500
- }
- ParallelAnimation {
- PropertyAnimation {
- target: cursor
- property: "opacity"
- to: 1
- duration: General.animationDuration / 5
- }
- PropertyAnimation {
- target: cursor
- property: "scale"
- to: 1
- duration: General.animationDuration / 5
- }
- }
- }
- }
- HoverHandler {
- cursorShape: Qt.IBeamCursor
- }
- onTextChanged: {
- if (launcher.state.input !== textInput.text)
- pendingUpdate = true;
-
- Qt.callLater(() => {
- if (pendingUpdate) {
- pendingUpdate = false;
- launcher.state.input = textInput.text; // TODO: find ways to optimize this, like how i was using an alias
- }
- });
- }
- onCursorPositionChanged: {
- launcher.state.cursorPosition = textInput.cursorPosition;
- }
- // onActiveFocusChanged: {
- // parentLoader.active = activeFocus;
- // }
- onAccepted: {
- launcher.state?.priorities[launcher.state.selectedPriority]?._exec(); // TODO: kde like waiting animation for app to launch
- parentLoader.active = false;
- textInput.text = "";
- }
- Component.onCompleted: {
- selectAll();
- }
- }
- IRect {
- opacity: launcher.state?.priorities[launcher.state.selectedPriority]?.predictiveCompletion ? 1 : 0
- Layout.fillHeight: true
- Layout.preferredWidth: text.width
- radius: Launcher.predictiveCompletionRadius
- color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency)
- IText {
- id: text
- // animate: true // too jumpy
- color: Colors.foreground3
- renderType: Text.CurveRendering
- antialiasing: true
- smooth: true
- font {
- pixelSize: Style.font.size.large
- family: Style.font.family.sans
- wordSpacing: 5
- }
- text: launcher.state?.priorities[launcher.state.selectedPriority]?.predictiveCompletion || ""
- }
- Behavior on Layout.preferredWidth {
- ISpringAnimation {}
- // NumberAnimation {
- // duration: General.animationDuration / 5
- // }
- }
- Behavior on opacity {
- NumberAnimation {
- duration: General.animationDuration / 2
- easing.type: Easing.InOutQuad
- }
- }
- }
- Item {
- Layout.fillWidth: true
- }
- Loader {
- active: launcher.state?.priorities[launcher.state.selectedPriority]?.priority || false // .priority should always be true if it's in priorities
- sourceComponent: launcher.state?.priorities[launcher.state.selectedPriority]?.preview
- }
- }
- }
-
- ColumnLayout {
- id: widgets
- anchors {
- top: searchBar.bottom
- left: parent.left
- right: parent.right
- topMargin: Launcher.innerMargin * 1.5 // gap in between, maybe seperator FIXME
- }
-
- Repeater {
- model: launcher.widgetItems
- delegate: Loader {
- active: true
- visible: item?.valid ?? true // not item?.standalone cuz when its standalone it doesnt appear in launcher.widgetItems
- sourceComponent: modelData
- asynchronous: true
- onLoaded: {
- launcher.state.widgets[index] = item;
- // FIXME: prev predictiveCompletion still exists here
- // workaround atm: just clear it or preserve the text manually
- }
-
- Connections {
- target: item
- ignoreUnknownSignals: true
-
- function onClose() {
- parentLoader.active = false;
- }
- }
- }
- }
- }
- }
-
- // not Keys.onPressed because textinput will steal it
- Shortcut {
- sequence: "Escape"
- context: Qt.ApplicationShortcut
- onActivated: parentLoader.active = false
- }
-
- Shortcut {
- sequence: "Ctrl+H"
- context: Qt.ApplicationShortcut
- onActivated: changePos(1)
- }
-
- Shortcut {
- sequence: "Ctrl+J"
- context: Qt.ApplicationShortcut
- onActivated: changePos(-2)
- }
-
- Shortcut {
- sequence: "Ctrl+K"
- context: Qt.ApplicationShortcut
- onActivated: changePos(2)
- }
-
- Shortcut {
- sequence: "Ctrl+L"
- context: Qt.ApplicationShortcut
- onActivated: changePos(-1)
- }
-
- Shortcut {
- sequence: "Down"
- context: Qt.ApplicationShortcut
- onActivated: changePos(-2)
- }
-
- Shortcut {
- sequence: "Up"
- context: Qt.ApplicationShortcut
- onActivated: changePos(2)
- }
-
- Shortcut {
- sequence: "PgDown"
- context: Qt.ApplicationShortcut
- onActivated: changePos(-20)
- }
-
- Shortcut {
- sequence: "PgUp"
- context: Qt.ApplicationShortcut
- onActivated: changePos(20)
- }
-
- Shortcut {
- id: homeShortcut
- sequence: "Home"
- context: Qt.ApplicationShortcut
- onActivated: changePos(200)
- }
-
- Shortcut {
- id: endShortcut
- sequence: StandardKey.MoveToEndOfDocument
- context: Qt.ApplicationShortcut
- onActivated: changePos(-200)
- }
- }
- // 1 = left
- // -1 = right
- // 2 = up
- // -2 = down
- function changePos(direction: int) {
- const item = launcher.state?.priorities[launcher.state.selectedPriority];
- if (!item)
- return;
-
- let set = 0;
-
- switch (direction) {
- case 1:
- if (item.prev())
- set = -1;
- break;
- case -1:
- if (item.next())
- set = 1;
- break;
- case 2:
- if (item.up())
- set = -1;
- break;
- case -2:
- if (item.down())
- set = 1;
- break;
- case 20:
- if (item.pgup())
- set = -1;
- break;
- case -20:
- if (item.pgdn())
- set = 1;
- break;
- case 200:
- if (item.home())
- set = -1;
- break;
- case -200:
- if (item.end())
- set = 1;
- break;
- }
-
- if (set !== 0) {
- switch (set) {
- case 1:
- if (launcher.state.selectedPriority < launcher.state.priorities.length - 1) {
- launcher.state.selectedPriority++;
- launcher.state.priorities[launcher.state.selectedPriority].home();
- }
- break;
- case -1:
- if (launcher.state.selectedPriority > 0) {
- launcher.state.selectedPriority--;
- launcher.state.priorities[launcher.state.selectedPriority].end();
- }
- break;
- }
- }
- }
-
- implicitWidth: container.width
- implicitHeight: container.height
-
- Connections {
- target: launcher?.state
- // launcher.state may be null
- ignoreUnknownSignals: true
-
- function onSyncSelectionState() {
- selectionSync.running = true;
- }
- }
+ id: launcher
+
+ property list<Component> widgetItems: Launcher.widgets
+ property var state: SelectionState
+
+ name: "quickshell::launcher::launcher"
+
+ anchors.top: true
+ margins.top: Launcher.topMargin
+ aboveWindows: true
+ exclusionMode: ExclusionMode.Ignore
+
+ IRect {
+ id: container
+ property var selection: launcher.state?.selected
+ property var mappedSelection: selection?.mapToItem(null, 0, 0)
+
+ onMappedSelectionChanged: {
+ // launcher.state?.selected may be slow.. smh qt
+ // my guess is mapToItem is called when its not finished doing whatever it needs to do,
+ // so it doesnt get the right vars, but it doesn't update after since it already triggered it
+ selectionSync.running = true;
+ }
+
+ // for some reason selection changing doesnt call onMappedSelectionChanged, so we manually trigger it
+ onSelectionChanged: {
+ selectionSync.running = true;
+ }
+
+ Timer {
+ id: selectionSync
+ // TODO: evaluate weather i just leave it running repeat, might be costy though
+ running: false
+ repeat: false
+ // sync w/ IComponent y animation duration
+ interval: General.animationDuration / 4
+ onTriggered: {
+ parent.mappedSelection = launcher.state?.selected?.mapToItem(null, 0, 0);
+ }
+ }
+
+ IRect {
+ id: activeRect
+ visible: parent.mappedSelection || false
+ y: parent.mappedSelection?.y || 0
+ x: parent.mappedSelection?.x || 0
+ implicitWidth: launcher.state?.selected?.width || 0
+ implicitHeight: launcher.state?.selected?.height || 0
+ radius: Launcher.borderRadius
+ color: Qt.rgba(Colors.background1.r, Colors.background1.g, Colors.background1.b, Launcher.bgTransparency)
+ Behavior on x {
+ ISpringAnimation {
+ id: springAnim
+ speed: 1.5
+ }
+ }
+ Behavior on y {
+ ISpringAnimation {
+ speed: 1.5
+ }
+ }
+ Behavior on implicitWidth {
+ NumberAnimation {
+ duration: springAnim.duration
+ easing.type: Easing.BezierSpline
+ // fast slow
+ easing.bezierCurve: [0.33, 0.8, 0, 1]
+ }
+ }
+ Behavior on implicitHeight {
+ NumberAnimation {
+ duration: springAnim.duration
+ easing.type: Easing.BezierSpline
+ // fast slow
+ easing.bezierCurve: [0.33, 0.8, 0, 1]
+ }
+ }
+ }
+ color: Qt.rgba(Colors.background3.r, Colors.background3.g, Colors.background3.b, Launcher.bgTransparency)
+ radius: Launcher.borderRadius
+
+ width: Math.max(root.width, Launcher.defaultWidth) + Launcher.innerMargin
+ height: root.height
+
+ IRect {
+ id: root
+ property alias input: textInput.text
+
+ height: searchBar.height + widgets.height + textInput.height / 2 // * 1.5
+ width: Math.max(widgets.implicitWidth, Launcher.defaultWidth)
+
+ anchors.centerIn: parent
+
+ color: "transparent"
+
+ RowLayout {
+ id: searchBar
+ anchors {
+ top: parent.top
+ left: parent.left
+ right: parent.right
+ leftMargin: Launcher.innerMargin
+ rightMargin: Launcher.innerMargin
+ // try to center it when no widgets are present
+ topMargin: widgets.height === Launcher.widgets.length * 5 - 5 ? parent.height / 2 - textInput.height / 2 : Launcher.innerMargin // textInput or Icon is the height of this
+
+ Behavior on topMargin {
+ ISpringAnimation {}
+ }
+ }
+
+ spacing: Launcher.innerMargin * 2
+
+ Icon {
+ text: ""
+ }
+
+ RowLayout {
+ spacing: 0
+ TextInput {
+ id: textInput
+ property bool pendingUpdate: false
+ Keys.onPressed: event => {
+ if (event.key === Qt.Key_End || event.key === Qt.Key_Home) {
+ if (event.key === Qt.Key_End) {
+ endShortcut.activated();
+ } else if (event.key === Qt.Key_Home) {
+ homeShortcut.activated();
+ }
+ event.accepted = true;
+ }
+ }
+
+ Layout.fillHeight: true
+ Layout.fillWidth: true
+ Layout.maximumWidth: implicitWidth
+
+ color: Colors.foreground1
+ selectionColor: Colors.background3
+
+ text: launcher.state?.input || ""
+ clip: true
+ focus: true
+
+ antialiasing: true
+ smooth: true
+ font {
+ pixelSize: Style.font.size.large
+ family: Style.font.family.sans
+ wordSpacing: 5
+ }
+ // move to different file if we have more textinput
+ cursorDelegate: IRect {
+ id: cursor
+ color: Colors.cursor
+ // width: 1.5
+ width: 2
+ height: 1
+ // blinking animation
+ SequentialAnimation {
+ running: true
+ loops: Animation.Infinite
+ PauseAnimation {
+ duration: 500
+ }
+ ParallelAnimation {
+ PropertyAnimation {
+ target: cursor
+ property: "opacity"
+ to: 0
+ duration: General.animationDuration / 5
+ }
+ PropertyAnimation {
+ target: cursor
+ property: "scale"
+ to: 0
+ duration: General.animationDuration / 5
+ }
+ }
+ PauseAnimation {
+ duration: 500
+ }
+ ParallelAnimation {
+ PropertyAnimation {
+ target: cursor
+ property: "opacity"
+ to: 1
+ duration: General.animationDuration / 5
+ }
+ PropertyAnimation {
+ target: cursor
+ property: "scale"
+ to: 1
+ duration: General.animationDuration / 5
+ }
+ }
+ }
+ }
+ HoverHandler {
+ cursorShape: Qt.IBeamCursor
+ }
+ onTextChanged: {
+ if (launcher.state.input !== textInput.text)
+ pendingUpdate = true;
+
+ Qt.callLater(() => {
+ if (pendingUpdate) {
+ pendingUpdate = false;
+ launcher.state.input = textInput.text; // TODO: find ways to optimize this, like how i was using an alias
+ }
+ });
+ }
+ onCursorPositionChanged: {
+ launcher.state.cursorPosition = textInput.cursorPosition;
+ }
+ // onActiveFocusChanged: {
+ // parentLoader.active = activeFocus;
+ // }
+ onAccepted: {
+ launcher.state?.priorities[launcher.state.selectedPriority]?._exec(); // TODO: kde like waiting animation for app to launch
+ parentLoader.active = false;
+ textInput.text = "";
+ }
+ Component.onCompleted: {
+ selectAll();
+ }
+ }
+ IRect {
+ opacity: launcher.state?.priorities[launcher.state.selectedPriority]?.predictiveCompletion ? 1 : 0
+ Layout.fillHeight: true
+ Layout.preferredWidth: text.width
+ radius: Launcher.predictiveCompletionRadius
+ color: Qt.rgba(Colors.background2.r, Colors.background2.g, Colors.background2.b, Launcher.widgetBgTransparency)
+ IText {
+ id: text
+ // animate: true // too jumpy
+ color: Colors.foreground3
+ renderType: Text.CurveRendering
+ antialiasing: true
+ smooth: true
+ font {
+ pixelSize: Style.font.size.large
+ family: Style.font.family.sans
+ wordSpacing: 5
+ }
+ text: launcher.state?.priorities[launcher.state.selectedPriority]?.predictiveCompletion || ""
+ }
+ Behavior on Layout.preferredWidth {
+ ISpringAnimation {}
+ // NumberAnimation {
+ // duration: General.animationDuration / 5
+ // }
+ }
+ Behavior on opacity {
+ NumberAnimation {
+ duration: General.animationDuration / 2
+ easing.type: Easing.InOutQuad
+ }
+ }
+ }
+ Item {
+ Layout.fillWidth: true
+ }
+ Loader {
+ active: launcher.state?.priorities[launcher.state.selectedPriority]?.priority || false // .priority should always be true if it's in priorities
+ sourceComponent: launcher.state?.priorities[launcher.state.selectedPriority]?.preview
+ }
+ }
+ }
+
+ ColumnLayout {
+ id: widgets
+ anchors {
+ top: searchBar.bottom
+ left: parent.left
+ right: parent.right
+ topMargin: Launcher.innerMargin * 1.5 // gap in between, maybe seperator FIXME
+ }
+
+ Repeater {
+ model: launcher.widgetItems
+ delegate: Loader {
+ active: true
+ visible: item?.valid ?? true // not item?.standalone cuz when its standalone it doesnt appear in launcher.widgetItems
+ sourceComponent: modelData
+ asynchronous: true
+ onLoaded: {
+ launcher.state.widgets[index] = item;
+ // FIXME: prev predictiveCompletion still exists here
+ // workaround atm: just clear it or preserve the text manually
+ }
+
+ Connections {
+ target: item
+ ignoreUnknownSignals: true
+
+ function onClose() {
+ parentLoader.active = false;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // not Keys.onPressed because textinput will steal it
+ Shortcut {
+ sequence: "Escape"
+ context: Qt.ApplicationShortcut
+ onActivated: parentLoader.active = false
+ }
+
+ Shortcut {
+ sequence: "Ctrl+H"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(1)
+ }
+
+ Shortcut {
+ sequence: "Ctrl+J"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(-2)
+ }
+
+ Shortcut {
+ sequence: "Ctrl+K"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(2)
+ }
+
+ Shortcut {
+ sequence: "Ctrl+L"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(-1)
+ }
+
+ Shortcut {
+ sequence: "Down"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(-2)
+ }
+
+ Shortcut {
+ sequence: "Up"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(2)
+ }
+
+ Shortcut {
+ sequence: "PgDown"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(-20)
+ }
+
+ Shortcut {
+ sequence: "PgUp"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(20)
+ }
+
+ Shortcut {
+ id: homeShortcut
+ sequence: "Home"
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(200)
+ }
+
+ Shortcut {
+ id: endShortcut
+ sequence: StandardKey.MoveToEndOfDocument
+ context: Qt.ApplicationShortcut
+ onActivated: changePos(-200)
+ }
+ }
+ // 1 = left
+ // -1 = right
+ // 2 = up
+ // -2 = down
+ function changePos(direction: int) {
+ const item = launcher.state?.priorities[launcher.state.selectedPriority];
+ if (!item)
+ return;
+
+ let set = 0;
+
+ switch (direction) {
+ case 1:
+ if (item.prev())
+ set = -1;
+ break;
+ case -1:
+ if (item.next())
+ set = 1;
+ break;
+ case 2:
+ if (item.up())
+ set = -1;
+ break;
+ case -2:
+ if (item.down())
+ set = 1;
+ break;
+ case 20:
+ if (item.pgup())
+ set = -1;
+ break;
+ case -20:
+ if (item.pgdn())
+ set = 1;
+ break;
+ case 200:
+ if (item.home())
+ set = -1;
+ break;
+ case -200:
+ if (item.end())
+ set = 1;
+ break;
+ }
+
+ if (set !== 0) {
+ switch (set) {
+ case 1:
+ if (launcher.state.selectedPriority < launcher.state.priorities.length - 1) {
+ launcher.state.selectedPriority++;
+ launcher.state.priorities[launcher.state.selectedPriority].home();
+ }
+ break;
+ case -1:
+ if (launcher.state.selectedPriority > 0) {
+ launcher.state.selectedPriority--;
+ launcher.state.priorities[launcher.state.selectedPriority].end();
+ }
+ break;
+ }
+ }
+ }
+
+ implicitWidth: container.width
+ implicitHeight: container.height
+
+ Connections {
+ target: launcher?.state
+ // launcher.state may be null
+ ignoreUnknownSignals: true
+
+ function onSyncSelectionState() {
+ selectionSync.running = true;
+ }
+ }
}
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 = [];
+ }
+ }
}