From d85d9bd7dae120e3e7ebaf64e7b78a975fab94a6 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 26 Nov 2016 13:39:26 +0200 Subject: [PATCH] Allow overriding the spacing between two widgets in LinearArrangement --- source/arrangement.cpp | 13 +++++++++---- source/arrangement.h | 4 ++-- source/lineararrangement.cpp | 17 +++++++++++++++-- source/lineararrangement.h | 3 +++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/source/arrangement.cpp b/source/arrangement.cpp index 9982691..5eeebbb 100644 --- a/source/arrangement.cpp +++ b/source/arrangement.cpp @@ -37,16 +37,21 @@ void Arrangement::arrange(Arrangement &arr) finish_slot(); } -void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side side) +void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, Side side, int spacing) { - add_constraint(wdg, type, edges[side]); + add_constraint(wdg, type, edges[side], spacing); } -void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge) +void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge, int spacing) { for(list::const_iterator i=edge.widgets.begin(); i!=edge.widgets.end(); ++i) if(*i!=&wdg) - layout.add_constraint(wdg, type, **i); + { + if(spacing<0) + layout.add_constraint(wdg, type, **i); + else + layout.add_constraint(wdg, type, **i, spacing); + } } Layout::ConstraintType Arrangement::get_order_constraint(Side s, bool slack) diff --git a/source/arrangement.h b/source/arrangement.h index f323a9b..7028aed 100644 --- a/source/arrangement.h +++ b/source/arrangement.h @@ -57,8 +57,8 @@ protected: virtual void finish_widget(Widget &) = 0; virtual void finish_slot() = 0; const Edge &get_edge(Side s) const { return edges[s]; } - void add_constraint(Widget &, Layout::ConstraintType, Side); - void add_constraint(Widget &, Layout::ConstraintType, const Edge &); + void add_constraint(Widget &, Layout::ConstraintType, Side, int = -1); + void add_constraint(Widget &, Layout::ConstraintType, const Edge &, int = -1); static Layout::ConstraintType get_order_constraint(Side, bool); static Layout::ConstraintType get_align_constraint(Side); diff --git a/source/lineararrangement.cpp b/source/lineararrangement.cpp index 6148be3..fb2e71c 100644 --- a/source/lineararrangement.cpp +++ b/source/lineararrangement.cpp @@ -10,7 +10,8 @@ LinearArrangement::LinearArrangement(Layout &l, Side p): first(true), split_here(false), gravity(opposite), - internal_aligned(false) + internal_aligned(false), + next_spacing(-1) { } void LinearArrangement::split() @@ -35,12 +36,17 @@ void LinearArrangement::expand() gravity = primary; } +void LinearArrangement::spacing(unsigned s) +{ + next_spacing = s; +} + void LinearArrangement::process_widget(Widget &wdg, Side side, bool aligned) { if(side==opposite) { bool snug = (internal_aligned && aligned && !split_here); - add_constraint(wdg, get_order_constraint(primary, !snug), primary); + add_constraint(wdg, get_order_constraint(primary, !snug), primary, next_spacing); if(first) edges[side].add(wdg, (aligned && gravity==opposite)); } @@ -63,6 +69,7 @@ void LinearArrangement::finish_slot() next.clear(); split_here = false; first = false; + next_spacing = -1; } @@ -70,6 +77,7 @@ LinearArrangement::Loader::Loader(LinearArrangement &c): DataFile::ObjectLoader(c) { add("expand", &Loader::expand); + add("spacing", &Loader::spacing); add("split", &Loader::split); } @@ -78,6 +86,11 @@ void LinearArrangement::Loader::expand() obj.expand(); } +void LinearArrangement::Loader::spacing(unsigned s) +{ + obj.spacing(s); +} + void LinearArrangement::Loader::split() { obj.split(); diff --git a/source/lineararrangement.h b/source/lineararrangement.h index a18c849..4b149a4 100644 --- a/source/lineararrangement.h +++ b/source/lineararrangement.h @@ -16,6 +16,7 @@ public: Loader(LinearArrangement &); private: void expand(); + void spacing(unsigned); void split(); }; @@ -27,12 +28,14 @@ protected: bool split_here; Side gravity; bool internal_aligned; + int next_spacing; LinearArrangement(Layout &, Side); public: void split(); void expand(); + void spacing(unsigned); protected: virtual void process_widget(Widget &, Side, bool); -- 2.45.2