Magnifier+ThemeEditor: Use CommonMenus::make_accessibility_menu()

This commit is contained in:
thankyouverycool 2022-09-26 08:57:11 -04:00 committed by Andreas Kling
parent f31a56d086
commit e99277611b
Notes: sideshowbarker 2024-07-17 09:49:48 +09:00
4 changed files with 13 additions and 126 deletions

View File

@ -8,17 +8,19 @@
#pragma once
#include <AK/CircularQueue.h>
#include <LibGUI/ColorFilterer.h>
#include <LibGUI/Frame.h>
#include <LibGfx/Filters/ColorBlindnessFilter.h>
class MagnifierWidget final : public GUI::Frame {
class MagnifierWidget final
: public GUI::Frame
, public GUI::ColorFilterer {
C_OBJECT(MagnifierWidget);
public:
virtual ~MagnifierWidget() override = default;
void set_scale_factor(int scale_factor);
void set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter>);
virtual void set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter>) override;
void pause_capture(bool pause)
{
m_pause_capture = pause;

View File

@ -144,66 +144,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(timeline_menu->try_add_action(previous_frame_action));
TRY(timeline_menu->try_add_action(next_frame_action));
auto accessibility_menu = TRY(window->try_add_menu("&Accessibility"));
auto default_accessibility_action = GUI::Action::create_checkable("Default - non-impaired", { Mod_AltGr, Key_1 }, [&](auto&) {
magnifier->set_color_filter(nullptr);
});
default_accessibility_action->set_checked(true);
auto pratanopia_accessibility_action = GUI::Action::create_checkable("Protanopia", { Mod_AltGr, Key_2 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_protanopia());
});
auto pratanomaly_accessibility_action = GUI::Action::create_checkable("Protanomaly", { Mod_AltGr, Key_3 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_protanomaly());
});
auto tritanopia_accessibility_action = GUI::Action::create_checkable("Tritanopia", { Mod_AltGr, Key_4 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_tritanopia());
});
auto tritanomaly_accessibility_action = GUI::Action::create_checkable("Tritanomaly", { Mod_AltGr, Key_5 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_tritanomaly());
});
auto deuteranopia_accessibility_action = GUI::Action::create_checkable("Deuteranopia", { Mod_AltGr, Key_6 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_deuteranopia());
});
auto deuteranomaly_accessibility_action = GUI::Action::create_checkable("Deuteranomaly", { Mod_AltGr, Key_7 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_deuteranomaly());
});
auto achromatopsia_accessibility_action = GUI::Action::create_checkable("Achromatopsia", { Mod_AltGr, Key_8 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_achromatopsia());
});
auto achromatomaly_accessibility_action = GUI::Action::create_checkable("Achromatomaly", { Mod_AltGr, Key_9 }, [&](auto&) {
magnifier->set_color_filter(Gfx::ColorBlindnessFilter::create_achromatomaly());
});
auto preview_type_action_group = make<GUI::ActionGroup>();
preview_type_action_group->set_exclusive(true);
preview_type_action_group->add_action(*default_accessibility_action);
preview_type_action_group->add_action(*pratanopia_accessibility_action);
preview_type_action_group->add_action(*pratanomaly_accessibility_action);
preview_type_action_group->add_action(*tritanopia_accessibility_action);
preview_type_action_group->add_action(*tritanomaly_accessibility_action);
preview_type_action_group->add_action(*deuteranopia_accessibility_action);
preview_type_action_group->add_action(*deuteranomaly_accessibility_action);
preview_type_action_group->add_action(*achromatopsia_accessibility_action);
preview_type_action_group->add_action(*achromatomaly_accessibility_action);
TRY(accessibility_menu->try_add_action(default_accessibility_action));
TRY(accessibility_menu->try_add_action(pratanopia_accessibility_action));
TRY(accessibility_menu->try_add_action(pratanomaly_accessibility_action));
TRY(accessibility_menu->try_add_action(tritanopia_accessibility_action));
TRY(accessibility_menu->try_add_action(tritanomaly_accessibility_action));
TRY(accessibility_menu->try_add_action(deuteranopia_accessibility_action));
TRY(accessibility_menu->try_add_action(deuteranomaly_accessibility_action));
TRY(accessibility_menu->try_add_action(achromatopsia_accessibility_action));
TRY(accessibility_menu->try_add_action(achromatomaly_accessibility_action));
TRY(window->try_add_menu(TRY(GUI::CommonMenus::make_accessibility_menu(magnifier))));
auto help_menu = TRY(window->try_add_menu("&Help"));
help_menu->add_action(GUI::CommonActions::make_command_palette_action(window));

View File

