From cc9402d2cd8fa05f934a274057102b5b6ceb6b64 Mon Sep 17 00:00:00 2001 From: Hans Kokx Date: Thu, 12 Feb 2026 17:04:11 +0100 Subject: [PATCH] first commit --- contents/config/main.xml | 11 +++ contents/ui/main.qml | 187 +++++++++++++++++++++++++++++++++++++++ metadata.json | 20 +++++ refresh.sh | 11 +++ 4 files changed, 229 insertions(+) create mode 100644 contents/config/main.xml create mode 100644 contents/ui/main.qml create mode 100644 metadata.json create mode 100755 refresh.sh diff --git a/contents/config/main.xml b/contents/config/main.xml new file mode 100644 index 0000000..f0bc9fa --- /dev/null +++ b/contents/config/main.xml @@ -0,0 +1,11 @@ + + + + + ["Ä", "ä", "Å", "å", "Ö", "ö", "€"] + + + diff --git a/contents/ui/main.qml b/contents/ui/main.qml new file mode 100644 index 0000000..c18e02e --- /dev/null +++ b/contents/ui/main.qml @@ -0,0 +1,187 @@ +import QtQuick +import QtQuick.Layouts +import QtQuick.Controls +import org.kde.plasma.plasmoid +import org.kde.plasma.components 3.0 as PlasmaComponents +import org.kde.kirigami as Kirigami + +PlasmoidItem { + id: root + + // Data Management + ListModel { + id: charModel + Component.onCompleted: loadChars() + } + + function loadChars() { + charModel.clear() + var configStr = Plasmoid.configuration.savedCharacters || '[]' + try { + var chars = JSON.parse(configStr) + for (var i = 0; i < chars.length; i++) { + charModel.append({ "charText": chars[i] }) + } + } catch (e) { + console.log("Error loading characters: " + e) + } + } + + function saveChars() { + var chars = [] + for (var i = 0; i < charModel.count; i++) { + chars.push(charModel.get(i).charText) + } + Plasmoid.configuration.savedCharacters = JSON.stringify(chars) + } + + function resetToDefaults() { + // Explicitly set to the defaults defined in your main.xml + Plasmoid.configuration.savedCharacters = '["Ä", "ä", "Å", "å", "Ö", "ö", "€"]' + loadChars() + } + + function clearAll() { + charModel.clear() + Plasmoid.configuration.savedCharacters = "[]" + } + + function addChar(text) { + if (text.trim() === "") return + charModel.append({ "charText": text }) + saveChars() + } + + function removeChar(index) { + charModel.remove(index) + saveChars() + } + + TextEdit { + id: clipboardHelper + visible: false + } + + function copyToClipboard(str) { + clipboardHelper.text = str + clipboardHelper.selectAll() + clipboardHelper.copy() + } + + compactRepresentation: PlasmaComponents.Button { + icon.name: "accessories-character-map" + flat: true + padding: 0 + onClicked: root.expanded = !root.expanded + } + + fullRepresentation: Item { + implicitWidth: Kirigami.Units.gridUnit * 12 + implicitHeight: Kirigami.Units.gridUnit * 14 + + ColumnLayout { + anchors.fill: parent + anchors.margins: Kirigami.Units.smallSpacing + + // --- HEADER --- + RowLayout { + Layout.fillWidth: true + PlasmaComponents.Label { + text: "Quick Characters" + font.bold: true + Layout.fillWidth: true + } + // Reset to Defaults Button + PlasmaComponents.Button { + icon.name: "edit-undo" + flat: true + onClicked: root.resetToDefaults() + display: PlasmaComponents.AbstractButton.IconOnly + + // Use the standard ToolTip component + ToolTip.text: "Reset to defaults" + ToolTip.visible: hovered + } + // Clear All Button + PlasmaComponents.Button { + icon.name: "edit-clear-all" + flat: true + onClicked: root.clearAll() + display: PlasmaComponents.AbstractButton.IconOnly + + ToolTip.text: "Clear all" + ToolTip.visible: hovered + } + } + + // --- GRID & PLACEHOLDER --- + Item { + Layout.fillWidth: true + Layout.fillHeight: true + + // Dimmed placeholder label + PlasmaComponents.Label { + anchors.centerIn: parent + text: "Add a character..." + opacity: 0.5 + font.italic: true + visible: charModel.count === 0 + } + + ScrollView { + anchors.fill: parent + visible: charModel.count > 0 + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + + GridView { + id: grid + model: charModel + cellWidth: 60 + cellHeight: 60 + clip: true + + delegate: Item { + width: grid.cellWidth + height: grid.cellHeight + PlasmaComponents.Button { + anchors.centerIn: parent + width: 48 + height: 48 + text: model.charText + onClicked: { + copyToClipboard(model.charText) + root.expanded = false + } + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.RightButton + onClicked: root.removeChar(index) + } + } + } + } + } + } + + // --- INPUT --- + RowLayout { + PlasmaComponents.TextField { + id: inputField + Layout.fillWidth: true + placeholderText: "Add..." + onAccepted: { + addChar(text) + text = "" + } + } + PlasmaComponents.Button { + icon.name: "list-add" + onClicked: { + addChar(inputField.text) + inputField.text = "" + } + } + } + } + } +} \ No newline at end of file diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..48f2723 --- /dev/null +++ b/metadata.json @@ -0,0 +1,20 @@ +{ + "KPlugin": { + "Id": "org.hadak.kdequickchar", + "Name": "Quick Copy Character", + "Description": "Quickly copy saved characters to your clipboard.", + "Icon": "character-set", + "Authors": [ + { + "Name": "Hans Kokx", + "Email": "hans.d.kokx@gmail.com" + } + ], + "Category": "Utilities", + "Version": "1.0", + "License": "GPL-3.0+", + "EnabledByDefault": true + }, + "KPackageStructure": "Plasma/Applet", + "X-Plasma-API-Minimum-Version": "6.0" +} \ No newline at end of file diff --git a/refresh.sh b/refresh.sh new file mode 100755 index 0000000..151e650 --- /dev/null +++ b/refresh.sh @@ -0,0 +1,11 @@ +#!/bin/bash +rm -rf ~/.local/share/plasma/plasmoids/org.hadak.kdequickchar + +# 1. Re-install the widget +kpackagetool6 --type Plasma/Applet --install . + +# 2. Clear the cache +kbuildsycoca6 + +# 3. Restart the shell to see changes +kquitapp6 plasmashell && kstart plasmashell