mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
MouseSettings: Convert setting widgets to a failable factory
This commit is contained in:
parent
ab8be9aed5
commit
90819e2d71
6 changed files with 43 additions and 13 deletions
|
@ -9,9 +9,16 @@
|
||||||
#include <Applications/MouseSettings/HighlightWidgetGML.h>
|
#include <Applications/MouseSettings/HighlightWidgetGML.h>
|
||||||
#include <LibGUI/ConnectionToWindowServer.h>
|
#include <LibGUI/ConnectionToWindowServer.h>
|
||||||
|
|
||||||
HighlightWidget::HighlightWidget()
|
ErrorOr<NonnullRefPtr<HighlightWidget>> HighlightWidget::try_create()
|
||||||
{
|
{
|
||||||
load_from_gml(highlight_widget_gml).release_value_but_fixme_should_propagate_errors();
|
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) HighlightWidget()));
|
||||||
|
TRY(widget->setup());
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> HighlightWidget::setup()
|
||||||
|
{
|
||||||
|
TRY(load_from_gml(highlight_widget_gml));
|
||||||
|
|
||||||
m_highlight_preview = find_descendant_of_type_named<GUI::Frame>("preview_frame")->add<MouseSettings::HighlightPreviewWidget>(palette());
|
m_highlight_preview = find_descendant_of_type_named<GUI::Frame>("preview_frame")->add<MouseSettings::HighlightPreviewWidget>(palette());
|
||||||
|
|
||||||
|
@ -41,6 +48,7 @@ HighlightWidget::HighlightWidget()
|
||||||
|
|
||||||
m_highlight_preview->set_color(highlight_color());
|
m_highlight_preview->set_color(highlight_color());
|
||||||
m_highlight_preview->set_radius(highlight_radius());
|
m_highlight_preview->set_radius(highlight_radius());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
Gfx::Color HighlightWidget::highlight_color()
|
Gfx::Color HighlightWidget::highlight_color()
|
||||||
|
|
|
@ -13,19 +13,22 @@
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
|
|
||||||
class HighlightWidget final : public GUI::SettingsWindow::Tab {
|
class HighlightWidget final : public GUI::SettingsWindow::Tab {
|
||||||
C_OBJECT(HighlightWidget)
|
C_OBJECT_ABSTRACT(HighlightWidget)
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<HighlightWidget>> try_create();
|
||||||
virtual ~HighlightWidget() override = default;
|
virtual ~HighlightWidget() override = default;
|
||||||
|
|
||||||
virtual void apply_settings() override;
|
virtual void apply_settings() override;
|
||||||
virtual void reset_default_values() override;
|
virtual void reset_default_values() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
HighlightWidget() = default;
|
||||||
|
ErrorOr<void> setup();
|
||||||
|
|
||||||
Gfx::Color highlight_color();
|
Gfx::Color highlight_color();
|
||||||
|
|
||||||
int highlight_radius();
|
int highlight_radius();
|
||||||
|
|
||||||
HighlightWidget();
|
|
||||||
RefPtr<MouseSettings::HighlightPreviewWidget> m_highlight_preview;
|
RefPtr<MouseSettings::HighlightPreviewWidget> m_highlight_preview;
|
||||||
RefPtr<GUI::ColorInput> m_highlight_color_input;
|
RefPtr<GUI::ColorInput> m_highlight_color_input;
|
||||||
RefPtr<GUI::Slider> m_highlight_opacity_slider;
|
RefPtr<GUI::Slider> m_highlight_opacity_slider;
|
||||||
|
|
|
@ -19,10 +19,16 @@ constexpr double speed_slider_scale = 100.0;
|
||||||
constexpr int default_scroll_length = 4;
|
constexpr int default_scroll_length = 4;
|
||||||
constexpr int double_click_speed_default = 250;
|
constexpr int double_click_speed_default = 250;
|
||||||
|
|
||||||
MouseWidget::MouseWidget()
|
ErrorOr<NonnullRefPtr<MouseWidget>> MouseWidget::try_create()
|
||||||
{
|
{
|
||||||
load_from_gml(mouse_widget_gml).release_value_but_fixme_should_propagate_errors();
|
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MouseWidget()));
|
||||||
|
TRY(widget->setup());
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> MouseWidget::setup()
|
||||||
|
{
|
||||||
|
TRY(load_from_gml(mouse_widget_gml));
|
||||||
m_speed_label = *find_descendant_of_type_named<GUI::Label>("speed_label");
|
m_speed_label = *find_descendant_of_type_named<GUI::Label>("speed_label");
|
||||||
m_speed_slider = *find_descendant_of_type_named<GUI::HorizontalSlider>("speed_slider");
|
m_speed_slider = *find_descendant_of_type_named<GUI::HorizontalSlider>("speed_slider");
|
||||||
m_speed_slider->set_range(WindowServer::mouse_accel_min * speed_slider_scale, WindowServer::mouse_accel_max * speed_slider_scale);
|
m_speed_slider->set_range(WindowServer::mouse_accel_min * speed_slider_scale, WindowServer::mouse_accel_max * speed_slider_scale);
|
||||||
|
@ -70,6 +76,7 @@ MouseWidget::MouseWidget()
|
||||||
update_double_click_speed_label();
|
update_double_click_speed_label();
|
||||||
update_switch_buttons_image_label();
|
update_switch_buttons_image_label();
|
||||||
m_double_click_arrow_widget->set_double_click_speed(m_double_click_speed_slider->value());
|
m_double_click_arrow_widget->set_double_click_speed(m_double_click_speed_slider->value());
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MouseWidget::apply_settings()
|
void MouseWidget::apply_settings()
|
||||||
|
|
|
@ -12,15 +12,17 @@
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
|
|
||||||
class MouseWidget final : public GUI::SettingsWindow::Tab {
|
class MouseWidget final : public GUI::SettingsWindow::Tab {
|
||||||
C_OBJECT(MouseWidget)
|
C_OBJECT_ABSTRACT(MouseWidget)
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<MouseWidget>> try_create();
|
||||||
virtual ~MouseWidget() override = default;
|
virtual ~MouseWidget() override = default;
|
||||||
|
|
||||||
virtual void apply_settings() override;
|
virtual void apply_settings() override;
|
||||||
virtual void reset_default_values() override;
|
virtual void reset_default_values() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MouseWidget();
|
MouseWidget() = default;
|
||||||
|
ErrorOr<void> setup();
|
||||||
|
|
||||||
void update_speed_label();
|
void update_speed_label();
|
||||||
void update_double_click_speed_label();
|
void update_double_click_speed_label();
|
||||||
|
|
|
@ -97,9 +97,16 @@ void ThemeModel::invalidate()
|
||||||
Model::invalidate();
|
Model::invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
ThemeWidget::ThemeWidget()
|
ErrorOr<NonnullRefPtr<ThemeWidget>> ThemeWidget::try_create()
|
||||||
{
|
{
|
||||||
load_from_gml(theme_widget_gml).release_value_but_fixme_should_propagate_errors();
|
auto widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) ThemeWidget()));
|
||||||
|
TRY(widget->setup());
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
ErrorOr<void> ThemeWidget::setup()
|
||||||
|
{
|
||||||
|
TRY(load_from_gml(theme_widget_gml));
|
||||||
m_cursors_tableview = find_descendant_of_type_named<GUI::TableView>("cursors_tableview");
|
m_cursors_tableview = find_descendant_of_type_named<GUI::TableView>("cursors_tableview");
|
||||||
m_cursors_tableview->set_highlight_selected_rows(true);
|
m_cursors_tableview->set_highlight_selected_rows(true);
|
||||||
m_cursors_tableview->set_alternating_row_colors(false);
|
m_cursors_tableview->set_alternating_row_colors(false);
|
||||||
|
@ -108,7 +115,7 @@ ThemeWidget::ThemeWidget()
|
||||||
m_cursors_tableview->set_highlight_key_column(false);
|
m_cursors_tableview->set_highlight_key_column(false);
|
||||||
|
|
||||||
m_mouse_cursor_model = MouseCursorModel::create();
|
m_mouse_cursor_model = MouseCursorModel::create();
|
||||||
auto sorting_proxy_model = MUST(GUI::SortingProxyModel::create(*m_mouse_cursor_model));
|
auto sorting_proxy_model = TRY(GUI::SortingProxyModel::create(*m_mouse_cursor_model));
|
||||||
sorting_proxy_model->set_sort_role(GUI::ModelRole::Display);
|
sorting_proxy_model->set_sort_role(GUI::ModelRole::Display);
|
||||||
|
|
||||||
m_cursors_tableview->set_model(sorting_proxy_model);
|
m_cursors_tableview->set_model(sorting_proxy_model);
|
||||||
|
@ -127,6 +134,7 @@ ThemeWidget::ThemeWidget()
|
||||||
m_theme_name_box->set_model(ThemeModel::create());
|
m_theme_name_box->set_model(ThemeModel::create());
|
||||||
m_theme_name_box->model()->invalidate();
|
m_theme_name_box->model()->invalidate();
|
||||||
m_theme_name_box->set_text(theme_name, GUI::AllowCallback::No);
|
m_theme_name_box->set_text(theme_name, GUI::AllowCallback::No);
|
||||||
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThemeWidget::apply_settings()
|
void ThemeWidget::apply_settings()
|
||||||
|
|
|
@ -63,15 +63,17 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThemeWidget final : public GUI::SettingsWindow::Tab {
|
class ThemeWidget final : public GUI::SettingsWindow::Tab {
|
||||||
C_OBJECT(ThemeWidget)
|
C_OBJECT_ABSTRACT(ThemeWidget)
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<ThemeWidget>> try_create();
|
||||||
virtual ~ThemeWidget() override = default;
|
virtual ~ThemeWidget() override = default;
|
||||||
|
|
||||||
virtual void apply_settings() override;
|
virtual void apply_settings() override;
|
||||||
virtual void reset_default_values() override;
|
virtual void reset_default_values() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ThemeWidget();
|
ThemeWidget() = default;
|
||||||
|
ErrorOr<void> setup();
|
||||||
|
|
||||||
RefPtr<GUI::TableView> m_cursors_tableview;
|
RefPtr<GUI::TableView> m_cursors_tableview;
|
||||||
RefPtr<GUI::ComboBox> m_theme_name_box;
|
RefPtr<GUI::ComboBox> m_theme_name_box;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue