looper/backends/ui/qt/aboutwindow.cpp
Zachary Hall 27113f6443
Some checks failed
Build / build-gentoo (push) Failing after 22s
Build / download-system-deps (push) Successful in 3m16s
Build / get-source-code (push) Successful in 12m8s
Build / build-appimage (push) Successful in 3m58s
Build / build-android (push) Failing after 2m59s
Build / build-windows (push) Failing after 7m22s
WTF - Asserting the return value of a function causes it to not run?!
2024-12-08 09:55:27 -08:00

67 lines
2.5 KiB
C++

#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() {
license_text = new QTextBrowser();
license_list = new QListView();
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);
QBoxLayout *mainLayout = new QBoxLayout(QBoxLayout::TopToBottom);
QLabel *title = new QLabel("Looper");
auto font = title->font();
font.setPointSize(24);
title->setFont(font);
mainLayout->addWidget(title);
QLabel *versionText = new QLabel(TAG);
mainLayout->addWidget(versionText);
QSplitter *splitter = new QSplitter(Qt::Orientation::Horizontal);
splitter->addWidget(license_list);
splitter->addWidget(license_text);
mainLayout->addWidget(splitter);
setLayout(mainLayout);
license_list->clicked(license_list->model()->index(0, 0));
setWindowTitle("About Looper");
}