-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathimageview.cpp
86 lines (67 loc) · 1.84 KB
/
imageview.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
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
#include <QtWidgets>
#include <QtGui>
#include <QtCore>
#include "threadedimageloader.h"
#include "QProgressIndicator.h"
#include "imagefile.h"
#include "imageview.h"
#include "utils.h"
#include "ui_imageview.h"
ImageView::ImageView(QWidget *parent)
: QStackedWidget(parent)
, ui(new Ui::ImageView)
, m_imageFile(nullptr)
, m_threadedImageLoader(new ThreadedImageLoader(this))
{
ui->setupUi(this);
// the image has been loaded
connect(m_threadedImageLoader, SIGNAL(loaded(QImage)), this, SLOT(slotImageFileLoaded(QImage)));
// proxying signals
connect(ui->imageViewer, SIGNAL(zoomChanged(double)), this, SIGNAL(zoomChanged(double)));
connect(ui->imageViewer, SIGNAL(platesChanged()), this, SIGNAL(platesChanged()));
}
ImageView::~ImageView()
{
delete ui;
}
void ImageView::setImageFile(ImageFile *imageFile)
{
qDebug("Loading image '%s'", qPrintable(imageFile->fileInfo().canonicalFilePath()));
if(busy())
return;
m_imageFile = imageFile;
setCurrentIndex(0);
ui->progress->startAnimation();
m_threadedImageLoader->loadImageFromFile(imageFile->fileInfo().canonicalFilePath());
}
bool ImageView::busy() const
{
return m_threadedImageLoader->isRunning();
}
void ImageView::reset()
{
if(busy())
return;
setCurrentIndex(0);
m_imageFile = nullptr;
ui->imageViewer->reset();
}
void ImageView::setImage(const QImage &image)
{
if(!m_imageFile)
return;
setCurrentIndex(1);
ui->progress->stopAnimation();
ui->imageViewer->setImageFile(m_imageFile);
ui->imageViewer->setImage(image);
}
void ImageView::slotImageFileLoaded(const QImage &image)
{
if(image.isNull())
{
setCurrentIndex(1);
Utils::error(tr("Cannot load the specified image. Possibly it's corrupted"), this);
return;
}
setImage(image);
}