1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

Applications+Demos+LibGUI: Migrate to fallible WizardDialogs and Pages

And port page text to String. Also removes WizardDialog::show() helper
as all current implementations prefer to derive their own Dialog.
This commit is contained in:
thankyouverycool 2023-06-08 07:46:11 -04:00 committed by Andreas Kling
parent 96e60c98cf
commit caa8f43dbe
12 changed files with 178 additions and 115 deletions

View file

@ -116,10 +116,13 @@ ErrorOr<void> MainWidget::create_actions()
m_new_action = GUI::Action::create("&New Font...", { Mod_Ctrl, Key_N }, g_resources.new_font, [this](auto&) { m_new_action = GUI::Action::create("&New Font...", { Mod_Ctrl, Key_N }, g_resources.new_font, [this](auto&) {
if (!request_close()) if (!request_close())
return; return;
auto new_font_wizard = NewFontDialog::construct(window()); auto maybe_wizard = NewFontDialog::create(window());
if (new_font_wizard->exec() != GUI::Dialog::ExecResult::OK) if (maybe_wizard.is_error())
return show_error(maybe_wizard.release_error(), "Creating font wizard failed"sv);
auto wizard = maybe_wizard.release_value();
if (wizard->exec() != GUI::Dialog::ExecResult::OK)
return; return;
auto maybe_font = new_font_wizard->create_font(); auto maybe_font = wizard->create_font();
if (maybe_font.is_error()) if (maybe_font.is_error())
return show_error(maybe_font.release_error(), "Creating new font failed"sv); return show_error(maybe_font.release_error(), "Creating new font failed"sv);
if (auto result = initialize({}, move(maybe_font.value())); result.is_error()) if (auto result = initialize({}, move(maybe_font.value())); result.is_error())

View file

@ -122,13 +122,19 @@ private:
REGISTER_WIDGET(FontEditor, GlyphPreviewWidget); REGISTER_WIDGET(FontEditor, GlyphPreviewWidget);
NewFontDialog::NewFontDialog(GUI::Window* parent_window) ErrorOr<NonnullRefPtr<NewFontDialog>> NewFontDialog::create(GUI::Window* parent_window)
: GUI::WizardDialog(parent_window)
{ {
set_title("New Font"); auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) NewFontDialog(parent_window)));
TRY(dialog->build());
return dialog;
}
m_font_properties_page = GUI::WizardPage::construct("Typeface properties", "Edit details about this font."); ErrorOr<void> NewFontDialog::build()
m_font_properties_page->body_widget().load_from_gml(new_font_dialog_page_1_gml).release_value_but_fixme_should_propagate_errors(); {
TRY(GUI::WizardDialog::build());
m_font_properties_page = TRY(GUI::WizardPage::create("Typeface properties"sv, "Edit details about this font."sv));
TRY(m_font_properties_page->body_widget().load_from_gml(new_font_dialog_page_1_gml));
m_name_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("name_textbox"); m_name_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("name_textbox");
m_family_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("family_textbox"); m_family_textbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::TextBox>("family_textbox");
@ -136,14 +142,16 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window)
m_slope_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::ComboBox>("slope_combobox"); m_slope_combobox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::ComboBox>("slope_combobox");
m_presentation_spinbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("presentation_spinbox"); m_presentation_spinbox = m_font_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("presentation_spinbox");
TRY(m_font_weight_list.try_ensure_capacity(Gfx::font_weight_names.size()));
for (auto& it : Gfx::font_weight_names) for (auto& it : Gfx::font_weight_names)
m_font_weight_list.append(it.name); m_font_weight_list.unchecked_append(TRY(String::from_utf8(it.name)));
m_weight_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_font_weight_list)); m_weight_combobox->set_model(TRY(GUI::ItemListModel<String>::try_create(m_font_weight_list)));
m_weight_combobox->set_selected_index(3); m_weight_combobox->set_selected_index(3);
TRY(m_font_slope_list.try_ensure_capacity(Gfx::font_slope_names.size()));
for (auto& it : Gfx::font_slope_names) for (auto& it : Gfx::font_slope_names)
m_font_slope_list.append(it.name); m_font_slope_list.unchecked_append(TRY(String::from_utf8(it.name)));
m_slope_combobox->set_model(*GUI::ItemListModel<DeprecatedString>::create(m_font_slope_list)); m_slope_combobox->set_model(TRY(GUI::ItemListModel<String>::try_create(m_font_slope_list)));
m_slope_combobox->set_selected_index(0); m_slope_combobox->set_selected_index(0);
m_presentation_spinbox->set_value(12); m_presentation_spinbox->set_value(12);
@ -155,8 +163,8 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window)
return m_glyph_properties_page; return m_glyph_properties_page;
}; };
m_glyph_properties_page = GUI::WizardPage::construct("Glyph properties", "Edit details about this font."); m_glyph_properties_page = TRY(GUI::WizardPage::create("Glyph properties"sv, "Edit details about this font."sv));
m_glyph_properties_page->body_widget().load_from_gml(new_font_dialog_page_2_gml).release_value_but_fixme_should_propagate_errors(); TRY(m_glyph_properties_page->body_widget().load_from_gml(new_font_dialog_page_2_gml));
m_glyph_properties_page->set_is_final_page(true); m_glyph_properties_page->set_is_final_page(true);
m_glyph_height_spinbox = m_glyph_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("height_spinbox"); m_glyph_height_spinbox = m_glyph_properties_page->body_widget().find_descendant_of_type_named<GUI::SpinBox>("height_spinbox");
@ -197,6 +205,15 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window)
}; };
push_page(*m_font_properties_page); push_page(*m_font_properties_page);
return {};
}
NewFontDialog::NewFontDialog(GUI::Window* parent_window)
: GUI::WizardDialog(parent_window)
{
set_title("New Font");
set_icon(parent_window->icon());
} }
void NewFontDialog::save_metadata() void NewFontDialog::save_metadata()

