diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-05-09 19:34:33 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-10 12:36:05 +0200 |
commit | 1674d06f78b0fecbc7bdb7ec9302d2d7ab4d0b12 (patch) | |
tree | 814b1cea1adc37005375f11e85650edbc60a99e5 | |
parent | 3be9af769599eec55290c131d1ec1378fc94e736 (diff) | |
download | serenity-1674d06f78b0fecbc7bdb7ec9302d2d7ab4d0b12.zip |
Userland: Allow the Analog Clock window border to be hidden
Introduce the ability to hide the Analog Clock window borde. With this
feature enabled it looks like the clock is floating and integrated into
the desktop.
The "Cube Demo" has the same feature, and was used as inspiration when
implementing the feature in the Analog Clock.
-rw-r--r-- | Userland/Applications/AnalogClock/AnalogClock.cpp | 19 | ||||
-rw-r--r-- | Userland/Applications/AnalogClock/AnalogClock.h | 7 | ||||
-rw-r--r-- | Userland/Applications/AnalogClock/main.cpp | 16 |
3 files changed, 39 insertions, 3 deletions
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<void(GUI::ContextMenuEvent&)> 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 <LibCore/DateTime.h> #include <LibGUI/Application.h> #include <LibGUI/Icon.h> +#include <LibGUI/Menu.h> +#include <LibGUI/Menubar.h> #include <LibGUI/Window.h> #include <unistd.h> @@ -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<AnalogClock>(); 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<AnalogClock>(); + + 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(); |