forked from gnudles/stereograma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
imagefiledialog.cpp
54 lines (49 loc) · 1.21 KB
/
imagefiledialog.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
#include "imagefiledialog.h"
#include <QMessageBox>
#include <QLayout>
#include <QSplitter>
#include <QDebug>
void ImageFileDialog::init()
{
_preview = 0;
QSplitter *splitter;
splitter = ((QFileDialog*)this)->findChild<QSplitter*>("splitter");
if (splitter == 0)
{
return;
}
_preview = new QLabel();
QRect geomerty = _preview->geometry();
geomerty.setWidth(160);
_preview->setGeometry(geomerty);
splitter->addWidget(_preview);
connect(this, SIGNAL(currentChanged(QString)),
this, SLOT(fileChanged(QString)));
}
void ImageFileDialog::deinit()
{
if (_preview != 0)
{
delete _preview;
_preview=0;
}
}
void ImageFileDialog::fileChanged(const QString &file)
{
if (_preview == 0)
{
return;
}
QImage img=QImage(file);
if (img.isNull())
{
_preview->setPixmap(QPixmap());
}
else
{
QSize size = _preview->size();
QImage smallimage=img.convertToFormat(QImage::Format_ARGB32).scaled(size, Qt::KeepAspectRatio);
QPixmap pix=QPixmap::fromImage(smallimage);
_preview->setPixmap(pix);
}
}