From eaa6623d1b82982509b8f5f51a44205a3d5f9b5f Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 19 Apr 2020 14:22:29 +0300 Subject: move lib/about to src/about - add AboutDialog test - add SVG icon in place of application icon --- src/about/aboutdialog.cpp | 78 ++++++++++++++++++ src/about/aboutdialog.h | 31 +++++++ src/about/aboutdialog.ui | 201 ++++++++++++++++++++++++++++++++++++++++++++++ src/about/aboutplugin.cpp | 111 +++++++++++++++++++++++++ src/about/aboutplugin.h | 31 +++++++ src/about/aboutplugin.ui | 196 ++++++++++++++++++++++++++++++++++++++++++++ src/about/meson.build | 21 +++++ src/about/test/main.cpp | 21 +++++ src/meson.build | 2 + 9 files changed, 692 insertions(+) create mode 100644 src/about/aboutdialog.cpp create mode 100644 src/about/aboutdialog.h create mode 100644 src/about/aboutdialog.ui create mode 100644 src/about/aboutplugin.cpp create mode 100644 src/about/aboutplugin.h create mode 100644 src/about/aboutplugin.ui create mode 100644 src/about/meson.build create mode 100644 src/about/test/main.cpp (limited to 'src') diff --git a/src/about/aboutdialog.cpp b/src/about/aboutdialog.cpp new file mode 100644 index 0000000..894b1ec --- /dev/null +++ b/src/about/aboutdialog.cpp @@ -0,0 +1,78 @@ +/* + * 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://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "aboutdialog.h" +#include "ui_aboutdialog.h" +#include + +// compiler +// clang also defines __GNUC__, so we need to check for clang first +#if defined(__clang__) +#define compiler "Clang " __clang_version__ +#elif defined(__GNUC__) +#define compiler "GCC " __VERSION__ +#elif defined(_MSC_VER) +#define compiler "MSVC" +#else +#define compiler "unknown compiler" +#endif + +AboutDialog::AboutDialog(QWidget *parent) + : QDialog(parent) + , ui(new Ui::AboutDialog) +{ + //setAttribute(Qt::WA_DeleteOnClose, true); + ui->setupUi(this); + + const QByteArray icon_svg = R"SVG( + + + + + + +)SVG"; + ui->appIcon_svg->load(icon_svg); + + ui->appName_label->setText(qApp->applicationName()); + ui->appVersion_label->setText(qApp->applicationVersion()); + + ui->aboutLabel->setText(tr("

%1 %2

" + "

yet another no-frills browser

" + "

This program is free software, see License for more information.

") + .arg(qApp->applicationName(), qApp->applicationVersion())); + + ui->licenseLabel->setText(tr("

Copyright 2017 - 2020 aqua@

" + "

This program is free software, and you are welcome to use it under the conditions set by the GNU GPLv3.
" + "This is a short summary:

" + "

This program is distributed in the hope that it will be useful, but without any warranty.

" + "

You can read the full terms of the license on the GNU website.

")); + + ui->detailsLabel->setText(tr("

Version " poi_Version "

" + "

Compiled with " compiler "

" + "

Libraries:

")); +} + +AboutDialog::~AboutDialog() +{ + delete ui; +} diff --git a/src/about/aboutdialog.h b/src/about/aboutdialog.h new file mode 100644 index 0000000..e114e7c --- /dev/null +++ b/src/about/aboutdialog.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://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#ifndef SMOLBOTE_ABOUTDIALOG_H +#define SMOLBOTE_ABOUTDIALOG_H + +#include + +namespace Ui +{ +class AboutDialog; +} + +class AboutDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = nullptr); + ~AboutDialog() override; + +private: + Ui::AboutDialog *ui; +}; + +#endif // SMOLBOTE_ABOUTDIALOG_H diff --git a/src/about/aboutdialog.ui b/src/about/aboutdialog.ui new file mode 100644 index 0000000..5b1c12a --- /dev/null +++ b/src/about/aboutdialog.ui @@ -0,0 +1,201 @@ + + + AboutDialog + + + + 0 + 0 + 600 + 420 + + + + About + + + + + + + + + 120 + 120 + + + + + 120 + 120 + + + + + + + + smolbote + + + Qt::AlignCenter + + + + + + + 0.1.0 + + + Qt::AlignCenter + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + QTabWidget::West + + + 0 + + + + About + + + + + + TextLabel + + + true + + + + + + + + License + + + + + + TextLabel + + + true + + + true + + + + + + + + Details + + + + + + TextLabel + + + true + + + true + + + + + + + + Plugins + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + + QSvgWidget + QWidget +
QSvgWidget
+ 1 +
+
+ + + + buttonBox + accepted() + AboutDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AboutDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/about/aboutplugin.cpp b/src/about/aboutplugin.cpp new file mode 100644 index 0000000..99c04ec --- /dev/null +++ b/src/about/aboutplugin.cpp @@ -0,0 +1,111 @@ +/* + * 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, QLatin1String("---") }); + + switch(json.type()) { + case QJsonValue::Bool: + item->setText(1, json.toBool() ? QLatin1String("true") : QLatin1String("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 auto &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, QLatin1String("null")); + break; + + case QJsonValue::Undefined: + item->setText(1, QLatin1String("undefined")); + break; + } + + return item; +} + +AboutPluginDialog::AboutPluginDialog(QPluginLoader *loader, QWidget *parent) + : QDialog(parent) + , ui(new Ui::AboutPluginDialog) +{ + setAttribute(Qt::WA_DeleteOnClose, true); + ui->setupUi(this); + + // load button icon + { + QIcon load_icon; + load_icon.addPixmap(style()->standardPixmap(QStyle::SP_MediaPlay), QIcon::Normal, QIcon::On); + load_icon.addPixmap(style()->standardPixmap(QStyle::SP_MediaStop), QIcon::Normal, QIcon::Off); + ui->load->setIcon(load_icon); + } + + auto metaData = loader->metaData()["MetaData"].toObject(); + + this->setWindowTitle(metaData["name"].toString()); + + ui->path->setText(loader->fileName()); + ui->load->setChecked(loader->isLoaded()); + + connect(ui->load, &QToolButton::clicked, this, [this, loader](bool checked) { + if(checked) { + // load plugin + if(!loader->load()) { + ui->load->setChecked(false); + ui->error->setText(loader->errorString()); + } + } else { + // unload plugin + if(!loader->unload()) { + ui->load->setChecked(true); + ui->error->setText(loader->errorString()); + } + } + }); + + ui->name->setText(metaData[QLatin1String("name")].toString()); + ui->author->setText(metaData[QLatin1String("author")].toString()); + ui->license->setText(metaData[QLatin1String("license")].toString()); + ui->shortcut->setText(metaData[QLatin1String("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/src/about/aboutplugin.h b/src/about/aboutplugin.h new file mode 100644 index 0000000..9651060 --- /dev/null +++ b/src/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(QPluginLoader *loader, QWidget *parent = nullptr); + ~AboutPluginDialog() override; + +private: + Ui::AboutPluginDialog *ui; +}; + +#endif // SMOLBOTE_ABOUTPLUGIN_H diff --git a/src/about/aboutplugin.ui b/src/about/aboutplugin.ui new file mode 100644 index 0000000..5df1c0d --- /dev/null +++ b/src/about/aboutplugin.ui @@ -0,0 +1,196 @@ + + + AboutPluginDialog + + + + 0 + 0 + 500 + 400 + + + + Dialog + + + + + + 0 + + + + General + + + + + + Name + + + + + + + + + + + + + + Author + + + + + + + + + + + + + + Shortcut + + + + + + + + + + + + + + + + + + + + + + + + License + + + + + + + + Details + + + + + + TextLabel + + + + + + + + Key + + + + + Value + + + + + + + + + Controls + + + + + + Load + + + true + + + + + + + + + + + + + + Status + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close + + + + + + + + + buttonBox + accepted() + AboutPluginDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AboutPluginDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/about/meson.build b/src/about/meson.build new file mode 100644 index 0000000..49274a8 --- /dev/null +++ b/src/about/meson.build @@ -0,0 +1,21 @@ +about_moc = mod_qt5.preprocess( + moc_headers: ['aboutdialog.h', 'aboutplugin.h'], + ui_files: ['aboutdialog.ui', 'aboutplugin.ui'], + dependencies: dep_qt5 +) + +dep_about = declare_dependency( + include_directories: '.', + link_with: static_library('about', + [ 'aboutdialog.cpp', 'aboutplugin.cpp', about_moc, version_h], + dependencies: [dep_qt5]) +) + +poi_sourceset.add(dep_about) + +test('about dialog', executable('about', + sources: 'test/main.cpp', + dependencies: [ dep_qt5, dep_about, dep_catch ]), + args: [ '-platform', 'offscreen' ], + env: 'autoclose=1' +) diff --git a/src/about/test/main.cpp b/src/about/test/main.cpp new file mode 100644 index 0000000..18037e1 --- /dev/null +++ b/src/about/test/main.cpp @@ -0,0 +1,21 @@ +#include +#include +#include "aboutdialog.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + app.setApplicationName("about"); + app.setApplicationVersion("1.2.3"); + + AboutDialog dlg; + QObject::connect(&dlg, &AboutDialog::finished, &app, &QApplication::quit); + dlg.show(); + + if(qEnvironmentVariableIsSet("autoclose")) { + QTimer::singleShot(200, &dlg, &AboutDialog::accept); + } + + return app.exec(); +} + diff --git a/src/meson.build b/src/meson.build index 31f4ffc..1101b7a 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,6 +7,8 @@ poi_settings_h = custom_target('default_config_value', command: [ python3, '@INPUT0@', '--kconfig=@INPUT1@', '--dotconfig=@INPUT2@', '--input=@INPUT3@', '--output=@OUTPUT@' ] ) +subdir('about') + poi_sourceset.add(mod_qt5.preprocess( moc_headers: ['browser.h', 'mainwindow/mainwindow.h', 'mainwindow/addressbar.h', 'mainwindow/menubar.h', 'mainwindow/widgets/completer.h', 'mainwindow/widgets/urllineedit.h', 'mainwindow/widgets/dockwidget.h', 'mainwindow/widgets/navigationbar.h', 'mainwindow/widgets/searchform.h', -- cgit v1.2.1