-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagethumbwidget.cpp
52 lines (44 loc) · 1.16 KB
/
imagethumbwidget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "imagethumbwidget.h"
#include "ui_imagethumbwidget.h"
#include <QImage>
#include <QMetaObject>
#include <resizeimage.h>
#include "mainwindow.h"
#include <QtConcurrent>
ImageThumbWidget::ImageThumbWidget(ImageInfo *Info,QWidget *parent) :
QWidget(parent),
ui(new Ui::ImageThumbWidget)
{
ui->setupUi(this);
ImgInfo=Info;
ui->NameLabel->setText(Info->Name);
static_cast<void>(QtConcurrent::run([this] {LoadThumb();}));
}
ImageThumbWidget::~ImageThumbWidget()
{
QMutexLocker lock(&mutex);
isDestroyed=true;
delete ui;
}
void ImageThumbWidget::onImgFileLoaded(void * ImgPtr) const
{
if (ImgPtr!=nullptr)
{
const QImage * Img=static_cast<QImage*>(ImgPtr);
ui->ImgLabel->setPixmap(QPixmap::fromImage(*Img));
delete Img;
}
}
void ImageThumbWidget::LoadThumb()
{
QMutexLocker lock(&mutex);
if (isDestroyed) return;
void * ImgPtr=nullptr;
const QImage OriginalImg(MainWindow::MainWindowPtr->GetThumbFileName(ImgInfo->FolderID,ImgInfo->Name));
if (!OriginalImg.isNull())
{
QImage * Img=ResizeImage::Resize(&OriginalImg,ThumbSize,ThumbSize);
ImgPtr=Img;
}
QMetaObject::invokeMethod(this,"onImgFileLoaded",Qt::QueuedConnection,Q_ARG(void *,ImgPtr));
}