20 const int VuoCompositionMetadataPanel::defaultPopoverTextWidth = 192;
21 const int VuoCompositionMetadataPanel::margin = 8;
22 const QString VuoCompositionMetadataPanel::editLink =
"vuo-edit";
30 this->composition = composition;
31 this->isUserComposition =
true;
34 this->textLabel =
new QLabel(
"",
this);
36 textLabel->setTextInteractionFlags(textLabel->textInteractionFlags() | Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
37 textLabel->setOpenExternalLinks(
false);
38 connect(textLabel, &QLabel::linkActivated,
this, &VuoCompositionMetadataPanel::handleMetadataLinkClick);
41 layout =
new QVBoxLayout(
this);
42 layout->setContentsMargins(margin, margin, margin, margin);
43 layout->addWidget(textLabel, 0, Qt::AlignTop);
44 layout->setStretch(0, 0);
57 void VuoCompositionMetadataPanel::setStyle()
60 textLabel->setMargin(0);
61 textLabel->setFixedWidth(defaultPopoverTextWidth);
62 textLabel->setWordWrap(
true);
64 Qt::WindowFlags flags = windowFlags();
65 flags |= Qt::FramelessWindowHint;
66 flags |= Qt::WindowStaysOnTopHint;
68 setWindowFlags(flags);
71 setBackgroundRole(QPalette::Base);
73 pal.setColor(QPalette::Base, QColor(Qt::transparent));
76 QSizePolicy sizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
77 textLabel->setSizePolicy(sizePolicy);
79 setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
90 QPainter painter(
this);
91 QRect popoverRect(0, 0, width(), height());
92 QColor popoverColor = isDark ? QColor(
"#282828") : QColor(
"#f9f9f9");
94 painter.setBrush(popoverColor);
95 painter.setRenderHint(QPainter::Antialiasing,
true);
96 painter.fillRect(popoverRect, popoverColor);
110 QString compositionVersion = QString::fromStdString(metadata->
getVersion());
118 QString formattedName = QString(
"<h2>%1</h2>").arg(name);
122 QString formattedCompositionVersion = isUserComposition && !compositionVersion.isEmpty()
123 ?
"<span>" + tr(
"Version %1").arg(compositionVersion) +
"</span><br>\n"
128 QString formattedCreatedInVuoVersion = isUserComposition && !createdInVuoVersion.isEmpty()
129 ?
"<span>" + tr(
"Created in Vuo %1").arg(createdInVuoVersion) +
"</span><br>\n"
134 QString formattedLastSavedInVuoVersion = isUserComposition && !lastSavedInVuoVersion.isEmpty()
135 ?
"<span>" + tr(
"Last saved in Vuo %1").arg(lastSavedInVuoVersion) +
"</span><br>\n"
138 QString formattedVersionInfo = formattedCompositionVersion
139 .append(formattedCreatedInVuoVersion)
140 .append(formattedLastSavedInVuoVersion);
141 if (!formattedVersionInfo.isEmpty())
142 formattedVersionInfo.append(
"<br>\n");
144 QString formattedDescription =
"";
148 QString formattedCopyright=
"";
151 if (!copyright.empty() && copyright.find(
"Kosada Incorporated") == string::npos)
154 QString formattedLinks =
"";
155 if (!homepageURL.empty() || !documentationURL.empty())
157 formattedLinks =
"<p>";
158 if (!homepageURL.empty())
159 formattedLinks.append(QString(
"<a href=\""))
160 .append(homepageURL.c_str())
161 .append(
"\">Homepage</a>\n");
163 if (!homepageURL.empty() && !documentationURL.empty())
164 formattedLinks.append(QString(
"<br>\n"));
166 if (!documentationURL.empty())
167 formattedLinks.append(QString(
"<a href=\""))
168 .append(documentationURL.c_str())
169 .append(
"\">Documentation</a>\n");
171 formattedLinks.append(
"</p>");
174 QString editMetadataLink = (isUserComposition?
175 QString(
"<p><a href=\"")
176 .append(VuoCompositionMetadataPanel::editLink)
177 .append(
"\">Edit Composition Information…</a></p>") :
"");
181 .append(formattedDescription)
182 .append(formattedCopyright)
183 .append(formattedLinks)
184 .append(formattedVersionInfo)
185 .append(editMetadataLink);
195 int adjustedWidth = width-2*margin;
196 if (adjustedWidth != textLabel->width())
198 textLabel->setFixedWidth(adjustedWidth);
203 textLabel->setWordWrap(
true);
213 if (textLabel->hasSelectedText())
214 return textLabel->selectedText();
230 void VuoCompositionMetadataPanel::handleMetadataLinkClick(
const QString &url)
232 if (url == VuoCompositionMetadataPanel::editLink)
235 QDesktopServices::openUrl(url);
244 if (userComposition != this->isUserComposition)
246 this->isUserComposition = userComposition;