GAboutDialog.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <LibGUI/GAboutDialog.h>
  27. #include <LibGUI/GBoxLayout.h>
  28. #include <LibGUI/GButton.h>
  29. #include <LibGUI/GLabel.h>
  30. #include <LibGUI/GWidget.h>
  31. GAboutDialog::GAboutDialog(const StringView& name, const GraphicsBitmap* icon, CObject* parent)
  32. : GDialog(parent)
  33. , m_name(name)
  34. , m_icon(icon)
  35. {
  36. resize(230, 120);
  37. set_title(String::format("About %s", m_name.characters()));
  38. set_resizable(false);
  39. auto widget = GWidget::construct();
  40. set_main_widget(widget);
  41. widget->set_fill_with_background_color(true);
  42. widget->set_layout(make<GBoxLayout>(Orientation::Horizontal));
  43. auto left_container = GWidget::construct(widget.ptr());
  44. left_container->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
  45. left_container->set_preferred_size(48, 0);
  46. left_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
  47. auto icon_label = GLabel::construct(left_container);
  48. icon_label->set_icon(m_icon);
  49. icon_label->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
  50. icon_label->set_preferred_size(40, 40);
  51. left_container->layout()->add_spacer();
  52. auto right_container = GWidget::construct(widget.ptr());
  53. right_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
  54. right_container->layout()->set_margins({ 0, 4, 4, 4 });
  55. auto make_label = [&](const StringView& text, bool bold = false) {
  56. auto label = GLabel::construct(text, right_container);
  57. label->set_text_alignment(TextAlignment::CenterLeft);
  58. label->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
  59. label->set_preferred_size(0, 14);
  60. if (bold)
  61. label->set_font(Font::default_bold_font());
  62. };
  63. make_label(m_name, true);
  64. make_label("SerenityOS");
  65. make_label("(C) The SerenityOS developers");
  66. right_container->layout()->add_spacer();
  67. auto button_container = GWidget::construct(right_container.ptr());
  68. button_container->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
  69. button_container->set_preferred_size(0, 20);
  70. button_container->set_layout(make<GBoxLayout>(Orientation::Horizontal));
  71. button_container->layout()->add_spacer();
  72. auto ok_button = GButton::construct("OK", button_container);
  73. ok_button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
  74. ok_button->set_preferred_size(80, 20);
  75. ok_button->on_click = [this](auto&) {
  76. done(GDialog::ExecOK);
  77. };
  78. }
  79. GAboutDialog::~GAboutDialog()
  80. {
  81. }