diff layer/TimeValueLayer.cpp @ 43:78515b1e29eb

* Rejig project file a bit to do pkg-config detection &c and change some HAVE_* symbol names accordingly * Add selection move/resize/delete * First stubs for add layer / pane commands
author Chris Cannam
date Wed, 01 Mar 2006 18:13:01 +0000
parents 1bdf285c4eac
children ad214997dddb
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp	Mon Feb 27 17:34:41 2006 +0000
+++ b/layer/TimeValueLayer.cpp	Wed Mar 01 18:13:01 2006 +0000
@@ -695,6 +695,63 @@
     m_editing = false;
 }
 
+void
+TimeValueLayer::moveSelection(Selection s, size_t newStartFrame)
+{
+    SparseTimeValueModel::EditCommand *command =
+	new SparseTimeValueModel::EditCommand(m_model,
+					      tr("Drag Selection"));
+
+    SparseTimeValueModel::PointList points =
+	m_model->getPoints(s.getStartFrame(), s.getEndFrame());
+
+    for (SparseTimeValueModel::PointList::iterator i = points.begin();
+	 i != points.end(); ++i) {
+
+	if (s.contains(i->frame)) {
+	    SparseTimeValueModel::Point newPoint(*i);
+	    newPoint.frame = i->frame + newStartFrame - s.getStartFrame();
+	    command->deletePoint(*i);
+	    command->addPoint(newPoint);
+	}
+    }
+
+    command->finish();
+}
+
+void
+TimeValueLayer::resizeSelection(Selection s, Selection newSize)
+{
+    SparseTimeValueModel::EditCommand *command =
+	new SparseTimeValueModel::EditCommand(m_model,
+					      tr("Resize Selection"));
+
+    SparseTimeValueModel::PointList points =
+	m_model->getPoints(s.getStartFrame(), s.getEndFrame());
+
+    double ratio =
+	double(newSize.getEndFrame() - newSize.getStartFrame()) /
+	double(s.getEndFrame() - s.getStartFrame());
+
+    for (SparseTimeValueModel::PointList::iterator i = points.begin();
+	 i != points.end(); ++i) {
+
+	if (s.contains(i->frame)) {
+
+	    double target = i->frame;
+	    target = newSize.getStartFrame() + 
+		double(target - s.getStartFrame()) * ratio;
+
+	    SparseTimeValueModel::Point newPoint(*i);
+	    newPoint.frame = lrint(target);
+	    command->deletePoint(*i);
+	    command->addPoint(newPoint);
+	}
+    }
+
+    command->finish();
+}
+
 QString
 TimeValueLayer::toXmlString(QString indent, QString extraAttributes) const
 {