summaryrefslogtreecommitdiff
path: root/Applications/Calculator
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-02 15:07:41 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-02 15:15:33 +0100
commitc5bd9d4ed1d80ac91d46146565127b0c185f1b43 (patch)
treeb4ee9ba5999778450f8eb4006df89110617b4a10 /Applications/Calculator
parent2d39da5405a4527e91e853ddb1e56a539c96c6c1 (diff)
downloadserenity-c5bd9d4ed1d80ac91d46146565127b0c185f1b43.zip
LibGUI: Put all classes in the GUI namespace and remove the leading G
This took me a moment. Welcome to the new world of GUI::Widget! :^)
Diffstat (limited to 'Applications/Calculator')
-rw-r--r--Applications/Calculator/CalculatorWidget.cpp66
-rw-r--r--Applications/Calculator/CalculatorWidget.h60
-rw-r--r--Applications/Calculator/main.cpp18
3 files changed, 73 insertions, 71 deletions
diff --git a/Applications/Calculator/CalculatorWidget.cpp b/Applications/Calculator/CalculatorWidget.cpp
index 32fa5c494b..736cd4ecbf 100644
--- a/Applications/Calculator/CalculatorWidget.cpp
+++ b/Applications/Calculator/CalculatorWidget.cpp
@@ -30,16 +30,16 @@
#include <LibGUI/GLabel.h>
#include <LibGUI/GTextBox.h>
-CalculatorWidget::CalculatorWidget(GWidget* parent)
- : GWidget(parent)
+CalculatorWidget::CalculatorWidget(GUI::Widget* parent)
+ : GUI::Widget(parent)
{
set_fill_with_background_color(true);
- m_entry = GTextBox::construct(this);
+ m_entry = GUI::TextBox::construct(this);
m_entry->set_relative_rect(5, 5, 244, 26);
m_entry->set_text_alignment(TextAlignment::CenterRight);
- m_label = GLabel::construct(this);
+ m_label = GUI::Label::construct(this);
m_label->set_relative_rect(12, 42, 27, 27);
m_label->set_foreground_color(Color::NamedColor::Red);
m_label->set_frame_shadow(FrameShadow::Sunken);
@@ -49,7 +49,7 @@ CalculatorWidget::CalculatorWidget(GWidget* parent)
update_display();
for (int i = 0; i < 10; i++) {
- m_digit_button[i] = GButton::construct(this);
+ m_digit_button[i] = GUI::Button::construct(this);
auto& button = *m_digit_button[i];
int p = i ? i + 2 : 0;
int x = 55 + (p % 3) * 39;
@@ -59,34 +59,34 @@ CalculatorWidget::CalculatorWidget(GWidget* parent)
add_button(button, i);
}
- m_mem_add_button = GButton::construct(this);
+ m_mem_add_button = GUI::Button::construct(this);
m_mem_add_button->move_to(9, 177);
m_mem_add_button->set_foreground_color(Color::NamedColor::Red);
m_mem_add_button->set_text("M+");
add_button(*m_mem_add_button, Calculator::Operation::MemAdd);
- m_mem_save_button = GButton::construct(this);
+ m_mem_save_button = GUI::Button::construct(this);
m_mem_save_button->move_to(9, 144);
m_mem_save_button->set_foreground_color(Color::NamedColor::Red);
m_mem_save_button->set_text("MS");
add_button(*m_mem_save_button, Calculator::Operation::MemSave);
- m_mem_recall_button = GButton::construct(this);
+ m_mem_recall_button = GUI::Button::construct(this);
m_mem_recall_button->move_to(9, 111);
m_mem_recall_button->set_foreground_color(Color::NamedColor::Red);
m_mem_recall_button->set_text("MR");
add_button(*m_mem_recall_button, Calculator::Operation::MemRecall);
- m_mem_clear_button = GButton::construct(this);
+ m_mem_clear_button = GUI::Button::construct(this);
m_mem_clear_button->move_to(9, 78);
m_mem_clear_button->set_foreground_color(Color::NamedColor::Red);
m_mem_clear_button->set_text("MC");
add_button(*m_mem_clear_button, Calculator::Operation::MemClear);
- m_clear_button = GButton::construct(this);
+ m_clear_button = GUI::Button::construct(this);
m_clear_button->set_foreground_color(Color::NamedColor::Red);
m_clear_button->set_text("C");
- m_clear_button->on_click = [this](GButton&) {
+ m_clear_button->on_click = [this](GUI::Button&) {
m_keypad.set_value(0.0);
m_calculator.clear_operation();
update_display();
@@ -94,89 +94,89 @@ CalculatorWidget::CalculatorWidget(GWidget* parent)
add_button(*m_clear_button);
m_clear_button->set_relative_rect(187, 40, 60, 28);
- m_clear_error_button = GButton::construct(this);
+ m_clear_error_button = GUI::Button::construct(this);
m_clear_error_button->set_foreground_color(Color::NamedColor::Red);
m_clear_error_button->set_text("CE");
- m_clear_error_button->on_click = [this](GButton&) {
+ m_clear_error_button->on_click = [this](GUI::Button&) {
m_calculator.clear_error();
update_display();
};
add_button(*m_clear_error_button);
m_clear_error_button->set_relative_rect(124, 40, 59, 28);
- m_backspace_button = GButton::construct(this);
+ m_backspace_button = GUI::Button::construct(this);
m_backspace_button->set_foreground_color(Color::NamedColor::Red);
m_backspace_button->set_text("Backspace");
- m_backspace_button->on_click = [this](GButton&) {
+ m_backspace_button->on_click = [this](GUI::Button&) {
m_keypad.type_backspace();
update_display();
};
add_button(*m_backspace_button);
m_backspace_button->set_relative_rect(55, 40, 65, 28);
- m_decimal_point_button = GButton::construct(this);
+ m_decimal_point_button = GUI::Button::construct(this);
m_decimal_point_button->move_to(133, 177);
m_decimal_point_button->set_foreground_color(Color::NamedColor::Blue);
m_decimal_point_button->set_text(".");
- m_decimal_point_button->on_click = [this](GButton&) {
+ m_decimal_point_button->on_click = [this](GUI::Button&) {
m_keypad.type_decimal_point();
update_display();
};
add_button(*m_decimal_point_button);
- m_sign_button = GButton::construct(this);
+ m_sign_button = GUI::Button::construct(this);
m_sign_button->move_to(94, 177);
m_sign_button->set_foreground_color(Color::NamedColor::Blue);
m_sign_button->set_text("+/-");
add_button(*m_sign_button, Calculator::Operation::ToggleSign);
- m_add_button = GButton::construct(this);
+ m_add_button = GUI::Button::construct(this);
m_add_button->move_to(172, 177);
m_add_button->set_foreground_color(Color::NamedColor::Red);
m_add_button->set_text("+");
add_button(*m_add_button, Calculator::Operation::Add);
- m_subtract_button = GButton::construct(this);
+ m_subtract_button = GUI::Button::construct(this);
m_subtract_button->move_to(172, 144);
m_subtract_button->set_foreground_color(Color::NamedColor::Red);
m_subtract_button->set_text("-");
add_button(*m_subtract_button, Calculator::Operation::Subtract);
- m_multiply_button = GButton::construct(this);
+ m_multiply_button = GUI::Button::construct(this);
m_multiply_button->move_to(172, 111);
m_multiply_button->set_foreground_color(Color::NamedColor::Red);
m_multiply_button->set_text("*");
add_button(*m_multiply_button, Calculator::Operation::Multiply);
- m_divide_button = GButton::construct(this);
+ m_divide_button = GUI::Button::construct(this);
m_divide_button->move_to(172, 78);
m_divide_button->set_foreground_color(Color::NamedColor::Red);
m_divide_button->set_text("/");
add_button(*m_divide_button, Calculator::Operation::Divide);
- m_sqrt_button = GButton::construct(this);
+ m_sqrt_button = GUI::Button::construct(this);
m_sqrt_button->move_to(211, 78);
m_sqrt_button->set_foreground_color(Color::NamedColor::Blue);
m_sqrt_button->set_text("sqrt");
add_button(*m_sqrt_button, Calculator::Operation::Sqrt);
- m_inverse_button = GButton::construct(this);
+ m_inverse_button = GUI::Button::construct(this);
m_inverse_button->move_to(211, 144);
m_inverse_button->set_foreground_color(Color::NamedColor::Blue);
m_inverse_button->set_text("1/x");
add_button(*m_inverse_button, Calculator::Operation::Inverse);
- m_percent_button = GButton::construct(this);
+ m_percent_button = GUI::Button::construct(this);
m_percent_button->move_to(211, 111);
m_percent_button->set_foreground_color(Color::NamedColor::Blue);
m_percent_button->set_text("%");
add_button(*m_percent_button, Calculator::Operation::Percent);
- m_equals_button = GButton::construct(this);
+ m_equals_button = GUI::Button::construct(this);
m_equals_button->move_to(211, 177);
m_equals_button->set_foreground_color(Color::NamedColor::Red);
m_equals_button->set_text("=");
- m_equals_button->on_click = [this](GButton&) {
+ m_equals_button->on_click = [this](GUI::Button&) {
double argument = m_keypad.value();
double res = m_calculator.finish_operation(argument);
m_keypad.set_value(res);
@@ -189,10 +189,10 @@ CalculatorWidget::~CalculatorWidget()
{
}
-void CalculatorWidget::add_button(GButton& button, Calculator::Operation operation)
+void CalculatorWidget::add_button(GUI::Button& button, Calculator::Operation operation)
{
add_button(button);
- button.on_click = [this, operation](GButton&) {
+ button.on_click = [this, operation](GUI::Button&) {
double argument = m_keypad.value();
double res = m_calculator.begin_operation(operation, argument);
m_keypad.set_value(res);
@@ -200,17 +200,17 @@ void CalculatorWidget::add_button(GButton& button, Calculator::Operation operati
};
}
-void CalculatorWidget::add_button(GButton& button, int digit)
+void CalculatorWidget::add_button(GUI::Button& button, int digit)
{
add_button(button);
button.set_text(String::number(digit));
- button.on_click = [this, digit](GButton&) {
+ button.on_click = [this, digit](GUI::Button&) {
m_keypad.type_digit(digit);
update_display();
};
}
-void CalculatorWidget::add_button(GButton& button)
+void CalculatorWidget::add_button(GUI::Button& button)
{
button.resize(35, 28);
}
@@ -224,7 +224,7 @@ void CalculatorWidget::update_display()
m_label->set_text("");
}
-void CalculatorWidget::keydown_event(GKeyEvent& event)
+void CalculatorWidget::keydown_event(GUI::KeyEvent& event)
{
//Clear button selection when we are typing
m_equals_button->set_focus(true);
diff --git a/Applications/Calculator/CalculatorWidget.h b/Applications/Calculator/CalculatorWidget.h
index bc0d163535..8400ca756f 100644
--- a/Applications/Calculator/CalculatorWidget.h
+++ b/Applications/Calculator/CalculatorWidget.h
@@ -31,47 +31,49 @@
#include <AK/Vector.h>
#include <LibGUI/GWidget.h>
-class GTextBox;
-class GButton;
-class GLabel;
+namespace GUI {
+class Button;
+class Label;
+class TextBox;
+}
-class CalculatorWidget final : public GWidget {
+class CalculatorWidget final : public GUI::Widget {
C_OBJECT(CalculatorWidget)
public:
virtual ~CalculatorWidget() override;
private:
- explicit CalculatorWidget(GWidget*);
- void add_button(GButton&, Calculator::Operation);
- void add_button(GButton&, int);
- void add_button(GButton&);
+ explicit CalculatorWidget(GUI::Widget*);
+ void add_button(GUI::Button&, Calculator::Operation);
+ void add_button(GUI::Button&, int);
+ void add_button(GUI::Button&);
void update_display();
- virtual void keydown_event(GKeyEvent&) override;
+ virtual void keydown_event(GUI::KeyEvent&) override;
Calculator m_calculator;
Keypad m_keypad;
- RefPtr<GTextBox> m_entry;
- RefPtr<GLabel> m_label;
+ RefPtr<GUI::TextBox> m_entry;
+ RefPtr<GUI::Label> m_label;
- RefPtr<GButton> m_digit_button[10];
- RefPtr<GButton> m_mem_add_button;
- RefPtr<GButton> m_mem_save_button;
- RefPtr<GButton> m_mem_recall_button;
- RefPtr<GButton> m_mem_clear_button;
- RefPtr<GButton> m_clear_button;
- RefPtr<GButton> m_clear_error_button;
- RefPtr<GButton> m_backspace_button;
- RefPtr<GButton> m_decimal_point_button;
- RefPtr<GButton> m_sign_button;
- RefPtr<GButton> m_add_button;
- RefPtr<GButton> m_subtract_button;
- RefPtr<GButton> m_multiply_button;
- RefPtr<GButton> m_divide_button;
- RefPtr<GButton> m_sqrt_button;
- RefPtr<GButton> m_inverse_button;
- RefPtr<GButton> m_percent_button;
- RefPtr<GButton> m_equals_button;
+ RefPtr<GUI::Button> m_digit_button[10];
+ RefPtr<GUI::Button> m_mem_add_button;
+ RefPtr<GUI::Button> m_mem_save_button;
+ RefPtr<GUI::Button> m_mem_recall_button;
+ RefPtr<GUI::Button> m_mem_clear_button;
+ RefPtr<GUI::Button> m_clear_button;
+ RefPtr<GUI::Button> m_clear_error_button;
+ RefPtr<GUI::Button> m_backspace_button;
+ RefPtr<GUI::Button> m_decimal_point_button;
+ RefPtr<GUI::Button> m_sign_button;
+ RefPtr<GUI::Button> m_add_button;
+ RefPtr<GUI::Button> m_subtract_button;
+ RefPtr<GUI::Button> m_multiply_button;
+ RefPtr<GUI::Button> m_divide_button;
+ RefPtr<GUI::Button> m_sqrt_button;
+ RefPtr<GUI::Button> m_inverse_button;
+ RefPtr<GUI::Button> m_percent_button;
+ RefPtr<GUI::Button> m_equals_button;
};
diff --git a/Applications/Calculator/main.cpp b/Applications/Calculator/main.cpp
index ab7780b9a4..fb8f035e0b 100644
--- a/Applications/Calculator/main.cpp
+++ b/Applications/Calculator/main.cpp
@@ -40,7 +40,7 @@ int main(int argc, char** argv)
return 1;
}
- GApplication app(argc, argv);
+ GUI::Application app(argc, argv);
if (pledge("stdio shared_buffer rpath accept", nullptr) < 0) {
perror("pledge");
@@ -54,7 +54,7 @@ int main(int argc, char** argv)
unveil(nullptr, nullptr);
- auto window = GWindow::construct();
+ auto window = GUI::Window::construct();
window->set_title("Calculator");
window->set_resizable(false);
window->set_rect({ 300, 200, 254, 213 });
@@ -65,18 +65,18 @@ int main(int argc, char** argv)
window->show();
window->set_icon(GraphicsBitmap::load_from_file("/res/icons/16x16/app-calculator.png"));
- auto menubar = make<GMenuBar>();
+ auto menubar = make<GUI::MenuBar>();
- auto app_menu = GMenu::construct("Calculator");
- app_menu->add_action(GCommonActions::make_quit_action([](auto&) {
- GApplication::the().quit(0);
+ auto app_menu = GUI::Menu::construct("Calculator");
+ app_menu->add_action(GUI::CommonActions::make_quit_action([](auto&) {
+ GUI::Application::the().quit(0);
return;
}));
menubar->add_menu(move(app_menu));
- auto help_menu = GMenu::construct("Help");
- help_menu->add_action(GAction::create("About", [&](const GAction&) {
- GAboutDialog::show("Calculator", load_png("/res/icons/16x16/app-calculator.png"), window);
+ auto help_menu = GUI::Menu::construct("Help");
+ help_menu->add_action(GUI::Action::create("About", [&](const GUI::Action&) {
+ GUI::AboutDialog::show("Calculator", load_png("/res/icons/16x16/app-calculator.png"), window);
}));
menubar->add_menu(move(help_menu));