Qt Utilities 6.14.4
Common Qt related C++ classes and routines used by my applications such as dialogs, widgets and models
Loading...
Searching...
No Matches
aboutdialog.cpp
Go to the documentation of this file.
1#include "./aboutdialog.h"
3
4#include "ui_aboutdialog.h"
5
6#include <c++utilities/application/argumentparser.h>
7
8#include <QApplication>
9#include <QGraphicsPixmapItem>
10#include <QMessageBox>
11#include <QStringBuilder>
12#include <QStyle>
13
17namespace QtUtilities {
18
40AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version,
41 const std::vector<const char *> &dependencyVersions, const QString &website, const QString &description, const QImage &image)
42 : QDialog(parent)
43 , m_ui(new Ui::AboutDialog)
44{
45 m_ui->setupUi(this);
46 makeHeading(m_ui->productNameLabel);
47 setStyleSheet(dialogStyleForPalette(palette()));
48 setWindowFlags((windowFlags()) & ~(Qt::WindowMinMaxButtonsHint | Qt::WindowContextHelpButtonHint | Qt::WindowFullscreenButtonHint));
49 if (!applicationName.isEmpty()) {
50 m_ui->productNameLabel->setText(applicationName);
51 } else if (!QApplication::applicationDisplayName().isEmpty()) {
52 m_ui->productNameLabel->setText(QApplication::applicationDisplayName());
53 } else {
54 m_ui->productNameLabel->setText(QApplication::applicationName());
55 }
56 if (creator.startsWith(QLatin1Char('<'))) {
57 // assign rich text as-is
58 m_ui->creatorLabel->setText(creator);
59 } else {
60 // add "developed by " before creator name
61 auto setCreator = [this, creator = std::move(creator)] {
62 m_ui->creatorLabel->setText(tr("developed by %1").arg(creator.isEmpty() ? QApplication::organizationName() : creator));
63 };
64 setCreator();
65 connect(this, &AboutDialog::retranslationRequired, this, std::move(setCreator));
66 }
67 m_ui->versionLabel->setText(version.isEmpty() ? QApplication::applicationVersion() : version);
68 const auto &deps(dependencyVersions.size() ? dependencyVersions : CppUtilities::applicationInfo.dependencyVersions);
69 if (!deps.empty()) {
70 QStringList linkedAgainst;
71 linkedAgainst.reserve(static_cast<int>(deps.size()));
72 for (const auto &dependencyVersion : deps) {
73 linkedAgainst << QString::fromUtf8(dependencyVersion);
74 }
75 m_ui->versionLabel->setToolTip(QStringLiteral("<p>") % tr("Linked against:") % QStringLiteral("</p><ul><li>")
76 % linkedAgainst.join(QStringLiteral("</li><li>")) % QStringLiteral("</li></ul>"));
77 }
78 if (!website.isEmpty() || CppUtilities::applicationInfo.url) {
79 auto setWebsite = [this, website = std::move(website)] {
80 m_ui->websiteLabel->setText(tr("For updates and bug reports visit the <a href=\"%1\" "
81 "style=\"text-decoration: underline; color: palette(link);\">project "
82 "website</a>.")
83 .arg(!website.isEmpty() ? website : QString::fromUtf8(CppUtilities::applicationInfo.url)));
84 };
85 setWebsite();
86 connect(this, &AboutDialog::retranslationRequired, this, std::move(setWebsite));
87 } else {
88 m_ui->websiteLabel->hide();
89 }
90 m_ui->descLabel->setText(description.isEmpty() && CppUtilities::applicationInfo.description
91 ? QString::fromUtf8(CppUtilities::applicationInfo.description)
92 : description);
93 m_iconScene = new QGraphicsScene(this);
94 auto *item = image.isNull()
95 ? new QGraphicsPixmapItem(QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation, nullptr, this).pixmap(128))
96 : new QGraphicsPixmapItem(QPixmap::fromImage(image));
97 m_iconScene->addItem(item);
98 m_ui->graphicsView->setScene(m_iconScene);
99 auto setQtVersion = [this] { m_ui->qtVersionLabel->setText(tr("Using <a href=\"qtversion\">Qt %1</a>").arg(QString::fromUtf8(qVersion()))); };
100 setQtVersion();
101 connect(this, &AboutDialog::retranslationRequired, this, std::move(setQtVersion));
102 connect(m_ui->qtVersionLabel, &QLabel::linkActivated, this, &AboutDialog::linkActivated);
103 centerWidget(this, parentWidget());
104}
105
109AboutDialog::AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website,
110 const QString &description, const QImage &image)
111 : AboutDialog(parent, applicationName, creator, version, {}, website, description, image)
112{
113}
114
119AboutDialog::AboutDialog(QWidget *parent, const QString &website, const QString &description, const QImage &image)
120 : AboutDialog(parent, QString(), QString(), QString(), website, description, image)
121{
122}
123
130
131bool AboutDialog::event(QEvent *event)
132{
133 const auto res = QDialog::event(event);
134 switch (event->type()) {
135 case QEvent::PaletteChange:
136 setStyleSheet(dialogStyleForPalette(palette()));
137 break;
138 case QEvent::LanguageChange:
139 setWindowTitle(QCoreApplication::translate("QtUtilities::AboutDialog", "About", nullptr));
141 break;
142 default:;
143 }
144 return res;
145}
146
147void AboutDialog::linkActivated(const QString &link)
148{
149 if (link == QLatin1String("qtversion")) {
150 QMessageBox::aboutQt(nullptr);
151 }
152}
153
154} // namespace QtUtilities
The AboutDialog class provides a simple about dialog.
Definition aboutdialog.h:18
~AboutDialog() override
Destroys the about dialog.
AboutDialog(QWidget *parent, const QString &applicationName, const QString &creator, const QString &version, const QString &website=QString(), const QString &description=QString(), const QImage &image=QImage())
Constructs an about dialog with the specified information.
bool event(QEvent *event) override