Mercurial > minori
annotate src/gui/dialog/about.cpp @ 68:2417121d894e
*: normalize usage of layouts
before, I used them two ways, once was by setting the layout later
by using setLayout(QWidget), and the other was just using the constructor.
I find the constructor to be easier to read, so I chose that one.
| author | Paper <mrpapersonic@gmail.com> | 
|---|---|
| date | Mon, 02 Oct 2023 21:33:25 -0400 | 
| parents | fe719c109dbc | 
| children | 5ccb99bfa605 | 
| rev | line source | 
|---|---|
| 51 | 1 #include "gui/dialog/about.h" | 
| 2 #include "core/json.h" | |
| 63 | 3 #include "core/version.h" | 
| 4 #include "gui/widgets/text.h" | |
| 
55
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
5 #include "pugixml.hpp" | 
| 51 | 6 #include <QFont> | 
| 7 #include <QHBoxLayout> | |
| 63 | 8 #include <QTextBrowser> | 
| 9 #include <QTextCharFormat> | |
| 10 #include <QTextCursor> | |
| 11 #include <curl/curl.h> | |
| 51 | 12 | 
| 63 | 13 #define CONCAT_VERSION_NX(major, minor, patch) ("v" #major "." #minor "." #patch) | 
| 51 | 14 | 
| 63 | 15 #define CONCAT_VERSION(major, minor, patch) CONCAT_VERSION_NX(major, minor, patch) | 
| 51 | 16 | 
| 17 #define SET_TITLE_FONT(font, format, cursor) \ | |
| 18 { \ | |
| 19 font = cursor.charFormat().font(); \ | |
| 20 font.setPointSize(10); \ | |
| 21 format.setFont(font); \ | |
| 22 cursor.setCharFormat(format); \ | |
| 23 } | |
| 24 | |
| 25 #define SET_PARAGRAPH_FONT(font, format, cursor) \ | |
| 26 { \ | |
| 27 font = cursor.charFormat().font(); \ | |
| 28 font.setPointSize(8); \ | |
| 29 format.setFont(font); \ | |
| 30 cursor.setCharFormat(format); \ | |
| 31 } | |
| 32 | |
| 33 #define SET_FONT_BOLD(font, format, cursor) \ | |
| 34 { \ | |
| 35 font = cursor.charFormat().font(); \ | |
| 36 font.setBold(true); \ | |
| 37 format.setFont(font); \ | |
| 38 cursor.setCharFormat(format); \ | |
| 39 } | |
| 40 | |
| 41 #define UNSET_FONT_BOLD(font, format, cursor) \ | |
| 42 { \ | |
| 43 font = cursor.charFormat().font(); \ | |
| 44 font.setBold(false); \ | |
| 45 format.setFont(font); \ | |
| 46 cursor.setCharFormat(format); \ | |
| 47 } | |
| 48 | |
| 49 #define SET_FORMAT_HYPERLINK(format, cursor, link) \ | |
| 50 { \ | |
| 51 format.setAnchor(true); \ | |
| 52 format.setAnchorHref(link); \ | |
| 53 cursor.setCharFormat(format); \ | |
| 54 } | |
| 55 #define UNSET_FORMAT_HYPERLINK(format, cursor) \ | |
| 56 { \ | |
| 57 format.setAnchor(false); \ | |
| 58 format.setAnchorHref(""); \ | |
| 59 cursor.setCharFormat(format); \ | |
| 60 } | |
| 61 | |
| 62 AboutWindow::AboutWindow(QWidget* parent) : QDialog(parent) { | |
| 63 setWindowTitle(tr("About Minori")); | |
| 64 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | |
| 64 | 65 QHBoxLayout* layout = new QHBoxLayout(this); | 
| 51 | 66 | 
| 67 QPalette pal = QPalette(); | |
| 68 pal.setColor(QPalette::Window, pal.color(QPalette::Base)); | |
| 69 setPalette(pal); | |
| 70 setAutoFillBackground(true); | |
| 71 | |
| 72 QFont font; | |
| 73 QTextCharFormat format; | |
| 74 QTextBrowser* paragraph = new QTextBrowser(this); | |
| 75 paragraph->setOpenExternalLinks(true); | |
| 
52
 
0c4138de2ea7
anime list: we are finally read-write
 
Paper <mrpapersonic@gmail.com> 
parents: 
51 
diff
changeset
 | 
76 paragraph->setFrameShape(QFrame::NoFrame); | 
| 
 
0c4138de2ea7
anime list: we are finally read-write
 
Paper <mrpapersonic@gmail.com> 
parents: 
51 
diff
changeset
 | 
77 paragraph->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
| 
 
0c4138de2ea7
anime list: we are finally read-write
 
Paper <mrpapersonic@gmail.com> 
parents: 
51 
diff
changeset
 | 
78 paragraph->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | 
| 51 | 79 QTextCursor cursor = paragraph->textCursor(); | 
| 80 SET_TITLE_FONT(font, format, cursor); | |
| 81 SET_FONT_BOLD(font, format, cursor); | |
| 82 cursor.insertText("Minori"); | |
| 83 UNSET_FONT_BOLD(font, format, cursor); | |
| 84 cursor.insertText(" " MINORI_VERSION); | |
| 85 SET_PARAGRAPH_FONT(font, format, cursor); | |
| 86 cursor.insertBlock(); | |
| 87 cursor.insertBlock(); | |
| 88 SET_FONT_BOLD(font, format, cursor); | |
| 89 cursor.insertText(tr("Author:")); | |
| 90 UNSET_FONT_BOLD(font, format, cursor); | |
| 91 cursor.insertBlock(); | |
| 92 cursor.insertText(tr("Paper")); | |
| 93 cursor.insertBlock(); | |
| 94 cursor.insertBlock(); | |
| 95 SET_FONT_BOLD(font, format, cursor); | |
| 96 cursor.insertText(tr("Third party components:")); | |
| 97 UNSET_FONT_BOLD(font, format, cursor); | |
| 98 cursor.insertBlock(); | |
| 99 SET_FORMAT_HYPERLINK(format, cursor, "https://github.com/nlohmann/json"); | |
| 63 | 100 cursor.insertText(tr("JSON for Modern C++ ") + CONCAT_VERSION(NLOHMANN_JSON_VERSION_MAJOR, | 
| 101 NLOHMANN_JSON_VERSION_MINOR, | |
| 102 NLOHMANN_JSON_VERSION_PATCH)); | |
| 51 | 103 UNSET_FORMAT_HYPERLINK(format, cursor); | 
| 104 cursor.insertText(", "); | |
| 105 { | |
| 106 curl_version_info_data* data = curl_version_info(CURLVERSION_NOW); | |
| 107 SET_FORMAT_HYPERLINK(format, cursor, "https://curl.se/"); | |
| 108 cursor.insertText(tr("libcurl v") + data->version); | |
| 109 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 110 cursor.insertText(", "); | |
| 111 } | |
| 112 SET_FORMAT_HYPERLINK(format, cursor, "https://p.yusukekamiyamane.com/"); | |
| 113 cursor.insertText(tr("Fugue Icons ") + CONCAT_VERSION(3, 5, 6)); | |
| 114 UNSET_FORMAT_HYPERLINK(format, cursor); | |
| 
55
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
115 cursor.insertText(", "); | 
| 
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
116 SET_FORMAT_HYPERLINK(format, cursor, "https://pugixml.org/"); | 
| 63 | 117 cursor.insertText(tr("pugixml v") + QString::number(PUGIXML_VERSION / 1000) + "." + | 
| 118 QString::number(PUGIXML_VERSION / 10 % 100) + "." + QString::number(PUGIXML_VERSION % 10)); | |
| 
55
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
119 UNSET_FORMAT_HYPERLINK(format, cursor); | 
| 
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
120 cursor.insertText(", "); | 
| 
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
121 SET_FORMAT_HYPERLINK(format, cursor, "https://github.com/erengy/anitomy"); | 
| 
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
122 cursor.insertText(tr("Anitomy")); | 
| 
 
d10b6c6b432e
add xml lib, we will need to use it eventually
 
Paper <mrpapersonic@gmail.com> 
parents: 
52 
diff
changeset
 | 
123 UNSET_FORMAT_HYPERLINK(format, cursor); | 
| 51 | 124 cursor.insertBlock(); | 
| 125 cursor.insertBlock(); | |
| 126 SET_FONT_BOLD(font, format, cursor); | |
| 127 cursor.insertText(tr("Links:")); | |
| 128 UNSET_FONT_BOLD(font, format, cursor); | |
| 129 cursor.insertBlock(); | |
| 64 | 130 layout->addWidget(paragraph); | 
| 51 | 131 } | 
