AboutDialog.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/StringBuilder.h>
  8. #include <LibGUI/AboutDialog.h>
  9. #include <LibGUI/BoxLayout.h>
  10. #include <LibGUI/Button.h>
  11. #include <LibGUI/ImageWidget.h>
  12. #include <LibGUI/Label.h>
  13. #include <LibGUI/Widget.h>
  14. #include <LibGfx/Font/Font.h>
  15. #include <LibGfx/Font/FontDatabase.h>
  16. namespace GUI {
  17. AboutDialog::AboutDialog(StringView name, Gfx::Bitmap const* icon, Window* parent_window, StringView version)
  18. : Dialog(parent_window)
  19. , m_name(name)
  20. , m_icon(icon)
  21. , m_version_string(version)
  22. {
  23. resize(413, 204);
  24. set_title(String::formatted("About {}", m_name));
  25. set_resizable(false);
  26. if (parent_window)
  27. set_icon(parent_window->icon());
  28. auto& widget = set_main_widget<Widget>();
  29. widget.set_fill_with_background_color(true);
  30. widget.set_layout<VerticalBoxLayout>();
  31. widget.layout()->set_spacing(0);
  32. auto& banner_image = widget.add<GUI::ImageWidget>();
  33. banner_image.load_from_file("/res/graphics/brand-banner.png");
  34. auto& content_container = widget.add<Widget>();
  35. content_container.set_layout<HorizontalBoxLayout>();
  36. auto& left_container = content_container.add<Widget>();
  37. left_container.set_fixed_width(60);
  38. left_container.set_layout<VerticalBoxLayout>();
  39. left_container.layout()->set_margins({ 12, 0, 0 });
  40. if (icon) {
  41. auto& icon_wrapper = left_container.add<Widget>();
  42. icon_wrapper.set_fixed_size(32, 48);
  43. icon_wrapper.set_layout<VerticalBoxLayout>();
  44. auto& icon_image = icon_wrapper.add<ImageWidget>();
  45. icon_image.set_bitmap(m_icon);
  46. }
  47. auto& right_container = content_container.add<Widget>();
  48. right_container.set_layout<VerticalBoxLayout>();
  49. right_container.layout()->set_margins({ 12, 4, 4, 0 });
  50. auto make_label = [&](StringView text, bool bold = false) {
  51. auto& label = right_container.add<Label>(text);
  52. label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  53. label.set_fixed_height(14);
  54. if (bold)
  55. label.set_font(Gfx::FontDatabase::default_font().bold_variant());
  56. };
  57. make_label(m_name, true);
  58. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  59. if (m_name != "SerenityOS")
  60. make_label("SerenityOS");
  61. make_label(m_version_string);
  62. make_label("Copyright \xC2\xA9 the SerenityOS developers, 2018-2022");
  63. right_container.layout()->add_spacer();
  64. auto& button_container = right_container.add<Widget>();
  65. button_container.set_fixed_height(22);
  66. button_container.set_layout<HorizontalBoxLayout>();
  67. button_container.layout()->add_spacer();
  68. auto& ok_button = button_container.add<Button>("OK");
  69. ok_button.set_fixed_width(80);
  70. ok_button.on_click = [this](auto) {
  71. done(ExecResult::OK);
  72. };
  73. }
  74. }