From 319fd64fc66e218f1c1d25f4956baa8ffabdf9b6 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 6 Jul 2026 20:34:41 +0800 Subject: [PATCH] refactor: use html resource to replace manual html in code --- app/aboutdialog.cpp | 168 ++++++++++------------------- app/settings.cpp | 2 +- assets/plain/about.html | 29 +++++ assets/plain/help.html | 24 +++++ assets/plain/license.html | 29 +++++ assets/plain/special-thanks.html | 32 ++++++ assets/plain/third-party-libs.html | 15 +++ assets/resources.qrc | 6 +- 8 files changed, 190 insertions(+), 115 deletions(-) create mode 100644 assets/plain/about.html create mode 100644 assets/plain/help.html create mode 100644 assets/plain/license.html create mode 100644 assets/plain/special-thanks.html create mode 100644 assets/plain/third-party-libs.html diff --git a/app/aboutdialog.cpp b/app/aboutdialog.cpp index b486bfb..62b8ea1 100644 --- a/app/aboutdialog.cpp +++ b/app/aboutdialog.cpp @@ -5,144 +5,86 @@ #include "aboutdialog.h" #include "ui_aboutdialog.h" -#include -#include -#include -#include -#include #include -#include -#include #include using namespace Qt::Literals::StringLiterals; +static QString loadEmbeddedHtml(QString&& path) { + QFile htmlFile(path); + bool canOpenFile = htmlFile.open(QIODevice::ReadOnly); + QByteArray htmlRawContent = canOpenFile ? htmlFile.readAll() : QByteArrayLiteral(""); + return QString::fromUtf8(htmlRawContent); +} + AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui(new Ui::AboutDialog) { ui->setupUi(this); setWindowFlag(Qt::WindowContextHelpButtonHint, false); - const QStringList helpStr { - u"

%1

"_s.arg(tr("Launch application with image file path as argument to load the file.")), - u"

%1

"_s.arg(tr("Drag and drop image file onto the window is also supported.")), - u"

%1

"_s.arg(tr("None of the operations in this application will alter the pictures on disk.")), - u"

%1

"_s.arg(tr("Context menu option explanation:")), - u"
    "_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. - u"
  • %1:
    %2
  • "_s - .arg(QCoreApplication::translate("MainWindow", "Stay on top")) - .arg(tr("Make window stay on top of all other windows.")), - u"
  • %1:
    %2
  • "_s - .arg(QCoreApplication::translate("MainWindow", "Protected mode")) - .arg(tr("Avoid close window accidentally. (eg. by double clicking the window)")), - u"
  • %1:
    %2
  • "_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"
"_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. + const QString HELP_HTML = loadEmbeddedHtml(u":/plain/help.html"_s) + .arg(tr("General Help")) + .arg(tr("Launch application with image file path as argument to load the file.")) + .arg(tr("Passing in a single image file will load all the images in that directory and start viewing from that image.")) + .arg(tr("Passing in multiple image files lets you view them one by one.")) + .arg(tr("Drag and drop image file onto the window is also supported.")) + .arg(tr("None of the operations in this application will alter the pictures on disk.")) + .arg(tr("Context Menu Help")) + .arg(tr("Keep transformation", "The same meaning of MainWindow's Keep transformation.")) + .arg(tr("Avoid resetting the zoom/rotation/flip state that was applied to the image view when switching between images.")); - const QStringList aboutStr { - u"

"_s, - qApp->applicationDisplayName(), - (u"
"_s + tr("Version: %1").arg( + const QString APP_NAME_ARG = qApp->applicationDisplayName(); + const QString APP_VERSION_ARG = #ifdef GIT_DESCRIBE_VERSION_STRING - GIT_DESCRIBE_VERSION_STRING + GIT_DESCRIBE_VERSION_STRING; #else - qApp->applicationVersion() + qApp->applicationVersion(); #endif // GIT_DESCRIBE_VERSION_STRING - )), - u"
"_s, - tr("Copyright (c) %1 %2", "%1 is year, %2 is the name of copyright holder(s)") - .arg(u"2026"_s, u"@BLumia"_s), - u"
"_s, - tr("Logo designed by %1").arg(u"@Lovelyblack"_s), - u"
"_s, - tr("Built with Qt %1 (%2)").arg(QT_VERSION_STR, QSysInfo::buildCpuArchitecture()), - QStringLiteral("
%2").arg("https://github.com/BLumia/pineapple-pictures", tr("Source code")), - u"
"_s - }; + const QString QT_VERSION_ARG = QT_VERSION_STR; + const QString QT_ARCH_ARG = QSysInfo::buildCpuArchitecture(); + const QString ABOUT_HTML = loadEmbeddedHtml(u":/plain/about.html"_s) + .arg(APP_NAME_ARG) + .arg(tr("Version: %1").arg(APP_VERSION_ARG)) + .arg(tr("Upstream author")) + .arg(tr("Hard fork author")) + .arg(tr("Logo designer")) + .arg(tr("Built with Qt %1 (%2)").arg(QT_VERSION_ARG).arg(QT_ARCH_ARG)) + .arg(tr("Source code")); - QFile translaterHtml(u":/plain/translators.html"_s); - bool canOpenFile = translaterHtml.open(QIODevice::ReadOnly); - const QByteArray & translatorList = canOpenFile ? translaterHtml.readAll() : QByteArrayLiteral(""); + const QString SPECIAL_THANKS_HTML = loadEmbeddedHtml(u":/plain/special-thanks.html"_s) + .arg(tr("Contributors")) + .arg(tr("List of contributors on GitHub")) + .arg(tr("Thanks to all people who contributed to this project.")) + .arg(tr("Translators")) + .arg(tr("I would like to thank the following people who volunteered to translate this application.")); - const QStringList specialThanksStr { - u"

%1

%3

%4

"_s.arg( - tr("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.") - ), + const QString LICENSE_HTML = loadEmbeddedHtml(u":/plain/license.html"_s) + .arg(tr("License")) + .arg(tr("This application is released under the MIT License.")) + .arg(tr("License Verbatim Copy")); - u"

%1

%2

%3"_s.arg( - tr("Translators"), - tr("I would like to thank the following people who volunteered to translate this application."), - translatorList - ) - }; + const QString THIRD_PARTY_LIBS_HTML = loadEmbeddedHtml(u":/plain/third-party-libs.html"_s) + .arg(tr("Third-party Libraries")) + .arg(tr("This application is built on the following free software libraries.", "Free as in freedom")) + .arg(tr("Some of them are optional and might not be included with this distribution depending on the build environment.")); - const QStringList licenseStr { - u"

%1

"_s.arg(tr("Your Rights")), - u"

%1

%2

  • %3
  • %4
  • %5
  • %6
"_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(u"%1"_s), - u"

%1

"_s.arg(tr("The MIT license guarantees you this freedom. Nobody is ever permitted to take it away.")), - u"
%2
"_s - }; + ui->m_helpTextEdit->setHtml(HELP_HTML); + ui->m_helpTextEdit->setOpenExternalLinks(false); - const QString mitLicense(QStringLiteral(R"(Expat/MIT License - -Copyright © 2026 BLumia - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -)")); - - const QStringList thirdPartyLibsStr { - u"

%1

"_s.arg(tr("Third-party Libraries used by %1")), - tr("%1 is built on the following free software libraries:", "Free as in freedom"), - u"
    "_s, -#ifdef HAVE_EXIV2_VERSION - u"
  • %2: %3
  • "_s.arg("https://www.exiv2.org/", "Exiv2", "GPLv2"), -#endif // EXIV2_VERSION - u"
  • %2: %3
  • "_s.arg("https://www.qt.io/", "Qt", "GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3"), - u"
"_s - }; - - ui->m_helpTextEdit->setText(helpStr.join('\n')); - - ui->m_aboutTextEdit->setText(aboutStr.join('\n')); + ui->m_aboutTextEdit->setHtml(ABOUT_HTML); ui->m_aboutTextEdit->setOpenExternalLinks(true); - ui->m_specialThanksTextEdit->setText(specialThanksStr.join('\n')); + ui->m_specialThanksTextEdit->setHtml(SPECIAL_THANKS_HTML); ui->m_specialThanksTextEdit->setOpenExternalLinks(true); - ui->m_licenseTextEdit->setText(licenseStr.join('\n').arg(qApp->applicationDisplayName(), mitLicense)); + ui->m_licenseTextEdit->setHtml(LICENSE_HTML); + ui->m_licenseTextEdit->setOpenExternalLinks(false); - ui->m_3rdPartyLibsTextEdit->setText(thirdPartyLibsStr.join('\n').arg(u"%1"_s).arg(qApp->applicationDisplayName())); + ui->m_3rdPartyLibsTextEdit->setHtml(THIRD_PARTY_LIBS_HTML); ui->m_3rdPartyLibsTextEdit->setOpenExternalLinks(true); connect(ui->m_buttonBox, QOverload::of(&QDialogButtonBox::clicked), this, [this](QAbstractButton * btn){ diff --git a/app/settings.cpp b/app/settings.cpp index 1b90c44..f8cb29a 100644 --- a/app/settings.cpp +++ b/app/settings.cpp @@ -80,7 +80,7 @@ Settings::MouseWheelBehavior Settings::mouseWheelBehavior() const Settings::WindowSizeBehavior Settings::initWindowSizeBehavior() const { QString result = m_qsettings->value("init_window_size_behavior", "").toString(); - return QEnumHelper::fromString(result, WindowSizeBehavior::Maximized); + return QEnumHelper::fromString(result, WindowSizeBehavior::Windowed); } Qt::HighDpiScaleFactorRoundingPolicy Settings::hiDpiScaleFactorBehavior() const diff --git a/assets/plain/about.html b/assets/plain/about.html new file mode 100644 index 0000000..65dcb31 --- /dev/null +++ b/assets/plain/about.html @@ -0,0 +1,29 @@ +
+

+ +
+ + %1 +
+ + %2 +

+
+

+ + %3@BLumia +
+ %4@yyc12345 +
+ + %5@Lovelyblack +

+
+

+ + %6 +
+ + %7GitHub +

+
diff --git a/assets/plain/help.html b/assets/plain/help.html new file mode 100644 index 0000000..3953d44 --- /dev/null +++ b/assets/plain/help.html @@ -0,0 +1,24 @@ + +

%1

+
    +
  • + %2 +
      +
    • %3
    • +
    • %4
    • +
    +
  • +
  • %5
  • +
  • %6
  • +
+
+ +

%7

+ +
    +
  • + %8: +
    + %9 +
  • +
diff --git a/assets/plain/license.html b/assets/plain/license.html new file mode 100644 index 0000000..84e9e59 --- /dev/null +++ b/assets/plain/license.html @@ -0,0 +1,29 @@ + +

%1

+

%2

+
+ +

%3

+
+Expat/MIT License
+
+Copyright © 2026 BLumia
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/assets/plain/special-thanks.html b/assets/plain/special-thanks.html new file mode 100644 index 0000000..47367ad --- /dev/null +++ b/assets/plain/special-thanks.html @@ -0,0 +1,32 @@ + +

%1

+ +%2 + +

%3

+ + +

%4

+ +

%5

+
    +
  • Catalan: Toni Estévez
  • +
  • Chinese (Simplified): Percy Hong
  • +
  • Dutch: Heimen Stoffels
  • +
  • French: J. Lavoie, K. Herbert, Maxime Leroy
  • +
  • German: K. Herbert, J. Lavoie, sal0max
  • +
  • Indonesian: liimee, Reza Almanda
  • +
  • Italian: albanobattistella
  • +
  • Japanese: Black Cat, mmahhi, Percy Hong
  • +
  • Korean: VenusGirl
  • +
  • Norwegian Bokmål: Allan Nordhøy, ovl-1
  • +
  • Punjabi (Pakistan): bgo-eiu
  • +
  • Russian: Sergey Shornikov, Artem, Andrey
  • +
  • Sinhala: HelaBasa
  • +
  • Slovenian: Andrej Poženel - SDT
  • +
  • Spanish: Toni Estévez, Génesis Toxical, William(ѕ)ⁿ, gallegonovato
  • +
  • Tamil: தமிழ்நேரம் (TamilNeram)
  • +
  • Turkish: E-Akcaer, Oğuz Ersen, Sabri Ünal
  • +
  • Ukrainian: Dan, volkov, Сергій
  • +
  • Vietnamese: Loc Huynh
  • +
diff --git a/assets/plain/third-party-libs.html b/assets/plain/third-party-libs.html new file mode 100644 index 0000000..398689a --- /dev/null +++ b/assets/plain/third-party-libs.html @@ -0,0 +1,15 @@ + +

%1

+ +

%2

+

%3

+
    +
  • + Qt: + GPLv2 + GPLv3 + LGPLv2.1 + LGPLv3 +
  • +
  • + Exiv2: + GPLv2 +
  • +
diff --git a/assets/resources.qrc b/assets/resources.qrc index 82d4976..58dc1fa 100644 --- a/assets/resources.qrc +++ b/assets/resources.qrc @@ -10,6 +10,10 @@ icons/window-close.svg icons/go-next.svg icons/go-previous.svg - plain/translators.html + plain/help.html + plain/about.html + plain/special-thanks.html + plain/license.html + plain/third-party-libs.html