Vuo  2.1.0
VuoEditorAboutBox.cc
Go to the documentation of this file.
1 
10 #include "VuoStringUtilities.hh"
11 #include "VuoEditorAboutBox.hh"
12 #include "ui_VuoEditorAboutBox.h"
13 
14 const 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  QString missionMarkdown = tr(
39  "**Create memorable interactive experiences — without coding.**\n"
40  "\n"
41  "Drag, drop, and connect Vuo's simple building blocks to support your creative work: \n"
42  "VJ gigs, exhibits, installations, stage productions, dome graphics, visual signage, \n"
43  "video effects, maker projects, trade show booths, and more. \n"
44  "\n"
45  "Learn more at %1.")
46  .arg("[vuo.org](https://vuo.org)");
47 
48  QString missionHTML = QString::fromStdString(VuoStringUtilities::generateHtmlFromMarkdown(missionMarkdown.toStdString()));
49 
50  QString descriptiveText = \
51  QString("<html>%3<body>"
52  "<p><span style=\"font-size:28pt;\">Vuo</span>"
53  "<span style=\"font-size:20pt;\"> %1</span>%5<br>"
54  "<span style=\"font-size:12pt; color:rgba(0,0,0,.5)\">" + tr("Built on %2") + "<br>"
55  "Copyright © 2012–2020 Kosada Incorporated</span></p>%4"
56  "</body></html>").
57  arg(
58  versionNumber,
59  buildDate + commitHash,
60  htmlHead,
61  missionHTML,
62  versionSuffix
63  );
64 
65  // Text style
66  contributorFont = ui->textEdit->font();
67 
68  licenseFont.setFamily("Monaco");
69  licenseFont.setStyleHint(QFont::Monospace);
70  licenseFont.setFixedPitch(true);
71  licenseFont.setPointSize(11);
72 
73  const int tabStop = 8; // 8 characters/tab
74  QFontMetrics licenseFontMetrics(licenseFont);
75  ui->textEdit->setTabStopWidth(tabStop * licenseFontMetrics.width(' '));
76 
77  // Set the introductory text.
78  ui->textLabel->setText(descriptiveText);
79 
80  // Populate the "Details" pane.
81  contributors = new QTreeWidgetItem(ui->treeWidget);
82  contributors->setText(0, tr("Contributors"));
83  dependencyLicenses = new QTreeWidgetItem(ui->treeWidget);
84  dependencyLicenses->setText(0, tr("Dependency Licenses"));
85 
86  // Populate the text file content pane.
87  populateContributorsList();
88  populateLicenseTexts();
89 
90  ui->textEdit->setReadOnly(true);
91 
92  // Update the text content in response to selection changes within the "Details" pane.
93  connect(ui->treeWidget, &QTreeWidget::currentItemChanged, this, &VuoEditorAboutBox::updateDisplayedTextContent);
94 
95  // Select the contributors list by default.
96  ui->treeWidget->setCurrentItem(contributors);
97 
98  setFixedSize(size());
99  setAttribute(Qt::WA_DeleteOnClose, false);
100 }
101 
106 void VuoEditorAboutBox::populateContributorsList()
107 {
108  QFile contributorsList(QApplication::applicationDirPath().append("/../Resources/CONTRIBUTORS.md"));
109 
110  if (!contributorsList.open(QIODevice::ReadOnly))
111  contributorText = "Please see our list of contributors at <a href=\"https://vuo.org/contributors\">https://vuo.org/contributors</a>. ";
112 
113  else
114  {
115  // Display the contents of the contributors list.
116  QTextStream textStream(&contributorsList);
117  contributorText = VuoStringUtilities::generateHtmlFromMarkdown(textStream.readAll().toUtf8().constData()).c_str();
118  }
119 }
120 
124 void VuoEditorAboutBox::populateLicenseTexts()
125 {
126  QDir licenseTextDir(QApplication::applicationDirPath().append("/../Frameworks/Vuo.framework/Documentation/Licenses"));
127  if (!licenseTextDir.exists())
128  return;
129 
130  QStringList licenseFileList(licenseTextDir.entryList(QDir::Files|QDir::Readable));
131  foreach (QString licenseFileName, licenseFileList)
132  {
133  QFile licenseFile(licenseTextDir.filePath(licenseFileName));
134  if (licenseFile.open(QIODevice::ReadOnly))
135  {
136  QFileInfo licenseFileInfo(licenseFile);
137  QString dependencyIdentifier = licenseFileInfo.completeBaseName();
138  QTreeWidgetItem *dependencyLicenseItem = new QTreeWidgetItem();
139  dependencyLicenseItem->setText(0, dependencyIdentifier);
140  dependencyLicenses->addChild(dependencyLicenseItem);
141 
142  QTextStream textStream(&licenseFile);
143  licenseTextForDependency[dependencyIdentifier] = textStream.readAll();
144  }
145  }
146 }
147 
152 void VuoEditorAboutBox::updateDisplayedTextContent()
153 {
154  QTreeWidgetItem *currentItem = ui->treeWidget->currentItem();
155  if (currentItem == contributors)
156  {
157  ui->textEdit->setFont(contributorFont);
158  ui->textEdit->setText(htmlHead + contributorText);
159  }
160  else if (currentItem == dependencyLicenses)
161  ui->textEdit->setText("");
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 
178 VuoEditorAboutBox::~VuoEditorAboutBox()
179 {
180  delete ui;
181 }