SettingsWindow.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
  3. * Copyright (c) 2021-2022, the SerenityOS developers.
  4. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/HashMap.h>
  10. #include <LibGUI/Button.h>
  11. #include <LibGUI/TabWidget.h>
  12. #include <LibGUI/Window.h>
  13. namespace GUI {
  14. class SettingsWindow : public GUI::Window {
  15. C_OBJECT(SettingsWindow)
  16. public:
  17. class Tab : public GUI::Widget {
  18. public:
  19. virtual void apply_settings() = 0;
  20. virtual void cancel_settings() { }
  21. virtual void reset_default_values() { }
  22. };
  23. enum class ShowDefaultsButton {
  24. Yes,
  25. No,
  26. };
  27. static ErrorOr<NonnullRefPtr<SettingsWindow>> create(String title, ShowDefaultsButton = ShowDefaultsButton::No);
  28. virtual ~SettingsWindow() override = default;
  29. template<class T, class... Args>
  30. ErrorOr<NonnullRefPtr<T>> add_tab(String title, StringView id, Args&&... args)
  31. {
  32. auto tab = TRY(m_tab_widget->try_add_tab<T>(move(title), forward<Args>(args)...));
  33. TRY(m_tabs.try_set(id, tab));
  34. return tab;
  35. }
  36. private:
  37. SettingsWindow() = default;
  38. RefPtr<GUI::TabWidget> m_tab_widget;
  39. HashMap<StringView, NonnullRefPtr<Tab>> m_tabs;
  40. RefPtr<GUI::Button> m_ok_button;
  41. RefPtr<GUI::Button> m_cancel_button;
  42. RefPtr<GUI::Button> m_apply_button;
  43. RefPtr<GUI::Button> m_reset_button;
  44. };
  45. }