SettingsWindow.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2021, the SerenityOS developers.
  4. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  5. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  6. *
  7. * SPDX-License-Identifier: BSD-2-Clause
  8. */
  9. #include <LibGUI/Application.h>
  10. #include <LibGUI/BoxLayout.h>
  11. #include <LibGUI/Button.h>
  12. #include <LibGUI/SettingsWindow.h>
  13. #include <LibGUI/Widget.h>
  14. namespace GUI {
  15. ErrorOr<NonnullRefPtr<SettingsWindow>> SettingsWindow::create(String title, ShowDefaultsButton show_defaults_button)
  16. {
  17. auto window = TRY(SettingsWindow::try_create());
  18. window->set_title(move(title));
  19. window->resize(400, 480);
  20. window->set_resizable(false);
  21. window->set_minimizable(false);
  22. auto main_widget = TRY(window->try_set_main_widget<GUI::Widget>());
  23. main_widget->set_fill_with_background_color(true);
  24. (void)TRY(main_widget->try_set_layout<GUI::VerticalBoxLayout>());
  25. main_widget->layout()->set_margins(4);
  26. main_widget->layout()->set_spacing(6);
  27. window->m_tab_widget = TRY(main_widget->try_add<GUI::TabWidget>());
  28. auto button_container = TRY(main_widget->try_add<GUI::Widget>());
  29. button_container->set_shrink_to_fit(true);
  30. (void)TRY(button_container->try_set_layout<GUI::HorizontalBoxLayout>());
  31. button_container->layout()->set_spacing(6);
  32. if (show_defaults_button == ShowDefaultsButton::Yes) {
  33. window->m_reset_button = TRY(button_container->try_add<GUI::Button>("Defaults"));
  34. window->m_reset_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
  35. for (auto& tab : window->m_tabs) {
  36. tab.reset_default_values();
  37. tab.apply_settings();
  38. }
  39. };
  40. }
  41. TRY(button_container->layout()->try_add_spacer());
  42. window->m_ok_button = TRY(button_container->try_add<GUI::Button>("OK"));
  43. window->m_ok_button->set_fixed_width(75);
  44. window->m_ok_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
  45. for (auto& tab : window->m_tabs)
  46. tab.apply_settings();
  47. GUI::Application::the()->quit();
  48. };
  49. window->m_cancel_button = TRY(button_container->try_add<GUI::Button>("Cancel"));
  50. window->m_cancel_button->set_fixed_width(75);
  51. window->m_cancel_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
  52. for (auto& tab : window->m_tabs)
  53. tab.cancel_settings();
  54. GUI::Application::the()->quit();
  55. };
  56. window->m_apply_button = TRY(button_container->try_add<GUI::Button>("Apply"));
  57. window->m_apply_button->set_fixed_width(75);
  58. window->m_apply_button->on_click = [window = window->make_weak_ptr<SettingsWindow>()](auto) mutable {
  59. for (auto& tab : window->m_tabs)
  60. tab.apply_settings();
  61. };
  62. return window;
  63. }
  64. SettingsWindow::SettingsWindow()
  65. {
  66. }
  67. SettingsWindow::~SettingsWindow()
  68. {
  69. }
  70. }