diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-09-20 10:22:10 -0400 |
---|---|---|
committer | Sam Atkins <atkinssj@gmail.com> | 2022-09-22 11:46:53 +0100 |
commit | 73fcaaeda461be3dcae4cb8d2bece12db5fac84b (patch) | |
tree | 1db32247a1a21f8d303131b78f4ee108845429a9 | |
parent | c64a5ccf29273a0684734b339c164cf3840ebe63 (diff) | |
download | serenity-73fcaaeda461be3dcae4cb8d2bece12db5fac84b.zip |
Taskbar: Add a context menu to open clock settings from the clock widget
-rw-r--r-- | Userland/Services/Taskbar/ClockWidget.cpp | 19 | ||||
-rw-r--r-- | Userland/Services/Taskbar/ClockWidget.h | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Userland/Services/Taskbar/ClockWidget.cpp b/Userland/Services/Taskbar/ClockWidget.cpp index 1089b87b1e..539e728cc2 100644 --- a/Userland/Services/Taskbar/ClockWidget.cpp +++ b/Userland/Services/Taskbar/ClockWidget.cpp @@ -6,10 +6,13 @@ #include "ClockWidget.h" #include <LibConfig/Client.h> +#include <LibGUI/Action.h> +#include <LibGUI/Menu.h> #include <LibGUI/Painter.h> #include <LibGUI/Process.h> #include <LibGUI/SeparatorWidget.h> #include <LibGUI/Window.h> +#include <LibGfx/Bitmap.h> #include <LibGfx/Font/FontDatabase.h> #include <LibGfx/Palette.h> @@ -196,6 +199,22 @@ void ClockWidget::mousedown_event(GUI::MouseEvent& event) } } +void ClockWidget::context_menu_event(GUI::ContextMenuEvent& event) +{ + if (!m_context_menu) { + m_context_menu = GUI::Menu::construct(); + + auto settings_icon = MUST(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/settings.png"sv)); + auto open_clock_settings_action = GUI::Action::create("Clock &Settings", *settings_icon, [this](auto&) { + GUI::Process::spawn_or_show_error(window(), "/bin/ClockSettings"sv, Array { "--open-tab", "clock" }); + }); + + m_context_menu->add_action(open_clock_settings_action); + } + + m_context_menu->popup(event.screen_position()); +} + void ClockWidget::open() { jump_to_current_date(); diff --git a/Userland/Services/Taskbar/ClockWidget.h b/Userland/Services/Taskbar/ClockWidget.h index 420d02a61a..a07971cb0f 100644 --- a/Userland/Services/Taskbar/ClockWidget.h +++ b/Userland/Services/Taskbar/ClockWidget.h @@ -31,6 +31,7 @@ private: virtual void paint_event(GUI::PaintEvent&) override; virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void context_menu_event(GUI::ContextMenuEvent&) override; void tick_clock() { @@ -52,6 +53,7 @@ private: RefPtr<GUI::Button> m_selected_calendar_button; RefPtr<GUI::Button> m_jump_to_button; RefPtr<GUI::Button> m_calendar_launcher; + RefPtr<GUI::Menu> m_context_menu; RefPtr<Core::Timer> m_timer; int m_time_width { 0 }; Gfx::IntSize m_window_size { 158, 186 }; |