Repository navigation
Expand file tree
/
Copy pathimageitem.cpp
More file actions
95 lines (74 loc) · 2.51 KB
/
Copy pathimageitem.cpp
File metadata and controls
95 lines (74 loc) · 2.51 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "imageitem.h"
#include <QImageReader>
#include <QDebug>
#include "imagescalerunner.h"
#include <QThreadPool>
ImageItem::ImageItem(QString filename, QSize ThumbnailSize, QObject *parent) :QObject(parent), QListWidgetItem()
{
this->parent = parent;
this->filename = filename;
this->ThumbnailSize = ThumbnailSize;
// change font size to 1 -> minimize the gap between the Items
// #define SHOW_FILENAMES
#ifndef SHOW_FILENAMES
QFont f = this->font();
f.setPointSizeF(1);
this->setFont(f);
// set text color to transparent --> invisible
setForeground(Qt::transparent);
#else
// make text visible
//setForeground(Qt::white);
#endif
// read the image and scale:
//QImageReader reader(filename);
//QStringList sl = reader.textKeys();
//#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
//reader.setAutoTransform(true);
//#endif
//const QImage newImage = reader.read().scaled(200,200,Qt::KeepAspectRatio );
//const QImage scaledImage = newImage.scaled(200,200,Qt::KeepAspectRatio );
//icon = QIcon(QPixmap::fromImage(newImage));
//this->setIcon(icon);
//instead do this threaded to improve loading:
// threaded loading:
ImageScaleRunner *runner = new ImageScaleRunner(filename, this->ThumbnailSize); // do not set parent of runner thread as emit will fail
QObject::connect(runner, SIGNAL(finished(QString, QImage)), this, SLOT(thumbnailLoaded(QString, QImage)),Qt::QueuedConnection);
QThreadPool::globalInstance()->start(runner);
}
ImageItem::~ImageItem()
{
}
QImage ImageItem::getImage()
{
QImageReader reader(filename);
#if QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)
reader.setAutoTransform(true);
#endif
return reader.read();
}
void ImageItem::thumbnailLoaded(QString file, QImage img)
{
qDebug() << "thumbLoaded receiving " << file;
if(file != (this->filename))
qDebug() << "file != filename" << file << " != " << filename ;
icon = QIcon(QPixmap::fromImage(img));
this->setIcon(icon);
// set filename as text, this helps sorting the images. the text is hidden, see constructor
this->setText(this->filename);
}
inline bool ImageItem::operator<(const ImageItem &other ) const
{
qDebug() << "hello";
return filename < other.filename;
}
inline bool operator<(const ImageItem &i1 , const ImageItem &i2 )
{
qDebug() << "hello";
return i1.filename < i2.filename;
}
inline bool operator<(ImageItem &i1 , ImageItem &i2 )
{
qDebug() << "hello";
return i1.filename < i2.filename;
}