make square version of thumb for icon view

This commit is contained in:
itsmattkc
2018-12-24 17:31:40 +11:00
parent ceb0078b2e
commit 4992b189f4
7 changed files with 59 additions and 14 deletions
+14
View File
@@ -2,6 +2,7 @@
#include <QDebug>
#include <QtMath>
#include <QPainter>
#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);
}
+3
View File
@@ -7,6 +7,7 @@
#include <QVariant>
#include <QMutex>
#include <QPixmap>
#include <QIcon>
#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<char> audio_preview;
void make_square_thumb();
};
struct Footage {
+4 -3
View File
@@ -8,6 +8,8 @@
#include "panels/project.h"
#include "projectmodel.h"
#include <QPainter>
#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;
}
}