Improve file dialog filter for adding custom icons.

This commit is contained in:
Felix Geyer 2012-05-10 18:09:42 +02:00
parent 5a08e4619c
commit ce0007acd2
3 changed files with 24 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <QtCore/QIODevice> #include <QtCore/QIODevice>
#include <QtCore/QLocale> #include <QtCore/QLocale>
#include <QtCore/QStringList> #include <QtCore/QStringList>
#include <QtGui/QImageReader>
namespace Tools { namespace Tools {
@ -84,4 +85,22 @@ QDateTime currentDateTimeUtc ()
#endif #endif
} }
QString imageReaderFilter()
{
QList<QByteArray> formats = QImageReader::supportedImageFormats();
QStringList formatsStringList;
Q_FOREACH (const QByteArray& format, formats) {
for (int i = 0; i < format.size(); i++) {
if (!QChar(format.at(i)).isLetterOrNumber()) {
continue;
}
}
formatsStringList.append("*." + QString::fromAscii(format).toLower());
}
return formatsStringList.join(" ");
}
} // namespace Tools } // namespace Tools

View File

@ -30,6 +30,7 @@ QString humanReadableFileSize(qint64 bytes);
bool hasChild(const QObject* parent, const QObject* child); bool hasChild(const QObject* parent, const QObject* child);
bool readAllFromDevice(QIODevice* device, QByteArray& data); bool readAllFromDevice(QIODevice* device, QByteArray& data);
QDateTime currentDateTimeUtc(); QDateTime currentDateTimeUtc();
QString imageReaderFilter();
} // namespace Tools } // namespace Tools

View File

@ -422,8 +422,11 @@ void EditEntryWidget::removeCurrentAttachment()
void EditEntryWidget::addCustomIcon() void EditEntryWidget::addCustomIcon()
{ {
if (m_metadata) { if (m_metadata) {
QString filter = QString("%1 (%2);;%3 (*.*)").arg(tr("Images"),
Tools::imageReaderFilter(), tr("All files"));
QString filename = QFileDialog::getOpenFileName( QString filename = QFileDialog::getOpenFileName(
this, tr("Select Image"), "", tr("Image Files (*.png *.jpg *.bmp)")); this, tr("Select Image"), "", filter);
if (!filename.isEmpty()) { if (!filename.isEmpty()) {
QImage image(filename); QImage image(filename);
if (!image.isNull()) { if (!image.isNull()) {