| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2024 Tuomas Nurmi <[email protected]> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
import QtQuick 2.15 |
| 18 |
import QtQuick.Controls 2.15 |
| 19 |
import QtQuick.Layouts 1.15 |
| 20 |
import org.kde.amarok.currenttrack 1.0 |
| 21 |
import org.kde.kirigami 2.14 as Kirigami |
| 22 |
|
| 23 |
MouseArea { |
| 24 |
property Button copyMarker |
| 25 |
property string targetText |
| 26 |
|
| 27 |
anchors.fill: parent |
| 28 |
hoverEnabled: true |
| 29 |
|
| 30 |
|
| 31 |
Rectangle { |
| 32 |
height: parent.height |
| 33 |
y: 0 |
| 34 |
anchors.left: parent.left |
| 35 |
width: copyMarker.x + 20 |
| 36 |
color: Kirigami.Theme.highlightColor |
| 37 |
opacity: parent.pressed ? 0.2 : parent.containsMouse ? 0.1 : 0.0 |
| 38 |
} |
| 39 |
|
| 40 |
function copy( str ) { |
| 41 |
copyEdit.text=str |
| 42 |
copyEdit.selectAll() |
| 43 |
copyEdit.copy() |
| 44 |
} |
| 45 |
|
| 46 |
onClicked: |
| 47 |
{ |
| 48 |
copyMarker.animationRunning = true |
| 49 |
copy(targetText); |
| 50 |
} |
| 51 |
onExited: |
| 52 |
{ |
| 53 |
copyMarker.opacity = 0 |
| 54 |
} |
| 55 |
onEntered: |
| 56 |
{ |
| 57 |
copyMarker.x = Math.min( parent.implicitWidth - copyMarker.width, parent.width - copyMarker.width ) |
| 58 |
copyMarker.opacity = 0.3 |
| 59 |
} |
| 60 |
|
| 61 |
TextEdit { |
| 62 |
id: copyEdit |
| 63 |
visible: false |
| 64 |
} |
| 65 |
|
| 66 |
Button { |
| 67 |
id: copyMarker |
| 68 |
|
| 69 |
property alias animationRunning: clickAnimation.running |
| 70 |
|
| 71 |
anchors.top: parent.top |
| 72 |
width: Kirigami.Units.iconSizes.small |
| 73 |
height: Kirigami.Units.iconSizes.small |
| 74 |
z: -1 |
| 75 |
opacity: 0 |
| 76 |
|
| 77 |
icon.name: "edit-copy" |
| 78 |
flat: true |
| 79 |
|
| 80 |
onClicked: |
| 81 |
{ |
| 82 |
animationRunning = true |
| 83 |
copy(parent.targetText); |
| 84 |
} |
| 85 |
SequentialAnimation { |
| 86 |
id: clickAnimation |
| 87 |
OpacityAnimator { target: copyMarker; from: 0.3; to: 0.9; duration: 50; } |
| 88 |
OpacityAnimator { target: copyMarker; from: 0.9; to: 0.3; duration: 250; } |
| 89 |
} |
| 90 |
Behavior on opacity { PropertyAnimation {} } |
| 91 |
} |
| 92 |
} |