summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Calculator/CalculatorWidget.cpp11
-rw-r--r--Userland/Applications/Calculator/CalculatorWidget.h2
-rw-r--r--Userland/Applications/Calculator/main.cpp17
3 files changed, 29 insertions, 1 deletions
diff --git a/Userland/Applications/Calculator/CalculatorWidget.cpp b/Userland/Applications/Calculator/CalculatorWidget.cpp
index df648640a0..f2ae66413a 100644
--- a/Userland/Applications/Calculator/CalculatorWidget.cpp
+++ b/Userland/Applications/Calculator/CalculatorWidget.cpp
@@ -147,6 +147,17 @@ void CalculatorWidget::add_digit_button(GUI::Button& button, int digit)
};
}
+String CalculatorWidget::get_entry()
+{
+ return m_entry->text();
+}
+
+void CalculatorWidget::set_entry(double value)
+{
+ m_keypad.set_value(value);
+ update_display();
+}
+
void CalculatorWidget::update_display()
{
m_entry->set_text(m_keypad.to_string());
diff --git a/Userland/Applications/Calculator/CalculatorWidget.h b/Userland/Applications/Calculator/CalculatorWidget.h
index 31d9548b3c..857f27fc82 100644
--- a/Userland/Applications/Calculator/CalculatorWidget.h
+++ b/Userland/Applications/Calculator/CalculatorWidget.h
@@ -36,6 +36,8 @@ class CalculatorWidget final : public GUI::Widget {
C_OBJECT(CalculatorWidget)
public:
virtual ~CalculatorWidget() override;
+ String get_entry();
+ void set_entry(double);
private:
CalculatorWidget();
diff --git a/Userland/Applications/Calculator/main.cpp b/Userland/Applications/Calculator/main.cpp
index a2a10f1029..91ee969d23 100644
--- a/Userland/Applications/Calculator/main.cpp
+++ b/Userland/Applications/Calculator/main.cpp
@@ -27,6 +27,7 @@
#include "CalculatorWidget.h"
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
+#include <LibGUI/Clipboard.h>
#include <LibGUI/Icon.h>
#include <LibGUI/Menu.h>
#include <LibGUI/MenuBar.h>
@@ -62,7 +63,7 @@ int main(int argc, char** argv)
window->set_resizable(false);
window->resize(254, 213);
- window->set_main_widget<CalculatorWidget>();
+ auto& widget = window->set_main_widget<CalculatorWidget>();
window->show();
window->set_icon(app_icon.bitmap_for_size(16));
@@ -75,6 +76,20 @@ int main(int argc, char** argv)
return;
}));
+ auto& edit_menu = menubar->add_menu("Edit");
+ edit_menu.add_action(GUI::Action::create("Copy", { Mod_Ctrl, Key_C }, Gfx::Bitmap::load_from_file("/res/icons/16x16/edit-copy.png"), [&](const GUI::Action&) {
+ GUI::Clipboard::the().set_plain_text(widget.get_entry());
+ }));
+ edit_menu.add_action(GUI::Action::create("Paste", { Mod_Ctrl, Key_V }, Gfx::Bitmap::load_from_file("/res/icons/16x16/paste.png"), [&](const GUI::Action&) {
+ auto clipboard = GUI::Clipboard::the().data_and_type();
+ if (clipboard.mime_type == "text/plain") {
+ if (!clipboard.data.is_empty()) {
+ auto data = atof(StringView(clipboard.data).to_string().characters());
+ widget.set_entry(data);
+ }
+ }
+ }));
+
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Calculator", app_icon, window));