Skip to content

Commit ba28ac3

Browse files
committed
panko: gui: added about dialog, despite the UI just being literally a blank window
1 parent 79dfaf8 commit ba28ac3

File tree

4 files changed

+251
-1
lines changed

4 files changed

+251
-1
lines changed

src/panko-gui/dialogs/about.cc

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
}

src/panko-gui/dialogs/about.hh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
#pragma once
3+
#if !defined(PANKO_GUI_DIALOGS_ABOUT_HH)
4+
#define PANKO_GUI_DIALOGS_ABOUT_HH
5+
6+
#include "panko/internal/defs.hh"
7+
8+
#include <memory>
9+
10+
PANKO_DIAGNOSTICS_PUSH()
11+
PANKO_DIAGNOSTICS_IGNORE("-Wsign-conversion")
12+
PANKO_DIAGNOSTICS_IGNORE("-Warith-conversion")
13+
PANKO_DIAGNOSTICS_IGNORE("-Wconversion")
14+
#include <QDialog>
15+
#include <QLabel>
16+
#include <QWidget>
17+
#include <QHBoxLayout>
18+
#include <QTextEdit>
19+
#include <QTabWidget>
20+
#include <QVBoxLayout>
21+
#include <QSpacerItem>
22+
PANKO_DIAGNOSTICS_POP()
23+
24+
namespace Panko::gui::dialogs {
25+
struct About final : public QDialog {
26+
Q_OBJECT
27+
private:
28+
std::unique_ptr<QHBoxLayout> _horizontal_layout;
29+
std::unique_ptr<QVBoxLayout> _sidebar_layout;
30+
std::unique_ptr<QLabel> _sidebar_img;
31+
std::unique_ptr<QSpacerItem> _sidebar_spacer;
32+
std::unique_ptr<QLabel> _sidebar_version;
33+
std::unique_ptr<QLabel> _sidebar_py_version;
34+
std::unique_ptr<QLabel> _sidebar_lua_version;
35+
std::unique_ptr<QLabel> _sidebar_platform;
36+
std::unique_ptr<QLabel> _sidebar_compiler;
37+
38+
std::unique_ptr<QTabWidget> _about_tabs;
39+
40+
std::unique_ptr<QWidget> _tab_about;
41+
std::unique_ptr<QVBoxLayout> _about_layout;
42+
std::unique_ptr<QLabel> _about_text;
43+
std::unique_ptr<QHBoxLayout> _flag_layout;
44+
std::unique_ptr<QLabel> _flag_trans;
45+
std::unique_ptr<QLabel> _flag_lesbian;
46+
47+
std::unique_ptr<QWidget> _tab_components;
48+
std::unique_ptr<QVBoxLayout> _components_layout;
49+
std::unique_ptr<QTextEdit> _components_text;
50+
51+
std::unique_ptr<QWidget> _tab_contributors;
52+
std::unique_ptr<QVBoxLayout> _contributors_layout;
53+
std::unique_ptr<QTextEdit> _contributors_text;
54+
55+
std::unique_ptr<QWidget> _tab_license;
56+
std::unique_ptr<QVBoxLayout> _license_layout;
57+
std::unique_ptr<QTextEdit> _license_text;
58+
59+
void _add_about_text();
60+
void _add_components_text();
61+
void _add_contributors_text();
62+
void _add_license_text();
63+
public:
64+
About(QWidget* parent = nullptr) noexcept;
65+
~About() = default;
66+
};
67+
}
68+
69+
#endif /* PANKO_GUI_DIALOGS_ABOUT_HH */

src/panko-gui/dialogs/meson.build

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
11
# SPDX-License-Identifier: BSD-3-Clause
2+
3+
panko_gui_srcs += files([
4+
'about.cc',
5+
])
6+
7+
8+
panko_gui_srcs += qt.compile_moc(
9+
headers: files([
10+
'about.hh'
11+
])
12+
)

src/panko-gui/windows/main.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "panko-gui/windows/main.hh"
77

8+
#include "panko-gui/dialogs/about.hh"
89

910
PANKO_DIAGNOSTICS_PUSH()
1011
PANKO_DIAGNOSTICS_IGNORE("-Wconversion")
@@ -109,7 +110,8 @@ namespace Panko::gui::windows {
109110
// _action_help_about->setShortcut(...);
110111
_action_help_about->setStatusTip(tr("About Panko"));
111112
connect(_action_help_about.get(), &QAction::triggered, this, [this](){
112-
113+
dialogs::About about{this};
114+
about.exec();
113115
});
114116

115117
_action_help_website = std::make_unique<QAction>(tr("Website"), this);

0 commit comments

Comments
 (0)