AboutDialog.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, the SerenityOS developers.
  4. * Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #include <AK/StringBuilder.h>
  9. #include <LibGUI/AboutDialog.h>
  10. #include <LibGUI/AboutDialogGML.h>
  11. #include <LibGUI/BoxLayout.h>
  12. #include <LibGUI/Button.h>
  13. #include <LibGUI/ImageWidget.h>
  14. #include <LibGUI/Label.h>
  15. #include <LibGUI/Widget.h>
  16. #include <LibGfx/Font/Font.h>
  17. #include <LibGfx/Font/FontDatabase.h>
  18. namespace GUI {
  19. NonnullRefPtr<AboutDialog> AboutDialog::create(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window)
  20. {
  21. auto dialog = adopt_ref(*new AboutDialog(name, version, icon, parent_window));
  22. dialog->set_title(DeprecatedString::formatted("About {}", name));
  23. auto widget = MUST(dialog->set_main_widget<Widget>());
  24. MUST(widget->load_from_gml(about_dialog_gml));
  25. auto icon_wrapper = widget->find_descendant_of_type_named<Widget>("icon_wrapper");
  26. if (icon) {
  27. icon_wrapper->set_visible(true);
  28. auto icon_image = widget->find_descendant_of_type_named<ImageWidget>("icon");
  29. icon_image->set_bitmap(icon);
  30. } else {
  31. icon_wrapper->set_visible(false);
  32. }
  33. widget->find_descendant_of_type_named<GUI::Label>("name")->set_text(name);
  34. // If we are displaying a dialog for an application, insert 'SerenityOS' below the application name
  35. widget->find_descendant_of_type_named<GUI::Label>("serenity_os")->set_visible(name != "SerenityOS");
  36. widget->find_descendant_of_type_named<GUI::Label>("version")->set_text(version);
  37. auto ok_button = widget->find_descendant_of_type_named<DialogButton>("ok_button");
  38. ok_button->on_click = [dialog](auto) {
  39. dialog->done(ExecResult::OK);
  40. };
  41. return dialog;
  42. }
  43. AboutDialog::AboutDialog(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window)
  44. : Dialog(parent_window)
  45. , m_name(move(name))
  46. , m_version_string(move(version))
  47. , m_icon(move(icon))
  48. {
  49. resize(413, 204);
  50. set_resizable(false);
  51. if (parent_window)
  52. set_icon(parent_window->icon());
  53. }
  54. void AboutDialog::show(String name, String version, RefPtr<Gfx::Bitmap const> icon, Window* parent_window, RefPtr<Gfx::Bitmap const> window_icon)
  55. {
  56. auto dialog = AboutDialog::create(move(name), move(version), move(icon), parent_window);
  57. if (window_icon)
  58. dialog->set_icon(window_icon);
  59. dialog->exec();
  60. }
  61. }