fixing small ui things and making audio picking use portal

This commit is contained in:
Chris Cochrun 2023-09-28 06:31:29 -05:00
parent 4b6a079a4e
commit 9f4d426a8f
7 changed files with 189 additions and 151 deletions

View file

@ -276,7 +276,7 @@ Kirigami.ApplicationWindow {
} }
function load() { function load() {
const file = fileHelper.loadFile(); const file = fileHelper.loadFile("Load Presentation");
const loaded = mainPage.serviceItems.load(file); const loaded = mainPage.serviceItems.load(file);
loaded ? showPassiveNotification("Loaded: " + file) loaded ? showPassiveNotification("Loaded: " + file)
: showPassiveNotification("FAILED!"); : showPassiveNotification("FAILED!");

View file

@ -3,144 +3,146 @@ import QtQuick.Layouts 1.15
import org.kde.kirigami 2.13 as Kirigami import org.kde.kirigami 2.13 as Kirigami
Item { Item {
id: root id: root
/** /**
* listItem: Item * @brief This property holds the delegate that will be dragged around.
* The id of the delegate that we want to drag around, which *must* *
* be a child of the actual ListView's delegate * This item *must* be a child of the actual ListView's delegate.
*/ */
property Item listItem property Item listItem
/** /**
* listView: Listview * @brief This property holds the ListView that the delegate belong to.
* The id of the ListView the delegates belong to. */
*/ property ListView listView
property ListView listView
property bool containsMouse /**
* @brief This signal is emitted when the drag handle wants to move the item in the model.
/** *
* Emitted when the drag handle wants to move the item in the model * The following example does the move in the case a ListModel is used:
* The following example does the move in the case a ListModel is used * @code{.qml}
* @code * onMoveRequested: listModel.move(oldIndex, newIndex, 1)
* onMoveRequested: listModel.move(oldIndex, newIndex, 1) * @endcode
* @endcode * @param oldIndex the index the item is currently at
* @param oldIndex the index the item is currently at * @param newIndex the index we want to move the item to
* @param newIndex the index we want to move the item to */
*/ signal moveRequested(int oldIndex, int newIndex)
signal moveRequested(int oldIndex, int newIndex)
/**
/** * @brief This signal is emitted when the drag operation is complete and the item has been
* Emitted when the drag operation is complete and the item has been * dropped in the new final position.
* dropped in the new final position */
*/ signal dropped()
signal dropped()
implicitWidth: Kirigami.Units.iconSizes.smallMedium
// Emitted when clicking to activate underneath mousearea implicitHeight: implicitWidth
signal clicked()
signal rightClicked() MouseArea {
id: mouseArea
MouseArea { anchors.fill: parent
id: mouseArea drag {
anchors.fill: parent target: listItem
drag { axis: Drag.YAxis
target: listItem minimumY: 0
axis: Drag.YAxis }
minimumY: 0 cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
maximumY: listView.height - listItem.height
filterChildren: true Kirigami.Icon {
} id: internal
/* cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor */ source: "handle-sort"
property int startY
property int startY property int mouseDownY
property int mouseDownY property Item originalParent
property Item originalParent opacity: mouseArea.pressed || (!Kirigami.Settings.tabletMode && listItem.hovered) ? 1 : 0.6
property int autoScrollThreshold: (listView.contentHeight > listView.height) ? listItem.height * 3 : 0 property int listItemLastY
property bool draggingUp
function arrangeItem() { color: "white"
var newIndex = listView.indexAt(1,
listView.contentItem.mapFromItem(listItem, 0, 0).y + function arrangeItem() {
mouseArea.mouseDownY); const newIndex = listView.indexAt(1, listView.contentItem.mapFromItem(mouseArea, 0, internal.mouseDownY).y);
if (Math.abs(listItem.y - mouseArea.startY) > height && newIndex > -1 && if (newIndex > -1 && ((internal.draggingUp && newIndex < index) || (!internal.draggingUp && newIndex > index))) {
newIndex !== index) { root.moveRequested(index, newIndex);
console.log("old index is: " + index + " and new index is: " + newIndex); }
root.moveRequested(index, newIndex); }
}
} anchors.fill: parent
}
preventStealing: false preventStealing: true
onPressed: {
listView.interactive = false;
mouseArea.originalParent = listItem.parent; onPressed: mouse => {
listItem.parent = listView; internal.originalParent = listItem.parent;
listItem.y = mouseArea.originalParent.mapToItem(listItem.parent, listItem.x, listItem.y).y; listItem.parent = listView;
mouseArea.originalParent.z = 99; listItem.y = internal.originalParent.mapToItem(listItem.parent, listItem.x, listItem.y).y;
mouseArea.startY = listItem.y; internal.originalParent.z = 99;
mouseArea.mouseDownY = mouse.y; internal.startY = listItem.y;
} internal.listItemLastY = listItem.y;
internal.mouseDownY = mouse.y;
onPositionChanged: { // while dragging listItem's height could change
if (!pressed) { // we want a const maximumY during the dragging time
return; mouseArea.drag.maximumY = listView.height - listItem.height;
} }
mouseArea.arrangeItem();
onPositionChanged: mouse => {
scrollTimer.interval = 500 * Math.max(0.1, (1-Math.max(mouseArea.autoScrollThreshold - listItem.y, listItem.y - listView.height + mouseArea.autoScrollThreshold + listItem.height) / mouseArea.autoScrollThreshold)); if (!pressed || listItem.y === internal.listItemLastY) {
scrollTimer.running = (listItem.y < mouseArea.autoScrollThreshold || return;
listItem.y > listView.height - mouseArea.autoScrollThreshold); }
}
onReleased: { internal.draggingUp = listItem.y < internal.listItemLastY
listView.interactive = true; internal.listItemLastY = listItem.y;
listItem.y = mouseArea.originalParent.mapFromItem(listItem, 0, 0).y;
listItem.parent = mouseArea.originalParent; internal.arrangeItem();
dropAnimation.running = true;
scrollTimer.running = false; // autoscroll when the dragging item reaches the listView's top/bottom boundary
root.dropped(); scrollTimer.running = (listView.contentHeight > listView.height)
} && ( (listItem.y === 0 && !listView.atYBeginning) ||
onCanceled: released() (listItem.y === mouseArea.drag.maximumY && !listView.atYEnd) );
SequentialAnimation { }
id: dropAnimation onReleased: mouse => {
YAnimator { listItem.y = internal.originalParent.mapFromItem(listItem, 0, 0).y;
target: listItem listItem.parent = internal.originalParent;
from: listItem.y dropAnimation.running = true;
to: 0 scrollTimer.running = false;
duration: Kirigami.Units.longDuration root.dropped();
easing.type: Easing.InOutQuad }
} onCanceled: released()
PropertyAction { SequentialAnimation {
target: listItem.parent id: dropAnimation
property: "z" YAnimator {
value: 0 target: listItem
} from: listItem.y
} to: 0
Timer { duration: Kirigami.Units.longDuration
id: scrollTimer easing.type: Easing.InOutQuad
interval: 500 }
repeat: true PropertyAction {
onTriggered: { target: listItem.parent
if (listItem.y < mouseArea.autoScrollThreshold) { property: "z"
listView.contentY = Math.max(0, listView.contentY - Kirigami.Units.gridUnit) value: 0
} else { }
listView.contentY = Math.min(listView.contentHeight - listView.height, listView.contentY + Kirigami.Units.gridUnit) }
} Timer {
mouseArea.arrangeItem(); id: scrollTimer
} interval: 50
} repeat: true
onTriggered: {
MouseArea { if (internal.draggingUp) {
id: clickArea listView.contentY -= Kirigami.Units.gridUnit;
anchors.fill: parent if (listView.atYBeginning) {
hoverEnabled: true listView.positionViewAtBeginning();
acceptedButtons: Qt.LeftButton | Qt.RightButton stop();
onEntered: root.containsMouse = true }
onExited: root.containsMouse = false } else {
onClicked: { listView.contentY += Kirigami.Units.gridUnit;
if (mouse.button === Qt.RightButton) if (listView.atYEnd) {
root.rightClicked(); listView.positionViewAtEnd();
else stop();
root.clicked(); }
} }
} internal.arrangeItem();
} }
} }
}
}

View file

@ -107,6 +107,7 @@ FocusScope {
implicitHeight: Kirigami.Units.gridUnit * 10 implicitHeight: Kirigami.Units.gridUnit * 10
anchors.right: previewSlide.left anchors.right: previewSlide.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: "white"
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onPressed: previousSlideAction() onPressed: previousSlideAction()
@ -141,6 +142,7 @@ FocusScope {
implicitHeight: Kirigami.Units.gridUnit * 10 implicitHeight: Kirigami.Units.gridUnit * 10
anchors.left: previewSlide.right anchors.left: previewSlide.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
color: "white"
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent
onPressed: nextSlideAction() onPressed: nextSlideAction()

View file

@ -263,7 +263,7 @@ Item {
} }
} }
Kirigami.ListItemDragHandle { Presenter.DragHandle {
id: dragHandle id: dragHandle
anchors.left: parent.left anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter

View file

@ -208,6 +208,23 @@ Item {
text: song.vorder text: song.vorder
padding: 10 padding: 10
onEditingFinished: updateVerseOrder(text); onEditingFinished: updateVerseOrder(text);
background: Rectangle {
color: songVorderField.enabled ? Kirigami.Theme.backgroundColor :
song.vorder.trim().length === 0 ?
Kirigami.Theme.negativeBackgroundColor :
Kirigami.Theme.backgroundColor
implicitWidth: parent.width
implicitHeight: parent.height
radius: 10
border.color: {
if (song.vorder.trim().length === 0)
return Kirigami.Theme.negativeTextColor
else if (songVorderField.enabled)
return Kirigami.Theme.highlightColor
else
return Kirigami.Theme.positiveColor
}
}
} }
Controls.Label { Controls.Label {
@ -251,6 +268,18 @@ Item {
editorTimer.running = false; editorTimer.running = false;
} }
onPressed: editorTimer.running = true onPressed: editorTimer.running = true
background: Rectangle {
color: Kirigami.Theme.backgroundColor
implicitWidth: parent.width
implicitHeight: parent.height
radius: 10
border.color: {
if (songVorderField.enabled)
return Kirigami.Theme.highlightColor
else
return Kirigami.Theme.positiveColor
}
}
} }
} }
@ -325,7 +354,7 @@ Item {
Layout.fillHeight: true Layout.fillHeight: true
text: "Audio" text: "Audio"
icon.name: "folder-music-symbolic" icon.name: "folder-music-symbolic"
onClicked: audioFileDialog.open() onClicked: updateAudioFile()
} }
} }
} }
@ -465,7 +494,8 @@ Item {
songProxyModel.songModel.updateVerseOrder(songIndex, vorder) songProxyModel.songModel.updateVerseOrder(songIndex, vorder)
} }
function updateAudioFile(file) { function updateAudioFile() {
const file = fileHelper.loadFile("Pick Audio");
songProxyModel.songModel.updateAudio(songIndex, file); songProxyModel.songModel.updateAudio(songIndex, file);
} }