View file

@ -12,13 +12,17 @@
#include <LibGfx/Font/BitmapFont.h> #include <LibGfx/Font/BitmapFont.h>
class NewFontDialog final : public GUI::WizardDialog { class NewFontDialog final : public GUI::WizardDialog {
C_OBJECT(NewFontDialog); C_OBJECT_ABSTRACT(NewFontDialog);
public: public:
static ErrorOr<NonnullRefPtr<NewFontDialog>> create(GUI::Window* parent_window);
ErrorOr<NonnullRefPtr<Gfx::BitmapFont>> create_font(); ErrorOr<NonnullRefPtr<Gfx::BitmapFont>> create_font();
private: private:
NewFontDialog(GUI::Window* parent_window); explicit NewFontDialog(GUI::Window* parent_window);
virtual ErrorOr<void> build() override;
void save_metadata(); void save_metadata();
@ -51,6 +55,6 @@ private:
RefPtr<GUI::SpinBox> m_spacing_spinbox; RefPtr<GUI::SpinBox> m_spacing_spinbox;
RefPtr<GUI::CheckBox> m_fixed_width_checkbox; RefPtr<GUI::CheckBox> m_fixed_width_checkbox;
Vector<DeprecatedString> m_font_weight_list; Vector<String> m_font_weight_list;
Vector<DeprecatedString> m_font_slope_list; Vector<String> m_font_slope_list;
}; };

View file

