diff --git a/Userland/Applications/AnalogClock/AnalogClock.cpp b/Userland/Applications/AnalogClock/AnalogClock.cpp index 8115d7b60c..749aa64b0a 100644 --- a/Userland/Applications/AnalogClock/AnalogClock.cpp +++ b/Userland/Applications/AnalogClock/AnalogClock.cpp @@ -110,7 +110,7 @@ void AnalogClock::draw_seconds_hand(GUI::Painter& painter, double angle) void AnalogClock::paint_event(GUI::PaintEvent& event) { GUI::Painter painter(*this); - painter.clear_rect(event.rect(), palette().window()); + painter.clear_rect(event.rect(), m_show_window_frame ? palette().window() : Gfx::Color::Transparent); draw_face(painter); @@ -132,3 +132,20 @@ void AnalogClock::update_title_date() { window()->set_title(Core::DateTime::now().to_string("Clock %d-%m-%Y")); } + +void AnalogClock::context_menu_event(GUI::ContextMenuEvent& event) +{ + if (on_context_menu_request) + on_context_menu_request(event); +} + +void AnalogClock::set_show_window_frame(bool show) +{ + if (show == m_show_window_frame) + return; + m_show_window_frame = show; + auto& w = *window(); + w.set_frameless(!m_show_window_frame); + w.set_has_alpha_channel(!m_show_window_frame); + w.set_alpha_hit_threshold(m_show_window_frame ? 0 : 1); +} diff --git a/Userland/Applications/AnalogClock/AnalogClock.h b/Userland/Applications/AnalogClock/AnalogClock.h index 6735ad2e29..a5655916ec 100644 --- a/Userland/Applications/AnalogClock/AnalogClock.h +++ b/Userland/Applications/AnalogClock/AnalogClock.h @@ -13,6 +13,10 @@ class AnalogClock : public GUI::Widget { C_OBJECT(AnalogClock) public: ~AnalogClock() override = default; + void set_show_window_frame(bool); + bool show_window_frame() const { return m_show_window_frame; } + + Function on_context_menu_request; private: AnalogClock() @@ -32,7 +36,10 @@ private: double m_hand_tail_length { 22 }; double m_hand_wing_span { 5 }; + bool m_show_window_frame { true }; + protected: + void context_menu_event(GUI::ContextMenuEvent& event) override; void paint_event(GUI::PaintEvent&) override; void draw_face(GUI::Painter&); void draw_mirrored_graduations(GUI::Painter&, Gfx::IntRect&, int x, int y, int rect_center_offset); diff --git a/Userland/Applications/AnalogClock/main.cpp b/Userland/Applications/AnalogClock/main.cpp index afe277b9f6..e98ca049e6 100644 --- a/Userland/Applications/AnalogClock/main.cpp +++ b/Userland/Applications/AnalogClock/main.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -32,12 +34,22 @@ int main(int argc, char** argv) auto app_icon = GUI::Icon::default_icon("app-analog-clock"); auto window = GUI::Window::construct(); - - window->set_main_widget(); window->set_title(Core::DateTime::now().to_string("Clock %d-%m-%Y")); window->set_icon(app_icon.bitmap_for_size(16)); window->resize(170, 170); window->set_resizable(false); + auto& clock = window->set_main_widget(); + + auto show_window_frame_action = GUI::Action::create_checkable( + "Show Window &Frame", { Mod_Alt, KeyCode::Key_F }, [&](auto& action) { + clock.set_show_window_frame(action.is_checked()); + }); + show_window_frame_action->set_checked(clock.show_window_frame()); + auto menu = GUI::Menu::construct(); + menu->add_action(move(show_window_frame_action)); + clock.on_context_menu_request = [&](auto& event) { + menu->popup(event.screen_position()); + }; window->show(); return app->exec();