66#include " App.h"
77#include " FilesModel.h"
88#include " StackItem.h"
9+ #include " WindowModel.h"
910
1011#include < dtk/ui/ScrollArea.h>
1112
@@ -49,6 +50,15 @@ namespace toucan
4950 {
5051 _select (shared_from_this (), selection);
5152 });
53+
54+ _thumbnailsObserver = dtk::ValueObserver<bool >::create (
55+ data.app ->getWindowModel ()->observeThumbnails (),
56+ [this ](bool value)
57+ {
58+ _thumbnails = value;
59+ _setSizeUpdate ();
60+ _setDrawUpdate ();
61+ });
5262 }
5363
5464 TimelineItem::~TimelineItem ()
@@ -98,9 +108,14 @@ namespace toucan
98108 for (const auto & child : getChildren ())
99109 {
100110 const dtk::Size2I& sizeHint = child->getSizeHint ();
111+ int h = timeHeight;
112+ if (_thumbnails)
113+ {
114+ h += _size.thumbnailHeight ;
115+ }
101116 child->setGeometry (dtk::Box2I (
102117 g.min .x ,
103- g.min .y + timeHeight + _size. thumbnailHeight ,
118+ g.min .y + h ,
104119 sizeHint.w ,
105120 sizeHint.h ));
106121 }
@@ -165,7 +180,10 @@ namespace toucan
165180 dtk::Size2I sizeHint (
166181 _timeRange.duration ().rescaled_to (1.0 ).value () * _scale,
167182 _size.fontMetrics .lineHeight + _size.margin * 2 );
168- sizeHint.h += _size.thumbnailHeight ;
183+ if (_thumbnails)
184+ {
185+ sizeHint.h += _size.thumbnailHeight ;
186+ }
169187 sizeHint.h += childSizeHint;
170188 _setSizeHint (sizeHint);
171189 }
@@ -177,35 +195,38 @@ namespace toucan
177195 const dtk::Box2I& g = getGeometry ();
178196 const int thumbnailWidth = _size.thumbnailHeight * _thumbnailGenerator->getAspect ();
179197 const int y = g.min .y + _size.fontMetrics .lineHeight + _size.margin * 2 ;
180- for ( int x = g. min . x ; x < g. max . x && thumbnailWidth > 0 ; x += thumbnailWidth )
198+ if (_thumbnails )
181199 {
182- const dtk::Box2I g2 (x, y, thumbnailWidth, _size.thumbnailHeight );
183- if (dtk::intersects (g2, drawRect))
200+ for (int x = g.min .x ; x < g.max .x && thumbnailWidth > 0 ; x += thumbnailWidth)
184201 {
185- const OTIO_NS::RationalTime t = posToTime (x);
186- std::shared_ptr<dtk::Image> image;
187- if (_thumbnailCache->get (getThumbnailCacheKey (nullptr , t, _size.thumbnailHeight ), image))
202+ const dtk::Box2I g2 (x, y, thumbnailWidth, _size.thumbnailHeight );
203+ if (dtk::intersects (g2, drawRect))
188204 {
189- if (image)
205+ const OTIO_NS::RationalTime t = posToTime (x);
206+ std::shared_ptr<dtk::Image> image;
207+ if (_thumbnailCache->get (getThumbnailCacheKey (nullptr , t, _size.thumbnailHeight ), image))
190208 {
191- event.render ->drawImage (
192- image,
193- dtk::Box2I (x, y, image->getWidth (), image->getHeight ()));
194- }
195- }
196- else
197- {
198- const auto j = std::find_if (
199- _thumbnailRequests.begin (),
200- _thumbnailRequests.end (),
201- [this , t](const ThumbnailRequest& request)
209+ if (image)
202210 {
203- return t == request.time && _size.thumbnailHeight == request.height ;
204- });
205- if (j == _thumbnailRequests.end ())
211+ event.render ->drawImage (
212+ image,
213+ dtk::Box2I (x, y, image->getWidth (), image->getHeight ()));
214+ }
215+ }
216+ else
206217 {
207- _thumbnailRequests.push_back (
208- _thumbnailGenerator->getThumbnail (t, _size.thumbnailHeight ));
218+ const auto j = std::find_if (
219+ _thumbnailRequests.begin (),
220+ _thumbnailRequests.end (),
221+ [this , t](const ThumbnailRequest& request)
222+ {
223+ return t == request.time && _size.thumbnailHeight == request.height ;
224+ });
225+ if (j == _thumbnailRequests.end ())
226+ {
227+ _thumbnailRequests.push_back (
228+ _thumbnailGenerator->getThumbnail (t, _size.thumbnailHeight ));
229+ }
209230 }
210231 }
211232 }
0 commit comments