MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / setDescription

Method setDescription

launcher/ui/widgets/InfoFrame.cpp:254–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

252}
253
254void InfoFrame::setDescription(QString text)
255{
256 if (text.isEmpty()) {
257 ui->descriptionLabel->setHidden(true);
258 updateHiddenState();
259 return;
260 } else {
261 ui->descriptionLabel->setHidden(false);
262 updateHiddenState();
263 }
264 ui->descriptionLabel->setToolTip("");
265 QString intermediatetext = text.trimmed();
266 bool prev(false);
267 QChar rem('\n');
268 QString finaltext;
269 finaltext.reserve(intermediatetext.size());
270 foreach (const QChar& c, intermediatetext) {
271 if (c == rem && prev) {
272 continue;
273 }
274 prev = c == rem;
275 finaltext += c;
276 }
277 QString labeltext;
278 labeltext.reserve(300);
279
280 // elide rich text by getting characters without formatting
281 const int maxCharacterElide = 290;
282 QTextDocument doc;
283 doc.setHtml(text);
284
285 if (doc.characterCount() > maxCharacterElide) {
286 ui->descriptionLabel->setOpenExternalLinks(false);
287 ui->descriptionLabel->setTextFormat(Qt::TextFormat::RichText); // This allows injecting HTML here.
288 m_description = text;
289
290 // move the cursor to the character elide, doesn't see html
291 QTextCursor cursor(&doc);
292 cursor.movePosition(QTextCursor::End);
293 cursor.setPosition(maxCharacterElide, QTextCursor::KeepAnchor);
294 cursor.removeSelectedText();
295
296 // insert the post fix at the cursor
297 cursor.insertHtml("<a href=\"#mod_desc\">...</a>");
298
299 labeltext.append(doc.toHtml());
300 QObject::connect(ui->descriptionLabel, &QLabel::linkActivated, this, &InfoFrame::descriptionEllipsisHandler);
301 } else {
302 ui->descriptionLabel->setTextFormat(Qt::TextFormat::AutoText);
303 labeltext.append(finaltext);
304 }
305 ui->descriptionLabel->setText(labeltext);
306}
307
308void InfoFrame::setLicense(QString text)
309{

Callers 1

packageCurrentMethod · 0.45

Calls 4

appendMethod · 0.80
isEmptyMethod · 0.45
sizeMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected