2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-02-26 10:50:04 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-05-24 14:26:33 +00:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/AboutDialog.h>
|
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2020-07-22 15:29:51 +02:00
|
|
|
#include <LibGUI/ImageWidget.h>
|
2020-09-18 09:49:51 +02:00
|
|
|
#include <LibGUI/Label.h>
|
2020-02-06 20:33:02 +01:00
|
|
|
#include <LibGUI/Widget.h>
|
2022-04-09 09:28:38 +02:00
|
|
|
#include <LibGfx/Font/Font.h>
|
|
|
|
|
#include <LibGfx/Font/FontDatabase.h>
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
namespace GUI {
|
|
|
|
|
|
2022-08-30 12:49:08 +02:00
|
|
|
AboutDialog::AboutDialog(StringView name, StringView version, Gfx::Bitmap const* icon, Window* parent_window)
|
2020-03-04 20:53:51 +01:00
|
|
|
: Dialog(parent_window)
|
2019-09-02 19:45:55 +02:00
|
|
|
, m_name(name)
|
|
|
|
|
, m_icon(icon)
|
2021-08-29 12:00:50 +02:00
|
|
|
, m_version_string(version)
|
2019-09-02 19:45:55 +02:00
|
|
|
{
|
2021-07-27 20:13:13 +02:00
|
|
|
resize(413, 204);
|
2022-12-04 18:02:33 +00:00
|
|
|
set_title(DeprecatedString::formatted("About {}", m_name));
|
2019-09-02 19:45:55 +02:00
|
|
|
set_resizable(false);
|
|
|
|
|
|
2020-03-30 09:01:02 +02:00
|
|
|
if (parent_window)
|
|
|
|
|
set_icon(parent_window->icon());
|
|
|
|
|
|
2023-01-06 16:48:37 +00:00
|
|
|
auto widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
|
|
|
|
|
widget->set_fill_with_background_color(true);
|
|
|
|
|
widget->set_layout<VerticalBoxLayout>();
|
|
|
|
|
widget->layout()->set_spacing(0);
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2023-01-06 16:48:37 +00:00
|
|
|
auto& banner_image = widget->add<GUI::ImageWidget>();
|
2022-07-11 17:32:29 +00:00
|
|
|
banner_image.load_from_file("/res/graphics/brand-banner.png"sv);
|
2020-05-24 14:26:33 +00:00
|
|
|
|
2023-01-06 16:48:37 +00:00
|
|
|
auto& content_container = widget->add<Widget>();
|
2020-05-24 14:26:33 +00:00
|
|
|
content_container.set_layout<HorizontalBoxLayout>();
|
|
|
|
|
|
|
|
|
|
auto& left_container = content_container.add<Widget>();
|
2020-12-30 01:23:32 +01:00
|
|
|
left_container.set_fixed_width(60);
|
2020-03-04 19:07:55 +01:00
|
|
|
left_container.set_layout<VerticalBoxLayout>();
|
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
2021-08-17 00:11:38 +00:00
|
|
|
left_container.layout()->set_margins({ 12, 0, 0 });
|
2020-05-24 14:26:33 +00:00
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
|
auto& icon_wrapper = left_container.add<Widget>();
|
2020-12-30 01:23:32 +01:00
|
|
|
icon_wrapper.set_fixed_size(32, 48);
|
2020-05-24 14:26:33 +00:00
|
|
|
icon_wrapper.set_layout<VerticalBoxLayout>();
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2020-07-22 15:29:51 +02:00
|
|
|
auto& icon_image = icon_wrapper.add<ImageWidget>();
|
2020-06-14 11:06:46 +03:00
|
|
|
icon_image.set_bitmap(m_icon);
|
2020-05-24 14:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto& right_container = content_container.add<Widget>();
|
2020-03-04 19:07:55 +01:00
|
|
|
right_container.set_layout<VerticalBoxLayout>();
|
2021-08-17 00:10:51 +00:00
|
|
|
right_container.layout()->set_margins({ 12, 4, 4, 0 });
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2021-11-11 00:55:02 +01:00
|
|
|
auto make_label = [&](StringView text, bool bold = false) {
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& label = right_container.add<Label>(text);
|
|
|
|
|
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
2020-12-30 01:23:32 +01:00
|
|
|
label.set_fixed_height(14);
|
2019-09-02 19:45:55 +02:00
|
|
|
if (bold)
|
2021-05-20 18:40:48 +02:00
|
|
|
label.set_font(Gfx::FontDatabase::default_font().bold_variant());
|
2019-09-02 19:45:55 +02:00
|
|
|
};
|
|
|
|
|
make_label(m_name, true);
|
2020-05-24 14:26:33 +00:00
|
|
|
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
|
|
|
|
|
if (m_name != "SerenityOS")
|
2022-07-11 17:32:29 +00:00
|
|
|
make_label("SerenityOS"sv);
|
2021-08-29 12:00:50 +02:00
|
|
|
make_label(m_version_string);
|
2023-01-11 16:16:04 +00:00
|
|
|
make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2023"sv);
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
right_container.layout()->add_spacer();
|
2019-09-02 19:45:55 +02:00
|
|
|
|
2020-03-04 19:07:55 +01:00
|
|
|
auto& button_container = right_container.add<Widget>();
|
2021-07-27 20:13:13 +02:00
|
|
|
button_container.set_fixed_height(22);
|
2020-03-04 19:07:55 +01:00
|
|
|
button_container.set_layout<HorizontalBoxLayout>();
|
|
|
|
|
button_container.layout()->add_spacer();
|
2022-06-10 23:03:11 +02:00
|
|
|
auto& ok_button = button_container.add<DialogButton>("OK");
|
2020-05-12 20:30:33 +02:00
|
|
|
ok_button.on_click = [this](auto) {
|
2022-05-13 13:10:27 +01:00
|
|
|
done(ExecResult::OK);
|
2019-09-02 19:45:55 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 15:07:41 +01:00
|
|
|
}
|