AboutDialog.cpp 2.9 KB

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