mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
ClockSettings: Add a factory function for TimeZoneSettingsWidget
This removes an unbelievable 4 FIXMEs :))
This commit is contained in:
parent
27a1798dd9
commit
626142c312
3 changed files with 25 additions and 14 deletions
|
@ -40,6 +40,25 @@ static constexpr auto TIME_ZONE_TEXT_HEIGHT = 40;
|
||||||
static constexpr auto TIME_ZONE_TEXT_PADDING = 5;
|
static constexpr auto TIME_ZONE_TEXT_PADDING = 5;
|
||||||
static constexpr auto TIME_ZONE_TEXT_COLOR = Gfx::Color::from_rgb(0xeaf688);
|
static constexpr auto TIME_ZONE_TEXT_COLOR = Gfx::Color::from_rgb(0xeaf688);
|
||||||
|
|
||||||
|
ErrorOr<NonnullRefPtr<TimeZoneSettingsWidget>> TimeZoneSettingsWidget::create()
|
||||||
|
{
|
||||||
|
auto timezonesettings_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) TimeZoneSettingsWidget));
|
||||||
|
|
||||||
|
auto time_zone_map_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/graphics/map.png"sv));
|
||||||
|
auto time_zone_rect = time_zone_map_bitmap->rect().shrunken(TIME_ZONE_MAP_NORTHERN_TRIM, 0, TIME_ZONE_MAP_SOUTHERN_TRIM, 0);
|
||||||
|
time_zone_map_bitmap = TRY(time_zone_map_bitmap->cropped(time_zone_rect));
|
||||||
|
|
||||||
|
timezonesettings_widget->m_time_zone_map = *timezonesettings_widget->find_descendant_of_type_named<GUI::ImageWidget>("time_zone_map");
|
||||||
|
timezonesettings_widget->m_time_zone_map->set_bitmap(time_zone_map_bitmap);
|
||||||
|
|
||||||
|
auto time_zone_marker = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/32x32/ladyball.png"sv));
|
||||||
|
timezonesettings_widget->m_time_zone_marker = TRY(time_zone_marker->scaled(0.75f, 0.75f));
|
||||||
|
|
||||||
|
timezonesettings_widget->set_time_zone_location();
|
||||||
|
|
||||||
|
return timezonesettings_widget;
|
||||||
|
}
|
||||||
|
|
||||||
TimeZoneSettingsWidget::TimeZoneSettingsWidget()
|
TimeZoneSettingsWidget::TimeZoneSettingsWidget()
|
||||||
{
|
{
|
||||||
load_from_gml(time_zone_settings_widget_gml);
|
load_from_gml(time_zone_settings_widget_gml);
|
||||||
|
@ -54,18 +73,6 @@ TimeZoneSettingsWidget::TimeZoneSettingsWidget()
|
||||||
m_time_zone_combo_box->on_change = [&](auto, auto) {
|
m_time_zone_combo_box->on_change = [&](auto, auto) {
|
||||||
set_modified(true);
|
set_modified(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto time_zone_map_bitmap = Gfx::Bitmap::try_load_from_file("/res/graphics/map.png"sv).release_value_but_fixme_should_propagate_errors();
|
|
||||||
auto time_zone_rect = time_zone_map_bitmap->rect().shrunken(TIME_ZONE_MAP_NORTHERN_TRIM, 0, TIME_ZONE_MAP_SOUTHERN_TRIM, 0);
|
|
||||||
time_zone_map_bitmap = time_zone_map_bitmap->cropped(time_zone_rect).release_value_but_fixme_should_propagate_errors();
|
|
||||||
|
|
||||||
m_time_zone_map = *find_descendant_of_type_named<GUI::ImageWidget>("time_zone_map");
|
|
||||||
m_time_zone_map->set_bitmap(time_zone_map_bitmap);
|
|
||||||
|
|
||||||
auto time_zone_marker = Gfx::Bitmap::try_load_from_file("/res/icons/32x32/ladyball.png"sv).release_value_but_fixme_should_propagate_errors();
|
|
||||||
m_time_zone_marker = time_zone_marker->scaled(0.75f, 0.75f).release_value_but_fixme_should_propagate_errors();
|
|
||||||
|
|
||||||
set_time_zone_location();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimeZoneSettingsWidget::second_paint_event(GUI::PaintEvent& event)
|
void TimeZoneSettingsWidget::second_paint_event(GUI::PaintEvent& event)
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
#include <LibGUI/Window.h>
|
#include <LibGUI/Window.h>
|
||||||
|
|
||||||
class TimeZoneSettingsWidget final : public GUI::SettingsWindow::Tab {
|
class TimeZoneSettingsWidget final : public GUI::SettingsWindow::Tab {
|
||||||
C_OBJECT(TimeZoneSettingsWidget)
|
C_OBJECT_ABSTRACT(TimeZoneSettingsWidget)
|
||||||
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<TimeZoneSettingsWidget>> create();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimeZoneSettingsWidget();
|
TimeZoneSettingsWidget();
|
||||||
|
|
|
@ -37,7 +37,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
|
||||||
auto window = TRY(GUI::SettingsWindow::create("Clock Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
|
auto window = TRY(GUI::SettingsWindow::create("Clock Settings", GUI::SettingsWindow::ShowDefaultsButton::Yes));
|
||||||
(void)TRY(window->add_tab<ClockSettingsWidget>("Clock"sv, "clock"sv));
|
(void)TRY(window->add_tab<ClockSettingsWidget>("Clock"sv, "clock"sv));
|
||||||
(void)TRY(window->add_tab<TimeZoneSettingsWidget>("Time Zone"sv, "time-zone"sv));
|
auto timezonesettings_widget = TRY(TimeZoneSettingsWidget::create());
|
||||||
|
TRY(window->add_tab(timezonesettings_widget, "Time Zone"sv, "time-zone"sv));
|
||||||
|
|
||||||
window->set_icon(app_icon.bitmap_for_size(16));
|
window->set_icon(app_icon.bitmap_for_size(16));
|
||||||
window->resize(540, 570);
|
window->resize(540, 570);
|
||||||
window->set_active_tab(selected_tab);
|
window->set_active_tab(selected_tab);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue