feat: cli argument to list supported image formats

This commit is contained in:
Gary Wang 2024-07-28 16:16:20 +08:00
parent cd01a05f23
commit a6e31a2c4d
No known key found for this signature in database
GPG Key ID: 5D30A4F15EA78760
3 changed files with 24 additions and 7 deletions

View File

@ -40,13 +40,20 @@ int main(int argc, char *argv[])
a.setApplicationName("Pineapple Pictures"); a.setApplicationName("Pineapple Pictures");
a.setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures")); a.setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures"));
// commandline options
QCommandLineOption supportedImageFormats(QStringLiteral("supported-image-formats"), QCoreApplication::translate("main", "List supported image format suffixes, and quit program."));
// parse commandline arguments // parse commandline arguments
QCommandLineParser parser; QCommandLineParser parser;
parser.addOption(supportedImageFormats);
parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list.")); parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list."));
parser.addHelpOption(); parser.addHelpOption();
parser.process(a); parser.process(a);
if (parser.isSet(supportedImageFormats)) {
fputs(qPrintable(MainWindow::supportedImageFormats().join(QChar('\n'))), stdout);
::exit(EXIT_SUCCESS);
}
MainWindow w; MainWindow w;
w.show(); w.show();

View File

@ -57,12 +57,7 @@ MainWindow::MainWindow(QWidget *parent)
this->setWindowIcon(QIcon(":/icons/app-icon.svg")); this->setWindowIcon(QIcon(":/icons/app-icon.svg"));
this->setMouseTracking(true); this->setMouseTracking(true);
// related to jfif: https://codereview.qt-project.org/c/qt/qtbase/+/577730 m_pm->setAutoLoadFilterSuffixes(supportedImageFormats());
QStringList formatFilters{ QStringLiteral("*.jfif") };
for (const QByteArray &item : QImageReader::supportedImageFormats()) {
formatFilters.append(QStringLiteral("*.") % QString::fromLocal8Bit(item));
}
m_pm->setAutoLoadFilterSuffixes(formatFilters);
m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity"); m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity");
m_fadeOutAnimation->setDuration(300); m_fadeOutAnimation->setDuration(300);
@ -278,6 +273,19 @@ void MainWindow::galleryCurrent()
} }
} }
QStringList MainWindow::supportedImageFormats()
{
QStringList formatFilters {
#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
QStringLiteral("*.jfif")
#endif // QT_VERSION < QT_VERSION_CHECK(6, 8, 0)
};
for (const QByteArray &item : QImageReader::supportedImageFormats()) {
formatFilters.append(QStringLiteral("*.") % QString::fromLocal8Bit(item));
}
return formatFilters;
}
void MainWindow::showEvent(QShowEvent *event) void MainWindow::showEvent(QShowEvent *event)
{ {
updateWidgetsPosition(); updateWidgetsPosition();

View File

@ -47,6 +47,8 @@ public:
void galleryNext(); void galleryNext();
void galleryCurrent(); void galleryCurrent();
static QStringList supportedImageFormats();
protected slots: protected slots:
void showEvent(QShowEvent *event) override; void showEvent(QShowEvent *event) override;
void enterEvent(QT_ENTER_EVENT *event) override; void enterEvent(QT_ENTER_EVENT *event) override;