CreateNewImageDialog.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright (c) 2020, Ben Jilks <benjyjilks@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "CreateNewImageDialog.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. CreateNewImageDialog::CreateNewImageDialog(GUI::Window* parent_window)
  14. : Dialog(parent_window)
  15. {
  16. set_title("Create new image");
  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->on_change = [this] {
  27. m_image_name = m_name_textbox->text();
  28. };
  29. auto& width_label = main_widget.add<GUI::Label>("Width:");
  30. width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  31. auto& width_spinbox = main_widget.add<GUI::SpinBox>();
  32. auto& height_label = main_widget.add<GUI::Label>("Height:");
  33. height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  34. auto& height_spinbox = main_widget.add<GUI::SpinBox>();
  35. auto& button_container = main_widget.add<GUI::Widget>();
  36. button_container.set_layout<GUI::HorizontalBoxLayout>();
  37. auto& ok_button = button_container.add<GUI::Button>("OK");
  38. ok_button.on_click = [this](auto) {
  39. done(ExecResult::OK);
  40. };
  41. auto& cancel_button = button_container.add<GUI::Button>("Cancel");
  42. cancel_button.on_click = [this](auto) {
  43. done(ExecResult::Cancel);
  44. };
  45. width_spinbox.on_change = [this](int value) {
  46. m_image_size.set_width(value);
  47. };
  48. height_spinbox.on_change = [this](int value) {
  49. m_image_size.set_height(value);
  50. };
  51. m_name_textbox->on_return_pressed = [this] {
  52. done(ExecResult::OK);
  53. };
  54. width_spinbox.set_range(1, 16384);
  55. height_spinbox.set_range(1, 16384);
  56. width_spinbox.set_value(510);
  57. height_spinbox.set_value(356);
  58. }
  59. }