1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Refactor image filter as discussed

This commit is contained in:
Dubslow 2015-02-15 17:35:27 -06:00
parent 484fb2e89c
commit 07b87616a2
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
3 changed files with 11 additions and 10 deletions

View File

@ -5,6 +5,7 @@
#include "widget/gui.h"
#include <QThread>
#include <QDebug>
#include <QImageReader>
#ifdef Q_OS_ANDROID
#include <src/widget/androidgui.h>
@ -154,3 +155,11 @@ Widget* Nexus::getDesktopGUI()
{
return getInstance().widget;
}
QString Nexus::getSupportedImageFilter()
{
QString res;
for (auto type : QImageReader::supportedImageFormats())
res += QString("*.%1 ").arg(QString(type));
return tr("Images (%1)", "filetype filter").arg(res.left(res.size()-1));
}

View File

@ -22,6 +22,7 @@ public:
static Core* getCore(); ///< Will return 0 if not started
static AndroidGUI* getAndroidGUI(); ///< Will return 0 if not started
static Widget* getDesktopGUI(); ///< Will return 0 if not started
static QString getSupportedImageFilter();
private:
explicit Nexus(QObject *parent = 0);

View File

@ -348,19 +348,10 @@ QString Widget::getUsername()
void Widget::onAvatarClicked()
{
QList<QByteArray> typeList = QImageReader::supportedImageFormats();
QString filter("Images (");
for(auto i=typeList.begin(); i!=typeList.end(); i++)
{
filter.append("*.");
filter.append(*i);
filter.append(" ");
}
filter[filter.size()-1] = ')';//take the last space and close the () instead
QString filename = QFileDialog::getOpenFileName(this,
tr("Choose a profile picture"),
QDir::homePath(),
filter);
Nexus::getSupportedImageFilter());
if (filename.isEmpty())
return;
QFile file(filename);