diff layer/Layer.h @ 268:70537b0434c4

* Use a command for adding layer measurements
author Chris Cannam
date Tue, 26 Jun 2007 11:08:21 +0000
parents 4ed1446ad604
children 7b58c5e91f20
line wrap: on
line diff
--- a/layer/Layer.h	Thu Jun 21 16:12:00 2007 +0000
+++ b/layer/Layer.h	Tue Jun 26 11:08:21 2007 +0000
@@ -27,6 +27,7 @@
 #include <QMutex>
 
 #include <map>
+#include <set>
 
 class ZoomConstraint;
 class Model;
@@ -396,22 +397,54 @@
 
     void layerParametersChanged();
     void layerParameterRangesChanged();
+    void layerMeasurementRectsChanged();
     void layerNameChanged();
 
     void verticalZoomChanged();
 
 protected:
     struct MeasureRect {
+
         mutable QRect pixrect;
-        long startFrame; // only valid for a layer that hasTimeXAxis
+        bool haveFrames;
+        long startFrame; // only valid if haveFrames
         long endFrame;   // ditto
+
+        bool operator<(const MeasureRect &mr) const;
     };
 
-    typedef std::vector<MeasureRect> MeasureRectList; // should be x-ordered
-    MeasureRectList m_measureRectList;
+    class AddMeasurementRectCommand : public Command
+    {
+    public:
+        AddMeasurementRectCommand(Layer *layer, MeasureRect rect) :
+            m_layer(layer), m_rect(rect) { }
+
+        virtual QString getName() const;
+        virtual void execute();
+        virtual void unexecute();
+
+    private:
+        Layer *m_layer;
+        MeasureRect m_rect;
+    };
+
+    void addMeasureRect(const MeasureRect &r) {
+        m_measureRects.insert(r);
+        emit layerMeasurementRectsChanged();
+    }
+
+    void deleteMeasureRect(const MeasureRect &r) {
+        m_measureRects.erase(r); 
+        emit layerMeasurementRectsChanged();
+    }
+
+    typedef std::set<MeasureRect> MeasureRectSet;
+    MeasureRectSet m_measureRects;
     MeasureRect m_draggingRect;
     bool m_haveDraggingRect;
 
+    void paintMeasurementRect(View *v, QPainter &paint, MeasureRect &r);
+
 private:
     mutable QMutex m_dormancyMutex;
     mutable std::map<const void *, bool> m_dormancy;