Vuo  2.3.2
VuoCompositionMetadataPanel.cc
Go to the documentation of this file.
1 
11 
12 #include "VuoComposition.hh"
14 #include "VuoRendererFonts.hh"
15 #include "VuoStringUtilities.hh"
16 #include "VuoEditor.hh"
17 #include "VuoEditorComposition.hh"
18 #include "VuoNodePopover.hh"
19 
20 const int VuoCompositionMetadataPanel::defaultPopoverTextWidth = 192;
21 const int VuoCompositionMetadataPanel::margin = 8;
22 const QString VuoCompositionMetadataPanel::editLink = "vuo-edit";
23 
28  VuoPanelDocumentation(parent)
29 {
30  this->composition = composition;
31  this->isUserComposition = true;
32 
33  // Text content
34  this->textLabel = new QLabel("", this);
35  textLabel->setText(generateCompositionMetadataText());
36  textLabel->setTextInteractionFlags(textLabel->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
37  textLabel->setOpenExternalLinks(false);
38  connect(textLabel, &QLabel::linkActivated, this, &VuoCompositionMetadataPanel::handleMetadataLinkClick);
39 
40  // Layout
41  layout = new QVBoxLayout(this);
42  layout->setContentsMargins(margin, margin, margin, margin);
43  layout->addWidget(textLabel, 0, Qt::AlignTop);
44  layout->setStretch(0, 0);
45 
46  // Style
47  setStyle();
48 
49  VuoEditor *editor = (VuoEditor *)qApp;
51 }
52 
57 void VuoCompositionMetadataPanel::setStyle()
58 {
59  textLabel->setFont(VuoRendererFonts::getSharedFonts()->portPopoverFont());
60  textLabel->setMargin(0);
61  textLabel->setFixedWidth(defaultPopoverTextWidth);
62  textLabel->setWordWrap(true);
63 
64  Qt::WindowFlags flags = windowFlags();
65  flags |= Qt::FramelessWindowHint;
66  flags |= Qt::WindowStaysOnTopHint;
67  flags |= Qt::ToolTip;
68  setWindowFlags(flags);
69 
70  // No border around embedded QGraphicsView
71  setBackgroundRole(QPalette::Base);
72  QPalette pal;
73  pal.setColor(QPalette::Base, QColor(Qt::transparent));
74  setPalette(pal);
75 
76  QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
77  textLabel->setSizePolicy(sizePolicy);
78 
79  setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
80 }
81 
86 {
87  VuoEditor *editor = (VuoEditor *)qApp;
88  bool isDark = editor->isInterfaceDark();
89 
90  QPainter painter(this);
91  QRect popoverRect(0, 0, width(), height());
92  QColor popoverColor = isDark ? QColor("#282828") : QColor("#f9f9f9");
93 
94  painter.setBrush(popoverColor);
95  painter.setRenderHint(QPainter::Antialiasing, true);
96  painter.fillRect(popoverRect, popoverColor);
97 }
98 
103 {
104  if (!composition || !composition->hasRenderer())
105  return "";
106 
107  QString name = static_cast<VuoEditorComposition *>(composition->getRenderer())->getFormattedName();
108 
109  VuoCompositionMetadata *metadata = composition->getMetadata();
110  QString compositionVersion = QString::fromStdString(metadata->getVersion());
111  QString createdInVuoVersion = QString::fromStdString(metadata->getCreatedInVuoVersion());
112  QString lastSavedInVuoVersion = QString::fromStdString(metadata->getLastSavedInVuoVersion());
113  string description = metadata->getDescription();
114  string copyright = metadata->getCopyright();
115  string homepageURL = metadata->getHomepageURL();
116  string documentationURL = metadata->getDocumentationURL();
117 
118  QString formattedName = QString("<h2>%1</h2>").arg(name);
119 
120  //: Appears in the documentation panel at the bottom of the node library.
121  //: Refers to a composition version string specified by the composition author in the Edit > Composition Information dialog.
122  QString formattedCompositionVersion = isUserComposition && !compositionVersion.isEmpty()
123  ? "<span>" + tr("Version %1").arg(compositionVersion) + "</span><br>\n"
124  : "";
125 
126  //: Appears in the documentation panel at the bottom of the node library.
127  //: Refers to the Vuo version in which the composition was created.
128  QString formattedCreatedInVuoVersion = isUserComposition && !createdInVuoVersion.isEmpty()
129  ? "<span>" + tr("Created in Vuo %1").arg(createdInVuoVersion) + "</span><br>\n"
130  : "";
131 
132  //: Appears in the documentation panel at the bottom of the node library.
133  //: Refers to the Vuo version in which the composition was most recently saved.
134  QString formattedLastSavedInVuoVersion = isUserComposition && !lastSavedInVuoVersion.isEmpty()
135  ? "<span>" + tr("Last saved in Vuo %1").arg(lastSavedInVuoVersion) + "</span><br>\n"
136  : "";
137 
138  QString formattedVersionInfo = formattedCompositionVersion
139  .append(formattedCreatedInVuoVersion)
140  .append(formattedLastSavedInVuoVersion);
141  if (!formattedVersionInfo.isEmpty())
142  formattedVersionInfo.append("<br>\n");
143 
144  QString formattedDescription = "";
145  if (!description.empty() && (description != VuoRendererComposition::deprecatedDefaultDescription))
146  formattedDescription = VuoStringUtilities::generateHtmlFromMarkdown(description).c_str();
147 
148  QString formattedCopyright= "";
149  // Show the copyright for community-authored compositions
150  // (can't use isUserComposition, since we want to show the original author for community-authored built-in example compositions).
151  if (!copyright.empty() && copyright.find("Kosada Incorporated") == string::npos)
152  formattedCopyright = VuoStringUtilities::generateHtmlFromMarkdown(copyright).c_str();
153 
154  QString formattedLinks = "";
155  if (!homepageURL.empty() || !documentationURL.empty())
156  {
157  formattedLinks = "<p>";
158  if (!homepageURL.empty())
159  formattedLinks.append(QString("<a href=\""))
160  .append(homepageURL.c_str())
161  .append("\">Homepage</a>\n");
162 
163  if (!homepageURL.empty() && !documentationURL.empty())
164  formattedLinks.append(QString("<br>\n"));
165 
166  if (!documentationURL.empty())
167  formattedLinks.append(QString("<a href=\""))
168  .append(documentationURL.c_str())
169  .append("\">Documentation</a>\n");
170 
171  formattedLinks.append("</p>");
172  }
173 
174  QString editMetadataLink = (isUserComposition?
175  QString("<p><a href=\"")
176  .append(VuoCompositionMetadataPanel::editLink)
177  .append("\">Edit Composition Information…</a></p>") : "");
178 
180  + formattedName
181  .append(formattedDescription)
182  .append(formattedCopyright)
183  .append(formattedLinks)
184  .append(formattedVersionInfo)
185  .append(editMetadataLink);
186 }
187 
194 {
195  int adjustedWidth = width-2*margin;
196  if (adjustedWidth != textLabel->width())
197  {
198  textLabel->setFixedWidth(adjustedWidth);
199 
200  // The following setWordWrap() call is for some reason necessary
201  // to ensure that the popover does not end up with empty
202  // vertical space when resized. (Word wrap remains on regardless.)
203  textLabel->setWordWrap(true);
204  }
205 }
206 
212 {
213  if (textLabel->hasSelectedText())
214  return textLabel->selectedText();
215  else
216  return QString("");
217 }
218 
223 {
224  textLabel->setText(generateCompositionMetadataText());
225 }
226 
230 void VuoCompositionMetadataPanel::handleMetadataLinkClick(const QString &url)
231 {
232  if (url == VuoCompositionMetadataPanel::editLink)
233  emit metadataEditRequested();
234  else
235  QDesktopServices::openUrl(url);
236 }
237 
243 {
244  if (userComposition != this->isUserComposition)
245  {
246  this->isUserComposition = userComposition;
247  update();
248  }
249 }
250 
255 {
256 }