summaryrefslogtreecommitdiff
path: root/Applications
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-03-04 09:46:23 +0100
committerAndreas Kling <kling@serenityos.org>2020-03-04 14:26:16 +0100
commit0f3e57a6fb037f6a8133e8ec2be8f0889ff9bc19 (patch)
tree3fc1f6f91d7e00783792e98bd23f226e591d99a3 /Applications
parent4697195645a4c66930761c85685f5752dc777bba (diff)
downloadserenity-0f3e57a6fb037f6a8133e8ec2be8f0889ff9bc19.zip
LibGUI: Use GUI::Window::set_main_widget<WidgetType>() in clients
Diffstat (limited to 'Applications')
-rw-r--r--Applications/FontEditor/main.cpp3
-rw-r--r--Applications/HexEditor/main.cpp7
-rw-r--r--Applications/IRCClient/IRCAppWindow.cpp13
-rw-r--r--Applications/PaintBrush/main.cpp11
-rw-r--r--Applications/Piano/main.cpp5
-rw-r--r--Applications/QuickShow/main.cpp11
-rw-r--r--Applications/SoundPlayer/main.cpp12
-rw-r--r--Applications/SystemMenu/PowerDialog.cpp19
-rw-r--r--Applications/SystemMonitor/main.cpp11
-rw-r--r--Applications/Taskbar/TaskbarWindow.cpp17
-rw-r--r--Applications/Terminal/main.cpp42
-rw-r--r--Applications/TextEditor/main.cpp9
-rw-r--r--Applications/Welcome/main.cpp17
13 files changed, 81 insertions, 96 deletions
diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp
index ff19eb45b7..92db3e2fc0 100644
--- a/Applications/FontEditor/main.cpp
+++ b/Applications/FontEditor/main.cpp
@@ -70,8 +70,7 @@ int main(int argc, char** argv)
window->set_title("Font Editor");
window->set_rect({ 50, 50, 390, 342 });
- auto font_editor = FontEditorWidget::construct(path, move(edited_font));
- window->set_main_widget(font_editor);
+ window->set_main_widget<FontEditorWidget>(path, move(edited_font));
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"));
diff --git a/Applications/HexEditor/main.cpp b/Applications/HexEditor/main.cpp
index ad5d44cef6..f20ade72e5 100644
--- a/Applications/HexEditor/main.cpp
+++ b/Applications/HexEditor/main.cpp
@@ -46,11 +46,10 @@ int main(int argc, char** argv)
window->set_title("Hex Editor");
window->set_rect(20, 200, 640, 400);
- auto hex_editor_widget = HexEditorWidget::construct();
- window->set_main_widget(hex_editor_widget);
+ auto& hex_editor_widget = window->set_main_widget<HexEditorWidget>();
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
- if (hex_editor_widget->request_close())
+ if (hex_editor_widget.request_close())
return GUI::Window::CloseRequestDecision::Close;
return GUI::Window::CloseRequestDecision::StayOpen;
};
@@ -59,7 +58,7 @@ int main(int argc, char** argv)
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-hexeditor.png"));
if (argc >= 2)
- hex_editor_widget->open_file(argv[1]);
+ hex_editor_widget.open_file(argv[1]);
return app.exec();
}
diff --git a/Applications/IRCClient/IRCAppWindow.cpp b/Applications/IRCClient/IRCAppWindow.cpp
index e1ebe4d0b7..b3b22c6d16 100644
--- a/Applications/IRCClient/IRCAppWindow.cpp
+++ b/Applications/IRCClient/IRCAppWindow.cpp
@@ -179,13 +179,12 @@ void IRCAppWindow::setup_menus()
void IRCAppWindow::setup_widgets()
{
- auto widget = GUI::Widget::construct();
- set_main_widget(widget);
- widget->set_fill_with_background_color(true);
- widget->set_layout<GUI::VerticalBoxLayout>();
- widget->layout()->set_spacing(0);
+ auto& widget = set_main_widget<GUI::Widget>();
+ widget.set_fill_with_background_color(true);
+ widget.set_layout<GUI::VerticalBoxLayout>();
+ widget.layout()->set_spacing(0);
- auto toolbar = widget->add<GUI::ToolBar>();
+ auto toolbar = widget.add<GUI::ToolBar>();
toolbar->set_has_frame(false);
toolbar->add_action(*m_change_nick_action);
toolbar->add_separator();
@@ -196,7 +195,7 @@ void IRCAppWindow::setup_widgets()
toolbar->add_action(*m_open_query_action);
toolbar->add_action(*m_close_query_action);
- auto outer_container = widget->add<GUI::Widget>();
+ auto outer_container = widget.add<GUI::Widget>();
outer_container->set_layout<GUI::VerticalBoxLayout>();
outer_container->layout()->set_margins({ 2, 0, 2, 2 });
diff --git a/Applications/PaintBrush/main.cpp b/Applications/PaintBrush/main.cpp
index 6e9b241db0..d79f2b83c6 100644
--- a/Applications/PaintBrush/main.cpp
+++ b/Applications/PaintBrush/main.cpp
@@ -58,14 +58,13 @@ int main(int argc, char** argv)
window->set_rect(100, 100, 640, 480);
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-paintbrush.png"));
- auto horizontal_container = GUI::Widget::construct();
- window->set_main_widget(horizontal_container);
- horizontal_container->set_layout<GUI::HorizontalBoxLayout>();
- horizontal_container->layout()->set_spacing(0);
+ auto& horizontal_container = window->set_main_widget<GUI::Widget>();
+ horizontal_container.set_layout<GUI::HorizontalBoxLayout>();
+ horizontal_container.layout()->set_spacing(0);
- horizontal_container->add<ToolboxWidget>();
+ horizontal_container.add<ToolboxWidget>();
- auto vertical_container = horizontal_container->add<GUI::Widget>();
+ auto vertical_container = horizontal_container.add<GUI::Widget>();
vertical_container->set_layout<GUI::VerticalBoxLayout>();
vertical_container->layout()->set_spacing(0);
diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp
index 13d1573422..9c396909a6 100644
--- a/Applications/Piano/main.cpp
+++ b/Applications/Piano/main.cpp
@@ -52,8 +52,7 @@ int main(int argc, char** argv)
AudioEngine audio_engine;
auto window = GUI::Window::construct();
- auto main_widget = MainWidget::construct(audio_engine);
- window->set_main_widget(main_widget);
+ auto& main_widget = window->set_main_widget<MainWidget>(audio_engine);
window->set_title("Piano");
window->set_rect(90, 90, 840, 600);
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-piano.png"));
@@ -74,7 +73,7 @@ int main(int argc, char** argv)
for (;;) {
audio_engine.fill_buffer(buffer);
audio->write(reinterpret_cast<u8*>(buffer.data()), buffer_size);
- Core::EventLoop::current().post_event(*main_widget, make<Core::CustomEvent>(0));
+ Core::EventLoop::current().post_event(main_widget, make<Core::CustomEvent>(0));
Core::EventLoop::wake();
if (need_to_write_wav) {
diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp
index df90187b08..1233fe8209 100644
--- a/Applications/QuickShow/main.cpp
+++ b/Applications/QuickShow/main.cpp
@@ -87,22 +87,21 @@ int main(int argc, char** argv)
}
auto window = GUI::Window::construct();
- auto widget = QSWidget::construct();
- widget->set_path(path);
- widget->set_bitmap(*bitmap);
+ auto& widget = window->set_main_widget<QSWidget>();
+ widget.set_path(path);
+ widget.set_bitmap(*bitmap);
auto update_window_title = [&](int scale) {
- window->set_title(String::format("QuickShow: %s %s %d%%", widget->path().characters(), widget->bitmap()->size().to_string().characters(), scale));
+ window->set_title(String::format("QuickShow: %s %s %d%%", widget.path().characters(), widget.bitmap()->size().to_string().characters(), scale));
};
window->set_double_buffering_enabled(true);
update_window_title(100);
window->set_rect(200, 200, bitmap->width(), bitmap->height());
- widget->on_scale_change = [&](int scale) {
+ widget.on_scale_change = [&](int scale) {
update_window_title(scale);
};
- window->set_main_widget(widget);
window->show();
diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp
index a6433e7395..5a4fe56edf 100644
--- a/Applications/SoundPlayer/main.cpp
+++ b/Applications/SoundPlayer/main.cpp
@@ -66,24 +66,24 @@ int main(int argc, char** argv)
auto menubar = make<GUI::MenuBar>();
auto app_menu = GUI::Menu::construct("SoundPlayer");
- auto player = SoundPlayerWidget::construct(window, audio_client);
+ auto& player = window->set_main_widget<SoundPlayerWidget>(window, audio_client);
if (argc > 1) {
String path = argv[1];
- player->open_file(path);
- player->manager().play();
+ player.open_file(path);
+ player.manager().play();
}
auto hide_scope = GUI::Action::create("Hide scope", { Mod_Ctrl, Key_H }, [&](GUI::Action& action) {
action.set_checked(!action.is_checked());
- player->hide_scope(action.is_checked());
+ player.hide_scope(action.is_checked());
});
hide_scope->set_checkable(true);
app_menu->add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<String> path = GUI::FilePicker::get_open_filepath("Open wav file...");
if (path.has_value()) {
- player->open_file(path.value());
+ player.open_file(path.value());
}
}));
app_menu->add_action(move(hide_scope));
@@ -101,8 +101,6 @@ int main(int argc, char** argv)
menubar->add_menu(move(help_menu));
app.set_menubar(move(menubar));
- window->set_main_widget(player);
window->show();
-
return app.exec();
}
diff --git a/Applications/SystemMenu/PowerDialog.cpp b/Applications/SystemMenu/PowerDialog.cpp
index c65f1495a2..1fe8fde82d 100644
--- a/Applications/SystemMenu/PowerDialog.cpp
+++ b/Applications/SystemMenu/PowerDialog.cpp
@@ -69,14 +69,13 @@ PowerDialog::PowerDialog()
set_title("SerenityOS");
set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/power.png"));
- auto main = GUI::Widget::construct();
- set_main_widget(main);
- main->set_layout<GUI::VerticalBoxLayout>();
- main->layout()->set_margins({ 8, 8, 8, 8 });
- main->layout()->set_spacing(8);
- main->set_fill_with_background_color(true);
-
- auto header = main->add<GUI::Label>();
+ auto& main = set_main_widget<GUI::Widget>();
+ main.set_layout<GUI::VerticalBoxLayout>();
+ main.layout()->set_margins({ 8, 8, 8, 8 });
+ main.layout()->set_spacing(8);
+ main.set_fill_with_background_color(true);
+
+ auto header = main.add<GUI::Label>();
header->set_text("What would you like to do?");
header->set_preferred_size(0, 16);
header->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
@@ -84,7 +83,7 @@ PowerDialog::PowerDialog()
for (size_t i = 0; i < options.size(); i++) {
auto action = options[i];
- auto radio = main->add<GUI::RadioButton>();
+ auto radio = main.add<GUI::RadioButton>();
radio->set_enabled(action.enabled);
radio->set_text(action.title);
@@ -98,7 +97,7 @@ PowerDialog::PowerDialog()
}
}
- auto button_box = main->add<GUI::Widget>();
+ auto button_box = main.add<GUI::Widget>();
button_box->set_layout<GUI::HorizontalBoxLayout>();
button_box->layout()->set_spacing(8);
diff --git a/Applications/SystemMonitor/main.cpp b/Applications/SystemMonitor/main.cpp
index 736ffe8120..6965f5c49e 100644
--- a/Applications/SystemMonitor/main.cpp
+++ b/Applications/SystemMonitor/main.cpp
@@ -115,13 +115,12 @@ int main(int argc, char** argv)
window->set_title("System Monitor");
window->set_rect(20, 200, 680, 400);
- auto keeper = GUI::Widget::construct();
- window->set_main_widget(keeper);
- keeper->set_layout<GUI::VerticalBoxLayout>();
- keeper->set_fill_with_background_color(true);
- keeper->layout()->set_margins({ 4, 4, 4, 4 });
+ auto& keeper = window->set_main_widget<GUI::Widget>();
+ keeper.set_layout<GUI::VerticalBoxLayout>();
+ keeper.set_fill_with_background_color(true);
+ keeper.layout()->set_margins({ 4, 4, 4, 4 });
- auto tabwidget = keeper->add<GUI::TabWidget>();
+ auto tabwidget = keeper.add<GUI::TabWidget>();
auto process_container_splitter = tabwidget->add_tab<GUI::VerticalSplitter>("Processes");
diff --git a/Applications/Taskbar/TaskbarWindow.cpp b/Applications/Taskbar/TaskbarWindow.cpp
index f5ec210829..c4655a6b48 100644
--- a/Applications/Taskbar/TaskbarWindow.cpp
+++ b/Applications/Taskbar/TaskbarWindow.cpp
@@ -46,15 +46,14 @@ TaskbarWindow::TaskbarWindow()
GUI::Desktop::the().on_rect_change = [this](const Gfx::Rect& rect) { on_screen_rect_change(rect); };
- auto widget = GUI::Frame::construct();
- widget->set_fill_with_background_color(true);
- widget->set_layout<GUI::HorizontalBoxLayout>();
- widget->layout()->set_margins({ 3, 2, 3, 2 });
- widget->layout()->set_spacing(3);
- widget->set_frame_thickness(1);
- widget->set_frame_shape(Gfx::FrameShape::Panel);
- widget->set_frame_shadow(Gfx::FrameShadow::Raised);
- set_main_widget(widget);
+ auto& widget = set_main_widget<GUI::Frame>();
+ widget.set_fill_with_background_color(true);
+ widget.set_layout<GUI::HorizontalBoxLayout>();
+ widget.layout()->set_margins({ 3, 2, 3, 2 });
+ widget.layout()->set_spacing(3);
+ widget.set_frame_thickness(1);
+ widget.set_frame_shape(Gfx::FrameShape::Panel);
+ widget.set_frame_shadow(Gfx::FrameShadow::Raised);
WindowList::the().aid_create_button = [this](auto& identifier) {
return create_button(identifier);
diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp
index 9f36dd439e..8f62196bb9 100644
--- a/Applications/Terminal/main.cpp
+++ b/Applications/Terminal/main.cpp
@@ -134,14 +134,13 @@ RefPtr<GUI::Window> create_settings_window(TerminalWidget& terminal)
window->set_rect(50, 50, 200, 140);
window->set_modal(true);
- auto settings = GUI::Widget::construct();
- window->set_main_widget(settings);
- settings->set_fill_with_background_color(true);
- settings->set_background_role(ColorRole::Button);
- settings->set_layout<GUI::VerticalBoxLayout>();
- settings->layout()->set_margins({ 4, 4, 4, 4 });
-
- auto radio_container = settings->add<GUI::GroupBox>("Bell Mode");
+ auto& settings = window->set_main_widget<GUI::Widget>();
+ settings.set_fill_with_background_color(true);
+ settings.set_background_role(ColorRole::Button);
+ settings.set_layout<GUI::VerticalBoxLayout>();
+ settings.layout()->set_margins({ 4, 4, 4, 4 });
+
+ auto radio_container = settings.add<GUI::GroupBox>("Bell Mode");
radio_container->set_layout<GUI::VerticalBoxLayout>();
radio_container->layout()->set_margins({ 6, 16, 6, 6 });
radio_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
@@ -155,7 +154,7 @@ RefPtr<GUI::Window> create_settings_window(TerminalWidget& terminal)
terminal.set_should_beep(checked);
};
- auto slider_container = settings->add<GUI::GroupBox>("Background Opacity");
+ auto slider_container = settings.add<GUI::GroupBox>("Background Opacity");
slider_container->set_layout<GUI::VerticalBoxLayout>();
slider_container->layout()->set_margins({ 6, 16, 6, 6 });
slider_container->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
@@ -227,24 +226,23 @@ int main(int argc, char** argv)
window->set_double_buffering_enabled(false);
RefPtr<Core::ConfigFile> config = Core::ConfigFile::get_for_app("Terminal");
- auto terminal = TerminalWidget::construct(ptm_fd, true, config);
- terminal->on_command_exit = [&] {
+ auto& terminal = window->set_main_widget<TerminalWidget>(ptm_fd, true, config);
+ terminal.on_command_exit = [&] {
app.quit(0);
};
- terminal->on_title_change = [&](auto& title) {
+ terminal.on_title_change = [&](auto& title) {
window->set_title(title);
};
- window->set_main_widget(terminal);
window->move_to(300, 300);
- terminal->apply_size_increments_to_window(*window);
+ terminal.apply_size_increments_to_window(*window);
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"));
- terminal->set_should_beep(config->read_bool_entry("Window", "AudibleBeep", false));
+ terminal.set_should_beep(config->read_bool_entry("Window", "AudibleBeep", false));
RefPtr<GUI::Window> settings_window;
auto new_opacity = config->read_num_entry("Window", "Opacity", 255);
- terminal->set_opacity(new_opacity);
+ terminal.set_opacity(new_opacity);
window->set_has_alpha_channel(new_opacity < 255);
auto menubar = make<GUI::MenuBar>();
@@ -259,7 +257,7 @@ int main(int argc, char** argv)
app_menu->add_action(GUI::Action::create("Settings...", Gfx::Bitmap::load_from_file("/res/icons/gear16.png"),
[&](const GUI::Action&) {
if (!settings_window) {
- settings_window = create_settings_window(*terminal);
+ settings_window = create_settings_window(terminal);
settings_window->on_close_request = [&] {
settings_window = nullptr;
return GUI::Window::CloseRequestDecision::Close;
@@ -276,8 +274,8 @@ int main(int argc, char** argv)
menubar->add_menu(move(app_menu));
auto edit_menu = GUI::Menu::construct("Edit");
- edit_menu->add_action(terminal->copy_action());
- edit_menu->add_action(terminal->paste_action());
+ edit_menu->add_action(terminal.copy_action());
+ edit_menu->add_action(terminal.paste_action());
menubar->add_menu(move(edit_menu));
GUI::ActionGroup font_action_group;
@@ -286,16 +284,16 @@ int main(int argc, char** argv)
GFontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) {
auto action = GUI::Action::create(font_name, [&](GUI::Action& action) {
action.set_checked(true);
- terminal->set_font(GFontDatabase::the().get_by_name(action.text()));
+ terminal.set_font(GFontDatabase::the().get_by_name(action.text()));
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
ASSERT(metadata.has_value());
config->write_entry("Text", "Font", metadata.value().path);
config->sync();
- terminal->force_repaint();
+ terminal.force_repaint();
});
font_action_group.add_action(*action);
action->set_checkable(true);
- if (terminal->font().name() == font_name)
+ if (terminal.font().name() == font_name)
action->set_checked(true);
font_menu->add_action(*action);
});
diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp
index 73e9ebb9fd..23d67ae586 100644
--- a/Applications/TextEditor/main.cpp
+++ b/Applications/TextEditor/main.cpp
@@ -46,19 +46,18 @@ int main(int argc, char** argv)
window->set_title("Text Editor");
window->set_rect(20, 200, 640, 400);
- auto text_widget = TextEditorWidget::construct();
- window->set_main_widget(text_widget);
+ auto& text_widget = window->set_main_widget<TextEditorWidget>();
- text_widget->editor().set_focus(true);
+ text_widget.editor().set_focus(true);
window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
- if (text_widget->request_close())
+ if (text_widget.request_close())
return GUI::Window::CloseRequestDecision::Close;
return GUI::Window::CloseRequestDecision::StayOpen;
};
if (argc >= 2)
- text_widget->open_sesame(argv[1]);
+ text_widget.open_sesame(argv[1]);
window->show();
window->set_icon(Gfx::Bitmap::load_from_file("/res/icons/TextEditor16.png"));
diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp
index d2544fb1a4..bf46960de1 100644
--- a/Applications/Welcome/main.cpp
+++ b/Applications/Welcome/main.cpp
@@ -161,19 +161,18 @@ int main(int argc, char** argv)
window->set_resizable(true);
window->set_rect(window_rect);
- auto background = BackgroundWidget::construct();
- window->set_main_widget(background);
- background->set_fill_with_background_color(false);
- background->set_layout<GUI::VerticalBoxLayout>();
- background->layout()->set_margins({ 16, 8, 16, 8 });
- background->layout()->set_spacing(8);
- background->set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
+ auto& background = window->set_main_widget<BackgroundWidget>();
+ background.set_fill_with_background_color(false);
+ background.set_layout<GUI::VerticalBoxLayout>();
+ background.layout()->set_margins({ 16, 8, 16, 8 });
+ background.layout()->set_spacing(8);
+ background.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fill);
//
// header
//
- auto header = background->add<GUI::Label>();
+ auto header = background.add<GUI::Label>();
header->set_font(Gfx::Font::load_from_file("/res/fonts/PebbletonBold11.font"));
header->set_text("Welcome to SerenityOS!");
header->set_text_alignment(Gfx::TextAlignment::CenterLeft);
@@ -184,7 +183,7 @@ int main(int argc, char** argv)
// main section
//
- auto main_section = background->add<GUI::Widget>();
+ auto main_section = background.add<GUI::Widget>();
main_section->set_layout<GUI::HorizontalBoxLayout>();
main_section->layout()->set_margins({ 0, 0, 0, 0 });
main_section->layout()->set_spacing(8);