CreateNewLayerDialog.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "CreateNewLayerDialog.h"
  7. #include <LibGUI/BoxLayout.h>
  8. #include <LibGUI/Button.h>
  9. #include <LibGUI/Label.h>
  10. #include <LibGUI/SpinBox.h>
  11. #include <LibGUI/TextBox.h>
  12. namespace PixelPaint {
  13. CreateNewLayerDialog::CreateNewLayerDialog(Gfx::IntSize suggested_size, GUI::Window* parent_window)
  14. : Dialog(parent_window)
  15. {
  16. set_title("Create new layer");
  17. set_icon(parent_window->icon());
  18. resize(200, 200);
  19. auto main_widget = set_main_widget<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
  20. main_widget->set_fill_with_background_color(true);
  21. main_widget->set_layout<GUI::VerticalBoxLayout>(4);
  22. auto& name_label = main_widget->add<GUI::Label>("Name:");
  23. name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  24. m_name_textbox = main_widget->add<GUI::TextBox>();
  25. m_name_textbox->set_text("Layer"sv);
  26. m_name_textbox->select_all();
  27. m_name_textbox->on_change = [this] {
  28. m_layer_name = m_name_textbox->text();
  29. };
  30. auto& width_label = main_widget->add<GUI::Label>("Width:");
  31. width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  32. auto& width_spinbox = main_widget->add<GUI::SpinBox>();
  33. auto& height_label = main_widget->add<GUI::Label>("Height:");
  34. height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  35. auto& height_spinbox = main_widget->add<GUI::SpinBox>();
  36. auto& button_container = main_widget->add<GUI::Widget>();
  37. button_container.set_layout<GUI::HorizontalBoxLayout>();
  38. auto& ok_button = button_container.add<GUI::Button>(String::from_utf8_short_string("OK"sv));
  39. ok_button.on_click = [this](auto) {
  40. done(ExecResult::OK);
  41. };
  42. ok_button.set_default(true);
  43. auto& cancel_button = button_container.add<GUI::Button>(String::from_utf8_short_string("Cancel"sv));
  44. cancel_button.on_click = [this](auto) {
  45. done(ExecResult::Cancel);
  46. };
  47. width_spinbox.on_change = [this](int value) {
  48. m_layer_size.set_width(value);
  49. };
  50. height_spinbox.on_change = [this](int value) {
  51. m_layer_size.set_height(value);
  52. };
  53. width_spinbox.set_range(1, 16384);
  54. height_spinbox.set_range(1, 16384);
  55. width_spinbox.set_value(suggested_size.width());
  56. height_spinbox.set_value(suggested_size.height());
  57. }
  58. }