@ -34,9 +34,10 @@ CSVExportDialogPage::CSVExportDialogPage(Sheet const& sheet)
{ {
m_headers.extend(m_data.take_first()); m_headers.extend(m_data.take_first());
m_page = GUI::WizardPage::construct( m_page = GUI::WizardPage::create(
"CSV Export Options", "CSV Export Options"sv,
"Please select the options for the csv file you wish to export to"); "Please select the options for the csv file you wish to export to"sv)
.release_value_but_fixme_should_propagate_errors();
m_page->body_widget().load_from_gml(csv_export_gml).release_value_but_fixme_should_propagate_errors(); m_page->body_widget().load_from_gml(csv_export_gml).release_value_but_fixme_should_propagate_errors();
m_page->set_is_final_page(true); m_page->set_is_final_page(true);
@ -180,7 +181,7 @@ void CSVExportDialogPage::update_preview()
ErrorOr<void> ExportDialog::make_and_run_for(StringView mime, Core::File& file, DeprecatedString filename, Workbook& workbook) ErrorOr<void> ExportDialog::make_and_run_for(StringView mime, Core::File& file, DeprecatedString filename, Workbook& workbook)
{ {
auto wizard = GUI::WizardDialog::construct(GUI::Application::the()->active_window()); auto wizard = TRY(GUI::WizardDialog::create(GUI::Application::the()->active_window()));
wizard->set_title("File Export Wizard"); wizard->set_title("File Export Wizard");
wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet"sv).bitmap_for_size(16)); wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet"sv).bitmap_for_size(16));
@ -213,9 +214,9 @@ ErrorOr<void> ExportDialog::make_and_run_for(StringView mime, Core::File& file,
} else if (mime == "application/x-sheets+json") { } else if (mime == "application/x-sheets+json") {
return export_worksheet(); return export_worksheet();
} else { } else {
auto page = GUI::WizardPage::construct( auto page = TRY(GUI::WizardPage::create(
"Export File Format", "Export File Format"sv,
DeprecatedString::formatted("Select the format you wish to export to '{}' as", LexicalPath::basename(filename))); TRY(String::formatted("Select the format you wish to export to '{}' as", LexicalPath::basename(filename)))));
page->on_next_page = [] { return nullptr; }; page->on_next_page = [] { return nullptr; };

View file

@ -27,9 +27,10 @@ namespace Spreadsheet {
CSVImportDialogPage::CSVImportDialogPage(StringView csv) CSVImportDialogPage::CSVImportDialogPage(StringView csv)
: m_csv(csv) : m_csv(csv)
{ {
m_page = GUI::WizardPage::construct( m_page = GUI::WizardPage::create(
"CSV Import Options", "CSV Import Options"sv,
"Please select the options for the csv file you wish to import"); "Please select the options for the csv file you wish to import"sv)
.release_value_but_fixme_should_propagate_errors();
m_page->body_widget().load_from_gml(csv_import_gml).release_value_but_fixme_should_propagate_errors(); m_page->body_widget().load_from_gml(csv_import_gml).release_value_but_fixme_should_propagate_errors();
m_page->set_is_final_page(true); m_page->set_is_final_page(true);
@ -178,7 +179,7 @@ void CSVImportDialogPage::update_preview()
ErrorOr<Vector<NonnullRefPtr<Sheet>>, DeprecatedString> ImportDialog::make_and_run_for(GUI::Window& parent, StringView mime, String const& filename, Core::File& file, Workbook& workbook) ErrorOr<Vector<NonnullRefPtr<Sheet>>, DeprecatedString> ImportDialog::make_and_run_for(GUI::Window& parent, StringView mime, String const& filename, Core::File& file, Workbook& workbook)
{ {
auto wizard = GUI::WizardDialog::construct(&parent); auto wizard = GUI::WizardDialog::create(&parent).release_value_but_fixme_should_propagate_errors();
wizard->set_title("File Import Wizard"); wizard->set_title("File Import Wizard");
wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet"sv).bitmap_for_size(16)); wizard->set_icon(GUI::Icon::default_icon("app-spreadsheet"sv).bitmap_for_size(16));
@ -244,9 +245,10 @@ ErrorOr<Vector<NonnullRefPtr<Sheet>>, DeprecatedString> ImportDialog::make_and_r
} else if (mime == "application/x-sheets+json") { } else if (mime == "application/x-sheets+json") {
return import_worksheet(); return import_worksheet();
} else { } else {
auto page = GUI::WizardPage::construct( auto page = GUI::WizardPage::create(
"Import File Format", "Import File Format"sv,
DeprecatedString::formatted("Select the format you wish to import '{}' as", LexicalPath::basename(filename.to_deprecated_string()))); DeprecatedString::formatted("Select the format you wish to import '{}' as", LexicalPath::basename(filename.to_deprecated_string())))
.release_value_but_fixme_should_propagate_errors();
page->on_next_page = [] { return nullptr; }; page->on_next_page = [] { return nullptr; };

View file

@ -15,18 +15,22 @@
DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window) DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window)
: GUI::WizardDialog(parent_window) : GUI::WizardDialog(parent_window)
{ {
set_title("Demo Wizard");
build().release_value_but_fixme_should_propagate_errors();
// Create the front cover // Create the front cover
m_front_page = GUI::CoverWizardPage::try_create().release_value_but_fixme_should_propagate_errors(); m_front_page = GUI::CoverWizardPage::create(
m_front_page->set_header_text("Welcome to the SerenityOS demo wizard!"); "Welcome to the SerenityOS demo wizard!"sv,
m_front_page->set_body_text("This wizard demonstrates the amazing wizardry\ncapabilities of LibGUI :^)"); "This wizard demonstrates the amazing wizardry\ncapabilities of LibGUI :^)"sv)
.release_value_but_fixme_should_propagate_errors();
m_front_page->on_next_page = [&]() { m_front_page->on_next_page = [&]() {
return m_page_1; return m_page_1;
}; };
// Create Page 1 // Create Page 1
m_page_1 = GUI::WizardPage::try_create( m_page_1 = GUI::WizardPage::create(
"Installation location", "Installation location"sv,
"Choose where Demo Application is installed on your computer.") "Choose where Demo Application is installed on your computer."sv)
.release_value_but_fixme_should_propagate_errors(); .release_value_but_fixme_should_propagate_errors();
m_page_1->body_widget().load_from_gml(demo_wizard_page_1_gml).release_value_but_fixme_should_propagate_errors(); m_page_1->body_widget().load_from_gml(demo_wizard_page_1_gml).release_value_but_fixme_should_propagate_errors();
m_page_1_location_text_box = m_page_1->body_widget().find_descendant_of_type_named<GUI::TextBox>("page_1_location_text_box"); m_page_1_location_text_box = m_page_1->body_widget().find_descendant_of_type_named<GUI::TextBox>("page_1_location_text_box");
@ -35,9 +39,9 @@ DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window)
}; };
// Create Page 2 with a progress bar :^) // Create Page 2 with a progress bar :^)
m_page_2 = GUI::WizardPage::try_create( m_page_2 = GUI::WizardPage::create(
"Installation in progress...", "Installation in progress..."sv,
"Please wait. Do not turn off your computer.") "Please wait. Do not turn off your computer."sv)
.release_value_but_fixme_should_propagate_errors(); .release_value_but_fixme_should_propagate_errors();
m_page_2->body_widget().load_from_gml(demo_wizard_page_2_gml).release_value_but_fixme_should_propagate_errors(); m_page_2->body_widget().load_from_gml(demo_wizard_page_2_gml).release_value_but_fixme_should_propagate_errors();
m_page_2_progressbar = m_page_2->body_widget().find_descendant_of_type_named<GUI::Progressbar>("page_2_progressbar"); m_page_2_progressbar = m_page_2->body_widget().find_descendant_of_type_named<GUI::Progressbar>("page_2_progressbar");
@ -66,9 +70,10 @@ DemoWizardDialog::DemoWizardDialog(GUI::Window* parent_window)
// Don't set a on_next_page handler for page 2 as we automatically navigate to the final page on progress completion // Don't set a on_next_page handler for page 2 as we automatically navigate to the final page on progress completion
// Create the back cover // Create the back cover
m_back_page = GUI::CoverWizardPage::try_create().release_value_but_fixme_should_propagate_errors(); m_back_page = GUI::CoverWizardPage::create(
m_back_page->set_header_text("Wizard complete."); "Wizard complete."sv,
m_back_page->set_body_text("That concludes the SerenityOS demo wizard :^)"); "That concludes the SerenityOS demo wizard :^)"sv)
.release_value_but_fixme_should_propagate_errors();
m_back_page->set_is_final_page(true); m_back_page->set_is_final_page(true);
push_page(*m_front_page); push_page(*m_front_page);

View file

@ -13,36 +13,44 @@
namespace GUI { namespace GUI {
CoverWizardPage::CoverWizardPage() ErrorOr<NonnullRefPtr<CoverWizardPage>> CoverWizardPage::create(StringView title, StringView subtitle)
: AbstractWizardPage() {
auto page = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) CoverWizardPage()));
TRY(page->build(TRY(String::from_utf8(title)), TRY(String::from_utf8(subtitle))));
return page;
}
ErrorOr<void> CoverWizardPage::build(String title, String subtitle)
{ {
set_fill_with_background_color(true); set_fill_with_background_color(true);
set_background_role(Gfx::ColorRole::Base); set_background_role(Gfx::ColorRole::Base);
set_layout<HorizontalBoxLayout>(); TRY(try_set_layout<HorizontalBoxLayout>());
m_banner_image_widget = add<ImageWidget>(); m_banner_image_widget = TRY(try_add<ImageWidget>());
m_banner_image_widget->set_fixed_size(160, 315); m_banner_image_widget->set_fixed_size(160, 315);
m_banner_image_widget->load_from_file("/res/graphics/wizard-banner-simple.png"sv); m_banner_image_widget->load_from_file("/res/graphics/wizard-banner-simple.png"sv);
m_content_widget = add<Widget>(); m_content_widget = TRY(try_add<Widget>());
m_content_widget->set_layout<VerticalBoxLayout>(20); TRY(m_content_widget->try_set_layout<VerticalBoxLayout>(20));
m_header_label = m_content_widget->add<Label>(); m_header_label = TRY(m_content_widget->try_add<Label>(move(title)));
m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton", 14, 700, Gfx::FontWidth::Normal, 0)); m_header_label->set_font(Gfx::FontDatabase::the().get("Pebbleton", 14, 700, Gfx::FontWidth::Normal, 0));
m_header_label->set_text_alignment(Gfx::TextAlignment::TopLeft); m_header_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
m_header_label->set_fixed_height(48); m_header_label->set_fixed_height(48);
m_body_label = m_content_widget->add<Label>(); m_body_label = TRY(m_content_widget->try_add<Label>(move(subtitle)));
m_body_label->set_text_alignment(Gfx::TextAlignment::TopLeft); m_body_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
return {};
} }
void CoverWizardPage::set_header_text(DeprecatedString const& text) void CoverWizardPage::set_header_text(String text)
{ {
m_header_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors()); m_header_label->set_text(move(text));
} }
void CoverWizardPage::set_body_text(DeprecatedString const& text) void CoverWizardPage::set_body_text(String text)
{ {
m_body_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors()); m_body_label->set_text(move(text));
} }
} }

