Editor graph delegate: Add HorizontalFix, VerticalFix and StructureFix constraints

directional-lights
Sven Eberhardt 2016-11-12 21:23:00 -05:00
parent 3b2909fa95
commit 91af5a95be
6 changed files with 53 additions and 6 deletions

View File

@ -2157,6 +2157,12 @@ bool C4PropertyDelegatePoint::IsPasteValid(const C4Value &val) const
C4PropertyDelegateGraph::C4PropertyDelegateGraph(const class C4PropertyDelegateFactory *factory, C4PropList *props)
: C4PropertyDelegateShape(factory, props)
{
if (props)
{
horizontal_fix = props->GetPropertyBool(P_HorizontalFix);
vertical_fix = props->GetPropertyBool(P_VerticalFix);
structure_fix = props->GetPropertyBool(P_StructureFix);
}
}
void C4PropertyDelegateGraph::DoPaint(QPainter *painter, const QRect &inner_rect) const
@ -2215,6 +2221,10 @@ bool C4PropertyDelegateGraph::IsEdgePasteValid(const C4Value &val) const
bool C4PropertyDelegateGraph::IsPasteValid(const C4Value &val) const
{
// Unfortunately, there is no good way to determine the correct value for fixed structure / position graph pastes
// So just reject pastes for now
// (TODO: Could store a default structure in a property and compare to that)
if (horizontal_fix || vertical_fix || structure_fix) return false;
// Check storage as prop list
const int32_t n_props = 2;
C4Value prop_vals[n_props]; // vertices & edges

View File

@ -559,6 +559,10 @@ public:
class C4PropertyDelegateGraph : public C4PropertyDelegateShape
{
bool horizontal_fix = false;
bool vertical_fix = false;
bool structure_fix = false;
void DoPaint(QPainter *painter, const QRect &inner_rect) const override;
protected:
bool IsVertexPasteValid(const C4Value &val) const;

View File

@ -791,6 +791,9 @@ C4ConsoleQtGraph::C4ConsoleQtGraph(C4Object *for_obj, C4PropList *props, const c
props->GetProperty(P_EdgeDelegate, &edge_delegate);
allow_vertex_selection = !!vertex_delegate.getPropList();
allow_edge_selection = !!edge_delegate.getPropList();
horizontal_fix = props->GetPropertyBool(P_HorizontalFix);
vertical_fix = props->GetPropertyBool(P_VerticalFix);
structure_fix = props->GetPropertyBool(P_StructureFix);
}
}
@ -852,6 +855,27 @@ bool C4ConsoleQtGraph::IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::Cursor
++i;
}
}
// Check if structure change is allowed
if (has_hit && (shift_down || ctrl_down) && structure_fix)
{
*drag_cursor = Qt::CursorShape::ForbiddenCursor;
}
else if (*drag_cursor == Qt::CursorShape::SizeAllCursor)
{
// Adjust cursor for constrained movement
if (horizontal_fix && vertical_fix)
{
*drag_cursor = Qt::CursorShape::PointingHandCursor;
}
else if (horizontal_fix)
{
*drag_cursor = Qt::CursorShape::SizeVerCursor;
}
else if (vertical_fix)
{
*drag_cursor = Qt::CursorShape::SizeHorCursor;
}
}
return has_hit;
}
@ -966,7 +990,7 @@ bool C4ConsoleQtGraph::StartDragging(int32_t *border, int32_t x, int32_t y, bool
drag_snapped = false;
drag_snap_vertex = -1;
drag_source_vertex_index = -1;
if (shift_down && !ctrl_down)
if (shift_down && !ctrl_down && !structure_fix)
{
// Shift: Insert vertex
if (IsEdgeDrag(*border))
@ -983,7 +1007,7 @@ bool C4ConsoleQtGraph::StartDragging(int32_t *border, int32_t x, int32_t y, bool
// Start dragging
return true;
}
else if (ctrl_down && !shift_down)
else if (ctrl_down && !shift_down && !structure_fix)
{
// Ctrl: Delete vertex or edge
if (IsEdgeDrag(*border))
@ -1018,7 +1042,7 @@ bool C4ConsoleQtGraph::StartDragging(int32_t *border, int32_t x, int32_t y, bool
}
else
{
// Unknown modifiers
// Unknown modifiers or trying to modify a structure-fixed graph
return false;
}
}
@ -1033,10 +1057,10 @@ void C4ConsoleQtGraph::Drag(int32_t x, int32_t y, int32_t dx, int32_t dy, int32_
// Regular vertex movement
dx -= drag_snap_offset_x;
dy -= drag_snap_offset_y;
dragged_vertex.x += dx;
dragged_vertex.y += dy;
if (!horizontal_fix) dragged_vertex.x += dx;
if (!vertical_fix) dragged_vertex.y += dy;
// Handle snap to combine with other vertices
if (!IsPolyline())
if (!IsPolyline() && !structure_fix)
{
int32_t i = 0;
drag_snap_vertex = -1;

View File

@ -188,6 +188,9 @@ protected:
bool allow_vertex_selection = false; // If vertices on the graph can be selected
bool allow_edge_selection = false; // If edges on the graph can be selected
bool horizontal_fix = false; // If edges are locked horizontally
bool vertical_fix = false; // If edges are locked vertically
bool structure_fix = false; // If edge+vertex insertion/deletion is blocked
C4Value vertex_delegate, edge_delegate;

View File

@ -267,6 +267,9 @@ C4StringTable::C4StringTable()
P[P_Delegate] = "Delegate";
P[P_VertexDelegate] = "VertexDelegate";
P[P_EdgeDelegate] = "EdgeDelegate";
P[P_HorizontalFix] = "HorizontalFix";
P[P_VerticalFix] = "VerticalFix";
P[P_StructureFix] = "StructureFix";
P[P_Min] = "Min";
P[P_Max] = "Max";
P[P_Set] = "Set";

View File

@ -491,6 +491,9 @@ enum C4PropertyName
P_Delegate,
P_VertexDelegate,
P_EdgeDelegate,
P_HorizontalFix,
P_VerticalFix,
P_StructureFix,
P_Min,
P_Max,
P_Set,