SILICON
Loading...
Searching...
No Matches
aboutDialog.cpp
Go to the documentation of this file.
1/*
2 Copyright (c) 2025. Giulio Cocconi
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "aboutDialog.hpp"
19
20#include <stdexcept>
21
22#include <QApplication>
23#include <QDir>
24#include <QFile>
25#include <QMainWindow>
26#include <QPushButton>
27#include <QStringBuilder>
28
29
30namespace SILICON::ui {
31
32AboutDialog::AboutDialog(const QString& title, QWidget* parent) : QDialog(parent)
33{
34 setWindowTitle(QString("About %1").arg(title));
35 setFixedSize(600, 500);
36
37 const auto icon = QApplication::windowIcon();
38 if (icon.isNull())
39 throw std::logic_error("AboutDialog: application window icon is not set");
40
41 titleLabel = new QLabel(title, this);
42 titleLabel->setObjectName("titleLabel");
43
44 iconLabel = new QLabel(this);
45 iconLabel->setPixmap(icon.pixmap(QSize(128, 128)));
46 iconLabel->setScaledContents(true);
47
48 topLayout->setSpacing(20);
49 topLayout->addWidget(iconLabel, 20);
50 topLayout->addWidget(titleLabel, 80);
51
52 mainLayout->addLayout(topLayout);
53
54 explainatoryText->setWordWrap(true);
55
56 mainLayout->addWidget(explainatoryText);
57
58 licenseTextEdit = new QPlainTextEdit(this);
59 licenseTextEdit->setReadOnly(true);
60 licenseTextEdit->setFont(QFont("NovaMono"));
61
62 closeButton = new QPushButton(tr("Close"), this);
63 connect(closeButton, &QPushButton::clicked, this, &QDialog::accept);
64
65 mainLayout->addWidget(licenseTextEdit);
66 mainLayout->addWidget(closeButton);
67
68 // Load the licenses from the Qt resources
70}
71
73{
74 if (this->licenseText.isEmpty()) {
75 const QDir dir(":/licenses/");
76
77 QStringList fileList = dir.entryList(QDir::Files);
78
79 if (fileList.isEmpty()) {
80 licenseTextEdit->setPlainText("Error: License resource directory is empty.");
81 }
82
83 for (const QString& fileName : fileList) {
84 QString filePath = dir.filePath(fileName);
85
86 if (auto licenseFile = QFile(filePath);
87 licenseFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
88 // Add a header for each license to separate them clearly
89 this->licenseText.append(
90 "=================================================================\n");
91 this->licenseText.append("LICENSE: ");
92 this->licenseText.append(fileName);
93 this->licenseText.append(
94 "\n=================================================================\n\n");
95
96 // Append the content of the license file
97 QTextStream in(&licenseFile);
98 this->licenseText.append(in.readAll());
99
100 // Add some newlines to separate from the next license
101 this->licenseText.append("\n\n\n");
102
103 licenseFile.close();
104 }
105
106 if (this->licenseText.isEmpty())
107 throw std::logic_error("loadLicenses: license text is empty after reading file");
108
109 licenseTextEdit->setPlainText(this->licenseText);
110 }
111 }
112}
113
114} // namespace SILICON::ui
QPlainTextEdit * licenseTextEdit
AboutDialog(const QString &title="SILICON", QWidget *parent=nullptr)