@ -241,66 +241,7 @@ ErrorOr<void> MainWidget::initialize_menubar(GUI::Window& window)
GUI::Application::the()->quit();
})));
auto accessibility_menu = TRY(window.try_add_menu("&Accessibility"));
auto default_accessibility_action = GUI::Action::create_checkable("Default - non-impaired", { Mod_AltGr, Key_1 }, [&](auto&) {
m_preview_widget->set_color_filter(nullptr);
});
default_accessibility_action->set_checked(true);
auto pratanopia_accessibility_action = GUI::Action::create_checkable("Protanopia", { Mod_AltGr, Key_2 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_protanopia());
});
auto pratanomaly_accessibility_action = GUI::Action::create_checkable("Protanomaly", { Mod_AltGr, Key_3 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_protanomaly());
});
auto tritanopia_accessibility_action = GUI::Action::create_checkable("Tritanopia", { Mod_AltGr, Key_4 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_tritanopia());
});
auto tritanomaly_accessibility_action = GUI::Action::create_checkable("Tritanomaly", { Mod_AltGr, Key_5 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_tritanomaly());
});
auto deuteranopia_accessibility_action = GUI::Action::create_checkable("Deuteranopia", { Mod_AltGr, Key_6 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_deuteranopia());
});
auto deuteranomaly_accessibility_action = GUI::Action::create_checkable("Deuteranomaly", { Mod_AltGr, Key_7 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_deuteranomaly());
});
auto achromatopsia_accessibility_action = GUI::Action::create_checkable("Achromatopsia", { Mod_AltGr, Key_8 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_achromatopsia());
});
auto achromatomaly_accessibility_action = GUI::Action::create_checkable("Achromatomaly", { Mod_AltGr, Key_9 }, [&](auto&) {
m_preview_widget->set_color_filter(Gfx::ColorBlindnessFilter::create_achromatomaly());
});
m_preview_type_action_group = make<GUI::ActionGroup>();
m_preview_type_action_group->set_exclusive(true);
m_preview_type_action_group->add_action(*default_accessibility_action);
m_preview_type_action_group->add_action(*pratanopia_accessibility_action);
m_preview_type_action_group->add_action(*pratanomaly_accessibility_action);
m_preview_type_action_group->add_action(*tritanopia_accessibility_action);
m_preview_type_action_group->add_action(*tritanomaly_accessibility_action);
m_preview_type_action_group->add_action(*deuteranopia_accessibility_action);
m_preview_type_action_group->add_action(*deuteranomaly_accessibility_action);
m_preview_type_action_group->add_action(*achromatopsia_accessibility_action);
m_preview_type_action_group->add_action(*achromatomaly_accessibility_action);
TRY(accessibility_menu->try_add_action(default_accessibility_action));
TRY(accessibility_menu->try_add_action(pratanopia_accessibility_action));
TRY(accessibility_menu->try_add_action(pratanomaly_accessibility_action));
TRY(accessibility_menu->try_add_action(tritanopia_accessibility_action));
TRY(accessibility_menu->try_add_action(tritanomaly_accessibility_action));
TRY(accessibility_menu->try_add_action(deuteranopia_accessibility_action));
TRY(accessibility_menu->try_add_action(deuteranomaly_accessibility_action));
TRY(accessibility_menu->try_add_action(achromatopsia_accessibility_action));
TRY(accessibility_menu->try_add_action(achromatomaly_accessibility_action));
TRY(window.try_add_menu(TRY(GUI::CommonMenus::make_accessibility_menu(*m_preview_widget))));
auto help_menu = TRY(window.try_add_menu("&Help"));
TRY(help_menu->try_add_action(GUI::CommonActions::make_command_palette_action(&window)));

View File

@ -10,6 +10,7 @@
#pragma once
#include <LibGUI/AbstractThemePreview.h>
#include <LibGUI/ColorFilterer.h>
#include <LibGUI/Frame.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Filters/ColorBlindnessFilter.h>
@ -19,16 +20,18 @@ namespace ThemeEditor {
class MiniWidgetGallery;
class PreviewWidget final : public GUI::AbstractThemePreview {
class PreviewWidget final
: public GUI::AbstractThemePreview
, public GUI::ColorFilterer {
C_OBJECT(PreviewWidget);
public:
virtual ~PreviewWidget() override = default;
void set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter>);
virtual void set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter>) override;
private:
explicit PreviewWidget(Gfx::Palette const&);
explicit PreviewWidget(Gfx::Palette const& = GUI::Application::the()->palette());
virtual void paint_preview(GUI::PaintEvent&) override;
virtual void second_paint_event(GUI::PaintEvent&) override;