Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp Thu Jan 26 11:56:09 2006 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Jan 26 16:15:40 2006 +0000 @@ -17,12 +17,14 @@ #include "model/SparseOneDimensionalModel.h" #include <QPainter> +#include <QMouseEvent> #include <iostream> TimeInstantLayer::TimeInstantLayer(View *w) : Layer(w), m_model(0), + m_editingPoint(0, tr("New Point")), m_colour(QColor(200, 50, 255)) { m_view->addLayer(this); @@ -295,13 +297,22 @@ i != points.end(); ++i) { const SparseOneDimensionalModel::Point &p(*i); + SparseOneDimensionalModel::PointList::const_iterator j = i; + ++j; int x = (p.frame - startFrame) / zoomLevel; float w = float(m_model->getResolution()) / zoomLevel; int iw = w; if (iw < 2) { - if (w < 0.5) iw = 1; - else iw = 2; + if (iw < 1) { + iw = 2; + if (j != points.end()) { + int nx = ((*j).frame - startFrame) / zoomLevel; + if (nx < x + 3) iw = 1; + } + } else { + iw = 2; + } } if (p.frame == illuminateFrame) { @@ -319,8 +330,7 @@ int lw = paint.fontMetrics().width(p.label); bool good = true; - SparseOneDimensionalModel::PointList::const_iterator j = i; - if (++j != points.end()) { + if (j != points.end()) { int nx = (j->frame - startFrame) / zoomLevel; if (nx >= x && nx - x - w - 3 <= lw) good = false; } @@ -334,6 +344,40 @@ } } +void +TimeInstantLayer::drawStart(QMouseEvent *e) +{ + std::cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << std::endl; + + if (!m_model) return; + + long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); + if (frame < 0) frame = 0; + m_editingPoint = SparseOneDimensionalModel::Point(frame, tr("New Point")); + m_model->addPoint(m_editingPoint); +} + +void +TimeInstantLayer::drawDrag(QMouseEvent *e) +{ + std::cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << std::endl; + + if (!m_model) return; + + long frame = e->x() * m_view->getZoomLevel() + m_view->getStartFrame(); + if (frame < 0) frame = 0; + m_model->deletePoint(m_editingPoint); + m_editingPoint.frame = frame; + m_model->addPoint(m_editingPoint); +} + +void +TimeInstantLayer::drawEnd(QMouseEvent *e) +{ + std::cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << std::endl; + if (!m_model) return; +} + QString TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const {