2020-10-18 14:17:49 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020, Ben Jilks <benjyjilks@gmail.com>
|
|
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-10-18 14:17:49 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "CreateNewImageDialog.h"
|
2022-05-15 09:19:11 -03:00
|
|
|
#include <LibConfig/Client.h>
|
2020-10-18 14:17:49 -03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2022-08-11 03:04:51 -03:00
|
|
|
#include <LibGUI/CheckBox.h>
|
2020-10-18 14:17:49 -03:00
|
|
|
#include <LibGUI/Label.h>
|
|
|
|
|
#include <LibGUI/SpinBox.h>
|
|
|
|
|
#include <LibGUI/TextBox.h>
|
|
|
|
|
|
|
|
|
|
namespace PixelPaint {
|
|
|
|
|
|
|
|
|
|
CreateNewImageDialog::CreateNewImageDialog(GUI::Window* parent_window)
|
|
|
|
|
: Dialog(parent_window)
|
|
|
|
|
{
|
|
|
|
|
set_title("Create new image");
|
2021-09-18 08:11:32 -03:00
|
|
|
set_icon(parent_window->icon());
|
2022-08-11 03:04:51 -03:00
|
|
|
resize(200, 220);
|
2020-10-18 14:17:49 -03:00
|
|
|
|
|
|
|
|
auto& main_widget = set_main_widget<GUI::Widget>();
|
|
|
|
|
main_widget.set_fill_with_background_color(true);
|
|
|
|
|
|
|
|
|
|
auto& layout = main_widget.set_layout<GUI::VerticalBoxLayout>();
|
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
2021-08-16 21:11:38 -03:00
|
|
|
layout.set_margins(4);
|
2020-10-18 14:17:49 -03:00
|
|
|
|
|
|
|
|
auto& name_label = main_widget.add<GUI::Label>("Name:");
|
|
|
|
|
name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
|
|
|
|
|
m_name_textbox = main_widget.add<GUI::TextBox>();
|
|
|
|
|
m_name_textbox->on_change = [this] {
|
|
|
|
|
m_image_name = m_name_textbox->text();
|
|
|
|
|
};
|
2022-07-11 14:32:29 -03:00
|
|
|
auto default_name = Config::read_string("PixelPaint"sv, "NewImage"sv, "Name"sv);
|
2022-05-15 09:19:11 -03:00
|
|
|
m_name_textbox->set_text(default_name);
|
2020-10-18 14:17:49 -03:00
|
|
|
|
|
|
|
|
auto& width_label = main_widget.add<GUI::Label>("Width:");
|
|
|
|
|
width_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
|
|
|
|
|
auto& width_spinbox = main_widget.add<GUI::SpinBox>();
|
|
|
|
|
|
|
|
|
|
auto& height_label = main_widget.add<GUI::Label>("Height:");
|
|
|
|
|
height_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
|
|
|
|
|
auto& height_spinbox = main_widget.add<GUI::SpinBox>();
|
|
|
|
|
|
2022-08-11 03:04:51 -03:00
|
|
|
auto& set_defaults_checkbox = main_widget.add<GUI::CheckBox>();
|
|
|
|
|
set_defaults_checkbox.set_text("Use these settings as default");
|
|
|
|
|
|
2020-10-18 14:17:49 -03:00
|
|
|
auto& button_container = main_widget.add<GUI::Widget>();
|
|
|
|
|
button_container.set_layout<GUI::HorizontalBoxLayout>();
|
|
|
|
|
|
|
|
|
|
auto& ok_button = button_container.add<GUI::Button>("OK");
|
2022-08-11 03:04:51 -03:00
|
|
|
ok_button.on_click = [&](auto) {
|
|
|
|
|
if (set_defaults_checkbox.is_checked()) {
|
|
|
|
|
Config::write_string("PixelPaint"sv, "NewImage"sv, "Name"sv, m_image_name);
|
|
|
|
|
Config::write_i32("PixelPaint"sv, "NewImage"sv, "Width"sv, m_image_size.width());
|
|
|
|
|
Config::write_i32("PixelPaint"sv, "NewImage"sv, "Height"sv, m_image_size.height());
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-13 09:10:27 -03:00
|
|
|
done(ExecResult::OK);
|
2020-10-18 14:17:49 -03:00
|
|
|
};
|
2022-05-27 14:36:06 -03:00
|
|
|
ok_button.set_default(true);
|
2020-10-18 14:17:49 -03:00
|
|
|
|
|
|
|
|
auto& cancel_button = button_container.add<GUI::Button>("Cancel");
|
|
|
|
|
cancel_button.on_click = [this](auto) {
|
2022-05-13 09:10:27 -03:00
|
|
|
done(ExecResult::Cancel);
|
2020-10-18 14:17:49 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
width_spinbox.on_change = [this](int value) {
|
|
|
|
|
m_image_size.set_width(value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
height_spinbox.on_change = [this](int value) {
|
|
|
|
|
m_image_size.set_height(value);
|
|
|
|
|
};
|
|
|
|
|
|
2021-06-14 20:23:50 -03:00
|
|
|
width_spinbox.set_range(1, 16384);
|
|
|
|
|
height_spinbox.set_range(1, 16384);
|
2021-06-14 20:24:30 -03:00
|
|
|
|
2022-07-11 14:32:29 -03:00
|
|
|
auto default_width = Config::read_i32("PixelPaint"sv, "NewImage"sv, "Width"sv, 510);
|
|
|
|
|
auto default_height = Config::read_i32("PixelPaint"sv, "NewImage"sv, "Height"sv, 356);
|
2022-05-15 09:19:11 -03:00
|
|
|
width_spinbox.set_value(default_width);
|
|
|
|
|
height_spinbox.set_value(default_height);
|
2020-10-18 14:17:49 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|