1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00

HackStudio: Start implementing basic widget selection in CursorTool

You can now select widgets by clicking on them with the CursorTool,
and toggle the selection state of a widget by Ctrl+clicking it.
This commit is contained in:
Andreas Kling 2019-11-10 22:03:39 +01:00
parent e87756424d
commit f6576c4b7c
4 changed files with 78 additions and 2 deletions

View file

@ -18,12 +18,61 @@ public:
void set_tool(NonnullOwnPtr<Tool>);
class WidgetSelection {
public:
bool is_empty() const
{
return m_widgets.is_empty();
}
bool contains(GWidget& widget) const
{
return m_widgets.contains(&widget);
}
void toggle(GWidget& widget)
{
if (contains(widget))
remove(widget);
else
add(widget);
}
void set(GWidget& widget)
{
clear();
add(widget);
}
void remove(GWidget& widget)
{
ASSERT(m_widgets.contains(&widget));
m_widgets.remove(&widget);
}
void add(GWidget& widget)
{
m_widgets.set(&widget);
}
void clear()
{
m_widgets.clear();
}
WidgetSelection() {}
private:
HashTable<GWidget*> m_widgets;
};
WidgetSelection& selection() { return m_selection; }
private:
virtual void paint_event(GPaintEvent&) override;
explicit FormEditorWidget(GWidget* parent);
RefPtr<FormWidget> m_form_widget;
NonnullOwnPtr<Tool> m_tool;
WidgetSelection m_selection;
};