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