@@ -57,7 +57,7 @@
|
||||
#include <QtEvents>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkInterface>
|
||||
#include <QImageReader>
|
||||
#include <QMimeDatabase>
|
||||
#include <QtDebug>
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||
# include <QRandomGenerator>
|
||||
@@ -102,9 +102,6 @@
|
||||
|
||||
namespace Utilities {
|
||||
|
||||
QStringList kSupportedImageMimeTypes;
|
||||
QStringList kSupportedImageFormats;
|
||||
|
||||
static QString tr(const char *str) {
|
||||
return QCoreApplication::translate("", str);
|
||||
}
|
||||
@@ -945,41 +942,23 @@ bool IsColorDark(const QColor &color) {
|
||||
return ((30 * color.red() + 59 * color.green() + 11 * color.blue()) / 100) <= 130;
|
||||
}
|
||||
|
||||
QStringList SupportedImageMimeTypes() {
|
||||
QByteArray ReadDataFromFile(const QString &filename) {
|
||||
|
||||
if (kSupportedImageMimeTypes.isEmpty()) {
|
||||
for (const QByteArray &mimetype : QImageReader::supportedMimeTypes()) {
|
||||
kSupportedImageMimeTypes << mimetype;
|
||||
}
|
||||
QFile file(filename);
|
||||
QByteArray data;
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
data = file.readAll();
|
||||
file.close();
|
||||
}
|
||||
|
||||
return kSupportedImageMimeTypes;
|
||||
return data;
|
||||
|
||||
}
|
||||
|
||||
QStringList SupportedImageFormats() {
|
||||
QString MimeTypeFromData(const QByteArray &data) {
|
||||
|
||||
if (kSupportedImageFormats.isEmpty()) {
|
||||
for (const QByteArray &filetype : QImageReader::supportedImageFormats()) {
|
||||
kSupportedImageFormats << filetype;
|
||||
}
|
||||
}
|
||||
if (data.isEmpty()) return QString();
|
||||
|
||||
return kSupportedImageFormats;
|
||||
|
||||
}
|
||||
|
||||
QList<QByteArray> ImageFormatsForMimeType(const QByteArray &mimetype) {
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 12, 0))
|
||||
return QImageReader::imageFormatsForMimeType(mimetype);
|
||||
#else
|
||||
if (mimetype == "image/bmp") return QList<QByteArray>() << "BMP";
|
||||
else if (mimetype == "image/gif") return QList<QByteArray>() << "GIF";
|
||||
else if (mimetype == "image/jpeg") return QList<QByteArray>() << "JPG";
|
||||
else if (mimetype == "image/png") return QList<QByteArray>() << "PNG";
|
||||
else return QList<QByteArray>();
|
||||
#endif
|
||||
return QMimeDatabase().mimeTypeForData(data).name();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user