diff --git a/Qarma.cpp b/Qarma.cpp index 3708360..d1599c5 100644 --- a/Qarma.cpp +++ b/Qarma.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -785,6 +787,21 @@ char Qarma::showMessage(const QStringList &args, char type) return 0; } +QPixmap thumbnail(const QString &path, uint size) +{ + QImageReader thumbReader; + thumbReader.setFileName(path); + thumbReader.setQuality(50); + QSize sz = thumbReader.size(); + sz.scale(QSize(size,size), Qt::KeepAspectRatio); + thumbReader.setScaledSize(sz); + QImage thumb; + if (thumbReader.read(&thumb)) + return QPixmap::fromImage(thumb); + else + return QPixmap(); +} + char Qarma::showFileSelection(const QStringList &args) { QFileDialog *dlg = new QFileDialog; @@ -827,6 +844,16 @@ char Qarma::showFileSelection(const QStringList &args) if (idx > -1) mimeFilter = mimeFilter.left(idx).trimmed() + " (" + mimeFilter.mid(idx+1).trimmed() + ")"; mimeFilters << mimeFilter; + } else if (args.at(i) == "--preview-images") { + READ_INT(size, UInt, "--preview-images must be followed by a positive number for the thumbnail size"); + dlg->setOption(QFileDialog::DontUseNativeDialog); + if (QSplitter *splitter = dlg->findChild()) { + QLabel *preview = new QLabel(splitter); + splitter->addWidget(preview); + connect(dlg, &QFileDialog::currentChanged, [=](const QString &path) { + preview->setPixmap(thumbnail(path, size)); + }); + } } else { WARN_UNKNOWN_ARG("--file-selection") } }