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
|
diff --git a/Qarma.cpp b/Qarma.cpp
index 3708360..d1599c5 100644
--- a/Qarma.cpp
+++ b/Qarma.cpp
@@ -34,6 +34,7 @@
#include <QFontDialog>
#include <QFormLayout>
#include <QIcon>
+#include <QImageReader>
#include <QInputDialog>
#include <QLabel>
#include <QLocale>
@@ -48,6 +49,7 @@
#include <QSettings>
#include <QSlider>
#include <QSocketNotifier>
+#include <QSplitter>
#include <QStringBuilder>
#include <QStringList>
#include <QTextBrowser>
@@ -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<QSplitter*>()) {
+ 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") }
}
|