|
| 1 | +// SPDX-License-Identifier: BSD-3-Clause |
| 2 | + |
| 3 | +#include <memory> |
| 4 | +#include <format> |
| 5 | + |
| 6 | +#include "panko/config.hh" |
| 7 | + |
| 8 | +#include "panko-gui/dialogs/about.hh" |
| 9 | + |
| 10 | +PANKO_DIAGNOSTICS_PUSH() |
| 11 | +PANKO_DIAGNOSTICS_IGNORE("-Wsign-conversion") |
| 12 | +PANKO_DIAGNOSTICS_IGNORE("-Warith-conversion") |
| 13 | +PANKO_DIAGNOSTICS_IGNORE("-Wconversion") |
| 14 | +#include <QIcon> |
| 15 | +#include <QFile> |
| 16 | +PANKO_DIAGNOSTICS_POP() |
| 17 | + |
| 18 | +namespace Panko::gui::dialogs { |
| 19 | + namespace cfg = Panko::config; |
| 20 | + |
| 21 | + About::About(QWidget* parent) noexcept : QDialog{parent} { |
| 22 | + setWindowTitle(tr("About")); |
| 23 | + |
| 24 | + setMinimumSize(900, 550); |
| 25 | + setMaximumSize(900, 550); |
| 26 | + resize(900, 550); |
| 27 | + |
| 28 | + _horizontal_layout = std::make_unique<QHBoxLayout>(); |
| 29 | + _sidebar_layout = std::make_unique<QVBoxLayout>(); |
| 30 | + |
| 31 | + _sidebar_img = std::make_unique<QLabel>(); |
| 32 | + _sidebar_spacer = std::make_unique<QSpacerItem>(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding); |
| 33 | + _sidebar_version = std::make_unique<QLabel>(); |
| 34 | + _sidebar_py_version = std::make_unique<QLabel>(); |
| 35 | + _sidebar_lua_version = std::make_unique<QLabel>(); |
| 36 | + _sidebar_platform = std::make_unique<QLabel>(); |
| 37 | + _sidebar_compiler = std::make_unique<QLabel>(); |
| 38 | + |
| 39 | + /* TODO(aki): PLACEHOLDER */ |
| 40 | + _sidebar_img->setPixmap(QIcon::fromTheme("cpu").pixmap(256, 256)); |
| 41 | + _sidebar_img->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
| 42 | + |
| 43 | + _sidebar_version->setText(QString::fromStdString( |
| 44 | + std::format("Version: {}"sv, cfg::version_full) |
| 45 | + )); |
| 46 | + _sidebar_py_version->setText(QString::fromStdString( |
| 47 | + std::format("Python: {}"sv, cfg::python_version) |
| 48 | + )); |
| 49 | + _sidebar_lua_version->setText(QString::fromStdString( |
| 50 | + std::format("Lua: {} {}"sv, cfg::lua_backend, cfg::lua_version) |
| 51 | + )); |
| 52 | + _sidebar_platform->setText(QString::fromStdString( |
| 53 | + std::format("Platform: {}-{}"sv, cfg::target_system, cfg::target_arch) |
| 54 | + )); |
| 55 | + _sidebar_compiler->setText(QString::fromStdString( |
| 56 | + std::format("Compiler: {} {}"sv, cfg::compiler_name, cfg::compiler_version) |
| 57 | + )); |
| 58 | + |
| 59 | + _sidebar_layout->addWidget(_sidebar_img.get()); |
| 60 | + _sidebar_layout->addItem(_sidebar_spacer.release()); |
| 61 | + _sidebar_layout->addWidget(_sidebar_version.get()); |
| 62 | + _sidebar_layout->addWidget(_sidebar_py_version.get()); |
| 63 | + _sidebar_layout->addWidget(_sidebar_lua_version.get()); |
| 64 | + _sidebar_layout->addWidget(_sidebar_platform.get()); |
| 65 | + _sidebar_layout->addWidget(_sidebar_compiler.get()); |
| 66 | + |
| 67 | + _horizontal_layout->addLayout(_sidebar_layout.get()); |
| 68 | + |
| 69 | + _about_tabs = std::make_unique<QTabWidget>(); |
| 70 | + _about_tabs->setIconSize(QSize(32, 32)); |
| 71 | + |
| 72 | + _tab_about = std::make_unique<QWidget>(); |
| 73 | + _tab_components = std::make_unique<QWidget>(); |
| 74 | + _tab_contributors = std::make_unique<QWidget>(); |
| 75 | + _tab_license = std::make_unique<QWidget>(); |
| 76 | + |
| 77 | + _about_layout = std::make_unique<QVBoxLayout>(); |
| 78 | + _flag_layout = std::make_unique<QHBoxLayout>(); |
| 79 | + _components_layout = std::make_unique<QVBoxLayout>(); |
| 80 | + _contributors_layout = std::make_unique<QVBoxLayout>(); |
| 81 | + _license_layout = std::make_unique<QVBoxLayout>(); |
| 82 | + |
| 83 | + _tab_about->setLayout(_about_layout.get()); |
| 84 | + _tab_components->setLayout(_components_layout.get()); |
| 85 | + _tab_contributors->setLayout(_contributors_layout.get()); |
| 86 | + _tab_license->setLayout(_license_layout.get()); |
| 87 | + |
| 88 | + _about_text = std::make_unique<QLabel>(); |
| 89 | + _flag_trans = std::make_unique<QLabel>(); |
| 90 | + _flag_trans->setPixmap(QIcon(":/img/trans-flag.svg").pixmap(256, 512)); |
| 91 | + _flag_trans->setAlignment(Qt::AlignCenter); |
| 92 | + _flag_lesbian = std::make_unique<QLabel>(); |
| 93 | + _flag_lesbian->setPixmap(QIcon(":/img/lesbian-flag.svg").pixmap(256, 512)); |
| 94 | + _flag_lesbian->setAlignment(Qt::AlignCenter); |
| 95 | + _components_text = std::make_unique<QTextEdit>(); |
| 96 | + _contributors_text = std::make_unique<QTextEdit>(); |
| 97 | + _license_text = std::make_unique<QTextEdit>(); |
| 98 | + |
| 99 | + _about_layout->addWidget(_about_text.get()); |
| 100 | + _about_layout->addSpacerItem(new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding)); |
| 101 | + _flag_layout->addWidget(_flag_trans.get()); |
| 102 | + _flag_layout->addWidget(_flag_lesbian.get()); |
| 103 | + _about_layout->addLayout(_flag_layout.get()); |
| 104 | + _components_layout->addWidget(_components_text.get()); |
| 105 | + _contributors_layout->addWidget(_contributors_text.get()); |
| 106 | + _license_layout->addWidget(_license_text.get()); |
| 107 | + |
| 108 | + /* TODO(aki): PLACEHOLDERS */ |
| 109 | + _about_tabs->addTab(_tab_about.release(), QIcon::fromTheme("help-about"), tr("About")); |
| 110 | + _about_tabs->addTab(_tab_components.release(), QIcon::fromTheme("media-floppy"), tr("Components")); |
| 111 | + _about_tabs->addTab(_tab_contributors.release(), QIcon::fromTheme("im-user"), tr("Contributors")); |
| 112 | + _about_tabs->addTab(_tab_license.release(), QIcon::fromTheme("license"), tr("License")); |
| 113 | + |
| 114 | + _horizontal_layout->addWidget(_about_tabs.get()); |
| 115 | + |
| 116 | + _add_about_text(); |
| 117 | + _add_components_text(); |
| 118 | + _add_contributors_text(); |
| 119 | + _add_license_text(); |
| 120 | + |
| 121 | + setLayout(_horizontal_layout.get()); |
| 122 | + } |
| 123 | + |
| 124 | + void About::_add_about_text() { |
| 125 | + QFile about{":/txt/about"}; |
| 126 | + about.open(QIODevice::ReadOnly); |
| 127 | + |
| 128 | + _about_text->setText(QTextStream(&about).readAll()); |
| 129 | + about.close(); |
| 130 | + |
| 131 | + _about_text->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
| 132 | + _about_text->setWordWrap(true); |
| 133 | + |
| 134 | + } |
| 135 | + |
| 136 | + void About::_add_components_text() { |
| 137 | + |
| 138 | + QFile components{":/txt/components"}; |
| 139 | + components.open(QIODevice::ReadOnly); |
| 140 | + |
| 141 | + _components_text->setText(QTextStream(&components).readAll()); |
| 142 | + components.close(); |
| 143 | + |
| 144 | + _components_text->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
| 145 | + _components_text->setReadOnly(true); |
| 146 | + } |
| 147 | + |
| 148 | + void About::_add_contributors_text() { |
| 149 | + QFile contributors{":/txt/contributors"}; |
| 150 | + contributors.open(QIODevice::ReadOnly); |
| 151 | + |
| 152 | + _contributors_text->setText(QTextStream(&contributors).readAll()); |
| 153 | + contributors.close(); |
| 154 | + |
| 155 | + _contributors_text->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
| 156 | + _contributors_text->setReadOnly(true); |
| 157 | + } |
| 158 | + |
| 159 | + void About::_add_license_text() { |
| 160 | + QFile license{":/txt/license"}; |
| 161 | + license.open(QIODevice::ReadOnly); |
| 162 | + |
| 163 | + _license_text->setPlainText(QTextStream(&license).readAll()); |
| 164 | + license.close(); |
| 165 | + |
| 166 | + _license_text->setReadOnly(true); |
| 167 | + } |
| 168 | +} |
0 commit comments