diff --git a/Userland/Applications/Calculator/CMakeLists.txt b/Userland/Applications/Calculator/CMakeLists.txt index 2918d7fc18..2ffec7a22d 100644 --- a/Userland/Applications/Calculator/CMakeLists.txt +++ b/Userland/Applications/Calculator/CMakeLists.txt @@ -9,7 +9,6 @@ set(SOURCES main.cpp Calculator.cpp CalculatorWidget.cpp - RoundingDialog.cpp Keypad.cpp ) diff --git a/Userland/Applications/Calculator/RoundingDialog.cpp b/Userland/Applications/Calculator/RoundingDialog.cpp deleted file mode 100644 index 9f9e49e709..0000000000 --- a/Userland/Applications/Calculator/RoundingDialog.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2022, Lucas Chollet - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include "RoundingDialog.h" -#include -#include -#include -#include -#include - -RoundingDialog::ExecResult RoundingDialog::show(GUI::Window* parent_window, StringView title, unsigned& rounding_value) -{ - auto dialog = RoundingDialog::construct(parent_window, title); - - if (parent_window) { - dialog->set_icon(parent_window->icon()); - dialog->center_within(*parent_window); - } - - dialog->m_rounding_spinbox->set_value(rounding_value); - - auto const result = dialog->exec(); - - if (result != GUI::Dialog::ExecResult::OK) - return result; - - rounding_value = dialog->m_rounding_spinbox->value(); - - return GUI::Dialog::ExecResult::OK; -} - -RoundingDialog::RoundingDialog(GUI::Window* parent_window, StringView title) - : Dialog(parent_window) -{ - resize(m_dialog_length, m_dialog_height); - set_resizable(false); - set_title(title); - - auto main_widget = set_main_widget().release_value_but_fixme_should_propagate_errors(); - - main_widget->set_fill_with_background_color(true); - main_widget->set_layout(); - - m_rounding_spinbox = GUI::SpinBox::construct(); - m_buttons_container = GUI::Widget::construct(); - m_ok_button = GUI::DialogButton::construct("OK"_short_string); - m_cancel_button = GUI::DialogButton::construct("Cancel"_short_string); - - main_widget->add_child(*m_rounding_spinbox); - main_widget->add_child(*m_buttons_container); - - m_buttons_container->set_layout(); - m_buttons_container->add_spacer().release_value_but_fixme_should_propagate_errors(); - m_buttons_container->add_child(*m_ok_button); - m_buttons_container->add_child(*m_cancel_button); - - m_rounding_spinbox->on_return_pressed = [this] { - m_ok_button->click(); - }; - - m_ok_button->on_click = [this](auto) { - done(ExecResult::OK); - }; - - m_cancel_button->on_click = [this](auto) { - done(ExecResult::Cancel); - }; -} diff --git a/Userland/Applications/Calculator/RoundingDialog.h b/Userland/Applications/Calculator/RoundingDialog.h deleted file mode 100644 index 62828c5f03..0000000000 --- a/Userland/Applications/Calculator/RoundingDialog.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2022, Lucas Chollet - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -class RoundingDialog : public GUI::Dialog { - C_OBJECT(RoundingDialog); - -public: - static ExecResult show(GUI::Window* parent_window, StringView title, unsigned& rounding_value); - -private: - RoundingDialog(GUI::Window* parent_window, StringView title); - virtual ~RoundingDialog() override = default; - - RefPtr m_rounding_spinbox; - RefPtr m_buttons_container; - RefPtr m_ok_button; - RefPtr m_cancel_button; - - static constexpr unsigned m_dialog_length = 200; - static constexpr unsigned m_dialog_height = 54; -}; diff --git a/Userland/Applications/Calculator/main.cpp b/Userland/Applications/Calculator/main.cpp index 88dcd2b22b..f299edb7ce 100644 --- a/Userland/Applications/Calculator/main.cpp +++ b/Userland/Applications/Calculator/main.cpp @@ -5,7 +5,6 @@ */ #include "CalculatorWidget.h" -#include "RoundingDialog.h" #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -90,22 +90,23 @@ ErrorOr serenity_main(Main::Arguments arguments) constexpr auto format { "&Custom - {} ..."sv }; auto round_custom = GUI::Action::create_checkable(DeprecatedString::formatted(format, 0), [&](auto& action) { - unsigned custom_rounding_length = widget->rounding_length(); - - if (RoundingDialog::show(window, "Choose custom rounding"sv, custom_rounding_length) == GUI::Dialog::ExecResult::OK) { + int custom_rounding_length = widget->rounding_length(); + auto result = GUI::InputBox::show_numeric(window, custom_rounding_length, 0, 100, "Round to"sv); + if (!result.is_error() && result.value() == GUI::Dialog::ExecResult::OK) { action.set_text(DeprecatedString::formatted(format, custom_rounding_length)); widget->set_rounding_length(custom_rounding_length); last_rounding_mode.clear(); } else if (last_rounding_mode.has_value()) - round_menu.action_at(last_rounding_mode.value())->activate(); + round_menu.action_at(last_rounding_mode.value()) + ->activate(); }); widget->set_rounding_custom(round_custom, format); auto shrink_action = GUI::Action::create("&Shrink...", TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-cut.png"sv)), [&](auto&) { - unsigned shrink_length = widget->rounding_length(); - - if (RoundingDialog::show(window, "Choose shrinking length"sv, shrink_length) == GUI::Dialog::ExecResult::OK) { + int shrink_length = widget->rounding_length(); + auto result = GUI::InputBox::show_numeric(window, shrink_length, 0, 100, "Shrink to"sv); + if (!result.is_error() && result.value() == GUI::Dialog::ExecResult::OK) { round_custom->set_checked(true); round_custom->set_text(DeprecatedString::formatted(format, shrink_length)); widget->set_rounding_length(shrink_length);