CreateNewImageDialog.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. resize(200, 200);
  18. auto& main_widget = set_main_widget<GUI::Widget>();
  19. main_widget.set_fill_with_background_color(true);
  20. auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
  21. layout.set_margins({ 4, 4, 4, 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->on_change = [this] {
  26. m_image_name = m_name_textbox->text();
  27. };
  28. auto& width_label = main_widget.add<GUI::Label>("Width:");
  29. width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  30. auto& width_spinbox = main_widget.add<GUI::SpinBox>();
  31. auto& height_label = main_widget.add<GUI::Label>("Height:");
  32. height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
  33. auto& height_spinbox = main_widget.add<GUI::SpinBox>();
  34. auto& button_container = main_widget.add<GUI::Widget>();
  35. button_container.set_layout<GUI::HorizontalBoxLayout>();
  36. auto& ok_button = button_container.add<GUI::Button>("OK");
  37. ok_button.on_click = [this](auto) {
  38. done(ExecOK);
  39. };
  40. auto& cancel_button = button_container.add<GUI::Button>("Cancel");
  41. cancel_button.on_click = [this](auto) {
  42. done(ExecCancel);
  43. };
  44. width_spinbox.on_change = [this](int value) {
  45. m_image_size.set_width(value);
  46. };
  47. height_spinbox.on_change = [this](int value) {
  48. m_image_size.set_height(value);
  49. };
  50. width_spinbox.set_range(1, 16384);
  51. height_spinbox.set_range(1, 16384);
  52. width_spinbox.set_value(480);
  53. height_spinbox.set_value(360);
  54. }
  55. }