comparison layer/TimeInstantLayer.cpp @ 17:0183ebb725ca

* Add ability to create empty layers for editing * Add first basic editing capability (adding points to a time instant layer) * Add various keyboard and mouse shortcuts for navigation &c * Add ability to resize a selection by dragging its edges * Add maximum zoom level
author Chris Cannam
date Thu, 26 Jan 2006 16:15:40 +0000
parents 02a718909b2d
children 7c767d41bcee
comparison
equal deleted inserted replaced
16:02a718909b2d 17:0183ebb725ca
15 #include "base/Profiler.h" 15 #include "base/Profiler.h"
16 16
17 #include "model/SparseOneDimensionalModel.h" 17 #include "model/SparseOneDimensionalModel.h"
18 18
19 #include <QPainter> 19 #include <QPainter>
20 #include <QMouseEvent>
20 21
21 #include <iostream> 22 #include <iostream>
22 23
23 TimeInstantLayer::TimeInstantLayer(View *w) : 24 TimeInstantLayer::TimeInstantLayer(View *w) :
24 Layer(w), 25 Layer(w),
25 m_model(0), 26 m_model(0),
27 m_editingPoint(0, tr("New Point")),
26 m_colour(QColor(200, 50, 255)) 28 m_colour(QColor(200, 50, 255))
27 { 29 {
28 m_view->addLayer(this); 30 m_view->addLayer(this);
29 } 31 }
30 32
293 295
294 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); 296 for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin();
295 i != points.end(); ++i) { 297 i != points.end(); ++i) {
296 298
297 const SparseOneDimensionalModel::Point &p(*i); 299 const SparseOneDimensionalModel::Point &p(*i);
300 SparseOneDimensionalModel::PointList::const_iterator j = i;
301 ++j;
298 302
299 int x = (p.frame - startFrame) / zoomLevel; 303 int x = (p.frame - startFrame) / zoomLevel;
300 float w = float(m_model->getResolution()) / zoomLevel; 304 float w = float(m_model->getResolution()) / zoomLevel;
301 int iw = w; 305 int iw = w;
302 if (iw < 2) { 306 if (iw < 2) {
303 if (w < 0.5) iw = 1; 307 if (iw < 1) {
304 else iw = 2; 308 iw = 2;
309 if (j != points.end()) {
310 int nx = ((*j).frame - startFrame) / zoomLevel;
311 if (nx < x + 3) iw = 1;
312 }
313 } else {
314 iw = 2;
315 }
305 } 316 }
306 317
307 if (p.frame == illuminateFrame) { 318 if (p.frame == illuminateFrame) {
308 paint.setPen(Qt::black); //!!! 319 paint.setPen(Qt::black); //!!!
309 } else { 320 } else {
317 // only draw if there's enough room from here to the next point 328 // only draw if there's enough room from here to the next point
318 329
319 int lw = paint.fontMetrics().width(p.label); 330 int lw = paint.fontMetrics().width(p.label);
320 bool good = true; 331 bool good = true;
321 332
322 SparseOneDimensionalModel::PointList::const_iterator j = i; 333 if (j != points.end()) {
323 if (++j != points.end()) {
324 int nx = (j->frame - startFrame) / zoomLevel; 334 int nx = (j->frame - startFrame) / zoomLevel;
325 if (nx >= x && nx - x - w - 3 <= lw) good = false; 335 if (nx >= x && nx - x - w - 3 <= lw) good = false;
326 } 336 }
327 337
328 if (good) { 338 if (good) {
332 } 342 }
333 } 343 }
334 } 344 }
335 } 345 }
336 346
347 void
348 TimeInstantLayer::drawStart(QMouseEvent *e)
349 {
350 std::cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << std::endl;
351
352 if (!m_model) return;
353
354 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame();
355 if (frame < 0) frame = 0;
356 m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point"));
357 m_model->addPoint(m_editingPoint);
358 }
359
360 void
361 TimeInstantLayer::drawDrag(QMouseEvent *e)
362 {
363 std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl;
364
365 if (!m_model) return;
366
367 long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame();
368 if (frame < 0) frame = 0;
369 m_model->deletePoint(m_editingPoint);
370 m_editingPoint.frame = frame;
371 m_model->addPoint(m_editingPoint);
372 }
373
374 void
375 TimeInstantLayer::drawEnd(QMouseEvent *e)
376 {
377 std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl;
378 if (!m_model) return;
379 }
380
337 QString 381 QString
338 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const 382 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const
339 { 383 {
340 return Layer::toXmlString(indent, extraAttributes + 384 return Layer::toXmlString(indent, extraAttributes +
341 QString(" colour=\"%1\"").arg(encodeColour(m_colour))); 385 QString(" colour=\"%1\"").arg(encodeColour(m_colour)));