DisplaySettings: Migrate to using SettingsWindow :^)

This commit is contained in:
Sam Atkins 2021-11-20 15:28:46 +00:00 committed by Linus Groh
parent a4af8b2a64
commit 1dd5c838cf
Notes: sideshowbarker 2024-07-18 00:58:13 +09:00
5 changed files with 19 additions and 63 deletions

View file

@ -13,16 +13,17 @@
#include <LibGUI/ComboBox.h>
#include <LibGUI/Menu.h>
#include <LibGUI/RadioButton.h>
#include <LibGUI/SettingsWindow.h>
namespace DisplaySettings {
class BackgroundSettingsWidget : public GUI::Widget {
class BackgroundSettingsWidget : public GUI::SettingsWindow::Tab {
C_OBJECT(BackgroundSettingsWidget);
public:
virtual ~BackgroundSettingsWidget() override;
void apply_settings();
virtual void apply_settings() override;
private:
BackgroundSettingsWidget();

View file

@ -7,17 +7,18 @@
#pragma once
#include <LibCore/Timer.h>
#include <LibGUI/SettingsWindow.h>
#include <LibGUI/SpinBox.h>
namespace DisplaySettings {
class DesktopSettingsWidget : public GUI::Widget {
class DesktopSettingsWidget : public GUI::SettingsWindow::Tab {
C_OBJECT(DesktopSettingsWidget);
public:
virtual ~DesktopSettingsWidget() override;
void apply_settings();
virtual void apply_settings() override;
private:
DesktopSettingsWidget();

View file

@ -7,17 +7,17 @@
#pragma once
#include <LibGUI/Label.h>
#include <LibGUI/Widget.h>
#include <LibGUI/SettingsWindow.h>
namespace DisplaySettings {
class FontSettingsWidget : public GUI::Widget {
class FontSettingsWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT(FontSettingsWidget);
public:
virtual ~FontSettingsWidget() override;
void apply_settings();
virtual void apply_settings() override;
private:
FontSettingsWidget();

View file

@ -11,11 +11,12 @@
#include <LibGUI/ColorInput.h>
#include <LibGUI/ComboBox.h>
#include <LibGUI/RadioButton.h>
#include <LibGUI/SettingsWindow.h>
#include <WindowServer/ScreenLayout.h>
namespace DisplaySettings {
class MonitorSettingsWidget : public GUI::Widget {
class MonitorSettingsWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT(MonitorSettingsWidget);
public:
@ -25,7 +26,7 @@ public:
show_screen_numbers(false);
}
void apply_settings();
virtual void apply_settings() override;
void show_screen_numbers(bool);
protected:

View file

@ -1,6 +1,7 @@
/*
* Copyright (c) 2019-2020, Jesse Buhagiar <jooster669@gmail.com>
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -11,13 +12,8 @@
#include "MonitorSettingsWidget.h"
#include <LibConfig/Client.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/TabWidget.h>
#include <LibGUI/Window.h>
#include <LibGUI/SettingsWindow.h>
#include <stdio.h>
#include <unistd.h>
@ -33,54 +29,11 @@ int main(int argc, char** argv)
auto app_icon = GUI::Icon::default_icon("app-display-settings");
auto window = GUI::Window::construct();
window->set_title("Display Settings");
window->resize(400, 480);
window->set_resizable(false);
window->set_minimizable(false);
auto& main_widget = window->set_main_widget<GUI::Widget>();
main_widget.set_fill_with_background_color(true);
main_widget.set_layout<GUI::VerticalBoxLayout>();
main_widget.layout()->set_margins(4);
main_widget.layout()->set_spacing(6);
auto& tab_widget = main_widget.add<GUI::TabWidget>();
auto& background_settings_widget = tab_widget.add_tab<DisplaySettings::BackgroundSettingsWidget>("Background");
auto& font_settings_widget = tab_widget.add_tab<DisplaySettings::FontSettingsWidget>("Fonts");
auto& monitor_settings_widget = tab_widget.add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor");
auto& desktop_settings_widget = tab_widget.add_tab<DisplaySettings::DesktopSettingsWidget>("Workspaces");
auto& button_container = main_widget.add<GUI::Widget>();
button_container.set_shrink_to_fit(true);
button_container.set_layout<GUI::HorizontalBoxLayout>();
button_container.layout()->set_spacing(6);
button_container.layout()->add_spacer();
auto& ok_button = button_container.add<GUI::Button>("OK");
ok_button.set_fixed_width(75);
ok_button.on_click = [&](auto) {
background_settings_widget.apply_settings();
monitor_settings_widget.apply_settings();
desktop_settings_widget.apply_settings();
font_settings_widget.apply_settings();
app->quit();
};
auto& cancel_button = button_container.add<GUI::Button>("Cancel");
cancel_button.set_fixed_width(75);
cancel_button.on_click = [&](auto) {
app->quit();
};
auto& apply_button = button_container.add<GUI::Button>("Apply");
apply_button.set_fixed_width(75);
apply_button.on_click = [&](auto) {
background_settings_widget.apply_settings();
monitor_settings_widget.apply_settings();
desktop_settings_widget.apply_settings();
font_settings_widget.apply_settings();
};
auto window = GUI::SettingsWindow::construct("Display Settings");
window->add_tab<DisplaySettings::BackgroundSettingsWidget>("Background");
window->add_tab<DisplaySettings::FontSettingsWidget>("Fonts");
window->add_tab<DisplaySettings::MonitorSettingsWidget>("Monitor");
window->add_tab<DisplaySettings::DesktopSettingsWidget>("Workspaces");
window->set_icon(app_icon.bitmap_for_size(16));