mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
DisplaySettings: Propagate errors in MonitorWidget
This commit is contained in:
parent
f1d1517414
commit
9f2a396c6e
2 changed files with 18 additions and 9 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "MonitorWidget.h"
|
#include "MonitorWidget.h"
|
||||||
#include <LibGUI/Desktop.h>
|
#include <LibGUI/Desktop.h>
|
||||||
|
#include <LibGUI/MessageBox.h>
|
||||||
#include <LibGUI/Painter.h>
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Font/Font.h>
|
#include <LibGfx/Font/Font.h>
|
||||||
|
@ -16,13 +17,15 @@ REGISTER_WIDGET(DisplaySettings, MonitorWidget)
|
||||||
|
|
||||||
namespace DisplaySettings {
|
namespace DisplaySettings {
|
||||||
|
|
||||||
MonitorWidget::MonitorWidget()
|
ErrorOr<NonnullRefPtr<MonitorWidget>> MonitorWidget::try_create()
|
||||||
{
|
{
|
||||||
m_desktop_resolution = GUI::Desktop::the().rect().size();
|
auto monitor_widget = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) MonitorWidget()));
|
||||||
m_monitor_bitmap = Gfx::Bitmap::load_from_file("/res/graphics/monitor.png"sv).release_value_but_fixme_should_propagate_errors();
|
monitor_widget->m_desktop_resolution = GUI::Desktop::the().rect().size();
|
||||||
m_desktop_bitmap = Gfx::Bitmap::create(m_monitor_bitmap->format(), { 280, 158 }).release_value_but_fixme_should_propagate_errors();
|
monitor_widget->m_monitor_bitmap = TRY(Gfx::Bitmap::load_from_file("/res/graphics/monitor.png"sv));
|
||||||
m_monitor_rect = { { 12, 13 }, m_desktop_bitmap->size() };
|
monitor_widget->m_desktop_bitmap = TRY(Gfx::Bitmap::create(monitor_widget->m_monitor_bitmap->format(), { 280, 158 }));
|
||||||
set_fixed_size(304, 201);
|
monitor_widget->m_monitor_rect = { { 12, 13 }, monitor_widget->m_desktop_bitmap->size() };
|
||||||
|
monitor_widget->set_fixed_size(304, 201);
|
||||||
|
return monitor_widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MonitorWidget::set_wallpaper(DeprecatedString path)
|
bool MonitorWidget::set_wallpaper(DeprecatedString path)
|
||||||
|
@ -123,7 +126,12 @@ void MonitorWidget::redraw_desktop_if_needed()
|
||||||
float sh = (float)m_desktop_bitmap->height() / (float)m_desktop_resolution.height();
|
float sh = (float)m_desktop_bitmap->height() / (float)m_desktop_resolution.height();
|
||||||
|
|
||||||
auto scaled_size = m_wallpaper_bitmap->size().to_type<float>().scaled_by(sw, sh).to_type<int>();
|
auto scaled_size = m_wallpaper_bitmap->size().to_type<float>().scaled_by(sw, sh).to_type<int>();
|
||||||
auto scaled_bitmap = m_wallpaper_bitmap->scaled(sw, sh).release_value_but_fixme_should_propagate_errors();
|
auto scaled_bitmap_or_error = m_wallpaper_bitmap->scaled(sw, sh);
|
||||||
|
if (scaled_bitmap_or_error.is_error()) {
|
||||||
|
GUI::MessageBox::show_error(window(), "There was an error updating the desktop preview"sv);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto scaled_bitmap = scaled_bitmap_or_error.release_value();
|
||||||
|
|
||||||
if (m_desktop_wallpaper_mode == "Center") {
|
if (m_desktop_wallpaper_mode == "Center") {
|
||||||
auto centered_rect = Gfx::IntRect({}, scaled_size).centered_within(m_desktop_bitmap->rect());
|
auto centered_rect = Gfx::IntRect({}, scaled_size).centered_within(m_desktop_bitmap->rect());
|
||||||
|
|
|
@ -11,9 +11,10 @@
|
||||||
namespace DisplaySettings {
|
namespace DisplaySettings {
|
||||||
|
|
||||||
class MonitorWidget final : public GUI::Widget {
|
class MonitorWidget final : public GUI::Widget {
|
||||||
C_OBJECT(MonitorWidget);
|
C_OBJECT_ABSTRACT(MonitorWidget);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<MonitorWidget>> try_create();
|
||||||
bool set_wallpaper(DeprecatedString path);
|
bool set_wallpaper(DeprecatedString path);
|
||||||
StringView wallpaper() const;
|
StringView wallpaper() const;
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ public:
|
||||||
Gfx::Color background_color();
|
Gfx::Color background_color();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MonitorWidget();
|
MonitorWidget() = default;
|
||||||
|
|
||||||
void redraw_desktop_if_needed();
|
void redraw_desktop_if_needed();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue