diff options
Diffstat (limited to 'DevTools')
-rw-r--r-- | DevTools/HackStudio/CursorTool.cpp | 29 | ||||
-rw-r--r-- | DevTools/HackStudio/CursorTool.h | 1 | ||||
-rw-r--r-- | DevTools/HackStudio/FormWidget.cpp | 5 | ||||
-rw-r--r-- | DevTools/HackStudio/FormWidget.h | 3 | ||||
-rw-r--r-- | DevTools/HackStudio/Tool.h | 2 | ||||
-rw-r--r-- | DevTools/HackStudio/WidgetTool.cpp | 6 | ||||
-rw-r--r-- | DevTools/HackStudio/WidgetTool.h | 1 |
7 files changed, 47 insertions, 0 deletions
diff --git a/DevTools/HackStudio/CursorTool.cpp b/DevTools/HackStudio/CursorTool.cpp index e95f632282..643f9ef701 100644 --- a/DevTools/HackStudio/CursorTool.cpp +++ b/DevTools/HackStudio/CursorTool.cpp @@ -81,3 +81,32 @@ void CursorTool::on_mousemove(GMouseEvent& event) return; } } + +void CursorTool::on_keydown(GKeyEvent& event) +{ + dbg() << "CursorTool::on_keydown"; + + auto move_selected_widgets_by = [this](int x, int y) { + m_editor.selection().for_each([&](auto& widget) { + widget.move_by(x, y); + return IterationDecision::Continue; + }); + }; + + if (event.modifiers() == 0) { + switch (event.key()) { + case Key_Down: + move_selected_widgets_by(0, m_editor.form_widget().grid_size()); + break; + case Key_Up: + move_selected_widgets_by(0, -m_editor.form_widget().grid_size()); + break; + case Key_Left: + move_selected_widgets_by(-m_editor.form_widget().grid_size(), 0); + break; + case Key_Right: + move_selected_widgets_by(m_editor.form_widget().grid_size(), 0); + break; + } + } +} diff --git a/DevTools/HackStudio/CursorTool.h b/DevTools/HackStudio/CursorTool.h index 68fcbb534f..931b9eaa2a 100644 --- a/DevTools/HackStudio/CursorTool.h +++ b/DevTools/HackStudio/CursorTool.h @@ -19,6 +19,7 @@ private: virtual void on_mousedown(GMouseEvent&) override; virtual void on_mouseup(GMouseEvent&) override; virtual void on_mousemove(GMouseEvent&) override; + virtual void on_keydown(GKeyEvent&) override; Point m_drag_origin; HashMap<GWidget*, Point> m_positions_before_drag; diff --git a/DevTools/HackStudio/FormWidget.cpp b/DevTools/HackStudio/FormWidget.cpp index 985e758dec..4168f7e965 100644 --- a/DevTools/HackStudio/FormWidget.cpp +++ b/DevTools/HackStudio/FormWidget.cpp @@ -68,3 +68,8 @@ void FormWidget::mousemove_event(GMouseEvent& event) { editor().tool().on_mousemove(event); } + +void FormWidget::keydown_event(GKeyEvent& event) +{ + editor().tool().on_keydown(event); +} diff --git a/DevTools/HackStudio/FormWidget.h b/DevTools/HackStudio/FormWidget.h index 3258cede35..02a568e513 100644 --- a/DevTools/HackStudio/FormWidget.h +++ b/DevTools/HackStudio/FormWidget.h @@ -16,11 +16,14 @@ public: int grid_size() const { return m_grid_size; } private: + virtual bool accepts_focus() const override { return true; } + virtual void paint_event(GPaintEvent&) override; virtual void second_paint_event(GPaintEvent&) override; virtual void mousedown_event(GMouseEvent&) override; virtual void mouseup_event(GMouseEvent&) override; virtual void mousemove_event(GMouseEvent&) override; + virtual void keydown_event(GKeyEvent&) override; explicit FormWidget(FormEditorWidget& parent); diff --git a/DevTools/HackStudio/Tool.h b/DevTools/HackStudio/Tool.h index 75911209e1..6a9bb1c44a 100644 --- a/DevTools/HackStudio/Tool.h +++ b/DevTools/HackStudio/Tool.h @@ -3,6 +3,7 @@ #include <AK/Noncopyable.h> class FormEditorWidget; +class GKeyEvent; class GMouseEvent; class Tool { @@ -14,6 +15,7 @@ public: virtual void on_mousedown(GMouseEvent&) = 0; virtual void on_mouseup(GMouseEvent&) = 0; virtual void on_mousemove(GMouseEvent&) = 0; + virtual void on_keydown(GKeyEvent&) = 0; virtual const char* class_name() const = 0; diff --git a/DevTools/HackStudio/WidgetTool.cpp b/DevTools/HackStudio/WidgetTool.cpp index 032e3688df..04198b241a 100644 --- a/DevTools/HackStudio/WidgetTool.cpp +++ b/DevTools/HackStudio/WidgetTool.cpp @@ -18,3 +18,9 @@ void WidgetTool::on_mousemove(GMouseEvent& event) (void)event; dbg() << "WidgetTool::on_mousemove"; } + +void WidgetTool::on_keydown(GKeyEvent& event) +{ + (void)event; + dbg() << "WidgetTool::on_keydown"; +} diff --git a/DevTools/HackStudio/WidgetTool.h b/DevTools/HackStudio/WidgetTool.h index 24b9946ebf..cbde2ef58c 100644 --- a/DevTools/HackStudio/WidgetTool.h +++ b/DevTools/HackStudio/WidgetTool.h @@ -18,6 +18,7 @@ private: virtual void on_mousedown(GMouseEvent&) override; virtual void on_mouseup(GMouseEvent&) override; virtual void on_mousemove(GMouseEvent&) override; + virtual void on_keydown(GKeyEvent&) override; const GWidgetClassRegistration& m_meta_class; }; |