Skip to content

Commit

Permalink
feat: Implement feature to copy model name text to clipboard upon click.
Browse files Browse the repository at this point in the history
  • Loading branch information
imoize committed Nov 10, 2024
1 parent 1a20f75 commit c2568a6
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
42 changes: 42 additions & 0 deletions package/contents/ui/ModelsDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ PlasmaComponents.ItemDelegate {

property bool showSeparator

signal toInfoPage(string modelName)

onToInfoPage: (modelName) => {
stack.push(Qt.resolvedUrl("InfoPage.qml"), {
modelName: modelName
});
}

MouseArea {
anchors.fill: parent
hoverEnabled: isLoading ? false : true
Expand All @@ -24,6 +32,9 @@ PlasmaComponents.ItemDelegate {
if (modelListView.currentIndex === index)
modelListView.currentIndex = -1;
}
onClicked: {
modelItem.toInfoPage(modelName);
}

Item {
id: label
Expand All @@ -45,8 +56,39 @@ PlasmaComponents.ItemDelegate {

PlasmaComponents.Label {
Layout.bottomMargin: Kirigami.Units.smallSpacing
id: modelNameLabel
text: modelName
font.bold: true

PlasmaComponents.ToolTip {
id: modelNameTooltip
visible: false
text: i18n("Click to copy text")
}

MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
modelNameTooltip.visible = true
}
onExited: {
modelNameTooltip.visible = false
}
onClicked: {
// Use TextEdit as a helper to copy the text to the clipboard
textEditHelper.text = modelNameLabel.text;
textEditHelper.selectAll();
textEditHelper.copy();
listPage.showPassiveNotification();
}
}
}

// Helper TextEdit element to facilitate copying text to the clipboard
TextEdit {
id: textEditHelper
visible: false
}

RowLayout {
Expand Down
50 changes: 50 additions & 0 deletions package/contents/ui/components/PassiveNotification.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import QtQuick
import QtQuick.Layouts
import org.kde.kirigami as Kirigami
import org.kde.plasma.components as PlasmaComponents

PlasmaComponents.Popup {
id: passiveNotification

signal closePassiveNotification

width: Kirigami.Units.gridUnit * 6
height: Kirigami.Units.gridUnit * 2 - 4

// Position the Popup at the bottom of its parent
x: parent.width / 2 - width / 2 // Center horizontally
y: parent.height - height - 2 // Position at the bottom

modal: false
visible: true
closePolicy: PlasmaComponents.Popup.CloseOnPressOutside

PlasmaComponents.Label {
anchors.centerIn: parent
Layout.alignment: Qt.AlignHCenter
horizontalAlignment: Text.AlignHCenter
text: "Text copied !"
}

background: Rectangle {
anchors.fill: parent
radius: 50
Kirigami.Theme.colorSet: Kirigami.Theme.View
Kirigami.Theme.inherit: false
color: Kirigami.Theme.backgroundColor
}

// Timer to auto-close the Popup after a certain duration
Timer {
id: autoCloseTimer
interval: 1500
running: passiveNotification.visible
onTriggered: {
passiveNotification.close();
}
}

onClosed: {
passiveNotification.closePassiveNotification();
}
}

0 comments on commit c2568a6

Please sign in to comment.