Mercurial > minori
comparison src/gui/dialog/about.cc @ 104:27455104ea37
about: switch to using HTML
it's still generated at runtime, but only once now
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Sun, 05 Nov 2023 02:35:27 -0500 |
| parents | 9b2b41f83a5e |
| children | 6d8da6e64d61 |
comparison
equal
deleted
inserted
replaced
| 103:621084cc542c | 104:27455104ea37 |
|---|---|
| 1 #include "gui/dialog/about.h" | 1 #include "gui/dialog/about.h" |
| 2 #include "core/json.h" | 2 #include "core/json.h" |
| 3 #include "core/version.h" | 3 #include "core/version.h" |
| 4 #include "core/strings.h" | |
| 4 #include "gui/widgets/text.h" | 5 #include "gui/widgets/text.h" |
| 5 #include "pugixml.hpp" | 6 #include "pugixml.hpp" |
| 6 #include <QFont> | 7 #include <QFont> |
| 7 #include <QHBoxLayout> | 8 #include <QHBoxLayout> |
| 8 #include <QTextBrowser> | 9 #include <QTextBrowser> |
| 9 #include <QTextCharFormat> | 10 #include <QTextCharFormat> |
| 10 #include <QTextCursor> | 11 #include <QTextCursor> |
| 11 #include <curl/curl.h> | 12 #include <curl/curl.h> |
| 12 | 13 |
| 13 #define CONCAT_VERSION_NX(major, minor, patch) ("v" #major "." #minor "." #patch) | 14 template <typename T, size_t N> |
| 15 constexpr size_t array_size(T (&)[N]) { | |
| 16 return N; | |
| 17 } | |
| 14 | 18 |
| 19 #define CONCAT_VERSION_NX(major, minor, patch) "v" #major "." #minor "." #patch | |
| 15 #define CONCAT_VERSION(major, minor, patch) CONCAT_VERSION_NX(major, minor, patch) | 20 #define CONCAT_VERSION(major, minor, patch) CONCAT_VERSION_NX(major, minor, patch) |
| 16 | 21 |
| 17 #define SET_TITLE_FONT(font, format, cursor) \ | 22 /* Ahhh, my dumb little hack to get this to be constexpr :) */ |
| 18 { \ | 23 static constexpr const char pugixml_version[] = { |
| 19 QFont fnt; \ | 24 PUGIXML_VERSION / 1000 % 10 + '0', /* Major */ |
| 20 fnt.setPixelSize(16); \ | 25 '.', |
| 21 format.setFont(fnt); \ | 26 PUGIXML_VERSION / 100 % 10 + '0', /* Minor */ |
| 22 cursor.setCharFormat(format); \ | 27 PUGIXML_VERSION / 10 % 10 + '0', |
| 23 } | 28 '.', |
| 29 PUGIXML_VERSION % 10 + '0', /* Patch */ | |
| 30 '\0' | |
| 31 }; | |
| 24 | 32 |
| 25 #define SET_PARAGRAPH_FONT(font, format, cursor) \ | 33 const char* get_curl_version() { |
| 26 { \ | 34 const curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); |
| 27 QFont fnt; \ | 35 return data->version; |
| 28 fnt.setPixelSize(12); \ | 36 } |
| 29 format.setFont(fnt); \ | |
| 30 cursor.setCharFormat(format); \ | |
| 31 } | |
| 32 | 37 |
| 33 #define SET_FONT_BOLD(font, format, cursor) \ | 38 /* I hate HTML so much... */ |
| 34 { \ | 39 static const QString html = QString( |
| 35 font = cursor.charFormat().font(); \ | 40 "<body>" |
| 36 font.setBold(true); \ | 41 " <h2 style=\"font-weight: normal;\"><strong>Minori</strong> " MINORI_VERSION "</h2>" |
| 37 format.setFont(font); \ | 42 " <p>" |
| 38 cursor.setCharFormat(format); \ | 43 " <strong>Author:</strong><br>" |
| 39 } | 44 " Paper (@mrpapersonic)" |
| 40 | 45 " </p>" |
| 41 #define UNSET_FONT_BOLD(font, format, cursor) \ | 46 " <p>" |
| 42 { \ | 47 " <strong>Third party components:</strong><br>" |
| 43 font = cursor.charFormat().font(); \ | 48 "<a href=\"https://curl.se/\">libcurl v") + get_curl_version() + "</a>" |
| 44 font.setBold(false); \ | 49 ", " |
| 45 format.setFont(font); \ | 50 "<a href=\"https://p.yusukekamiyamane.com/\">Fugue Icons v3.5.6</a>" |
| 46 cursor.setCharFormat(format); \ | 51 ", " |
| 47 } | 52 "<a href=\"https://github.com/erengy/anitomy\">Anitomy</a>" |
| 48 | 53 ", " |
| 49 #define SET_FORMAT_HYPERLINK(format, cursor, link) \ | 54 "<a href=\"https://github.com/nlohmann/json\">JSON for Modern C++ " CONCAT_VERSION(NLOHMANN_JSON_VERSION_MAJOR, |
| 50 { \ | 55 NLOHMANN_JSON_VERSION_MINOR, |
| 51 font = cursor.charFormat().font(); \ | 56 NLOHMANN_JSON_VERSION_PATCH) "</a>" |
| 52 font.setUnderline(true); \ | 57 ", " |
| 53 format.setFont(font); \ | 58 "<a href=\"https://pugixml.org/\">pugixml v" + pugixml_version + "</a>" |
| 54 format.setAnchor(true); \ | 59 ", " |
| 55 format.setAnchorHref(link); \ | 60 "<a href=\"https://github.com/pulzed/mINI\">mINI v0.9.14</a>" |
| 56 cursor.setCharFormat(format); \ | 61 " </p>" |
| 57 } | 62 "<span>" |
| 58 #define UNSET_FORMAT_HYPERLINK(format, cursor) \ | 63 "<strong>Special thanks:</strong>" |
| 59 { \ | 64 "</span>" |
| 60 font = cursor.charFormat().font(); \ | 65 " <ul style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 15px; margin-right: 0px; -qt-list-indent:0;\">" |
| 61 font.setUnderline(false); \ | 66 " <li><strong>Eren Okka</strong> for creating Taiga</li>" |
| 62 format.setFont(font); \ | 67 " <li><strong>Alex Huszagh</strong> and <strong>Colin Duquesnoy</strong> for " |
| 63 format.setAnchor(false); \ | 68 "creating BreezeStyleSheets, on which the dark theme in this program is " |
| 64 format.setAnchorHref(""); \ | 69 "based off of</li>" |
| 65 cursor.setCharFormat(format); \ | 70 " </ul>" |
| 66 } | 71 "</body>"; |
| 67 | 72 |
| 68 AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { | 73 AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { |
| 74 setMinimumSize(641, 325); | |
| 69 setWindowTitle(tr("About Minori")); | 75 setWindowTitle(tr("About Minori")); |
| 70 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | 76 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); |
| 71 QHBoxLayout* layout = new QHBoxLayout(this); | 77 QHBoxLayout* layout = new QHBoxLayout(this); |
| 72 | 78 |
| 73 QPalette pal = QPalette(); | 79 QPalette pal = QPalette(); |
| 74 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | 80 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); |
| 75 setPalette(pal); | 81 setPalette(pal); |
| 76 setAutoFillBackground(true); | 82 setAutoFillBackground(true); |
| 77 | 83 |
| 78 QFont font; | |
| 79 QTextCharFormat format; | |
| 80 QTextBrowser* paragraph = new QTextBrowser(this); | 84 QTextBrowser* paragraph = new QTextBrowser(this); |
| 81 paragraph->setOpenExternalLinks(true); | 85 paragraph->setOpenExternalLinks(true); |
| 82 paragraph->setFrameShape(QFrame::NoFrame); | 86 paragraph->setFrameShape(QFrame::NoFrame); |
| 83 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 87 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 84 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 88 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
| 85 QTextCursor cursor = paragraph->textCursor(); | 89 paragraph->setHtml(html); |
| 86 SET_TITLE_FONT(font, format, cursor); | 90 |
| 87 SET_FONT_BOLD(font, format, cursor); | |
| 88 cursor.insertText("Minori"); | |
| 89 UNSET_FONT_BOLD(font, format, cursor); | |
| 90 cursor.insertText(" " MINORI_VERSION); | |
| 91 SET_PARAGRAPH_FONT(font, format, cursor); | |
| 92 cursor.insertBlock(); | |
| 93 cursor.insertBlock(); | |
| 94 SET_FONT_BOLD(font, format, cursor); | |
| 95 cursor.insertText(tr("Author:")); | |
| 96 UNSET_FONT_BOLD(font, format, cursor); | |
| 97 cursor.insertBlock(); | |
| 98 cursor.insertText(tr("Paper")); | |
| 99 cursor.insertBlock(); | |
| 100 cursor.insertBlock(); | |
| 101 SET_FONT_BOLD(font, format, cursor); | |
| 102 cursor.insertText(tr("Third party components:")); | |
| 103 UNSET_FONT_BOLD(font, format, cursor); | |
| 104 cursor.insertBlock(); | |
| 105 SET_FORMAT_HYPERLINK(format, cursor, "https://github.com/nlohmann/json"); | |
| 106 cursor.insertText(tr("JSON for Modern C++ ") + CONCAT_VERSION(NLOHMANN_JSON_VERSION_MAJOR, | |
| 107 NLOHMANN_JSON_VERSION_MINOR, | |
| 108 NLOHMANN_JSON_VERSION_PATCH)); | |
| 109 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 110 cursor.insertText(", "); | |
| 111 { | |
| 112 curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); | |
| 113 SET_FORMAT_HYPERLINK(format, cursor, "https://curl.se/"); | |
| 114 cursor.insertText(tr("libcurl v") + data->version); | |
| 115 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 116 cursor.insertText(", "); | |
| 117 } | |
| 118 SET_FORMAT_HYPERLINK(format, cursor, "https://p.yusukekamiyamane.com/"); | |
| 119 cursor.insertText(tr("Fugue Icons ") + CONCAT_VERSION(3, 5, 6)); | |
| 120 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 121 cursor.insertText(", "); | |
| 122 SET_FORMAT_HYPERLINK(format, cursor, "https://pugixml.org/"); | |
| 123 cursor.insertText(tr("pugixml v") + QString::number(PUGIXML_VERSION / 1000) + "." + | |
| 124 QString::number(PUGIXML_VERSION / 10 % 100) + "." + QString::number(PUGIXML_VERSION % 10)); | |
| 125 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 126 cursor.insertText(", "); | |
| 127 SET_FORMAT_HYPERLINK(format, cursor, "https://github.com/erengy/anitomy"); | |
| 128 cursor.insertText(tr("Anitomy")); | |
| 129 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 130 cursor.insertBlock(); | |
| 131 cursor.insertBlock(); | |
| 132 SET_FONT_BOLD(font, format, cursor); | |
| 133 cursor.insertText(tr("Links:")); | |
| 134 UNSET_FONT_BOLD(font, format, cursor); | |
| 135 cursor.insertBlock(); | |
| 136 layout->addWidget(paragraph); | 91 layout->addWidget(paragraph); |
| 137 } | 92 } |
