first commit

This commit is contained in:
2026-02-12 17:04:11 +01:00
commit cc9402d2cd
4 changed files with 229 additions and 0 deletions

187
contents/ui/main.qml Normal file
View File

@@ -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 = ""
}
}
}
}
}
}