Commit 751c5944 authored by Boudewijn Rempt's avatar Boudewijn Rempt

BUG:342896 Stop the reference image loading thread of app exit

parent 2d9289f7
......@@ -19,6 +19,7 @@
#include <KoIcon.h>
#include <QApplication>
#include <QDir>
#include <QPainter>
#include <QHash>
......@@ -30,45 +31,30 @@
/////////////////////////////////////////////////////////////////////////////////////////////
// ------------- ImageLoader ---------------------------------------------------------- //
ImageLoader::ImageLoader(float size)
: m_size(size)
, m_run(true)
{
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(stopExecution()));
}
void ImageLoader::run()
{
typedef QHash<ImageItem*,Data>::iterator Iterator;
QImageReader reader;
#ifdef Q_OS_WIN
for(Iterator data=m_data.begin(); data!=m_data.end() && m_run; ++data) {
data->image = QImage(data->path).scaled(m_size, m_size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
data->isLoaded = true;
emit sigItemContentChanged(data.key());
}
#else
for(Iterator data=m_data.begin(); data!=m_data.end() && m_run; ++data) {
reader.setFileName(data->path);
qreal w = m_size;
qreal h = m_size;
if (reader.supportsOption(QImageIOHandler::Size)) {
QSizeF imgSize = reader.size();
if(imgSize.width() > imgSize.height()) {
qreal div = m_size / imgSize.width();
h = imgSize.height() * div;
}
else {
qreal div = m_size / imgSize.height();
w = imgSize.width() * div;
}
for (Iterator data = m_data.begin(); data != m_data.end() && m_run; ++data) {
QImage img = QImage(data->path);
if (!img.isNull()) {
data->image = img.scaled(m_size, m_size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
reader.setScaledSize(QSize(w,h));
data->image = reader.read();
data->isLoaded = true;
emit sigItemContentChanged(data.key());
}
#endif
}
void ImageLoader::stopExecution()
{
m_run = false;
}
......@@ -80,10 +66,10 @@ void ImageItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
Q_UNUSED(option);
Q_UNUSED(widget);
if(m_loader->isImageLoaded(this)) {
if (m_loader->isImageLoaded(this)) {
QImage image = m_loader->getImage(this);
if(!image.isNull()) {
if (!image.isNull()) {
QPointF offset((m_size-image.width()) / 2.0, (m_size-image.height()) / 2.0);
painter->drawImage(offset, image);
}
......@@ -101,8 +87,7 @@ void ImageItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option,
painter->drawPixmap(rect, img, img.rect());
}
if(isSelected())
{
if (isSelected()) {
painter->setCompositionMode(QPainter::CompositionMode_HardLight);
painter->setOpacity(0.50);
painter->fillRect(boundingRect().toRect(), palette().color(QPalette::Active, QPalette::Highlight));
......@@ -140,14 +125,14 @@ bool ImageStripScene::setCurrentDirectory(const QString& path)
QDir directory(path);
QImageReader reader;
if(directory.exists()) {
if (directory.exists()) {
clear();
if(m_loader) {
if (m_loader) {
m_loader->disconnect(this);
m_loader->stopExecution();
if(!m_loader->wait(500)) {
if (!m_loader->wait(500)) {
m_loader->terminate();
m_loader->wait();
}
......@@ -162,11 +147,11 @@ bool ImageStripScene::setCurrentDirectory(const QString& path)
QStringList files = directory.entryList(QDir::Files);
QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
for(QStringList::iterator name=files.begin(); name!=files.end(); ++name) {
for (QStringList::iterator name=files.begin(); name!=files.end(); ++name) {
QString path = directory.absoluteFilePath(*name);
reader.setFileName(path);
if(reader.canRead()) {
if (reader.canRead()) {
ImageItem* item = new ImageItem(m_imgSize, path, m_loader);
m_loader->addPath(item, path);
layout->addItem(item);
......@@ -198,6 +183,7 @@ void ImageStripScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event)
{
ImageItem* item = static_cast<ImageItem*>(itemAt(event->scenePos()));
if(item)
if (item)
emit sigImageActivated(item->path());
}
......@@ -48,7 +48,7 @@ signals:
void sigItemContentChanged(ImageItem* item);
public:
ImageLoader(float size): m_size(size), m_run(true) { }
ImageLoader(float size);
void addPath(ImageItem* item, const QString& path) {
m_data[item] = Data(path);
......@@ -61,13 +61,13 @@ public:
QImage getImage(ImageItem* item) const {
return m_data[item].image;
}
void stopExecution() {
m_run = false;
}
virtual void run();
public slots:
void stopExecution();
private:
float m_size;
QHash<ImageItem*,Data> m_data;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment