| 1 |
import QtQuick 2.7 |
| 2 |
import QtQuick.Layouts 1.3 |
| 3 |
import QtQuick.Controls 2.0 |
| 4 |
|
| 5 |
import sfxr 1.0 |
| 6 |
|
| 7 |
ColumnLayout { |
| 8 |
id: root |
| 9 |
property alias model: listView.model |
| 10 |
property alias currentIndex: listView.currentIndex |
| 11 |
signal currentSoundClicked() |
| 12 |
|
| 13 |
property int innerMargin: 4 |
| 14 |
|
| 15 |
TitleLabel { |
| 16 |
text: qsTr("Sounds") |
| 17 |
} |
| 18 |
|
| 19 |
ListView { |
| 20 |
id: listView |
| 21 |
Layout.fillWidth: true |
| 22 |
Layout.fillHeight: true |
| 23 |
clip: true |
| 24 |
delegate: ItemDelegate { |
| 25 |
anchors { |
| 26 |
left: parent.left |
| 27 |
right: parent.right |
| 28 |
} |
| 29 |
text: model.text |
| 30 |
highlighted: model.index === listView.currentIndex |
| 31 |
|
| 32 |
onClicked: { |
| 33 |
if (highlighted) { |
| 34 |
currentSoundClicked(); |
| 35 |
} else { |
| 36 |
listView.currentIndex = model.index; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
Button { |
| 41 |
anchors { |
| 42 |
right: parent.right |
| 43 |
rightMargin: innerMargin |
| 44 |
verticalCenter: parent.verticalCenter |
| 45 |
} |
| 46 |
height: parent.height - 2 * innerMargin |
| 47 |
width: height |
| 48 |
flat: true |
| 49 |
text: "⨯" |
| 50 |
|
| 51 |
onClicked: { |
| 52 |
if (model.index < 0) { |
| 53 |
// This can happen when clicking fast enough on the button. |
| 54 |
// Especially when running under Valgrind. |
| 55 |
console.warn("Sound has already been removed"); |
| 56 |
return; |
| 57 |
} |
| 58 |
if (listView.count === 1) { |
| 59 |
// If the item is alone, reset it, do not remove it |
| 60 |
root.model.resetSoundAtRow(0); |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
if (model.index === listView.currentIndex) { |
| 65 |
selectAnother(); |
| 66 |
} |
| 67 |
root.model.remove(model.index); |
| 68 |
} |
| 69 |
|
| 70 |
function selectAnother() { |
| 71 |
if (model.index < listView.count - 1) { |
| 72 |
listView.currentIndex = model.index + 1; |
| 73 |
} else { |
| 74 |
listView.currentIndex = model.index - 1; |
| 75 |
} |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
ScrollIndicator.vertical: ScrollIndicator {} |
| 81 |
} |
| 82 |
} |