chore: make use of Qt::Literals::StringLiterals u""_s

Migrate string literal handling to Qt’s built‐in `u""_s` literals for consistency and readability.
This commit is contained in:
2025-05-31 13:10:21 +08:00
committed by GitHub
parent 291a98ea97
commit 3f7ebd2f6c
5 changed files with 154 additions and 150 deletions

View File

@ -14,6 +14,8 @@
#include <QPushButton>
#include <QFile>
using namespace Qt::Literals::StringLiterals;
AboutDialog::AboutDialog(QWidget *parent)
: QDialog(parent)
, m_tabWidget(new QTabWidget)
@ -27,60 +29,60 @@ AboutDialog::AboutDialog(QWidget *parent)
this->setWindowTitle(tr("About"));
const QStringList helpStr {
QStringLiteral("<p>%1</p>").arg(tr("Launch application with image file path as argument to load the file.")),
QStringLiteral("<p>%1</p>").arg(tr("Drag and drop image file onto the window is also supported.")),
QStringLiteral("<p>%1</p>").arg(tr("None of the operations in this application will alter the pictures on disk.")),
QStringLiteral("<p>%1</p>").arg(tr("Context menu option explanation:")),
QStringLiteral("<ul>"),
u"<p>%1</p>"_s.arg(tr("Launch application with image file path as argument to load the file.")),
u"<p>%1</p>"_s.arg(tr("Drag and drop image file onto the window is also supported.")),
u"<p>%1</p>"_s.arg(tr("None of the operations in this application will alter the pictures on disk.")),
u"<p>%1</p>"_s.arg(tr("Context menu option explanation:")),
u"<ul>"_s,
// blumia: Chain two arg() here since it seems lupdate will remove one of them if we use
// the old `arg(QCoreApp::translate(), tr())` way, but it's worth to mention
// `arg(QCoreApp::translate(), this->tr())` works, but lupdate will complain about the usage.
QStringLiteral("<li><b>%1</b>:<br/>%2</li>")
.arg(QCoreApplication::translate("MainWindow", "Stay on top"))
.arg(tr("Make window stay on top of all other windows.")),
QStringLiteral("<li><b>%1</b>:<br/>%2</li>")
.arg(QCoreApplication::translate("MainWindow", "Protected mode"))
.arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")),
QStringLiteral("<li><b>%1</b>:<br/>%2</li>")
.arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view"))
.arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")),
QStringLiteral("</ul>")
u"<li><b>%1</b>:<br/>%2</li>"_s
.arg(QCoreApplication::translate("MainWindow", "Stay on top"))
.arg(tr("Make window stay on top of all other windows.")),
u"<li><b>%1</b>:<br/>%2</li>"_s
.arg(QCoreApplication::translate("MainWindow", "Protected mode"))
.arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")),
u"<li><b>%1</b>:<br/>%2</li>"_s
.arg(QCoreApplication::translate("MainWindow", "Keep transformation", "The 'transformation' means the flip/rotation status that currently applied to the image view"))
.arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")),
u"</ul>"_s
};
const QStringList aboutStr {
QStringLiteral("<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"),
u"<center><img width='128' height='128' src=':/icons/app-icon.svg'/><br/>"_s,
qApp->applicationDisplayName(),
(QStringLiteral("<br/>") + tr("Version: %1").arg(
(u"<br/>"_s + tr("Version: %1").arg(
#ifdef GIT_DESCRIBE_VERSION_STRING
GIT_DESCRIBE_VERSION_STRING
#else
qApp->applicationVersion()
#endif // GIT_DESCRIBE_VERSION_STRING
)),
QStringLiteral("<hr/>"),
u"<hr/>"_s,
tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)")
.arg(QStringLiteral("2025"), QStringLiteral("<a href='https://github.com/BLumia'>@BLumia</a>")),
QStringLiteral("<br/>"),
tr("Logo designed by %1").arg(QStringLiteral("<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>")),
QStringLiteral("<hr/>"),
.arg(u"2025"_s, u"<a href='https://github.com/BLumia'>@BLumia</a>"_s),
u"<br/>"_s,
tr("Logo designed by %1").arg(u"<a href='https://github.com/Lovelyblack'>@Lovelyblack</a>"_s),
u"<hr/>"_s,
tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()),
QStringLiteral("<br/><a href='%1'>%2</a>").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")),
QStringLiteral("</center>")
u"</center>"_s
};
QFile translaterHtml(":/plain/translators.html");
QFile translaterHtml(u":/plain/translators.html"_s);
bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly);
const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral("");
const QStringList specialThanksStr {
QStringLiteral("<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>").arg(
u"<h1 align='center'>%1</h1><a href='%2'>%3</a><p>%4</p>"_s.arg(
tr("Contributors"),
QStringLiteral("https://github.com/BLumia/pineapple-pictures/graphs/contributors"),
u"https://github.com/BLumia/pineapple-pictures/graphs/contributors"_s,
tr("List of contributors on GitHub"),
tr("Thanks to all people who contributed to this project.")
),
QStringLiteral("<h1 align='center'>%1</h1><p>%2</p>%3").arg(
u"<h1 align='center'>%1</h1><p>%2</p>%3"_s.arg(
tr("Translators"),
tr("I would like to thank the following people who volunteered to translate this application."),
translatorList
@ -88,17 +90,17 @@ AboutDialog::AboutDialog(QWidget *parent)
};
const QStringList licenseStr {
QStringLiteral("<h1 align='center'><b>%1</b></h1>").arg(tr("Your Rights")),
QStringLiteral("<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>").arg(
u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Your Rights")),
u"<p>%1</p><p>%2</p><ul><li>%3</li><li>%4</li><li>%5</li><li>%6</li></ul>"_s.arg(
tr("%1 is released under the MIT License."), // %1
tr("This license grants people a number of freedoms:"), // %2
tr("You are free to use %1, for any purpose"), // %3
tr("You are free to distribute %1"), // %4
tr("You can study how %1 works and change it"), // %5
tr("You can distribute changed versions of %1") // %6
).arg(QStringLiteral("<i>%1</i>")),
QStringLiteral("<p>%1</p>").arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")),
QStringLiteral("<hr/><pre>%2</pre>")
).arg(u"<i>%1</i>"_s),
u"<p>%1</p>"_s.arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")),
u"<hr/><pre>%2</pre>"_s
};
const QString mitLicense(QStringLiteral(R"(Expat/MIT License
@ -125,14 +127,14 @@ SOFTWARE.
)"));
const QStringList thirdPartyLibsStr {
QStringLiteral("<h1 align='center'><b>%1</b></h1>").arg(tr("Third-party Libraries used by %1")),
u"<h1 align='center'><b>%1</b></h1>"_s.arg(tr("Third-party Libraries used by %1")),
tr("%1 is built on the following free software libraries:", "Free as in freedom"),
QStringLiteral("<ul>"),
u"<ul>"_s,
#ifdef HAVE_EXIV2_VERSION
QStringLiteral("<li><a href='%1'>%2</a>: %3</li>").arg("https://www.exiv2.org/", "Exiv2", "GPLv2"),
u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.exiv2.org/", "Exiv2", "GPLv2"),
#endif // EXIV2_VERSION
QStringLiteral("<li><a href='%1'>%2</a>: %3</li>").arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"),
QStringLiteral("</ul>")
u"<li><a href='%1'>%2</a>: %3</li>"_s.arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"),
u"</ul>"_s
};
m_helpTextEdit->setText(helpStr.join('\n'));
@ -145,7 +147,7 @@ SOFTWARE.
m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense));
m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(QStringLiteral("<i>%1</i>").arg(qApp->applicationDisplayName())));
m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"<i>%1</i>"_s).arg(qApp->applicationDisplayName()));
m_3rdPartyLibsTextEdit->setOpenExternalLinks(true);
m_tabWidget->addTab(m_helpTextEdit, tr("&Help"));