View file

@ -92,10 +92,12 @@ mod file_helper {
} }
#[qinvokable] #[qinvokable]
pub fn load_file(self: Pin<&mut Self>) -> QUrl { pub fn load_file(
let file = FileDialog::new() self: Pin<&mut Self>,
.set_title("Load Presentation") title: QString,
.pick_file(); ) -> QUrl {
let title = title.to_string();
let file = FileDialog::new().set_title(title).pick_file();
if let Some(file) = file { if let Some(file) = file {
println!("loading-file: {:?}", file); println!("loading-file: {:?}", file);
let mut string = let mut string =

View file

@ -859,8 +859,10 @@ pub mod song_model {
let mut verse_name = ""; let mut verse_name = "";
debug!(verse = verse); debug!(verse = verse);
for word in keywords.clone() { for word in keywords.clone() {
let end_verse = verse.get(1..2).unwrap(); let end_verse =
let beg_verse = verse.get(0..1).unwrap(); verse.get(1..2).unwrap_or_default();
let beg_verse =
verse.get(0..1).unwrap_or_default();
println!( println!(
"verse: {:?}, beginning: {:?}, end: {:?}, word: {:?}", "verse: {:?}, beginning: {:?}, end: {:?}, word: {:?}",
verse, beg_verse, end_verse, word verse, beg_verse, end_verse, word