View file

@ -14,15 +14,20 @@
namespace GUI { namespace GUI {
class CoverWizardPage : public AbstractWizardPage { class CoverWizardPage : public AbstractWizardPage {
C_OBJECT(CoverWizardPage); C_OBJECT_ABSTRACT(CoverWizardPage);
static ErrorOr<NonnullRefPtr<CoverWizardPage>> create(StringView title, StringView subtitle);
ImageWidget& banner_image_widget() { return *m_banner_image_widget; } ImageWidget& banner_image_widget() { return *m_banner_image_widget; }
void set_header_text(DeprecatedString const& text); void set_header_text(String);
void set_body_text(DeprecatedString const& text); void set_body_text(String);
protected:
virtual ErrorOr<void> build(String title, String subtitle);
private: private:
explicit CoverWizardPage(); CoverWizardPage() = default;
RefPtr<ImageWidget> m_banner_image_widget; RefPtr<ImageWidget> m_banner_image_widget;
RefPtr<Widget> m_content_widget; RefPtr<Widget> m_content_widget;

View file

@ -16,39 +16,37 @@
namespace GUI { namespace GUI {
WizardDialog::WizardDialog(Window* parent_window) ErrorOr<NonnullRefPtr<WizardDialog>> WizardDialog::create(Window* parent_window)
: Dialog(parent_window)
, m_page_stack()
{ {
resize(500, 360); auto dialog = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WizardDialog(parent_window)));
set_title(DeprecatedString::formatted("Sample wizard")); TRY(dialog->build());
set_resizable(false); return dialog;
}
if (parent_window) ErrorOr<void> WizardDialog::build()
set_icon(parent_window->icon()); {
auto main_widget = TRY(set_main_widget<Widget>());
auto main_widget = set_main_widget<Widget>().release_value_but_fixme_should_propagate_errors();
main_widget->set_fill_with_background_color(true); main_widget->set_fill_with_background_color(true);
main_widget->set_layout<VerticalBoxLayout>(GUI::Margins {}, 0); TRY(main_widget->try_set_layout<VerticalBoxLayout>(Margins {}, 0));
m_page_container_widget = main_widget->add<Widget>(); m_page_container_widget = TRY(main_widget->try_add<Widget>());
m_page_container_widget->set_fixed_size(500, 315); m_page_container_widget->set_fixed_size(500, 315);
m_page_container_widget->set_layout<VerticalBoxLayout>(); TRY(m_page_container_widget->try_set_layout<VerticalBoxLayout>());
auto& separator = main_widget->add<SeparatorWidget>(Gfx::Orientation::Horizontal); auto separator = TRY(main_widget->try_add<SeparatorWidget>(Gfx::Orientation::Horizontal));
separator.set_fixed_height(2); separator->set_fixed_height(2);
auto& nav_container_widget = main_widget->add<Widget>(); auto nav_container_widget = TRY(main_widget->try_add<Widget>());
nav_container_widget.set_layout<HorizontalBoxLayout>(GUI::Margins { 0, 10 }, 0); TRY(nav_container_widget->try_set_layout<HorizontalBoxLayout>(Margins { 0, 10 }, 0));
nav_container_widget.set_fixed_height(42); nav_container_widget->set_fixed_height(42);
nav_container_widget.add_spacer().release_value_but_fixme_should_propagate_errors(); TRY(nav_container_widget->add_spacer());
m_back_button = nav_container_widget.add<DialogButton>("< Back"_short_string); m_back_button = TRY(nav_container_widget->try_add<DialogButton>("< Back"_short_string));
m_back_button->on_click = [&](auto) { m_back_button->on_click = [&](auto) {
pop_page(); pop_page();
}; };
m_next_button = nav_container_widget.add<DialogButton>("Next >"_short_string); m_next_button = TRY(nav_container_widget->try_add<DialogButton>("Next >"_short_string));
m_next_button->on_click = [&](auto) { m_next_button->on_click = [&](auto) {
VERIFY(has_pages()); VERIFY(has_pages());
@ -62,15 +60,25 @@ WizardDialog::WizardDialog(Window* parent_window)
push_page(*next_page); push_page(*next_page);
}; };
auto& button_spacer = nav_container_widget.add<Widget>(); auto button_spacer = TRY(nav_container_widget->try_add<Widget>());
button_spacer.set_fixed_width(10); button_spacer->set_fixed_width(10);
m_cancel_button = nav_container_widget.add<DialogButton>("Cancel"_short_string); m_cancel_button = TRY(nav_container_widget->try_add<DialogButton>("Cancel"_short_string));
m_cancel_button->on_click = [&](auto) { m_cancel_button->on_click = [&](auto) {
handle_cancel(); handle_cancel();
}; };
update_navigation(); update_navigation();
return {};
}
WizardDialog::WizardDialog(Window* parent_window)
: Dialog(parent_window)
, m_page_stack()
{
resize(500, 360);
set_resizable(false);
} }
void WizardDialog::push_page(AbstractWizardPage& page) void WizardDialog::push_page(AbstractWizardPage& page)

View file

@ -13,16 +13,11 @@
namespace GUI { namespace GUI {
class WizardDialog : public Dialog { class WizardDialog : public Dialog {
C_OBJECT(WizardDialog) C_OBJECT_ABSTRACT(WizardDialog)
public: public:
virtual ~WizardDialog() override = default; virtual ~WizardDialog() override = default;
static void show(AbstractWizardPage& first_page, Window* parent_window = nullptr) static ErrorOr<NonnullRefPtr<WizardDialog>> create(Window* parent_window);
{
auto dialog = WizardDialog::construct(parent_window);
dialog->push_page(first_page);
dialog->exec();
}
Function<void()> on_cancel; Function<void()> on_cancel;
@ -36,8 +31,9 @@ public:
inline bool has_pages() const { return !m_page_stack.is_empty(); } inline bool has_pages() const { return !m_page_stack.is_empty(); }
protected: protected:
WizardDialog(Window* parent_window); explicit WizardDialog(Window* parent_window);
virtual ErrorOr<void> build();
virtual void handle_cancel(); virtual void handle_cancel();
private: private:

View file

@ -14,41 +14,50 @@
namespace GUI { namespace GUI {
WizardPage::WizardPage(DeprecatedString const& title_text, DeprecatedString const& subtitle_text) ErrorOr<NonnullRefPtr<WizardPage>> WizardPage::create(StringView title, StringView subtitle)
: AbstractWizardPage()
{ {
set_layout<VerticalBoxLayout>(GUI::Margins {}, 0); auto page = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) WizardPage()));
TRY(page->build(TRY(String::from_utf8(title)), TRY(String::from_utf8(subtitle))));
return page;
}
auto& header_widget = add<Widget>(); ErrorOr<void> WizardPage::build(String title, String subtitle)
header_widget.set_fill_with_background_color(true); {
header_widget.set_background_role(Gfx::ColorRole::Base); TRY(try_set_layout<VerticalBoxLayout>(Margins {}, 0));
header_widget.set_fixed_height(58);
header_widget.set_layout<VerticalBoxLayout>(GUI::Margins { 15, 30, 0 }); auto header_widget = TRY(try_add<Widget>());
m_title_label = header_widget.add<Label>(String::from_deprecated_string(title_text).release_value_but_fixme_should_propagate_errors()); header_widget->set_fill_with_background_color(true);
header_widget->set_background_role(Gfx::ColorRole::Base);
header_widget->set_fixed_height(58);
TRY(header_widget->try_set_layout<VerticalBoxLayout>(Margins { 15, 30, 0 }));
m_title_label = TRY(header_widget->try_add<Label>(move(title)));
m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant()); m_title_label->set_font(Gfx::FontDatabase::default_font().bold_variant());
m_title_label->set_fixed_height(m_title_label->font().pixel_size_rounded_up() + 2); m_title_label->set_fixed_height(m_title_label->font().pixel_size_rounded_up() + 2);
m_title_label->set_text_alignment(Gfx::TextAlignment::TopLeft); m_title_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
m_subtitle_label = header_widget.add<Label>(String::from_deprecated_string(subtitle_text).release_value_but_fixme_should_propagate_errors());
m_subtitle_label = TRY(header_widget->try_add<Label>(move(subtitle)));
m_subtitle_label->set_text_alignment(Gfx::TextAlignment::TopLeft); m_subtitle_label->set_text_alignment(Gfx::TextAlignment::TopLeft);
m_subtitle_label->set_fixed_height(m_subtitle_label->font().pixel_size_rounded_up()); m_subtitle_label->set_fixed_height(m_subtitle_label->font().pixel_size_rounded_up());
header_widget.add_spacer().release_value_but_fixme_should_propagate_errors(); TRY(header_widget->add_spacer());
auto& separator = add<SeparatorWidget>(Gfx::Orientation::Horizontal); auto separator = TRY(try_add<SeparatorWidget>(Gfx::Orientation::Horizontal));
separator.set_fixed_height(2); separator->set_fixed_height(2);
m_body_widget = add<Widget>(); m_body_widget = TRY(try_add<Widget>());
m_body_widget->set_layout<VerticalBoxLayout>(20); TRY(m_body_widget->try_set_layout<VerticalBoxLayout>(20));
return {};
} }
void WizardPage::set_page_title(DeprecatedString const& text) void WizardPage::set_page_title(String text)
{ {
m_title_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors()); m_title_label->set_text(move(text));
} }
void WizardPage::set_page_subtitle(DeprecatedString const& text) void WizardPage::set_page_subtitle(String text)
{ {
m_subtitle_label->set_text(String::from_deprecated_string(text).release_value_but_fixme_should_propagate_errors()); m_subtitle_label->set_text(move(text));
} }
} }

View file

@ -14,15 +14,20 @@
namespace GUI { namespace GUI {
class WizardPage : public AbstractWizardPage { class WizardPage : public AbstractWizardPage {
C_OBJECT(WizardPage); C_OBJECT_ABSTRACT(WizardPage);
static ErrorOr<NonnullRefPtr<WizardPage>> create(StringView title, StringView subtitle);
Widget& body_widget() { return *m_body_widget; }; Widget& body_widget() { return *m_body_widget; };
void set_page_title(DeprecatedString const& text); void set_page_title(String);
void set_page_subtitle(DeprecatedString const& text); void set_page_subtitle(String);
protected:
virtual ErrorOr<void> build(String title, String subtitle);
private: private:
explicit WizardPage(DeprecatedString const& title_text, DeprecatedString const& subtitle_text); WizardPage() = default;
RefPtr<Widget> m_body_widget; RefPtr<Widget> m_body_widget;