mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 09:49:15 +03:00
LibGUI+ThemeEditor: Split preview-widget palette-change callback
There are two different things in ThemeEditor that want to know when a palette changes: 1. The PreviewWidget subclass, so it can update its preview. 2. The ThemeEditor itself, so we know that the palette is modified. Using a protected virtual function for 1 means that we can do 2 without them fighting over the same on_palette_change callback.
This commit is contained in:
parent
5fd0140772
commit
6c572006a3
Notes:
sideshowbarker
2024-07-17 11:27:47 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/6c572006a3 Pull-request: https://github.com/SerenityOS/serenity/pull/13834 Reviewed-by: https://github.com/krkk
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
@ -82,14 +82,16 @@ private:
|
||||
PreviewWidget::PreviewWidget(Gfx::Palette const& initial_preview_palette)
|
||||
: GUI::AbstractThemePreview(initial_preview_palette)
|
||||
{
|
||||
on_palette_change = [&] {
|
||||
m_gallery->set_preview_palette(preview_palette());
|
||||
update_preview_window_locations();
|
||||
};
|
||||
m_gallery = add<MiniWidgetGallery>();
|
||||
set_greedy_for_hits(true);
|
||||
}
|
||||
|
||||
void PreviewWidget::palette_changed()
|
||||
{
|
||||
m_gallery->set_preview_palette(preview_palette());
|
||||
update_preview_window_locations();
|
||||
}
|
||||
|
||||
void PreviewWidget::set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter> color_filter)
|
||||
{
|
||||
m_color_filter = move(color_filter);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
@ -34,6 +34,7 @@ private:
|
||||
virtual void second_paint_event(GUI::PaintEvent&) override;
|
||||
virtual void resize_event(GUI::ResizeEvent&) override;
|
||||
virtual void drop_event(GUI::DropEvent&) override;
|
||||
virtual void palette_changed() override;
|
||||
|
||||
void paint_hightlight_window();
|
||||
void update_preview_window_locations();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
@ -71,9 +71,9 @@ void AbstractThemePreview::load_theme_bitmaps()
|
||||
void AbstractThemePreview::set_preview_palette(Gfx::Palette const& palette)
|
||||
{
|
||||
m_preview_palette = palette;
|
||||
if (on_palette_change) {
|
||||
palette_changed();
|
||||
if (on_palette_change)
|
||||
on_palette_change();
|
||||
}
|
||||
load_theme_bitmaps();
|
||||
update();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
||||
* Copyright (c) 2022, the SerenityOS developers.
|
||||
*
|
||||
@ -45,6 +45,8 @@ protected:
|
||||
return *m_inactive_window_icon;
|
||||
}
|
||||
|
||||
virtual void palette_changed() {};
|
||||
|
||||
private:
|
||||
virtual void paint_preview(GUI::PaintEvent&) = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user