From 240fb8427a89d0aa78da07c8d147a0d57df5bb67 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 22 Nov 2018 10:23:47 +0100 Subject: Add AboutPlugin dialog --- lib/about/aboutplugin.cpp | 87 ++++++++++++++++++++++ lib/about/aboutplugin.h | 31 ++++++++ lib/about/aboutplugin.ui | 179 ++++++++++++++++++++++++++++++++++++++++++++++ lib/about/meson.build | 6 +- 4 files changed, 300 insertions(+), 3 deletions(-) create mode 100644 lib/about/aboutplugin.cpp create mode 100644 lib/about/aboutplugin.h create mode 100644 lib/about/aboutplugin.ui (limited to 'lib/about') diff --git a/lib/about/aboutplugin.cpp b/lib/about/aboutplugin.cpp new file mode 100644 index 0000000..7df75fa --- /dev/null +++ b/lib/about/aboutplugin.cpp @@ -0,0 +1,87 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "aboutplugin.h" +#include "ui_aboutplugin.h" +#include +#include + +QTreeWidgetItem *createItem(const QString &key, const QJsonValue &json, QTreeWidgetItem *parent) +{ + auto *item = new QTreeWidgetItem(parent, { key, QLatin1Literal("---") }); + + switch(json.type()) { + case QJsonValue::Bool: + item->setText(1, json.toBool() ? QLatin1Literal("true") : QLatin1Literal("false")); + break; + + case QJsonValue::Double: + item->setText(1, QString::number(json.toDouble())); + break; + + case QJsonValue::String: + item->setText(1, json.toString()); + break; + + case QJsonValue::Array: + item->setText(1, QString()); + for(const QJsonValue &v : json.toArray()) { + createItem(QString(), v, item); + } + break; + + case QJsonValue::Object: + item->setText(1, QString()); + for(const QString &k : json.toObject().keys()) { + createItem(k, json.toObject()[k], item); + } + break; + + case QJsonValue::Null: + item->setText(1, QLatin1Literal("null")); + break; + + case QJsonValue::Undefined: + item->setText(1, QLatin1Literal("undefined")); + break; + } + + return item; +} + +AboutPluginDialog::AboutPluginDialog(const QPluginLoader *loader, QWidget *parent) + : QDialog(parent) + , ui(new Ui::AboutPluginDialog) +{ + setAttribute(Qt::WA_DeleteOnClose, true); + ui->setupUi(this); + + auto metaData = loader->metaData()["MetaData"].toObject(); + + this->setWindowTitle(metaData["name"].toString()); + + ui->path->setText(loader->fileName()); + ui->loaded->setChecked(loader->isLoaded()); + + ui->name->setText(metaData[QLatin1Literal("name")].toString()); + ui->author->setText(metaData[QLatin1Literal("author")].toString()); + ui->license->setText(metaData[QLatin1Literal("license")].toString()); + ui->shortcut->setText(metaData[QLatin1Literal("shortcut")].toString()); + + for(const QString &key : loader->metaData().keys()) { + auto *i = createItem(key, loader->metaData()[key], nullptr); + + if(i != nullptr) + ui->details_treeWidget->insertTopLevelItem(0, i); + } +} + +AboutPluginDialog::~AboutPluginDialog() +{ + delete ui; +} diff --git a/lib/about/aboutplugin.h b/lib/about/aboutplugin.h new file mode 100644 index 0000000..adab215 --- /dev/null +++ b/lib/about/aboutplugin.h @@ -0,0 +1,31 @@ +/* + * This file is part of smolbote. It's copyrighted by the contributors recorded + * in the version control history of the file, available from its original + * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef SMOLBOTE_ABOUTPLUGIN_H +#define SMOLBOTE_ABOUTPLUGIN_H + +#include + +namespace Ui +{ +class AboutPluginDialog; +} +class QPluginLoader; +class AboutPluginDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutPluginDialog(const QPluginLoader *loader, QWidget *parent = nullptr); + ~AboutPluginDialog() override; + +private: + Ui::AboutPluginDialog *ui; +}; + +#endif // SMOLBOTE_ABOUTPLUGIN_H diff --git a/lib/about/aboutplugin.ui b/lib/about/aboutplugin.ui new file mode 100644 index 0000000..f2d4848 --- /dev/null +++ b/lib/about/aboutplugin.ui @@ -0,0 +1,179 @@ + + + AboutPluginDialog + + + + 0 + 0 + 474 + 329 + + + + Dialog + + + + + + 0 + + + + General + + + + + + Name + + + + + + + + + + + + + + Author + + + + + + + + + + + + + + Shortcut + + + + + + + + + + + + + + + + false + + + Load + + + true + + + + + + + + + + + + + + + + License + + + + + + + + Details + + + + + + TextLabel + + + + + + + + Key + + + + + Value + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + AboutPluginDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AboutPluginDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/lib/about/meson.build b/lib/about/meson.build index 35598b3..961c7ef 100644 --- a/lib/about/meson.build +++ b/lib/about/meson.build @@ -1,11 +1,11 @@ about_moc = qt5.preprocess( - moc_headers: ['aboutdialog.h'], - ui_files: ['aboutdialog.ui'], + moc_headers: ['aboutdialog.h', 'aboutplugin.h'], + ui_files: ['aboutdialog.ui', 'aboutplugin.ui'], dependencies: dep_qt5 ) about_inc = include_directories('.') -about_lib = static_library('about', ['aboutdialog.cpp', about_moc], +about_lib = static_library('about', ['aboutdialog.cpp', 'aboutplugin.cpp', about_moc], dependencies: [dep_qt5, dep_genheaders] ) -- cgit v1.2.1