Mercurial > hg > svgui
comparison layer/Layer.cpp @ 267:4ed1446ad604
* more on measurement tool -- pull out some logic from pane to layer &c
still more to do
author | Chris Cannam |
---|---|
date | Thu, 21 Jun 2007 16:12:00 +0000 |
parents | 6d113226bb4c |
children | 70537b0434c4 |
comparison
equal
deleted
inserted
replaced
266:aee39d8c0b83 | 267:4ed1446ad604 |
---|---|
18 #include "data/model/Model.h" | 18 #include "data/model/Model.h" |
19 | 19 |
20 #include <iostream> | 20 #include <iostream> |
21 | 21 |
22 #include <QMutexLocker> | 22 #include <QMutexLocker> |
23 #include <QMouseEvent> | |
23 | 24 |
24 #include "LayerFactory.h" | 25 #include "LayerFactory.h" |
25 #include "base/PlayParameterRepository.h" | 26 #include "base/PlayParameterRepository.h" |
26 | 27 |
27 Layer::Layer() | 28 Layer::Layer() : |
29 m_haveDraggingRect(false) | |
28 { | 30 { |
29 } | 31 } |
30 | 32 |
31 Layer::~Layer() | 33 Layer::~Layer() |
32 { | 34 { |
121 setLayerDormant(view, !show); | 123 setLayerDormant(view, !show); |
122 emit layerParametersChanged(); | 124 emit layerParametersChanged(); |
123 } | 125 } |
124 | 126 |
125 bool | 127 bool |
126 Layer::getXScaleValue(View *v, int x, float &value, QString &unit) const | 128 Layer::getXScaleValue(const View *v, int x, float &value, QString &unit) const |
127 { | 129 { |
128 if (!hasTimeXAxis()) return false; | 130 if (!hasTimeXAxis()) return false; |
129 | 131 |
130 const Model *m = getModel(); | 132 const Model *m = getModel(); |
131 if (!m) return false; | 133 if (!m) return false; |
133 value = float(v->getFrameForX(x)) / m->getSampleRate(); | 135 value = float(v->getFrameForX(x)) / m->getSampleRate(); |
134 unit = "s"; | 136 unit = "s"; |
135 return true; | 137 return true; |
136 } | 138 } |
137 | 139 |
140 void | |
141 Layer::measureStart(View *v, QMouseEvent *e) | |
142 { | |
143 m_draggingRect.pixrect = QRect(e->x(), e->y(), 0, 0); | |
144 if (hasTimeXAxis()) { | |
145 m_draggingRect.startFrame = v->getFrameForX(e->x()); | |
146 m_draggingRect.endFrame = m_draggingRect.startFrame; | |
147 } | |
148 m_haveDraggingRect = true; | |
149 } | |
150 | |
151 void | |
152 Layer::measureDrag(View *v, QMouseEvent *e) | |
153 { | |
154 if (!m_haveDraggingRect) return; | |
155 m_draggingRect.pixrect = QRect(m_draggingRect.pixrect.x(), | |
156 m_draggingRect.pixrect.y(), | |
157 e->x() - m_draggingRect.pixrect.x(), | |
158 e->y() - m_draggingRect.pixrect.y()); | |
159 if (hasTimeXAxis()) { | |
160 m_draggingRect.endFrame = v->getFrameForX(e->x()); | |
161 } | |
162 } | |
163 | |
164 void | |
165 Layer::measureEnd(View *v, QMouseEvent *e) | |
166 { | |
167 //!!! command | |
168 if (!m_haveDraggingRect) return; | |
169 measureDrag(v, e); | |
170 m_measureRectList.push_back(m_draggingRect); | |
171 m_haveDraggingRect = false; | |
172 } | |
173 | |
174 void | |
175 Layer::paintMeasurementRects(View *v, QPainter &paint) const | |
176 { | |
177 if (m_haveDraggingRect) { | |
178 v->drawMeasurementRect(paint, this, m_draggingRect.pixrect); | |
179 } | |
180 | |
181 bool timex = hasTimeXAxis(); | |
182 | |
183 for (MeasureRectList::const_iterator i = m_measureRectList.begin(); | |
184 i != m_measureRectList.end(); ++i) { | |
185 | |
186 if (timex) { | |
187 int x0 = v->getXForFrame(i->startFrame); | |
188 int x1 = v->getXForFrame(i->endFrame); | |
189 QRect pr = QRect(x0, i->pixrect.y(), x1 - x0, i->pixrect.height()); | |
190 i->pixrect = pr; | |
191 } | |
192 | |
193 v->drawMeasurementRect(paint, this, i->pixrect); | |
194 } | |
195 } | |
196 |