summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2021-11-20 15:09:28 +0000
committerLinus Groh <mail@linusgroh.de>2021-11-20 21:05:20 +0000
commitf20b0403bc7e3d00a875a5e7cc56a8c02333a357 (patch)
tree953d845fdffdadbb6fde5105078d92966bda1b4f /Userland/Applications
parentfca7924437e2771243838927c6573e30c1f14612 (diff)
downloadserenity-f20b0403bc7e3d00a875a5e7cc56a8c02333a357.zip
MouseSettings: Migrate to using SettingsWindow :^)
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/MouseSettings/CMakeLists.txt1
-rw-r--r--Userland/Applications/MouseSettings/MouseSettingsWindow.cpp68
-rw-r--r--Userland/Applications/MouseSettings/MouseSettingsWindow.h25
-rw-r--r--Userland/Applications/MouseSettings/MouseWidget.cpp3
-rw-r--r--Userland/Applications/MouseSettings/MouseWidget.h10
-rw-r--r--Userland/Applications/MouseSettings/ThemeWidget.cpp4
-rw-r--r--Userland/Applications/MouseSettings/ThemeWidget.h13
-rw-r--r--Userland/Applications/MouseSettings/main.cpp13
8 files changed, 20 insertions, 117 deletions
diff --git a/Userland/Applications/MouseSettings/CMakeLists.txt b/Userland/Applications/MouseSettings/CMakeLists.txt
index a266dd7be3..586f5cb6ff 100644
--- a/Userland/Applications/MouseSettings/CMakeLists.txt
+++ b/Userland/Applications/MouseSettings/CMakeLists.txt
@@ -10,7 +10,6 @@ compile_gml(Theme.gml ThemeWidgetGML.h theme_widget_gml)
set(SOURCES
main.cpp
DoubleClickArrowWidget.cpp
- MouseSettingsWindow.cpp
MouseWidget.cpp
MouseWidget.h
MouseWidgetGML.h
diff --git a/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp b/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp
deleted file mode 100644
index c0a7ba7db9..0000000000
--- a/Userland/Applications/MouseSettings/MouseSettingsWindow.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
- * Copyright (c) 2021, the SerenityOS developers.
- * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "MouseSettingsWindow.h"
-#include "MouseWidget.h"
-#include "ThemeWidget.h"
-#include <LibGUI/Application.h>
-#include <LibGUI/BoxLayout.h>
-#include <LibGUI/Button.h>
-#include <LibGUI/TabWidget.h>
-#include <LibGUI/Widget.h>
-
-MouseSettingsWindow::MouseSettingsWindow()
-{
- auto& main_widget = 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& mouse_widget = tab_widget.add_tab<MouseWidget>("Mouse");
- auto& theme_widget = tab_widget.add_tab<ThemeWidget>("Cursor Theme");
-
- 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);
-
- m_reset_button = button_container.add<GUI::Button>("Defaults");
- m_reset_button->on_click = [&](auto) {
- mouse_widget.reset_default_values();
- theme_widget.reset_default_values();
- };
-
- button_container.layout()->add_spacer();
-
- m_ok_button = button_container.add<GUI::Button>("OK");
- m_ok_button->set_fixed_width(75);
- m_ok_button->on_click = [&](auto) {
- mouse_widget.update_window_server();
- theme_widget.update_window_server();
- GUI::Application::the()->quit();
- };
-
- m_cancel_button = button_container.add<GUI::Button>("Cancel");
- m_cancel_button->set_fixed_width(75);
- m_cancel_button->on_click = [&](auto) {
- GUI::Application::the()->quit();
- };
-
- m_apply_button = button_container.add<GUI::Button>("Apply");
- m_apply_button->set_fixed_width(75);
- m_apply_button->on_click = [&](auto) {
- mouse_widget.update_window_server();
- theme_widget.update_window_server();
- };
-}
-
-MouseSettingsWindow::~MouseSettingsWindow()
-{
-}
diff --git a/Userland/Applications/MouseSettings/MouseSettingsWindow.h b/Userland/Applications/MouseSettings/MouseSettingsWindow.h
deleted file mode 100644
index 3c45d7a96d..0000000000
--- a/Userland/Applications/MouseSettings/MouseSettingsWindow.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
- * Copyright (c) 2021, the SerenityOS developers.
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibGUI/Button.h>
-#include <LibGUI/Window.h>
-
-class MouseSettingsWindow final : public GUI::Window {
- C_OBJECT(MouseSettingsWindow)
-public:
- virtual ~MouseSettingsWindow() override;
-
-private:
- MouseSettingsWindow();
-
- RefPtr<GUI::Button> m_ok_button;
- RefPtr<GUI::Button> m_cancel_button;
- RefPtr<GUI::Button> m_apply_button;
- RefPtr<GUI::Button> m_reset_button;
-};
diff --git a/Userland/Applications/MouseSettings/MouseWidget.cpp b/Userland/Applications/MouseSettings/MouseWidget.cpp
index 0816f0bb33..865a4cf3d4 100644
--- a/Userland/Applications/MouseSettings/MouseWidget.cpp
+++ b/Userland/Applications/MouseSettings/MouseWidget.cpp
@@ -57,7 +57,7 @@ MouseWidget::MouseWidget()
switch_buttons_image_label.set_icon(Gfx::Bitmap::try_load_from_file("/res/graphics/switch-mouse-buttons.png").release_value_but_fixme_should_propagate_errors());
}
-void MouseWidget::update_window_server()
+void MouseWidget::apply_settings()
{
float const factor = m_speed_slider->value() / speed_slider_scale;
GUI::WindowServerConnection::the().async_set_mouse_acceleration(factor);
@@ -72,7 +72,6 @@ void MouseWidget::reset_default_values()
m_scroll_length_spinbox->set_value(default_scroll_length);
m_double_click_speed_slider->set_value(double_click_speed_default);
m_switch_buttons_checkbox->set_checked(false);
- update_window_server();
}
MouseWidget::~MouseWidget()
diff --git a/Userland/Applications/MouseSettings/MouseWidget.h b/Userland/Applications/MouseSettings/MouseWidget.h
index 967709ae9f..ab9181d9fd 100644
--- a/Userland/Applications/MouseSettings/MouseWidget.h
+++ b/Userland/Applications/MouseSettings/MouseWidget.h
@@ -6,18 +6,18 @@
#pragma once
+#include "DoubleClickArrowWidget.h"
#include <LibGUI/CheckBox.h>
+#include <LibGUI/SettingsWindow.h>
#include <LibGUI/Window.h>
-#include "DoubleClickArrowWidget.h"
-
-class MouseWidget final : public GUI::Widget {
+class MouseWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT(MouseWidget)
public:
virtual ~MouseWidget() override;
- void update_window_server();
- void reset_default_values();
+ virtual void apply_settings() override;
+ virtual void reset_default_values() override;
private:
MouseWidget();
diff --git a/Userland/Applications/MouseSettings/ThemeWidget.cpp b/Userland/Applications/MouseSettings/ThemeWidget.cpp
index cb7b498881..1589e9baad 100644
--- a/Userland/Applications/MouseSettings/ThemeWidget.cpp
+++ b/Userland/Applications/MouseSettings/ThemeWidget.cpp
@@ -6,6 +6,7 @@
#include "ThemeWidget.h"
+#include <AK/LexicalPath.h>
#include <Applications/MouseSettings/ThemeWidgetGML.h>
#include <LibCore/DirIterator.h>
#include <LibGUI/Button.h>
@@ -127,7 +128,7 @@ ThemeWidget::ThemeWidget()
m_theme_name_box->set_text(m_theme_name);
}
-void ThemeWidget::update_window_server()
+void ThemeWidget::apply_settings()
{
GUI::WindowServerConnection::the().async_apply_cursor_theme(m_theme_name_box->text());
}
@@ -135,7 +136,6 @@ void ThemeWidget::update_window_server()
void ThemeWidget::reset_default_values()
{
m_theme_name_box->set_text("Default");
- update_window_server();
}
ThemeWidget::~ThemeWidget()
diff --git a/Userland/Applications/MouseSettings/ThemeWidget.h b/Userland/Applications/MouseSettings/ThemeWidget.h
index 58c64af07c..5e54ce1f05 100644
--- a/Userland/Applications/MouseSettings/ThemeWidget.h
+++ b/Userland/Applications/MouseSettings/ThemeWidget.h
@@ -6,14 +6,11 @@
#pragma once
+#include "DoubleClickArrowWidget.h"
#include <LibGUI/Model.h>
-#include <LibGUI/Window.h>
-#include <LibGUI/WindowServerConnection.h>
+#include <LibGUI/SettingsWindow.h>
#include <LibGfx/CursorParams.h>
-#include "DoubleClickArrowWidget.h"
-#include "LibGUI/FilePicker.h"
-
class MouseCursorModel final : public GUI::Model {
public:
static NonnullRefPtr<MouseCursorModel> create() { return adopt_ref(*new MouseCursorModel); }
@@ -65,13 +62,13 @@ private:
Vector<String> m_themes;
};
-class ThemeWidget final : public GUI::Widget {
+class ThemeWidget final : public GUI::SettingsWindow::Tab {
C_OBJECT(ThemeWidget)
public:
virtual ~ThemeWidget() override;
- void update_window_server();
- void reset_default_values();
+ virtual void apply_settings() override;
+ virtual void reset_default_values() override;
private:
ThemeWidget();
diff --git a/Userland/Applications/MouseSettings/main.cpp b/Userland/Applications/MouseSettings/main.cpp
index 4ca4e05f91..9a906c331c 100644
--- a/Userland/Applications/MouseSettings/main.cpp
+++ b/Userland/Applications/MouseSettings/main.cpp
@@ -2,14 +2,17 @@
* Copyright (c) 2020, Idan Horowitz <idan.horowitz@serenityos.org>
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include "MouseSettingsWindow.h"
+#include "MouseWidget.h"
+#include "ThemeWidget.h"
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/Icon.h>
+#include <LibGUI/SettingsWindow.h>
#include <unistd.h>
int main(int argc, char** argv)
@@ -28,11 +31,9 @@ int main(int argc, char** argv)
auto app_icon = GUI::Icon::default_icon("app-mouse");
- auto window = MouseSettingsWindow::construct();
- window->set_title("Mouse Settings");
- window->resize(400, 480);
- window->set_resizable(false);
- window->set_minimizable(false);
+ auto window = GUI::SettingsWindow::construct("Mouse Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes);
+ window->add_tab<MouseWidget>("Mouse");
+ window->add_tab<ThemeWidget>("Cursor Theme");
window->set_icon(app_icon.bitmap_for_size(16));
window->show();