void MainWindow
::populateModel( QStringList fileNames,
int sizeW,
int sizeH
) {
listView
->setIconSize
( QSize( sizeW
+10, sizeH
+10 ) );
tableView
->setIconSize
( QSize( 100,
75 ) );
model.setRowCount( fileNames.length() );
model.setColumnCount( 8 );
model.
setHorizontalHeaderLabels( QStringList() <<
"Miniaturka" <<
"Ścieżka" <<
"Wymiar zdjęcia" <<
"Rozmiar pliku" );
for( int i = 0; i < fileNames.length(); ++i)
{
imgRead.setFileName( fileNames[i] );
tmp.loadFromData( imgRead.readAll() );
imgRead.close();
if( tmp.width() > sizeW || tmp.height() > sizeH ){
//for speed first fast scalle then smooth
thumb = tmp.scaled( sizeW, sizeH ).scaled( sizeW, sizeH, Qt::KeepAspectRatio, Qt::SmoothTransformation );
}else{
thumb = tmp.scaled( 640, 480).scaled( sizeW, sizeH, Qt::KeepAspectRatio, Qt::SmoothTransformation );
}
rowsNumbers.
append( QVariant(i
+1).
toString() );
tableView->setRowHeight( i, 75 );
tableView->setColumnWidth( 0, 100 );
model.setData( model.index( i, 0 ), thumb, Qt::DecorationRole );
model.setData( model.index( i, 1 ), fileNames[i], Qt::DisplayRole );
model.
setData( model.
index( i,
2 ),
QVariant( tmp.
width() ).
toString() + "X" + QVariant( tmp.
height() ).
toString() , Qt::DisplayRole );
model.
setData( model.
index( i,
3 ),
QVariant( fi.
size()/1024 ).
toString() + " KB", Qt
::DisplayRole );
model.
setData( model.
index( i,
4 ),
QVariant(tmp.
width()).
toString(), Qt
::DisplayRole );
model.
setData( model.
index( i,
5 ),
QVariant(tmp.
height()).
toString(), Qt
::DisplayRole );
model.setData( model.index( i, 6 ), fi.fileName(), Qt::DisplayRole );
model.setData( model.index( i, 7 ), thumb, Qt::DecorationRole );
}
}
void MainWindow::populateModel( QStringList fileNames, int sizeW, int sizeH )
{
listView->setIconSize( QSize( sizeW+10, sizeH+10 ) );
tableView->setIconSize( QSize( 100, 75 ) );
QStringList rowsNumbers;
QPixmap thumb, tmp;
QFile imgRead;
model.setRowCount( fileNames.length() );
model.setColumnCount( 8 );
model.setHorizontalHeaderLabels( QStringList() << "Miniaturka" << "Ścieżka" << "Wymiar zdjęcia" << "Rozmiar pliku" );
for( int i = 0; i < fileNames.length(); ++i)
{
imgRead.setFileName( fileNames[i] );
imgRead.open( QIODevice::ReadOnly );
tmp.loadFromData( imgRead.readAll() );
imgRead.close();
if( tmp.width() > sizeW || tmp.height() > sizeH ){
//for speed first fast scalle then smooth
thumb = tmp.scaled( sizeW, sizeH ).scaled( sizeW, sizeH, Qt::KeepAspectRatio, Qt::SmoothTransformation );
}else{
thumb = tmp.scaled( 640, 480).scaled( sizeW, sizeH, Qt::KeepAspectRatio, Qt::SmoothTransformation );
}
rowsNumbers.append( QVariant(i+1).toString() );
tableView->setRowHeight( i, 75 );
tableView->setColumnWidth( 0, 100 );
QFileInfo fi( fileNames[i] );
model.setData( model.index( i, 0 ), thumb, Qt::DecorationRole );
model.setData( model.index( i, 1 ), fileNames[i], Qt::DisplayRole );
model.setData( model.index( i, 2 ), QVariant( tmp.width() ).toString() + "X" + QVariant( tmp.height() ).toString()
, Qt::DisplayRole );
model.setData( model.index( i, 3 ), QVariant( fi.size()/1024 ).toString() + " KB", Qt::DisplayRole );
model.setData( model.index( i, 4 ), QVariant(tmp.width()).toString(), Qt::DisplayRole );
model.setData( model.index( i, 5 ), QVariant(tmp.height()).toString(), Qt::DisplayRole );
model.setData( model.index( i, 6 ), fi.fileName(), Qt::DisplayRole );
model.setData( model.index( i, 7 ), thumb, Qt::DecorationRole );
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks