summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorthankyouverycool <66646555+thankyouverycool@users.noreply.github.com>2023-04-16 16:07:11 -0400
committerAndreas Kling <kling@serenityos.org>2023-04-18 10:05:21 +0200
commit8d86f2e69f9f06ed3cc80aee879b66d898bd5af5 (patch)
treea493097439cf2a857f921e6a839c3e18b5a5960e /Userland/Applications
parenta55d2be14788fd83942ee14fe9d35a60a18d365e (diff)
downloadserenity-8d86f2e69f9f06ed3cc80aee879b66d898bd5af5.zip
Calculator: Use numeric InputBox for digit rounding and shrinking
Calc was using a bespoke SpinBox dialog which is no longer necessary.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Calculator/CMakeLists.txt1
-rw-r--r--Userland/Applications/Calculator/RoundingDialog.cpp71
-rw-r--r--Userland/Applications/Calculator/RoundingDialog.h29
-rw-r--r--Userland/Applications/Calculator/main.cpp17
4 files changed, 9 insertions, 109 deletions
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 <lucas.chollet@free.fr>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include "RoundingDialog.h"
-#include <LibGUI/BoxLayout.h>
-#include <LibGUI/Button.h>
-#include <LibGUI/Label.h>
-#include <LibGUI/SpinBox.h>
-#include <LibGUI/TextEditor.h>
-
-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<GUI::Widget>().release_value_but_fixme_should_propagate_errors();
-
- main_widget->set_fill_with_background_color(true);
- main_widget->set_layout<GUI::VerticalBoxLayout>();
-
- 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<GUI::HorizontalBoxLayout>();
- 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 <lucas.chollet@free.fr>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/Vector.h>
-#include <LibGUI/Dialog.h>
-
-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<GUI::SpinBox> m_rounding_spinbox;
- RefPtr<GUI::Widget> m_buttons_container;
- RefPtr<GUI::DialogButton> m_ok_button;
- RefPtr<GUI::DialogButton> 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 <LibCore/System.h>
#include <LibCrypto/NumberTheory/ModularFunctions.h>
#include <LibGUI/Action.h>
@@ -13,6 +12,7 @@
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
#include <LibGUI/Icon.h>
+#include <LibGUI/InputBox.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Menubar.h>
#include <LibGUI/Window.h>
@@ -90,22 +90,23 @@ ErrorOr<int> 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);