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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include "FenPrincipale.h"
#include <qtconcurrentmap.h>
QImage scale(const QString &name)
{
QImage image(name);
return image.scaled(100, 100,Qt::KeepAspectRatio);
}
void FenPrincipale::traitementImages()
{
QTimer::singleShot(0 , this , SLOT( charger() ));
miniLayout = new QHBoxLayout;
QGroupBox *groupMiniatures = new QGroupBox("Miniatures:");
groupMiniatures->setLayout(miniLayout);
imageGrandeLayout = new QHBoxLayout;
QGroupBox *groupImageGrande = new QGroupBox("Image:");
groupImageGrande->setLayout(imageGrandeLayout);
QLabel *metaData = new QLabel;
QHBoxLayout *metaDataLayout = new QHBoxLayout;
metaDataLayout->addWidget(metaData);
QGroupBox *groupMetaData = new QGroupBox("Métadonnées:");
groupMetaData->setLayout(metaDataLayout);
QGridLayout *triLayout = new QGridLayout;
triLayout->addWidget(groupMetaData,0,0,1,1);
triLayout->addWidget(groupImageGrande,0,1,1,1);
triLayout->addWidget(groupMiniatures,1,0,1,2);
QWidget *w = new QWidget;
w->setLayout(triLayout);
mainLayout->addWidget(w);
}
void FenPrincipale::charger()
{
/*recupere un repertoire*/
QString s = QFileDialog::getExistingDirectory(this);
if(s.isEmpty()) return;
QDir imageDir(s);
QStringList fileFilter;
/*recupere toute les nom d'image*/
fileFilter << "*.png" << "*.jpg" <<"*.gif" << "*.bmp" << "*.ppm" << "*.pgm";
QStringList lImage = imageDir.entryList(fileFilter,QDir::Files);
/*ajoute le path des images*/
for(int i=0;i<lImage.size();++i)
{
lImage[i] = imageDir.absolutePath() + "/" + lImage[i];
}
pathImages = new QStringList;
pathImages = &lImage;
/*dialog avec bar de progression*/
QProgressDialog dialog
(
QString("Progression utilisant %1 thread(s)...").arg(QThread::idealThreadCount()),
"Stop",
0,100
);
/*futurewatcher recuperant l'avancement et le resultat du mapped*/
QFutureWatcher<QImage> futureWatcher;
QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int)));
QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));
/*a chaque nouvelle imagette genere on l'affiche*/
QObject::connect(&futureWatcher, SIGNAL(resultReadyAt ( int )),this,SLOT(newImage(int)));
/*lancement du mapped*/
futureWatcher.setFuture(QtConcurrent::mapped(lImage,scale ));
/*permet de certifier que futureWatcher et lImage ne sont pas détruit avant la fin du mapped*/
dialog.exec();
/*attend la fin des traitement en cours*/
futureWatcher.waitForFinished();
}
void FenPrincipale::newImage(int index)
{
/*on récuper le sender du signal connecte*/
QFutureWatcher<QImage> * watcher =static_cast< QFutureWatcher<QImage> * >(sender());
if (!watcher) return;
/*creation d'un QLabel et ajout dans le layout d'image*/
monLabel *label = new monLabel;
label->setPixmap( QPixmap::fromImage(watcher->resultAt (index)) );
label->setValue(index);
miniLayout->addWidget(label);
connect(label, SIGNAL(onClicked(int)), this, SLOT(afficheImageGrand(int)));
}
void FenPrincipale::afficheImageGrand(int i)
{
QLabel *imageGrande = new QLabel;
QMessageBox::critical(this, "test", pathImages->at(i));
//QImage image(pathImages->at(i));
//imageGrande->setPixmap(QPixmap::fromImage(image));
imageGrandeLayout->addWidget(imageGrande);
}
monLabel::monLabel(QWidget * parent,Qt::WindowFlags f) : QLabel(parent,f)
{
m_var=-1;
}
void monLabel::mouseReleaseEvent(QMouseEvent *)
{
emit onClicked(m_var);
}
void monLabel::setValue(int var)
{
m_var=var;
}
int monLabel::getValue()
{
return m_var;
} |
Partager