Vuo 2.4.4
Loading...
Searching...
No Matches
VuoEditorAboutBox.cc
Go to the documentation of this file.
1
10#include "VuoStringUtilities.hh"
11#include "VuoEditorAboutBox.hh"
12#include "ui_VuoEditorAboutBox.h"
13
14const QString VuoEditorAboutBox::htmlHead = "<head><style>a { color: #0099a9; }</style></head>";
15
21 ui(new Ui::VuoEditorAboutBox)
22{
23 ui->setupUi(this);
24
25 QString buildDate = __DATE__;
26
27 QString versionAndBuild = VUO_VERSION_AND_BUILD_STRING;
28 QRegularExpressionMatch match = QRegularExpression("\\d+\\.\\d+\\.\\d+").match(versionAndBuild);
29 QString versionNumber = match.captured(0);
30 QString versionSuffix = versionAndBuild.mid(match.capturedEnd());
31 if (!versionSuffix.isEmpty())
32 versionSuffix = "<span style=\"font-size:20pt; color:rgba(0,0,0,.35)\">" + versionSuffix + "</span>";
33
34 QString commitHash = VUO_GIT_COMMIT;
35 if (!commitHash.isEmpty())
36 commitHash = QString(" (revision ") + VUO_GIT_COMMIT + ")";
37
38 // Keep this description in sync with VuoManual.txt.
39 QString missionMarkdown = tr(
40 "**Create memorable interactive experiences — without coding.**\n"
41 "\n"
42 "Drag, drop, and connect Vuo's simple building blocks to support your creative work: \n"
43 "VJ gigs, exhibits, installations, stage productions, dome graphics, visual signage, \n"
44 "video effects, maker projects, trade show booths, and more. \n"
45 "\n"
46 "Learn more at %1.")
47 .arg("[vuo.org](https://vuo.org)");
48
49 QString missionHTML = QString::fromStdString(VuoStringUtilities::generateHtmlFromMarkdown(missionMarkdown.toStdString()));
50
51 QString descriptiveText = \
52 QString("<html>%3<body>"
53 "<p><span style=\"font-size:28pt;\">Vuo</span>"
54 "<span style=\"font-size:20pt;\"> %1</span>%5<br>"
55 "<span style=\"font-size:12pt; color:rgba(0,0,0,.5)\">" + tr("Built on %2") + "<br>"
56 "Copyright © 2012–2023 Kosada Incorporated</span></p>%4"
57 "</body></html>").
58 arg(
59 versionNumber,
60 buildDate + commitHash,
61 htmlHead,
62 missionHTML,
63 versionSuffix
64 );
65
66 // Text style
67 contributorFont = ui->textEdit->font();
68
69 licenseFont.setFamily("Monaco");
70 licenseFont.setStyleHint(QFont::Monospace);
71 licenseFont.setFixedPitch(true);
72 licenseFont.setPointSize(11);
73
74 int spacesPerTab = 8;
75 QFontMetricsF fontMetrics(licenseFont);
76 ui->textEdit->setTabStopDistance(spacesPerTab * fontMetrics.horizontalAdvance(' '));
77
78 // Set the introductory text.
79 ui->textLabel->setText(descriptiveText);
80
81 // Populate the "Details" pane.
82 contributors = new QTreeWidgetItem(ui->treeWidget);
83 contributors->setText(0, tr("Contributors"));
84 dependencies = new QTreeWidgetItem(ui->treeWidget);
85 dependencies->setText(0, tr("Dependencies"));
86
87 // Populate the text file content panes.
88 contributorsText = fetchMarkdown("CONTRIBUTORS.md", tr("Please see the list of contributors at <a href=\"%1\">%1</a>.").arg("https://community.vuo.org/badges"));
89 dependenciesText = fetchMarkdown("DEPENDENCIES.md", tr("Please see the list of dependencies at <a href=\"%1\">%1</a>.").arg("https://github.com/vuo/vuo/blob/main/conanfile.py"));
90 populateLicenseTexts();
91
92 ui->textEdit->setReadOnly(true);
93
94 // Update the text content in response to selection changes within the "Details" pane.
95 connect(ui->treeWidget, &QTreeWidget::currentItemChanged, this, &VuoEditorAboutBox::updateDisplayedTextContent);
96
97 // Select the contributors list by default.
98 ui->treeWidget->setCurrentItem(contributors);
99
100 setFixedSize(size());
101 setAttribute(Qt::WA_DeleteOnClose, false);
102}
103
108QString VuoEditorAboutBox::fetchMarkdown(const QString &filename, const QString &fallback)
109{
110 QFile f(QApplication::applicationDirPath().append("/../Resources/").append(filename));
111 if (!f.open(QIODevice::ReadOnly))
112 return fallback;
113
114 QTextStream textStream(&f);
115 return QString::fromStdString(VuoStringUtilities::generateHtmlFromMarkdown(textStream.readAll().toUtf8().constData()));
116}
117
121void VuoEditorAboutBox::populateLicenseTexts()
122{
123 QDir licenseTextDir(QApplication::applicationDirPath().append("/../Frameworks/Vuo.framework/Documentation/Licenses"));
124 if (!licenseTextDir.exists())
125 return;
126
127 QStringList licenseFileList(licenseTextDir.entryList(QDir::Files|QDir::Readable));
128 foreach (QString licenseFileName, licenseFileList)
129 {
130 QFile licenseFile(licenseTextDir.filePath(licenseFileName));
131 if (licenseFile.open(QIODevice::ReadOnly))
132 {
133 QFileInfo licenseFileInfo(licenseFile);
134 QString dependencyIdentifier = licenseFileInfo.completeBaseName();
135 QTreeWidgetItem *dependencyLicenseItem = new QTreeWidgetItem();
136 dependencyLicenseItem->setText(0, dependencyIdentifier);
137 dependencies->addChild(dependencyLicenseItem);
138
139 QTextStream textStream(&licenseFile);
140 licenseTextForDependency[dependencyIdentifier] = textStream.readAll();
141 }
142 }
143}
144
149void VuoEditorAboutBox::updateDisplayedTextContent()
150{
151 QTreeWidgetItem *currentItem = ui->treeWidget->currentItem();
152 if (currentItem == contributors)
153 {
154 ui->textEdit->setFont(contributorFont);
155 ui->textEdit->setText(htmlHead + contributorsText);
156 }
157 else if (currentItem == dependencies)
158 {
159 ui->textEdit->setFont(contributorFont);
160 ui->textEdit->setText(htmlHead + dependenciesText);
161 }
162 else
163 {
164 ui->textEdit->setFont(licenseFont);
165
166 // Use ui->textEdit->document()->setHtml(...) and ui->textEdit->document()->setPlainText(...)
167 // rather than ui->textEdit->setText(...) to avoid bug where viewing a license text after
168 // clicking on any link within the contributor text caused the full license text to
169 // be displayed as a link.
170 QString licenseText = licenseTextForDependency[currentItem->text(0)];
171 if (Qt::mightBeRichText(licenseText))
172 ui->textEdit->document()->setHtml(htmlHead + licenseText);
173 else
174 ui->textEdit->document()->setPlainText(licenseText);
175 }
176}
177
178VuoEditorAboutBox::~VuoEditorAboutBox()
179{
180 delete ui;
181}