Mercurial > minori
comparison src/gui/dialog/licenses.cc @ 339:eac06513db86
dialog/about: add licenses button
otherwise we wouldn't be complying with most of the libraries
and external software we use
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Wed, 19 Jun 2024 14:02:11 -0400 |
| parents | |
| children | a0aa8c8c4307 |
comparison
equal
deleted
inserted
replaced
| 338:f63dfa309380 | 339:eac06513db86 |
|---|---|
| 1 #include "gui/dialog/licenses.h" | |
| 2 #include "core/json.h" | |
| 3 #include "core/session.h" | |
| 4 #include "core/strings.h" | |
| 5 #include "gui/widgets/text.h" | |
| 6 | |
| 7 #include "pugixml.hpp" | |
| 8 | |
| 9 #include "utf8proc.h" | |
| 10 | |
| 11 #include <fmt/core.h> | |
| 12 | |
| 13 #include <QCoreApplication> | |
| 14 #include <QFont> | |
| 15 #include <QHBoxLayout> | |
| 16 #include <QTabWidget> | |
| 17 #include <QTextBrowser> | |
| 18 #include <QTextCharFormat> | |
| 19 #include <QTextCursor> | |
| 20 | |
| 21 #include <curl/curl.h> | |
| 22 #ifdef WIN32 | |
| 23 # include "sys/win32/dark_theme.h" | |
| 24 #endif | |
| 25 | |
| 26 static QWidget *create_license_widget(QWidget *parent, const std::string& license) { | |
| 27 QTextBrowser* paragraph = new QTextBrowser(parent); | |
| 28 paragraph->setFrameShape(QFrame::NoFrame); | |
| 29 paragraph->setPlainText(Strings::ToQString(license)); | |
| 30 paragraph->setFont(QFont("monospace")); | |
| 31 return paragraph; | |
| 32 } | |
| 33 | |
| 34 LicensesWindow::LicensesWindow(QWidget* parent) : QDialog(parent) { | |
| 35 resize(641, 500); | |
| 36 setWindowTitle(tr("About Minori")); | |
| 37 setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); | |
| 38 setAutoFillBackground(true); | |
| 39 | |
| 40 QHBoxLayout* layout = new QHBoxLayout(this); | |
| 41 | |
| 42 setBackgroundRole(QPalette::Base); | |
| 43 | |
| 44 QTabWidget *tab_widget = new QTabWidget(this); | |
| 45 | |
| 46 layout->addWidget(tab_widget); | |
| 47 | |
| 48 do { | |
| 49 QFile f(":/licenses/LICENSE.minori"); | |
| 50 if (!f.exists()) | |
| 51 break; | |
| 52 | |
| 53 f.open(QFile::ReadOnly | QFile::Text); | |
| 54 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("Minori")); | |
| 55 } while (0); | |
| 56 | |
| 57 do { | |
| 58 QFile f(":/licenses/LICENSE.MIT.animone"); | |
| 59 QFile b(":/licenses/LICENSE.BSD.animone"); | |
| 60 if (!f.exists() || !b.exists()) | |
| 61 break; | |
| 62 | |
| 63 f.open(QFile::ReadOnly | QFile::Text); | |
| 64 b.open(QFile::ReadOnly | QFile::Text); | |
| 65 | |
| 66 std::string mit = Strings::ToUtf8String(f.readAll()); | |
| 67 std::string bsd = Strings::ToUtf8String(b.readAll()); | |
| 68 | |
| 69 QWidget *dual = new QWidget(this); | |
| 70 QVBoxLayout *dual_layout = new QVBoxLayout(dual); | |
| 71 | |
| 72 QLabel *dual_notice = new QLabel(tr("Animone was originally forked from Anisthesia, where any changes divergent from Anisthesia are now under a different license. Both the licenses for Animone and Anisthesia are provided below, respectfully:"), dual); | |
| 73 dual_notice->setWordWrap(true); | |
| 74 dual_layout->addWidget(dual_notice); | |
| 75 dual_layout->addWidget(create_license_widget(dual, bsd)); | |
| 76 dual_layout->addWidget(create_license_widget(dual, mit)); | |
| 77 | |
| 78 tab_widget->addTab(dual, tr("Animone")); | |
| 79 } while (0); | |
| 80 | |
| 81 do { | |
| 82 QFile f(":/licenses/LICENSE.anitomy"); | |
| 83 if (!f.exists()) | |
| 84 break; | |
| 85 | |
| 86 f.open(QFile::ReadOnly | QFile::Text); | |
| 87 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("Anitomy")); | |
| 88 } while (0); | |
| 89 | |
| 90 do { | |
| 91 QFile f(":/licenses/LICENSE.fmt"); | |
| 92 if (!f.exists()) | |
| 93 break; | |
| 94 | |
| 95 f.open(QFile::ReadOnly | QFile::Text); | |
| 96 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("fmt")); | |
| 97 } while (0); | |
| 98 | |
| 99 do { | |
| 100 QFile f(":/licenses/LICENSE.nlohmann"); | |
| 101 if (!f.exists()) | |
| 102 break; | |
| 103 | |
| 104 f.open(QFile::ReadOnly | QFile::Text); | |
| 105 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("JSON for Modern C++")); | |
| 106 } while (0); | |
| 107 | |
| 108 do { | |
| 109 QFile f(":/licenses/LICENSE.pugixml"); | |
| 110 if (!f.exists()) | |
| 111 break; | |
| 112 | |
| 113 f.open(QFile::ReadOnly | QFile::Text); | |
| 114 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("pugixml")); | |
| 115 } while (0); | |
| 116 | |
| 117 do { | |
| 118 QFile f(":/licenses/LICENSE.semver"); | |
| 119 if (!f.exists()) | |
| 120 break; | |
| 121 | |
| 122 f.open(QFile::ReadOnly | QFile::Text); | |
| 123 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("semver")); | |
| 124 } while (0); | |
| 125 | |
| 126 do { | |
| 127 QFile f(":/licenses/LICENSE.toml11"); | |
| 128 if (!f.exists()) | |
| 129 break; | |
| 130 | |
| 131 f.open(QFile::ReadOnly | QFile::Text); | |
| 132 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("toml11")); | |
| 133 } while (0); | |
| 134 | |
| 135 do { | |
| 136 QFile f(":/licenses/LICENSE.utf8proc"); | |
| 137 if (!f.exists()) | |
| 138 break; | |
| 139 | |
| 140 f.open(QFile::ReadOnly | QFile::Text); | |
| 141 tab_widget->addTab(create_license_widget(this, Strings::ToUtf8String(f.readAll())), tr("utf8proc")); | |
| 142 } while (0); | |
| 143 } | |
| 144 | |
| 145 void LicensesWindow::showEvent(QShowEvent* event) { | |
| 146 QDialog::showEvent(event); | |
| 147 #ifdef WIN32 | |
| 148 win32::SetTitleBarsToBlack(session.config.theme.IsInDarkTheme()); | |
| 149 #endif | |
| 150 } |
