2019-04-11 00:05:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "VBWidget.h"
|
2019-06-27 13:49:26 +02:00
|
|
|
#include <AK/NonnullRefPtrVector.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibGUI/GWidget.h>
|
2019-04-11 00:05:47 +02:00
|
|
|
|
|
|
|
class VBForm : public GWidget {
|
2019-04-16 03:52:26 +02:00
|
|
|
friend class VBWidget;
|
2019-05-28 11:53:16 +02:00
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
public:
|
|
|
|
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
|
|
|
virtual ~VBForm() override;
|
|
|
|
|
2019-04-11 04:13:11 +02:00
|
|
|
static VBForm* current();
|
|
|
|
|
2019-04-11 03:34:37 +02:00
|
|
|
String name() const { return m_name; }
|
|
|
|
void set_name(const String& name) { m_name = name; }
|
|
|
|
|
2019-04-11 01:59:07 +02:00
|
|
|
bool is_selected(const VBWidget&) const;
|
|
|
|
VBWidget* widget_at(const Point&);
|
|
|
|
|
|
|
|
void set_should_snap_to_grip(bool snap) { m_should_snap_to_grid = snap; }
|
|
|
|
bool should_snap_to_grid() const { return m_should_snap_to_grid; }
|
|
|
|
|
2019-04-11 16:13:19 +02:00
|
|
|
void insert_widget(VBWidgetType);
|
2019-04-11 04:13:11 +02:00
|
|
|
|
2019-04-11 21:41:09 +02:00
|
|
|
Function<void(VBWidget*)> on_widget_selected;
|
|
|
|
|
2019-06-29 12:06:46 +02:00
|
|
|
void load_from_file(const String& path);
|
2019-05-08 04:39:42 +02:00
|
|
|
void write_to_file(const String& path);
|
2019-05-07 23:28:35 +02:00
|
|
|
void dump();
|
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
protected:
|
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
2019-04-11 03:34:37 +02:00
|
|
|
virtual void second_paint_event(GPaintEvent&) override;
|
2019-04-11 01:59:07 +02:00
|
|
|
virtual void mousedown_event(GMouseEvent&) override;
|
|
|
|
virtual void mousemove_event(GMouseEvent&) override;
|
|
|
|
virtual void mouseup_event(GMouseEvent&) override;
|
2019-04-18 04:12:27 +02:00
|
|
|
virtual void context_menu_event(GContextMenuEvent&) override;
|
2019-04-16 23:01:37 +02:00
|
|
|
virtual void keydown_event(GKeyEvent&) override;
|
2019-04-11 00:05:47 +02:00
|
|
|
|
|
|
|
private:
|
2019-04-19 23:09:38 +02:00
|
|
|
void grabber_mousedown_event(GMouseEvent&, Direction grabber);
|
2019-04-19 22:46:16 +02:00
|
|
|
void set_single_selected_widget(VBWidget*);
|
|
|
|
void add_to_selection(VBWidget&);
|
|
|
|
void remove_from_selection(VBWidget&);
|
|
|
|
void delete_selected_widgets();
|
2019-05-28 11:53:16 +02:00
|
|
|
template<typename Callback>
|
|
|
|
void for_each_selected_widget(Callback);
|
2019-08-29 22:41:41 -05:00
|
|
|
void set_cursor_type_from_grabber(Direction grabber);
|
2019-04-19 22:46:16 +02:00
|
|
|
|
|
|
|
VBWidget* single_selected_widget();
|
2019-04-11 02:35:30 +02:00
|
|
|
|
2019-04-11 00:05:47 +02:00
|
|
|
String m_name;
|
2019-04-11 13:16:18 +02:00
|
|
|
int m_grid_size { 5 };
|
2019-04-11 01:59:07 +02:00
|
|
|
bool m_should_snap_to_grid { true };
|
2019-06-27 13:49:26 +02:00
|
|
|
NonnullRefPtrVector<VBWidget> m_widgets;
|
2019-04-16 03:52:26 +02:00
|
|
|
HashMap<GWidget*, VBWidget*> m_gwidget_map;
|
2019-04-19 22:46:16 +02:00
|
|
|
HashTable<VBWidget*> m_selected_widgets;
|
2019-04-11 01:59:07 +02:00
|
|
|
Point m_transform_event_origin;
|
2019-04-11 04:13:11 +02:00
|
|
|
Point m_next_insertion_position;
|
2019-04-11 02:35:30 +02:00
|
|
|
Direction m_resize_direction { Direction::None };
|
2019-08-29 22:41:41 -05:00
|
|
|
Direction m_mouse_direction_type { Direction::None };
|
2019-04-18 04:12:27 +02:00
|
|
|
OwnPtr<GMenu> m_context_menu;
|
2019-04-11 00:05:47 +02:00
|
|
|
};
|