2019-04-11 00:05:47 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibGUI/GWidget.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include "VBWidget.h"
|
|
|
|
|
|
|
|
class VBForm : public GWidget {
|
2019-04-16 03:52:26 +02:00
|
|
|
friend class VBWidget;
|
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-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-11 02:35:30 +02:00
|
|
|
void grabber_mousedown_event(GMouseEvent&, VBWidget&, Direction grabber);
|
2019-04-16 23:11:35 +02:00
|
|
|
void set_selected_widget(VBWidget*);
|
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 };
|
|
|
|
Vector<Retained<VBWidget>> m_widgets;
|
2019-04-16 03:52:26 +02:00
|
|
|
HashMap<GWidget*, VBWidget*> m_gwidget_map;
|
2019-04-11 01:59:07 +02:00
|
|
|
WeakPtr<VBWidget> m_selected_widget;
|
|
|
|
Point m_transform_event_origin;
|
|
|
|
Rect m_transform_widget_origin_rect;
|
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-04-18 04:12:27 +02:00
|
|
|
OwnPtr<GMenu> m_context_menu;
|
2019-04-11 00:05:47 +02:00
|
|
|
};
|