switching to thumbnails from rust
This commit is contained in:
parent
30e552aa3d
commit
1ca9ab5fc4
2 changed files with 38 additions and 60 deletions
|
@ -718,7 +718,7 @@ QString SlideModel::thumbnailVideoRust(QString video, int serviceItemId, int ind
|
||||||
QFileInfo thumbnailInfo(dir.path() + "/" + vidName + ".jpg");
|
QFileInfo thumbnailInfo(dir.path() + "/" + vidName + ".jpg");
|
||||||
qDebug() << thumbnailInfo.filePath() << "FOR" << index;
|
qDebug() << thumbnailInfo.filePath() << "FOR" << index;
|
||||||
if (thumbnailInfo.exists()) {
|
if (thumbnailInfo.exists()) {
|
||||||
slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index);
|
// slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index);
|
||||||
return thumbnailInfo.filePath();
|
return thumbnailInfo.filePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -740,7 +740,7 @@ QString SlideModel::thumbnailVideoRust(QString video, int serviceItemId, int ind
|
||||||
qDebug() << QStringLiteral("Failed to save thumbnail for file: %1").arg(video);
|
qDebug() << QStringLiteral("Failed to save thumbnail for file: %1").arg(video);
|
||||||
}
|
}
|
||||||
|
|
||||||
slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index);
|
// slideModel->addVideoThumbnail("file://" + thumbnailInfo.absoluteFilePath(), serviceItemId, index);
|
||||||
|
|
||||||
return thumbnailInfo.filePath();
|
return thumbnailInfo.filePath();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,41 +27,23 @@ mod slide_model {
|
||||||
#[cxx_qt::qobject]
|
#[cxx_qt::qobject]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Slidey {
|
pub struct Slidey {
|
||||||
#[qproperty]
|
|
||||||
text: QString,
|
text: QString,
|
||||||
#[qproperty]
|
|
||||||
ty: QString,
|
ty: QString,
|
||||||
#[qproperty]
|
|
||||||
audio: QString,
|
audio: QString,
|
||||||
#[qproperty]
|
|
||||||
image_background: QString,
|
image_background: QString,
|
||||||
#[qproperty]
|
|
||||||
video_background: QString,
|
video_background: QString,
|
||||||
#[qproperty]
|
|
||||||
htext_alignment: QString,
|
htext_alignment: QString,
|
||||||
#[qproperty]
|
|
||||||
vtext_alignment: QString,
|
vtext_alignment: QString,
|
||||||
#[qproperty]
|
|
||||||
font: QString,
|
font: QString,
|
||||||
#[qproperty]
|
|
||||||
font_size: i32,
|
font_size: i32,
|
||||||
#[qproperty]
|
|
||||||
slide_count: i32,
|
slide_count: i32,
|
||||||
#[qproperty]
|
|
||||||
slide_index: i32,
|
slide_index: i32,
|
||||||
#[qproperty]
|
|
||||||
service_item_id: i32,
|
service_item_id: i32,
|
||||||
#[qproperty]
|
|
||||||
active: bool,
|
active: bool,
|
||||||
#[qproperty]
|
|
||||||
selected: bool,
|
selected: bool,
|
||||||
#[qproperty]
|
|
||||||
looping: bool,
|
looping: bool,
|
||||||
#[qproperty]
|
|
||||||
video_thumbnail: QString,
|
video_thumbnail: QString,
|
||||||
#[qproperty]
|
|
||||||
video_start_time: f32,
|
video_start_time: f32,
|
||||||
#[qproperty]
|
|
||||||
video_end_time: f32,
|
video_end_time: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,31 +108,26 @@ mod slide_model {
|
||||||
// use image::{ImageBuffer, Rgba};
|
// use image::{ImageBuffer, Rgba};
|
||||||
use crate::ffmpeg;
|
use crate::ffmpeg;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::thread;
|
||||||
impl qobject::SlideyMod {
|
impl qobject::SlideyMod {
|
||||||
pub fn video_thumbnail(mut self: Pin<&mut Self>, video: &QString) -> QString {
|
|
||||||
let video = video.to_string();
|
|
||||||
let path = PathBuf::from(video);
|
|
||||||
let video = ffmpeg::bg_from_video(&path);
|
|
||||||
|
|
||||||
QString::from(video.to_str().unwrap())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
pub fn add_video_thumbnail(
|
pub fn add_video_thumbnail(mut self: Pin<&mut Self>, index: i32) -> bool {
|
||||||
mut self: Pin<&mut Self>,
|
|
||||||
video: QString,
|
|
||||||
service_item_id: i32,
|
|
||||||
index: i32,
|
|
||||||
) {
|
|
||||||
let model_index = &self.as_ref().index(index, 0, &QModelIndex::default());
|
|
||||||
let mut vector_roles = QVector_i32::default();
|
let mut vector_roles = QVector_i32::default();
|
||||||
vector_roles.append(self.get_role(Role::VideoThumbnailRole));
|
vector_roles.append(self.get_role(Role::VideoThumbnailRole));
|
||||||
|
|
||||||
|
let model_index = &self.index(index, 0, &QModelIndex::default());
|
||||||
if let Some(slide) = self.as_mut().slides_mut().get_mut(index as usize) {
|
if let Some(slide) = self.as_mut().slides_mut().get_mut(index as usize) {
|
||||||
|
if !slide.video_background.is_empty() {
|
||||||
|
let path = PathBuf::from(slide.video_background.to_string());
|
||||||
|
let video = QString::from(ffmpeg::bg_from_video(&path).to_str().unwrap())
|
||||||
|
.insert(0, &QString::from("file://"))
|
||||||
|
.to_owned();
|
||||||
slide.video_thumbnail = video;
|
slide.video_thumbnail = video;
|
||||||
}
|
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.emit_data_changed(model_index, model_index, &vector_roles);
|
.emit_data_changed(model_index, model_index, &vector_roles);
|
||||||
println!("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
|
@ -207,15 +184,7 @@ mod slide_model {
|
||||||
fn add_slide(mut self: Pin<&mut Self>, slide: &Slidey) {
|
fn add_slide(mut self: Pin<&mut Self>, slide: &Slidey) {
|
||||||
let index = self.as_ref().slides().len() as i32;
|
let index = self.as_ref().slides().len() as i32;
|
||||||
println!("{:?}", slide);
|
println!("{:?}", slide);
|
||||||
let mut slide = slide.clone();
|
let slide = slide.clone();
|
||||||
if !&slide.video_background.is_empty() {
|
|
||||||
slide.video_thumbnail = self
|
|
||||||
.as_mut()
|
|
||||||
.video_thumbnail(&slide.video_background)
|
|
||||||
.insert(0, &QString::from("file://"))
|
|
||||||
.to_owned();
|
|
||||||
println!("rust-inserted: {:?}", slide.video_thumbnail);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
|
@ -223,26 +192,35 @@ mod slide_model {
|
||||||
self.as_mut().slides_mut().push(slide);
|
self.as_mut().slides_mut().push(slide);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
|
let thread = self.qt_thread();
|
||||||
|
thread::spawn(move || {
|
||||||
|
thread
|
||||||
|
.queue(move |slidemodel| {
|
||||||
|
slidemodel.add_video_thumbnail(index);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
|
// self.as_mut().add_video_thumbnail(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn insert_slide(mut self: Pin<&mut Self>, slide: &Slidey, id: i32) {
|
fn insert_slide(mut self: Pin<&mut Self>, slide: &Slidey, index: i32) {
|
||||||
let mut slide = slide.clone();
|
let mut slide = slide.clone();
|
||||||
slide.slide_index = id;
|
slide.slide_index = index;
|
||||||
if !&slide.video_background.is_empty() {
|
|
||||||
slide.video_thumbnail = self
|
|
||||||
.as_mut()
|
|
||||||
.video_thumbnail(&slide.video_background)
|
|
||||||
.insert(0, &QString::from("file://"))
|
|
||||||
.to_owned();
|
|
||||||
println!("rust-inserted: {:?}", slide.video_thumbnail);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
self.as_mut()
|
self.as_mut()
|
||||||
.begin_insert_rows(&QModelIndex::default(), id, id);
|
.begin_insert_rows(&QModelIndex::default(), index, index);
|
||||||
self.as_mut().slides_mut().insert(id as usize, slide);
|
self.as_mut().slides_mut().insert(index as usize, slide);
|
||||||
self.as_mut().end_insert_rows();
|
self.as_mut().end_insert_rows();
|
||||||
}
|
}
|
||||||
|
let thread = self.qt_thread();
|
||||||
|
thread::spawn(move || {
|
||||||
|
thread
|
||||||
|
.queue(move |slidemodel| {
|
||||||
|
slidemodel.add_video_thumbnail(index);
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[qinvokable]
|
#[qinvokable]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue