Mercurial > minori
comparison src/gui/dialog/about.cc @ 330:e9d040e2045f
dialog/about: templateize
this should be pretty useful for e.g. localization
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Mon, 17 Jun 2024 05:16:57 -0400 |
| parents | 3b355fa948c7 |
| children | 92f63cf29faa |
comparison
equal
deleted
inserted
replaced
| 329:4aeffed717ef | 330:e9d040e2045f |
|---|---|
| 5 #include "gui/widgets/text.h" | 5 #include "gui/widgets/text.h" |
| 6 | 6 |
| 7 #include "pugixml.hpp" | 7 #include "pugixml.hpp" |
| 8 | 8 |
| 9 #include "utf8proc.h" | 9 #include "utf8proc.h" |
| 10 | |
| 11 #include <fmt/core.h> | |
| 10 | 12 |
| 11 #include <QCoreApplication> | 13 #include <QCoreApplication> |
| 12 #include <QFont> | 14 #include <QFont> |
| 13 #include <QHBoxLayout> | 15 #include <QHBoxLayout> |
| 14 #include <QTextBrowser> | 16 #include <QTextBrowser> |
| 23 template<typename T, size_t N> | 25 template<typename T, size_t N> |
| 24 constexpr size_t array_size(T (&)[N]) { | 26 constexpr size_t array_size(T (&)[N]) { |
| 25 return N; | 27 return N; |
| 26 } | 28 } |
| 27 | 29 |
| 30 static constexpr semver::version fmt_version{FMT_VERSION / 10000, FMT_VERSION / 100 % 100, FMT_VERSION % 100}; | |
| 28 static constexpr semver::version pugixml_version{PUGIXML_VERSION / 1000 % 10, PUGIXML_VERSION / 10 % 100, | 31 static constexpr semver::version pugixml_version{PUGIXML_VERSION / 1000 % 10, PUGIXML_VERSION / 10 % 100, |
| 29 PUGIXML_VERSION % 10}; | 32 PUGIXML_VERSION % 10}; |
| 30 static constexpr semver::version json_version{NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, | 33 static constexpr semver::version json_version{NLOHMANN_JSON_VERSION_MAJOR, NLOHMANN_JSON_VERSION_MINOR, |
| 31 NLOHMANN_JSON_VERSION_PATCH}; | 34 NLOHMANN_JSON_VERSION_PATCH}; |
| 32 static constexpr semver::version semver_version{SEMVER_VERSION_MAJOR, SEMVER_VERSION_MINOR, SEMVER_VERSION_PATCH}; | 35 static constexpr semver::version semver_version{SEMVER_VERSION_MAJOR, SEMVER_VERSION_MINOR, SEMVER_VERSION_PATCH}; |
| 36 static constexpr semver::version fugue_icons_version{3, 5, 6}; | |
| 33 | 37 |
| 34 const char* get_curl_version() { | 38 const char* get_curl_version() { |
| 35 const curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); | 39 const curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); |
| 36 return data->version; | 40 return data->version; |
| 37 } | 41 } |
| 42 | |
| 43 static constexpr std::string_view about_template = | |
| 44 "<body>" | |
| 45 "<h2 style=\"font-weight: normal;\"><strong>Minori</strong> v{}</h2>" | |
| 46 "<p><strong>Author:</strong><br>Paper <paper@paper.us.eu.org></p>" | |
| 47 "<p><strong>Third party components:</strong><br>" | |
| 48 "<a href=\"https://curl.se/\">libcurl v{}</a>, " | |
| 49 "<a href=\"https://p.yusukekamiyamane.com/\">Fugue Icons v{}</a>, " | |
| 50 "<a href=\"https://github.com/erengy/anitomy\">Anitomy</a>, " | |
| 51 "<a href=\"https://github.com/nlohmann/json\">JSON for Modern C++ v{}</a>, " | |
| 52 "<a href=\"https://pugixml.org/\">pugixml v{}</a>, " | |
| 53 "<a href=\"https://github.com/Neargye/semver\">semver v{}</a>, " | |
| 54 "<a href=\"http://juliastrings.github.io/utf8proc/\">utf8proc v{}</a>, " | |
| 55 "<a href=\"https://github.com/fmtlib/fmt\">fmt v{}</a>, " | |
| 56 "parts of <a href=\"https://github.com/erengy/anisthesia\">Anisthesia</a>" | |
| 57 "</p>" | |
| 58 "<span><strong>Special thanks:</strong></span>" | |
| 59 "<ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 15px; margin-right: 0px; -qt-list-indent:0;\">" | |
| 60 "<li><strong>Eren Okka</strong> for creating <a href=\"https://taiga.moe/\">Taiga</a></li>" | |
| 61 "<li><strong>Alex Huszagh</strong> and <strong>Colin Duquesnoy</strong> for creating BreezeStyleSheets, on which the dark theme in this program is based off of</li>" | |
| 62 "<li><strong>Andy Brice</strong> for providing some sample code for detecting dark mode on Windows and macOS</li>" | |
| 63 "<li><strong>Manuel Wudka-Robles</strong> for providing information on getting open file descriptors on macOS</li>" | |
| 64 "</ul>" | |
| 65 "</body>"; | |
| 38 | 66 |
| 39 AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { | 67 AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { |
| 40 setMinimumSize(641, 325); | 68 setMinimumSize(641, 325); |
| 41 setWindowTitle(tr("About Minori")); | 69 setWindowTitle(tr("About Minori")); |
| 42 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 70 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
| 43 setAutoFillBackground(true); | 71 setAutoFillBackground(true); |
| 44 | 72 |
| 45 QHBoxLayout* layout = new QHBoxLayout(this); | 73 QHBoxLayout* layout = new QHBoxLayout(this); |
| 46 | 74 |
| 47 /* we have to generate this on-the-fly for localization purposes */ | 75 std::string html = fmt::format(about_template, session.version.to_string(), get_curl_version(), fugue_icons_version.to_string(), json_version.to_string(), pugixml_version.to_string(), semver_version.to_string(), utf8proc_version(), fmt_version.to_string()); |
| 48 const QString html = | |
| 49 QString("<body>" | |
| 50 " <h2 style=\"font-weight: normal;\"><strong>Minori</strong> v" + | |
| 51 Strings::ToQString(session.version.to_string()) + | |
| 52 "</h2>" | |
| 53 " <p>" | |
| 54 " <strong>" + | |
| 55 tr("Author:") + | |
| 56 "</strong><br>" | |
| 57 " Paper (@mrpapersonic)" | |
| 58 " </p>" | |
| 59 " <p>" | |
| 60 " <strong>" + | |
| 61 tr("Third party components:") + | |
| 62 "</strong><br>" | |
| 63 "<a href=\"https://curl.se/\">libcurl v") + | |
| 64 get_curl_version() + | |
| 65 "</a>" | |
| 66 ", " | |
| 67 "<a href=\"https://p.yusukekamiyamane.com/\">Fugue Icons v3.5.6</a>" | |
| 68 ", " | |
| 69 "<a href=\"https://github.com/erengy/anitomy\">Anitomy</a>" | |
| 70 ", " | |
| 71 "<a href=\"https://github.com/nlohmann/json\">JSON for Modern C++ v" + | |
| 72 Strings::ToQString(json_version.to_string()) + | |
| 73 "</a>" | |
| 74 ", " | |
| 75 "<a href=\"https://pugixml.org/\">pugixml v" + | |
| 76 Strings::ToQString(pugixml_version.to_string()) + | |
| 77 "</a>" | |
| 78 ", " | |
| 79 "<a href=\"https://github.com/Neargye/semver\">semver v" + | |
| 80 Strings::ToQString(semver_version.to_string()) + | |
| 81 "</a>" | |
| 82 ", " | |
| 83 "<a href=\"http://juliastrings.github.io/utf8proc/\">utf8proc v" + | |
| 84 Strings::ToQString(utf8proc_version()) + | |
| 85 "</a>" | |
| 86 ", parts of " | |
| 87 "<a href=\"https://github.com/erengy/anisthesia\">Anisthesia</a>" | |
| 88 " </p>" | |
| 89 "<span>" | |
| 90 "<strong>" + | |
| 91 tr("Special thanks:") + | |
| 92 "</strong>" | |
| 93 "</span>" | |
| 94 " <ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 15px; margin-right: 0px; -qt-list-indent:0;\">" | |
| 95 " <li><strong>Eren Okka</strong> " + | |
| 96 tr("for creating <a href=\"https://taiga.moe/\">Taiga</a>") + | |
| 97 "</li>" | |
| 98 " <li><strong>Alex Huszagh</strong> " + | |
| 99 tr("and") + " <strong>Colin Duquesnoy</strong> " + | |
| 100 tr("for creating BreezeStyleSheets, on which the dark theme in this program is " | |
| 101 "based off of") + | |
| 102 "</li>" | |
| 103 " <li><strong>Andy Brice</strong> " + | |
| 104 tr("for providing some sample code for " | |
| 105 "detecting dark mode on Windows and macOS") + | |
| 106 "</li>" | |
| 107 " <li><strong>Manuel Wudka-Robles</strong> " + | |
| 108 tr("for providing information on " | |
| 109 "getting open file descriptors on macOS") + | |
| 110 "</li>" | |
| 111 " </ul>" | |
| 112 "</body>"; | |
| 113 | 76 |
| 114 setBackgroundRole(QPalette::Base); | 77 setBackgroundRole(QPalette::Base); |
| 115 | 78 |
| 116 { | 79 { |
| 117 QTextBrowser* paragraph = new QTextBrowser(this); | 80 QTextBrowser* paragraph = new QTextBrowser(this); |
| 118 paragraph->setOpenExternalLinks(true); | 81 paragraph->setOpenExternalLinks(true); |
| 119 paragraph->setFrameShape(QFrame::NoFrame); | 82 paragraph->setFrameShape(QFrame::NoFrame); |
| 120 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 83 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 121 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 84 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 122 paragraph->setHtml(html); | 85 paragraph->setHtml(Strings::ToQString(html)); |
| 123 | 86 |
| 124 layout->addWidget(paragraph); | 87 layout->addWidget(paragraph); |
| 125 } | 88 } |
| 126 } | 89 } |
| 127 | 90 |
