2024-11-20 08:15:45 -08:00
|
|
|
#include "aboutwindow.h"
|
|
|
|
QModelIndex LicenseModel::index(int row, int column, const QModelIndex &parent) const {
|
|
|
|
return createIndex(row, 0, row);
|
|
|
|
}
|
|
|
|
QModelIndex LicenseModel::parent(const QModelIndex &child) const {
|
|
|
|
return QModelIndex();
|
|
|
|
}
|
|
|
|
Qt::ItemFlags LicenseModel::flags(const QModelIndex &index) const {
|
|
|
|
return Qt::ItemFlag::ItemIsEnabled|Qt::ItemFlag::ItemIsSelectable;
|
|
|
|
}
|
|
|
|
int LicenseModel::rowCount(const QModelIndex &parent) const {
|
|
|
|
return parent.isValid() ? 0 : licenseData.size();
|
|
|
|
}
|
|
|
|
int LicenseModel::columnCount(const QModelIndex &parent) const {
|
|
|
|
return parent.isValid() ? 0 : 1;
|
|
|
|
}
|
|
|
|
QVariant LicenseModel::data(const QModelIndex &index, int role) const {
|
|
|
|
if ((index.row() < 0 || licenseData.size() <= index.row()) && (role == Qt::DisplayRole || role == Qt::UserRole)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
switch (role) {
|
|
|
|
case Qt::DisplayRole: {
|
|
|
|
const LicenseData &data = licenseData[index.row()];
|
|
|
|
return QString::asprintf("%s (%s)", data.Project.c_str(), data.Spdx.c_str());
|
|
|
|
} break;
|
|
|
|
case Qt::UserRole: {
|
|
|
|
return QString(licenseData[index.row()].LicenseContents.c_str());
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
return QVariant();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LicenseModel::LicenseModel() {
|
|
|
|
auto tmp = get_license_data();
|
|
|
|
for (auto data : tmp) {
|
|
|
|
licenseData.push_back(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
LicenseModel::~LicenseModel() {
|
|
|
|
|
|
|
|
}
|
|
|
|
AboutWindow::AboutWindow() {
|
2024-12-08 10:58:16 -08:00
|
|
|
license_text = new QTextBrowser(this);
|
|
|
|
license_list = new QListView(this);
|
2024-11-20 08:15:45 -08:00
|
|
|
license_list->setModel(new LicenseModel());
|
|
|
|
QObject::connect(license_list, &QListView::clicked, [=,this](const QModelIndex &idx) {
|
|
|
|
license_text->setText(license_list->model()->data(idx, Qt::UserRole).toString());
|
|
|
|
});
|
|
|
|
license_list->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
license_list->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2024-12-08 10:58:16 -08:00
|
|
|
QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom, this);
|
|
|
|
QLabel *title = new QLabel("Looper", this);
|
2024-11-20 08:15:45 -08:00
|
|
|
auto font = title->font();
|
|
|
|
font.setPointSize(24);
|
|
|
|
title->setFont(font);
|
|
|
|
mainLayout->addWidget(title);
|
2024-12-08 10:58:16 -08:00
|
|
|
QLabel *versionText = new QLabel(TAG, this);
|
2024-11-20 08:15:45 -08:00
|
|
|
mainLayout->addWidget(versionText);
|
2024-12-08 10:58:16 -08:00
|
|
|
QSplitter *splitter = new QSplitter(Qt::Orientation::Horizontal, this);
|
2024-11-20 08:15:45 -08:00
|
|
|
splitter->addWidget(license_list);
|
|
|
|
splitter->addWidget(license_text);
|
|
|
|
mainLayout->addWidget(splitter);
|
|
|
|
setLayout(mainLayout);
|
|
|
|
license_list->clicked(license_list->model()->index(0, 0));
|
2024-12-08 09:55:27 -08:00
|
|
|
setWindowTitle("About Looper");
|
|
|
|
}
|