mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-01-14 08:50:08 -05:00
Improve file dialog filter for adding custom icons.
This commit is contained in:
parent
5a08e4619c
commit
ce0007acd2
@ -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
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user