From 301306c9f2d55c30bc08886a621afc9e22786192 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 5 Oct 2023 10:12:58 -0500 Subject: [PATCH] using rfd in more places and fixing non hovering buttons --- src/qml/presenter/SongEditor.qml | 9 ++++++--- src/rust/file_helper.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/qml/presenter/SongEditor.qml b/src/qml/presenter/SongEditor.qml index 27117b3..da9f868 100644 --- a/src/qml/presenter/SongEditor.qml +++ b/src/qml/presenter/SongEditor.qml @@ -126,7 +126,8 @@ Item { Layout.fillWidth: true text: "Video" icon.name: "emblem-videos-symbolic" - onClicked: videoFileDialog.open() & backgroundTypePopup.close() + onClicked: updateBackground("video") & backgroundTypePopup.close() + hoverEnabled: true } Controls.ToolButton { Layout.fillWidth: true @@ -134,6 +135,7 @@ Item { text: "Image" icon.name: "folder-pictures-symbolic" onClicked: updateBackground("image") & backgroundTypePopup.close() + hoverEnabled: true } } } @@ -355,6 +357,7 @@ Item { text: "Audio" icon.name: "folder-music-symbolic" onClicked: updateAudioFile() + hoverEnabled: true /* background: Presenter.TextBackground { */ /* control: audioPickerButton */ /* } */ @@ -498,13 +501,13 @@ Item { } function updateAudioFile() { - const file = fileHelper.loadFile("Pick Audio"); + const file = fileHelper.loadFile("Pick Audio", "audio"); songProxyModel.songModel.updateAudio(songIndex, file); } function updateBackground(backgroundType) { song.backgroundType = backgroundType; - const file = fileHelper.loadFile("Pick Background"); + const file = fileHelper.loadFile("Pick Background", backgroundType); song.background = file; songProxyModel.songModel.updateBackground(songIndex, file); songProxyModel.songModel.updateBackgroundType(songIndex, backgroundType); diff --git a/src/rust/file_helper.rs b/src/rust/file_helper.rs index 903b209..a8b002a 100644 --- a/src/rust/file_helper.rs +++ b/src/rust/file_helper.rs @@ -4,6 +4,7 @@ mod file_helper { use rfd::FileDialog; use std::path::Path; + use tracing::{debug, debug_span, error, info, instrument}; unsafe extern "C++" { include!("cxx-qt-lib/qstring.h"); @@ -95,9 +96,33 @@ mod file_helper { pub fn load_file( self: Pin<&mut Self>, title: QString, + filter: QString, ) -> QUrl { + let video_filters = [ + "mp4", "webm", "avi", "mkv", "MP4", "WEBM", "AVI", + "MKV", + ]; + let image_filters = [ + "jpg", "png", "gif", "jpeg", "JPG", "PNG", "webp", + "gif", + ]; + let audio_filters = ["mp3", "opus", "ogg", "flac", "wav"]; let title = title.to_string(); - let file = FileDialog::new().set_title(title).pick_file(); + let filter = filter.to_string(); + let mut file = FileDialog::new().set_title(title); + match filter.as_str() { + "video" => { + file = file.add_filter(filter, &video_filters); + } + "image" => { + file = file.add_filter(filter, &image_filters); + } + "audio" => { + file = file.add_filter(filter, &audio_filters); + } + _ => debug!("nothing"), + }; + let file = file.pick_file(); if let Some(file) = file { println!("loading-file: {:?}", file); let mut string =