| 252 | } |
| 253 | |
| 254 | void 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 | |
| 308 | void InfoFrame::setLicense(QString text) |
| 309 | { |
no test coverage detected