2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-05-24 11:26:33 -03:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/AboutDialog.h>
|
|
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2020-07-22 10:29:51 -03:00
|
|
|
#include <LibGUI/ImageWidget.h>
|
2020-09-18 04:49:51 -03:00
|
|
|
#include <LibGUI/Label.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Widget.h>
|
2020-02-14 19:53:11 -03:00
|
|
|
#include <LibGfx/Font.h>
|
2020-12-29 14:25:13 -03:00
|
|
|
#include <LibGfx/FontDatabase.h>
|
2019-09-02 14:45:55 -03:00
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
namespace GUI {
|
|
|
|
|
|
2021-11-10 20:55:02 -03:00
|
|
|
AboutDialog::AboutDialog(StringView name, const Gfx::Bitmap* icon, Window* parent_window, StringView version)
|
2020-03-04 16:53:51 -03:00
|
|
|
: Dialog(parent_window)
|
2019-09-02 14:45:55 -03:00
|
|
|
, m_name(name)
|
|
|
|
|
, m_icon(icon)
|
2021-08-29 07:00:50 -03:00
|
|
|
, m_version_string(version)
|
2019-09-02 14:45:55 -03:00
|
|
|
{
|
2021-07-27 15:13:13 -03:00
|
|
|
resize(413, 204);
|
2021-01-03 10:51:17 -03:00
|
|
|
set_title(String::formatted("About {}", m_name));
|
2019-09-02 14:45:55 -03:00
|
|
|
set_resizable(false);
|
|
|
|
|
|
2020-03-30 04:01:02 -03:00
|
|
|
if (parent_window)
|
|
|
|
|
set_icon(parent_window->icon());
|
|
|
|
|
|
2020-03-04 05:46:23 -03:00
|
|
|
auto& widget = set_main_widget<Widget>();
|
|
|
|
|
widget.set_fill_with_background_color(true);
|
2020-05-24 11:26:33 -03:00
|
|
|
widget.set_layout<VerticalBoxLayout>();
|
|
|
|
|
widget.layout()->set_spacing(0);
|
2019-09-02 14:45:55 -03:00
|
|
|
|
2020-07-22 10:29:51 -03:00
|
|
|
auto& banner_image = widget.add<GUI::ImageWidget>();
|
2020-08-24 07:03:30 -03:00
|
|
|
banner_image.load_from_file("/res/graphics/brand-banner.png");
|
2020-05-24 11:26:33 -03:00
|
|
|
|
|
|
|
|
auto& content_container = widget.add<Widget>();
|
|
|
|
|
content_container.set_layout<HorizontalBoxLayout>();
|
|
|
|
|
|
|
|
|
|
auto& left_container = content_container.add<Widget>();
|
2020-12-29 21:23:32 -03:00
|
|
|
left_container.set_fixed_width(60);
|
2020-03-04 15:07:55 -03: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-16 21:11:38 -03:00
|
|
|
left_container.layout()->set_margins({ 12, 0, 0 });
|
2020-05-24 11:26:33 -03:00
|
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
|
auto& icon_wrapper = left_container.add<Widget>();
|
2020-12-29 21:23:32 -03:00
|
|
|
icon_wrapper.set_fixed_size(32, 48);
|
2020-05-24 11:26:33 -03:00
|
|
|
icon_wrapper.set_layout<VerticalBoxLayout>();
|
2019-09-02 14:45:55 -03:00
|
|
|
|
2020-07-22 10:29:51 -03:00
|
|
|
auto& icon_image = icon_wrapper.add<ImageWidget>();
|
2020-06-14 05:06:46 -03:00
|
|
|
icon_image.set_bitmap(m_icon);
|
2020-05-24 11:26:33 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto& right_container = content_container.add<Widget>();
|
2020-03-04 15:07:55 -03:00
|
|
|
right_container.set_layout<VerticalBoxLayout>();
|
2021-08-16 21:10:51 -03:00
|
|
|
right_container.layout()->set_margins({ 12, 4, 4, 0 });
|
2019-09-02 14:45:55 -03:00
|
|
|
|
2021-11-10 20:55:02 -03:00
|
|
|
auto make_label = [&](StringView text, bool bold = false) {
|
2020-03-04 15:07:55 -03:00
|
|
|
auto& label = right_container.add<Label>(text);
|
|
|
|
|
label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
2020-12-29 21:23:32 -03:00
|
|
|
label.set_fixed_height(14);
|
2019-09-02 14:45:55 -03:00
|
|
|
if (bold)
|
2021-05-20 13:40:48 -03:00
|
|
|
label.set_font(Gfx::FontDatabase::default_font().bold_variant());
|
2019-09-02 14:45:55 -03:00
|
|
|
};
|
|
|
|
|
make_label(m_name, true);
|
2020-05-24 11:26:33 -03:00
|
|
|
// If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
|
|
|
|
|
if (m_name != "SerenityOS")
|
|
|
|
|
make_label("SerenityOS");
|
2021-08-29 07:00:50 -03:00
|
|
|
make_label(m_version_string);
|
2022-01-06 16:20:31 -03:00
|
|
|
make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2022");
|
2019-09-02 14:45:55 -03:00
|
|
|
|
2020-03-04 15:07:55 -03:00
|
|
|
right_container.layout()->add_spacer();
|
2019-09-02 14:45:55 -03:00
|
|
|
|
2020-03-04 15:07:55 -03:00
|
|
|
auto& button_container = right_container.add<Widget>();
|
2021-07-27 15:13:13 -03:00
|
|
|
button_container.set_fixed_height(22);
|
2020-03-04 15:07:55 -03:00
|
|
|
button_container.set_layout<HorizontalBoxLayout>();
|
|
|
|
|
button_container.layout()->add_spacer();
|
|
|
|
|
auto& ok_button = button_container.add<Button>("OK");
|
2021-07-27 15:13:13 -03:00
|
|
|
ok_button.set_fixed_width(80);
|
2020-05-12 15:30:33 -03:00
|
|
|
ok_button.on_click = [this](auto) {
|
2020-02-02 11:07:41 -03:00
|
|
|
done(Dialog::ExecOK);
|
2019-09-02 14:45:55 -03:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 11:07:41 -03:00
|
|
|
AboutDialog::~AboutDialog()
|
2019-09-02 14:45:55 -03:00
|
|
|
{
|
|
|
|
|
}
|
2020-02-02 11:07:41 -03:00
|
|
|
|
|
|
|
|
}
|