Mercurial > hg > svgui
comparison layer/Layer.cpp @ 283:86a112b5b319
* Make it possible to "measure" a feature on the spectrogram by double-
clicking in measure mode
* Make shift-click-drag (for zoom to region) work in measure mode as well
as navigate mode. It would be nice to be able to shift-doubleclick to
zoom on a feature directly using a combination of these last two features,
but that isn't possible yet.
* Make Del delete the measurement under the mouse pointer.
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2007 15:36:37 +0000 |
parents | 3c402c6052f6 |
children | c0b9eec70639 |
comparison
equal
deleted
inserted
replaced
282:4edaff85875d | 283:86a112b5b319 |
---|---|
27 #include "base/PlayParameterRepository.h" | 27 #include "base/PlayParameterRepository.h" |
28 | 28 |
29 #include <cmath> | 29 #include <cmath> |
30 | 30 |
31 Layer::Layer() : | 31 Layer::Layer() : |
32 m_haveDraggingRect(false) | 32 m_haveDraggingRect(false), |
33 m_haveCurrentMeasureRect(false) | |
33 { | 34 { |
34 } | 35 } |
35 | 36 |
36 Layer::~Layer() | 37 Layer::~Layer() |
37 { | 38 { |
225 Layer::AddMeasurementRectCommand::unexecute() | 226 Layer::AddMeasurementRectCommand::unexecute() |
226 { | 227 { |
227 m_layer->deleteMeasureRectFromSet(m_rect); | 228 m_layer->deleteMeasureRectFromSet(m_rect); |
228 } | 229 } |
229 | 230 |
231 QString | |
232 Layer::DeleteMeasurementRectCommand::getName() const | |
233 { | |
234 return tr("Delete Measurement"); | |
235 } | |
236 | |
237 void | |
238 Layer::DeleteMeasurementRectCommand::execute() | |
239 { | |
240 m_layer->deleteMeasureRectFromSet(m_rect); | |
241 } | |
242 | |
243 void | |
244 Layer::DeleteMeasurementRectCommand::unexecute() | |
245 { | |
246 m_layer->addMeasureRectToSet(m_rect); | |
247 } | |
248 | |
230 void | 249 void |
231 Layer::measureStart(View *v, QMouseEvent *e) | 250 Layer::measureStart(View *v, QMouseEvent *e) |
232 { | 251 { |
233 m_draggingRect.pixrect = QRect(e->x(), e->y(), 0, 0); | 252 setMeasureRectFromPixrect(v, m_draggingRect, |
234 if (hasTimeXAxis()) { | 253 QRect(e->x(), e->y(), 0, 0)); |
235 m_draggingRect.haveFrames = true; | |
236 m_draggingRect.startFrame = v->getFrameForX(e->x()); | |
237 m_draggingRect.endFrame = m_draggingRect.startFrame; | |
238 } else { | |
239 m_draggingRect.haveFrames = false; | |
240 } | |
241 setMeasureRectYCoord(v, m_draggingRect, true, e->y()); | |
242 m_haveDraggingRect = true; | 254 m_haveDraggingRect = true; |
243 } | 255 } |
244 | 256 |
245 void | 257 void |
246 Layer::measureDrag(View *v, QMouseEvent *e) | 258 Layer::measureDrag(View *v, QMouseEvent *e) |
247 { | 259 { |
248 if (!m_haveDraggingRect) return; | 260 if (!m_haveDraggingRect) return; |
249 | 261 |
250 m_draggingRect.pixrect = QRect(m_draggingRect.pixrect.x(), | 262 setMeasureRectFromPixrect(v, m_draggingRect, |
251 m_draggingRect.pixrect.y(), | 263 QRect(m_draggingRect.pixrect.x(), |
252 e->x() - m_draggingRect.pixrect.x(), | 264 m_draggingRect.pixrect.y(), |
253 e->y() - m_draggingRect.pixrect.y()); | 265 e->x() - m_draggingRect.pixrect.x(), |
254 | 266 e->y() - m_draggingRect.pixrect.y())); |
255 setMeasureRectYCoord(v, m_draggingRect, false, e->y()); | |
256 | |
257 if (hasTimeXAxis()) { | |
258 m_draggingRect.endFrame = v->getFrameForX(e->x()); | |
259 } | |
260 } | 267 } |
261 | 268 |
262 void | 269 void |
263 Layer::measureEnd(View *v, QMouseEvent *e) | 270 Layer::measureEnd(View *v, QMouseEvent *e) |
264 { | 271 { |
265 if (!m_haveDraggingRect) return; | 272 if (!m_haveDraggingRect) return; |
266 measureDrag(v, e); | 273 measureDrag(v, e); |
274 | |
275 if (!m_draggingRect.pixrect.isNull()) { | |
276 CommandHistory::getInstance()->addCommand | |
277 (new AddMeasurementRectCommand(this, m_draggingRect)); | |
278 } | |
279 | |
280 m_haveDraggingRect = false; | |
281 } | |
282 | |
283 void | |
284 Layer::measureDoubleClick(View *v, QMouseEvent *e) | |
285 { | |
286 // nothing, in the base class | |
287 } | |
288 | |
289 void | |
290 Layer::deleteCurrentMeasureRect() | |
291 { | |
292 if (!m_haveCurrentMeasureRect) return; | |
267 | 293 |
294 MeasureRectSet::const_iterator focusRectItr = | |
295 findFocusedMeasureRect(m_currentMeasureRectPoint); | |
296 | |
297 if (focusRectItr == m_measureRects.end()) return; | |
298 | |
268 CommandHistory::getInstance()->addCommand | 299 CommandHistory::getInstance()->addCommand |
269 (new AddMeasurementRectCommand(this, m_draggingRect)); | 300 (new DeleteMeasurementRectCommand(this, *focusRectItr)); |
270 | |
271 m_haveDraggingRect = false; | |
272 } | |
273 | |
274 void | |
275 Layer::measureDoubleClick(View *v, QMouseEvent *e) | |
276 { | |
277 // nothing | |
278 } | 301 } |
279 | 302 |
280 void | 303 void |
281 Layer::paintMeasurementRects(View *v, QPainter &paint, | 304 Layer::paintMeasurementRects(View *v, QPainter &paint, |
282 bool showFocus, QPoint focusPoint) const | 305 bool showFocus, QPoint focusPoint) const |
292 } else if (showFocus) { | 315 } else if (showFocus) { |
293 | 316 |
294 focusRectItr = findFocusedMeasureRect(focusPoint); | 317 focusRectItr = findFocusedMeasureRect(focusPoint); |
295 } | 318 } |
296 | 319 |
320 m_haveCurrentMeasureRect = false; | |
321 | |
297 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); | 322 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); |
298 i != m_measureRects.end(); ++i) { | 323 i != m_measureRects.end(); ++i) { |
299 paintMeasurementRect(v, paint, *i, i == focusRectItr); | 324 |
325 bool focused = (i == focusRectItr); | |
326 paintMeasurementRect(v, paint, *i, focused); | |
327 | |
328 if (focused) { | |
329 m_haveCurrentMeasureRect = true; | |
330 m_currentMeasureRectPoint = focusPoint; | |
331 } | |
300 } | 332 } |
301 } | 333 } |
302 | 334 |
303 bool | 335 bool |
304 Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const | 336 Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const |
365 r.startY = double(y) / double(v->height()); | 397 r.startY = double(y) / double(v->height()); |
366 r.endY = r.startY; | 398 r.endY = r.startY; |
367 } else { | 399 } else { |
368 r.endY = double(y) / double(v->height()); | 400 r.endY = double(y) / double(v->height()); |
369 } | 401 } |
402 } | |
403 | |
404 void | |
405 Layer::setMeasureRectFromPixrect(View *v, MeasureRect &r, QRect pixrect) const | |
406 { | |
407 r.pixrect = pixrect; | |
408 r.haveFrames = hasTimeXAxis(); | |
409 if (r.haveFrames) { | |
410 r.startFrame = v->getFrameForX(pixrect.x()); | |
411 r.endFrame = v->getFrameForX(pixrect.x() + pixrect.width()); | |
412 } | |
413 setMeasureRectYCoord(v, r, true, pixrect.y()); | |
414 setMeasureRectYCoord(v, r, false, pixrect.y() + pixrect.height()); | |
370 } | 415 } |
371 | 416 |
372 Layer::MeasureRectSet::const_iterator | 417 Layer::MeasureRectSet::const_iterator |
373 Layer::findFocusedMeasureRect(QPoint focusPoint) const | 418 Layer::findFocusedMeasureRect(QPoint focusPoint) const |
374 { | 419 { |