Lumiera  0.pre.03
»edit your freedom«
track-head-widget.cpp
Go to the documentation of this file.
1 /*
2  TrackHeadWidget - display of track heads within the timeline
3 
4  Copyright (C)
5  2016, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
39 #include "stage/gtk-base.hpp"
40 #include "stage/style-scheme.hpp"
42 
43 #include "lib/util.hpp"
44 
45 using util::max;
46 
47 
48 namespace stage {
49 namespace timeline {
50 
51 
52 
53 
54  TrackHeadWidget::~TrackHeadWidget() { }
55  HeadControlArea::~HeadControlArea() { }
56 
57 
58 
59  TrackHeadWidget::TrackHeadWidget()
60  : Gtk::Grid{}
62  , structure_{}
63  , padding_{}
64  , headCtrl_{}
65  , childCnt_{0}
66  {
67  get_style_context()->add_class (CLASS_fork_head);
68  headCtrl_.set_valign(Gtk::Align::ALIGN_CENTER);
69  headCtrl_.set_halign(Gtk::Align::ALIGN_FILL);
70  this->attach (trackName_, 0,0, 2,1);
71  this->attach (structure_, 0,1, 1,2);
72  this->attach (headCtrl_, 1,1, 1,1); // corresponds to direct content
73  this->attach (padding_, 1,2, 1,1);// used to sync with sub-track display
74  this->property_expand() = false; // do not expand to fill
75  this->set_column_spacing(0);
76  this->set_row_spacing(0);
77  this->show_all();
78  }
79 
80 
81  HeadControlArea::HeadControlArea()
82  : Gtk::Grid{}
83  , ctrlTODO_{"\n 💡"}
84  {
85  get_style_context()->add_class (CLASS_fork_control);
86  ctrlTODO_.set_xalign (0.3);
87  ctrlTODO_.set_yalign (0.5);
88  this->attach (ctrlTODO_, 0,0, 1,1);
89  this->property_expand() = true;
90  this->show_all();
91  }
92 
93 
94  void
95  TrackHeadWidget::setTrackName (cuString& trackName)
96  {
97  trackName_.setName (trackName);
98  }
99 
100  uint
101  TrackHeadWidget::getHeightAt (int left, int top) const
102  {
103  auto* cell = this->get_child_at(left,top);
104  if (cell == nullptr) return 0;
105  int actual = cell->get_height();
106  int minimal=0, natural=0;
107  cell->get_preferred_height(minimal, natural);
108  return max (0, max (actual, natural));
109  }
110 
111  uint
112  TrackHeadWidget::getOverallHeight() const
113  {
114  uint heightSum{0};
115  for (uint line=1; line <= 2u + childCnt_; ++line)
116  heightSum += getHeightAt (1,line);
117  heightSum = max (heightSum, getExpansionHeight());
118  return heightSum + getLabelHeight();
119  }
120 
121  void
122  TrackHeadWidget::enforceHeightAt(int left, int top, uint height)
123  {
124  auto* cell = this->get_child_at(left,top);
125  REQUIRE (cell);
126  cell->set_size_request (-1, height);
127  }
128 
129  void
130  TrackHeadWidget::accommodateContentHeight(uint contentHeight)
131  {
132  uint localHeight = getContentHeight();
133  if (contentHeight > localHeight)
134  enforceContentHeight (contentHeight);
135  }
136 
137  void
138  TrackHeadWidget::accommodateOverallHeight(uint overallHeight)
139  {
140  uint discrepancy{0};
141  uint localHeight = getOverallHeight();
142  if (overallHeight > localHeight)
143  {
144  enforceExpansionHeight (overallHeight - getLabelHeight());
145  discrepancy = overallHeight-localHeight;
146  }
147  linkSubTrackPositions (discrepancy);
148  }
149 
157  void
159  {
160  uint localHeight = getContentHeight() + getLabelHeight();
161  if (directHeight > localHeight)
162  enforceSyncPadHeight (directHeight - localHeight);
163  }
164 
171  void
173  {
174  structure_.clearConnectors();
175  uint offset = getContentHeight()
176  + getSyncPadHeight()
177  + discrepancy
178  + getLabelHeight() // offset by the label in the children
179  ;
180  for (uint child=0; child < childCnt_; ++child)
181  {
182  structure_.addConnector (offset);
183  offset += getHeightAt (1, child+3);
184  }
185  }
186 
187 
203  void
205  {
206  ++childCnt_;
207  uint act = 2 + childCnt_; // left,top
208  Gtk::Grid::attach (subForkHead, 1, act, 1,1);
209  // expand the structure display column....
210  Gtk::Grid::remove (structure_); // width,height
211  Gtk::Grid::attach (structure_, 0,1, 1, act);
212  }
213 
224  void
226  {
227  --childCnt_;
228  uint act = 2 + childCnt_;
229  Gtk::Grid::remove (subForkHead);
230  // reduce the structure display column....
231  Gtk::Grid::remove (structure_);
232  Gtk::Grid::attach (structure_, 0,1, 1,act);
233  }
234 
235 
236  void
238  {
239  if (not childCnt_) return;
240  Gtk::Grid::remove (structure_);
241  while (childCnt_ > 0)
242  {
243  Gtk::Grid::remove_row (childCnt_);
244  --childCnt_;
245  }
246  Gtk::Grid::attach (structure_, 0,1, 1,2);
247  }
248 
249 
250 
251  /* ==== Interface: ViewHook ===== */
252 
253  void
254  TrackHeadWidget::hook (TrackHeadWidget& subHead)
255  {
256  attachSubFork (subHead);
257  }
258 
259  void
260  TrackHeadWidget::remove (TrackHeadWidget& subHead)
261  {
262  detachSubFork (subHead);
263  }
264 
273  void
274  TrackHeadWidget::rehook (TrackHeadWidget& hookedSubHead) noexcept
275  {
276  detachSubFork (hookedSubHead);
277  attachSubFork (hookedSubHead);
278  }
279 
280 
281 
282 }}// namespace stage::timeline
Header pane control area corresponding to a Track with nested child Tracks.
void attachSubFork(TrackHeadWidget &subForkHead)
Integrate the control area for a nested sub track fork.
void clearFork()
Discard all nested sub track display widgets.
Widget represents an entity within a collection (Bin)
void syncSubtrackStartHeight(uint)
The first part of each track&#39;s display relates to the direct content; below that area, the content of sub-tracks may be added.
Widget to represent a track head with placement parameters, within the timeline header pane...
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
void linkSubTrackPositions(uint)
Coordinate the exact positions of sub-Track start during DisplayEvaluaton.
void rehook(TrackHeadWidget &) noexcept override
uint getHeightAt(int left, int top) const
get the height allocated at cell(x,y)
represents a label or descriptor
Definition of access keys for uniform UI styling.
A set of basic GTK includes for the UI.
void detachSubFork(TrackHeadWidget &subForkHead)