CreateNewLayerDialog.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 const& 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>();
  20. main_widget.set_fill_with_background_color(true);
  21. auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
  22. layout.set_margins(4);
  23. auto& name_label = main_widget.add<GUI::Label>("Name:");
  24. name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  25. m_name_textbox = main_widget.add<GUI::TextBox>();
  26. m_name_textbox->set_text("Layer");
  27. m_name_textbox->select_all();
  28. m_name_textbox->on_change = [this] {
  29. m_layer_name = m_name_textbox->text();
  30. };
  31. auto& width_label = main_widget.add<GUI::Label>("Width:");
  32. width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  33. auto& width_spinbox = main_widget.add<GUI::SpinBox>();
  34. auto& height_label = main_widget.add<GUI::Label>("Height:");
  35. height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  36. auto& height_spinbox = main_widget.add<GUI::SpinBox>();
  37. auto& button_container = main_widget.add<GUI::Widget>();
  38. button_container.set_layout<GUI::HorizontalBoxLayout>();
  39. auto& ok_button = button_container.add<GUI::Button>("OK");
  40. ok_button.on_click = [this](auto) {
  41. done(ExecResult::OK);
  42. };
  43. auto& cancel_button = button_container.add<GUI::Button>("Cancel");
  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. m_name_textbox->on_return_pressed = [this] {
  54. done(ExecResult::OK);
  55. };
  56. width_spinbox.set_range(1, 16384);
  57. height_spinbox.set_range(1, 16384);
  58. width_spinbox.set_value(suggested_size.width());
  59. height_spinbox.set_value(suggested_size.height());
  60. }
  61. }