From 4992b189f4ef11ff7439ab623ad3791f59407351 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 24 Dec 2018 17:31:40 +1100 Subject: [PATCH] make square version of thumb for icon view --- io/previewgenerator.cpp | 6 ++++-- mainwindow.cpp | 18 +++++++++--------- project/footage.cpp | 14 ++++++++++++++ project/footage.h | 3 +++ project/media.cpp | 7 ++++--- ui/otreeview.cpp | 9 +++++++++ ui/otreeview.h | 16 ++++++++++++++++ 7 files changed, 59 insertions(+), 14 deletions(-) create mode 100644 ui/otreeview.cpp create mode 100644 ui/otreeview.h diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index 696c7987a..40a8d9d3b 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -128,6 +128,7 @@ bool PreviewGenerator::retrieve_preview(const QString& hash) { QFile f(thumb_path); if (f.exists() && ms->video_preview.load(thumb_path)) { //dout << "loaded thumb" << ms->file_index << "from" << thumb_path; + ms->make_square_thumb(); ms->preview_done = true; } else { found = false; @@ -263,7 +264,7 @@ void PreviewGenerator::generate_waveform() { static_cast(temp_frame->format), dstW, dstH, - static_cast(AV_PIX_FMT_RGB24), + static_cast(AV_PIX_FMT_RGBA), SWS_FAST_BILINEAR, NULL, NULL, @@ -274,7 +275,8 @@ void PreviewGenerator::generate_waveform() { linesize[0] = dstW*3; sws_scale(sws_ctx, temp_frame->data, temp_frame->linesize, 0, temp_frame->height, &data, linesize); - s->video_preview = QImage(data, dstW, dstH, linesize[0], QImage::Format_RGB888); + s->video_preview = QImage(data, dstW, dstH, linesize[0], QImage::Format_RGBA8888); + s->make_square_thumb(); // is video interlaced? s->video_auto_interlacing = (temp_frame->interlaced_frame) ? ((temp_frame->top_field_first) ? VIDEO_TOP_FIELD_FIRST : VIDEO_BOTTOM_FIELD_FIRST) : VIDEO_PROGRESSIVE; diff --git a/mainwindow.cpp b/mainwindow.cpp index ee01aa846..adc24850e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -130,15 +130,6 @@ MainWindow::MainWindow(QWidget *parent) : layout()->invalidate(); - // TODO maybe replace these with non-pointers later on? - panel_sequence_viewer = new Viewer(this); - panel_footage_viewer = new Viewer(this); - panel_project = new Project(this); - panel_effect_controls = new EffectControls(this); - panel_timeline = new Timeline(this); - - setup_layout(false); - connect(ui->menuWindow, SIGNAL(aboutToShow()), this, SLOT(windowMenu_About_To_Be_Shown())); connect(ui->menu_View, SIGNAL(aboutToShow()), this, SLOT(viewMenu_About_To_Be_Shown())); connect(ui->menu_Tools, SIGNAL(aboutToShow()), this, SLOT(toolMenu_About_To_Be_Shown())); @@ -215,6 +206,15 @@ MainWindow::MainWindow(QWidget *parent) : } } + // TODO maybe replace these with non-pointers later on? + panel_sequence_viewer = new Viewer(this); + panel_footage_viewer = new Viewer(this); + panel_project = new Project(this); + panel_effect_controls = new EffectControls(this); + panel_timeline = new Timeline(this); + + setup_layout(false); + init_audio(); connect(ui->action_Undo, SIGNAL(triggered(bool)), this, SLOT(undo())); diff --git a/project/footage.cpp b/project/footage.cpp index 6dc841eb7..b54f5a4a3 100644 --- a/project/footage.cpp +++ b/project/footage.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "io/previewgenerator.h" extern "C" { @@ -55,3 +56,16 @@ FootageStream* Footage::get_stream_from_file_index(bool video, int index) { } return NULL; } + +void FootageStream::make_square_thumb() { + // generate square version for QListView? + int square_size = qMax(video_preview.width(), video_preview.height()); + QPixmap pixmap(square_size, square_size); + pixmap.fill(Qt::transparent); + QPainter p(&pixmap); + int diff = (video_preview.width() - video_preview.height())>>1; + int sqx = (diff < 0) ? -diff : 0; + int sqy = (diff > 0) ? diff : 0; + p.drawImage(sqx, sqy, video_preview); + video_preview_square = QIcon(pixmap); +} diff --git a/project/footage.h b/project/footage.h index 55442e3ed..015253173 100644 --- a/project/footage.h +++ b/project/footage.h @@ -7,6 +7,7 @@ #include #include #include +#include #define VIDEO_PROGRESSIVE 0 #define VIDEO_TOP_FIELD_FIRST 1 @@ -32,7 +33,9 @@ struct FootageStream { // preview thumbnail/waveform bool preview_done; QImage video_preview; + QIcon video_preview_square; QVector audio_preview; + void make_square_thumb(); }; struct Footage { diff --git a/project/media.cpp b/project/media.cpp index 4be8add33..cec9c7f8f 100644 --- a/project/media.cpp +++ b/project/media.cpp @@ -8,6 +8,8 @@ #include "panels/project.h" #include "projectmodel.h" +#include + #include "debug.h" extern "C" { @@ -253,12 +255,11 @@ QVariant Media::data(int column, int role) { switch (role) { case Qt::DecorationRole: if (column == 0) { - if (config.project_view_type == PROJECT_VIEW_ICON - && get_type() == MEDIA_TYPE_FOOTAGE) { + if (get_type() == MEDIA_TYPE_FOOTAGE) { Footage* f = to_footage(); if (f->video_tracks.size() > 0 && f->video_tracks.at(0)->preview_done) { - return QIcon(QPixmap::fromImage(f->video_tracks.at(0)->video_preview)); + return f->video_tracks.at(0)->video_preview_square; } } diff --git a/ui/otreeview.cpp b/ui/otreeview.cpp new file mode 100644 index 000000000..9ea03a828 --- /dev/null +++ b/ui/otreeview.cpp @@ -0,0 +1,9 @@ +#include "otreeview.h" + +OTreeView::OTreeView(QWidget *parent) : QTreeView(parent) { + setSortingEnabled(true); + sortByColumn(0, Qt::AscendingOrder); + setContextMenuPolicy(Qt::CustomContextMenu); + connect(this, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(show_context_menu())); + connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(item_click(const QModelIndex&))); +} diff --git a/ui/otreeview.h b/ui/otreeview.h new file mode 100644 index 000000000..810f8b5ec --- /dev/null +++ b/ui/otreeview.h @@ -0,0 +1,16 @@ +#ifndef OTREEVIEW_H +#define OTREEVIEW_H + +#include + +#include "ui/sourcetable.h" + +class OTreeView : public QTreeView { + Q_OBJECT +public: + OTreeView(QWidget* parent = 0); +private: + +}; + +#endif // OTREEVIEW_H