"Help message" or "About" dialog box */
| 29 | |
| 30 | /** "Help message" or "About" dialog box */ |
| 31 | HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool about) : |
| 32 | QDialog(parent, GUIUtil::dialog_flags), |
| 33 | ui(new Ui::HelpMessageDialog) |
| 34 | { |
| 35 | ui->setupUi(this); |
| 36 | |
| 37 | QString version = QString{PACKAGE_NAME} + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion()); |
| 38 | |
| 39 | if (about) |
| 40 | { |
| 41 | setWindowTitle(tr("About %1").arg(PACKAGE_NAME)); |
| 42 | |
| 43 | std::string licenseInfo = LicenseInfo(); |
| 44 | /// HTML-format the license message from the core |
| 45 | QString licenseInfoHTML = QString::fromStdString(LicenseInfo()); |
| 46 | // Make URLs clickable |
| 47 | QRegExp uri("<(.*)>", Qt::CaseSensitive, QRegExp::RegExp2); |
| 48 | uri.setMinimal(true); // use non-greedy matching |
| 49 | licenseInfoHTML.replace(uri, "<a href=\"\\1\">\\1</a>"); |
| 50 | // Replace newlines with HTML breaks |
| 51 | licenseInfoHTML.replace("\n", "<br>"); |
| 52 | |
| 53 | ui->aboutMessage->setTextFormat(Qt::RichText); |
| 54 | ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); |
| 55 | text = version + "\n" + QString::fromStdString(FormatParagraph(licenseInfo)); |
| 56 | ui->aboutMessage->setText(version + "<br><br>" + licenseInfoHTML); |
| 57 | ui->aboutMessage->setWordWrap(true); |
| 58 | ui->helpMessage->setVisible(false); |
| 59 | } else { |
| 60 | setWindowTitle(tr("Command-line options")); |
| 61 | QString header = "Usage: elements-qt [command-line options] \n"; |
| 62 | QTextCursor cursor(ui->helpMessage->document()); |
| 63 | cursor.insertText(version); |
| 64 | cursor.insertBlock(); |
| 65 | cursor.insertText(header); |
| 66 | cursor.insertBlock(); |
| 67 | |
| 68 | std::string strUsage = gArgs.GetHelpMessage(); |
| 69 | QString coreOptions = QString::fromStdString(strUsage); |
| 70 | text = version + "\n\n" + header + "\n" + coreOptions; |
| 71 | |
| 72 | QTextTableFormat tf; |
| 73 | tf.setBorderStyle(QTextFrameFormat::BorderStyle_None); |
| 74 | tf.setCellPadding(2); |
| 75 | QVector<QTextLength> widths; |
| 76 | widths << QTextLength(QTextLength::PercentageLength, 35); |
| 77 | widths << QTextLength(QTextLength::PercentageLength, 65); |
| 78 | tf.setColumnWidthConstraints(widths); |
| 79 | |
| 80 | QTextCharFormat bold; |
| 81 | bold.setFontWeight(QFont::Bold); |
| 82 | |
| 83 | for (const QString &line : coreOptions.split("\n")) { |
| 84 | if (line.startsWith(" -")) |
| 85 | { |
| 86 | cursor.currentTable()->appendRows(1); |
| 87 | cursor.movePosition(QTextCursor::PreviousCell); |
| 88 | cursor.movePosition(QTextCursor::NextRow); |
nothing calls this directly
no test coverage detected