Mercurial > hg > svgui
comparison view/Pane.cpp @ 645:c8f45afb83d5 tonioni
added NoteEdit tool mode
author | gyorgyf |
---|---|
date | Sat, 15 Jun 2013 16:16:24 +0100 |
parents | 5c9dcec5f3e9 |
children | ba76130ed7e5 |
comparison
equal
deleted
inserted
replaced
635:5c9dcec5f3e9 | 645:c8f45afb83d5 |
---|---|
165 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper(); | 165 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper(); |
166 if (rm) m_vthumb->setRangeMapper(rm); | 166 if (rm) m_vthumb->setRangeMapper(rm); |
167 } | 167 } |
168 | 168 |
169 m_reset = new NotifyingPushButton; | 169 m_reset = new NotifyingPushButton; |
170 m_reset->setFlat(true); | 170 m_reset->setFlat(true); |
171 m_reset->setCursor(Qt::ArrowCursor); | 171 m_reset->setCursor(Qt::ArrowCursor); |
172 m_reset->setFixedHeight(16); | 172 m_reset->setFixedHeight(16); |
173 m_reset->setFixedWidth(16); | 173 m_reset->setFixedWidth(16); |
174 m_reset->setIcon(QPixmap(":/icons/zoom-reset.png")); | 174 m_reset->setIcon(QPixmap(":/icons/zoom-reset.png")); |
175 m_reset->setToolTip(tr("Reset zoom to default")); | 175 m_reset->setToolTip(tr("Reset zoom to default")); |
334 if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) { | 334 if (m_manager && !m_manager->shouldIlluminateLocalFeatures()) { |
335 return false; | 335 return false; |
336 } | 336 } |
337 | 337 |
338 if (layer == getSelectedLayer() && | 338 if (layer == getSelectedLayer() && |
339 !shouldIlluminateLocalSelection(discard, b0, b1)) { | 339 !shouldIlluminateLocalSelection(discard, b0, b1)) { |
340 | 340 |
341 pos = m_identifyPoint; | 341 pos = m_identifyPoint; |
342 return m_identifyFeatures; | 342 return m_identifyFeatures; |
343 } | 343 } |
344 | 344 |
345 return false; | 345 return false; |
346 } | 346 } |
347 | 347 |
348 bool | 348 bool |
349 Pane::shouldIlluminateLocalSelection(QPoint &pos, | 349 Pane::shouldIlluminateLocalSelection(QPoint &pos, |
350 bool &closeToLeft, | 350 bool &closeToLeft, |
351 bool &closeToRight) const | 351 bool &closeToRight) const |
352 { | 352 { |
353 if (m_identifyFeatures && | 353 if (m_identifyFeatures && |
354 m_manager && | 354 m_manager && |
355 m_manager->getToolMode() == ViewManager::EditMode && | 355 m_manager->getToolMode() == ViewManager::EditMode && |
356 !m_manager->getSelections().empty() && | 356 !m_manager->getSelections().empty() && |
357 !selectionIsBeingEdited()) { | 357 !selectionIsBeingEdited()) { |
358 | 358 |
359 Selection s(getSelectionAt(m_identifyPoint.x(), | 359 Selection s(getSelectionAt(m_identifyPoint.x(), |
360 closeToLeft, closeToRight)); | 360 closeToLeft, closeToRight)); |
361 | 361 |
362 if (!s.isEmpty()) { | 362 if (!s.isEmpty()) { |
363 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { | 363 if (getSelectedLayer() && getSelectedLayer()->isLayerEditable()) { |
364 | 364 |
365 pos = m_identifyPoint; | 365 pos = m_identifyPoint; |
366 return true; | 366 return true; |
367 } | 367 } |
368 } | 368 } |
369 } | 369 } |
370 | 370 |
371 return false; | 371 return false; |
372 } | 372 } |
373 | 373 |
374 bool | 374 bool |
375 Pane::selectionIsBeingEdited() const | 375 Pane::selectionIsBeingEdited() const |
376 { | 376 { |
377 if (!m_editingSelection.isEmpty()) { | 377 if (!m_editingSelection.isEmpty()) { |
378 if (m_mousePos != m_clickPos && | 378 if (m_mousePos != m_clickPos && |
379 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { | 379 getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { |
380 return true; | 380 return true; |
381 } | 381 } |
382 } | 382 } |
383 return false; | 383 return false; |
384 } | 384 } |
385 | 385 |
386 void | 386 void |
623 | 623 |
624 if (!scaleLayer) m_scaleWidth = 0; | 624 if (!scaleLayer) m_scaleWidth = 0; |
625 | 625 |
626 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { | 626 if (m_scaleWidth > 0 && r.left() < m_scaleWidth) { |
627 | 627 |
628 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); | 628 // Profiler profiler("Pane::paintEvent - painting vertical scale", true); |
629 | 629 |
630 // SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl; | 630 // SVDEBUG << "Pane::paintEvent: calling paint.save() in vertical scale block" << endl; |
631 paint.save(); | 631 paint.save(); |
632 | 632 |
633 paint.setPen(getForeground()); | 633 paint.setPen(getForeground()); |
634 paint.setBrush(getBackground()); | 634 paint.setBrush(getBackground()); |
635 paint.drawRect(0, -1, m_scaleWidth, height()+1); | 635 paint.drawRect(0, -1, m_scaleWidth, height()+1); |
646 void | 646 void |
647 Pane::drawFeatureDescription(Layer *topLayer, QPainter &paint) | 647 Pane::drawFeatureDescription(Layer *topLayer, QPainter &paint) |
648 { | 648 { |
649 QPoint pos = m_identifyPoint; | 649 QPoint pos = m_identifyPoint; |
650 QString desc = topLayer->getFeatureDescription(this, pos); | 650 QString desc = topLayer->getFeatureDescription(this, pos); |
651 | 651 |
652 if (desc != "") { | 652 if (desc != "") { |
653 | 653 |
654 paint.save(); | 654 paint.save(); |
655 | 655 |
656 int tabStop = | 656 int tabStop = |
723 int y = height() - fontHeight + fontAscent - 6; | 723 int y = height() - fontHeight + fontAscent - 6; |
724 | 724 |
725 LayerList::iterator vi = m_layers.end(); | 725 LayerList::iterator vi = m_layers.end(); |
726 | 726 |
727 if (vi != m_layers.begin()) { | 727 if (vi != m_layers.begin()) { |
728 | 728 |
729 switch ((*--vi)->getPreferredFrameCountPosition()) { | 729 switch ((*--vi)->getPreferredFrameCountPosition()) { |
730 | 730 |
731 case Layer::PositionTop: | 731 case Layer::PositionTop: |
732 y = fontAscent + 6; | 732 y = fontAscent + 6; |
733 break; | 733 break; |
890 if (m_manager->getZoomWheelsEnabled()) { | 890 if (m_manager->getZoomWheelsEnabled()) { |
891 llx -= 36; | 891 llx -= 36; |
892 } | 892 } |
893 | 893 |
894 if (r.x() + r.width() >= llx - fontAscent - 3) { | 894 if (r.x() + r.width() >= llx - fontAscent - 3) { |
895 | 895 |
896 for (size_t i = 0; i < texts.size(); ++i) { | 896 for (size_t i = 0; i < texts.size(); ++i) { |
897 | 897 |
898 // std::cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << std::endl; | 898 // std::cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << std::endl; |
899 | 899 |
900 if (i + 1 == texts.size()) { | 900 if (i + 1 == texts.size()) { |
1145 | 1145 |
1146 if (!m_manager) return Selection(); | 1146 if (!m_manager) return Selection(); |
1147 | 1147 |
1148 long testFrame = getFrameForX(x - 5); | 1148 long testFrame = getFrameForX(x - 5); |
1149 if (testFrame < 0) { | 1149 if (testFrame < 0) { |
1150 testFrame = getFrameForX(x); | 1150 testFrame = getFrameForX(x); |
1151 if (testFrame < 0) return Selection(); | 1151 if (testFrame < 0) return Selection(); |
1152 } | 1152 } |
1153 | 1153 |
1154 Selection selection = m_manager->getContainingSelection(testFrame, true); | 1154 Selection selection = m_manager->getContainingSelection(testFrame, true); |
1155 if (selection.isEmpty()) return selection; | 1155 if (selection.isEmpty()) return selection; |
1156 | 1156 |
1301 if (mode == ViewManager::NavigateMode || | 1301 if (mode == ViewManager::NavigateMode || |
1302 (e->buttons() & Qt::MidButton) || | 1302 (e->buttons() & Qt::MidButton) || |
1303 (mode == ViewManager::MeasureMode && | 1303 (mode == ViewManager::MeasureMode && |
1304 (e->buttons() & Qt::LeftButton) && m_shiftPressed)) { | 1304 (e->buttons() & Qt::LeftButton) && m_shiftPressed)) { |
1305 | 1305 |
1306 if (mode != ViewManager::NavigateMode) { | 1306 if (mode != ViewManager::NavigateMode) { |
1307 setCursor(Qt::PointingHandCursor); | 1307 setCursor(Qt::PointingHandCursor); |
1308 } | 1308 } |
1309 | 1309 |
1310 m_navigating = true; | 1310 m_navigating = true; |
1311 m_dragCentreFrame = m_centreFrame; | 1311 m_dragCentreFrame = m_centreFrame; |
1312 m_dragStartMinValue = 0; | 1312 m_dragStartMinValue = 0; |
1313 | 1313 |
1314 float vmin, vmax, dmin, dmax; | 1314 float vmin, vmax, dmin, dmax; |
1315 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { | 1315 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { |
1316 m_dragStartMinValue = dmin; | 1316 m_dragStartMinValue = dmin; |
1318 | 1318 |
1319 } else if (mode == ViewManager::SelectMode) { | 1319 } else if (mode == ViewManager::SelectMode) { |
1320 | 1320 |
1321 if (!hasTopLayerTimeXAxis()) return; | 1321 if (!hasTopLayerTimeXAxis()) return; |
1322 | 1322 |
1323 bool closeToLeft = false, closeToRight = false; | 1323 bool closeToLeft = false, closeToRight = false; |
1324 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight); | 1324 Selection selection = getSelectionAt(e->x(), closeToLeft, closeToRight); |
1325 | 1325 |
1326 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { | 1326 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { |
1327 | 1327 |
1328 m_manager->removeSelection(selection); | 1328 m_manager->removeSelection(selection); |
1329 | 1329 |
1330 if (closeToLeft) { | 1330 if (closeToLeft) { |
1331 m_selectionStartFrame = selection.getEndFrame(); | 1331 m_selectionStartFrame = selection.getEndFrame(); |
1332 } else { | 1332 } else { |
1333 m_selectionStartFrame = selection.getStartFrame(); | 1333 m_selectionStartFrame = selection.getStartFrame(); |
1334 } | 1334 } |
1335 | 1335 |
1336 m_manager->setInProgressSelection(selection, false); | 1336 m_manager->setInProgressSelection(selection, false); |
1337 m_resizing = true; | 1337 m_resizing = true; |
1338 | 1338 |
1339 } else { | 1339 } else { |
1340 | 1340 |
1341 int mouseFrame = getFrameForX(e->x()); | 1341 int mouseFrame = getFrameForX(e->x()); |
1342 size_t resolution = 1; | 1342 size_t resolution = 1; |
1343 int snapFrame = mouseFrame; | 1343 int snapFrame = mouseFrame; |
1344 | 1344 |
1345 Layer *layer = getSelectedLayer(); | 1345 Layer *layer = getSelectedLayer(); |
1346 if (layer && !m_shiftPressed) { | 1346 if (layer && !m_shiftPressed) { |
1347 layer->snapToFeatureFrame(this, snapFrame, | 1347 layer->snapToFeatureFrame(this, snapFrame, |
1348 resolution, Layer::SnapLeft); | 1348 resolution, Layer::SnapLeft); |
1349 } | 1349 } |
1350 | 1350 |
1351 if (snapFrame < 0) snapFrame = 0; | 1351 if (snapFrame < 0) snapFrame = 0; |
1352 m_selectionStartFrame = snapFrame; | 1352 m_selectionStartFrame = snapFrame; |
1353 if (m_manager) { | 1353 if (m_manager) { |
1354 m_manager->setInProgressSelection | 1354 m_manager->setInProgressSelection |
1355 (Selection(alignToReference(snapFrame), | 1355 (Selection(alignToReference(snapFrame), |
1356 alignToReference(snapFrame + resolution)), | 1356 alignToReference(snapFrame + resolution)), |
1357 !m_ctrlPressed); | 1357 !m_ctrlPressed); |
1358 } | 1358 } |
1359 | 1359 |
1360 m_resizing = false; | 1360 m_resizing = false; |
1361 } | 1361 } |
1362 | 1362 |
1363 update(); | 1363 update(); |
1364 | 1364 |
1365 } else if (mode == ViewManager::DrawMode) { | 1365 } else if (mode == ViewManager::DrawMode) { |
1366 | 1366 |
1367 Layer *layer = getSelectedLayer(); | 1367 Layer *layer = getSelectedLayer(); |
1368 if (layer && layer->isLayerEditable()) { | 1368 if (layer && layer->isLayerEditable()) { |
1369 layer->drawStart(this, e); | 1369 layer->drawStart(this, e); |
1370 } | 1370 } |
1371 | 1371 |
1372 } else if (mode == ViewManager::EraseMode) { | 1372 } else if (mode == ViewManager::EraseMode) { |
1373 | 1373 |
1374 Layer *layer = getSelectedLayer(); | 1374 Layer *layer = getSelectedLayer(); |
1375 if (layer && layer->isLayerEditable()) { | 1375 if (layer && layer->isLayerEditable()) { |
1376 layer->eraseStart(this, e); | 1376 layer->eraseStart(this, e); |
1377 } | 1377 } |
1378 | 1378 |
1379 } else if (mode == ViewManager::EditMode) { | 1379 // GF: handle mouse press for NoteEditMode |
1380 | 1380 } else if (mode == ViewManager::NoteEditMode) { |
1381 std::cerr << "mouse pressed in edit mode" << std::endl; | 1381 |
1382 std::cerr << "mouse pressed in note edit mode" << std::endl; | |
1382 Layer *layer = getSelectedLayer(); | 1383 Layer *layer = getSelectedLayer(); |
1383 if (layer && layer->isLayerEditable()) { | 1384 if (layer && layer->isLayerEditable()) { |
1384 layer->splitStart(this, e); | 1385 layer->splitStart(this, e); |
1385 } | 1386 } |
1386 | 1387 |
1388 } else if (mode == ViewManager::EditMode) { | |
1389 | |
1387 // Do nothing here -- we'll do it in mouseMoveEvent when the | 1390 // Do nothing here -- we'll do it in mouseMoveEvent when the |
1388 // drag threshold has been passed | 1391 // drag threshold has been passed |
1389 | 1392 |
1390 } else if (mode == ViewManager::MeasureMode) { | 1393 } else if (mode == ViewManager::MeasureMode) { |
1391 | 1394 |
1410 if (m_manager) mode = m_manager->getToolMode(); | 1413 if (m_manager) mode = m_manager->getToolMode(); |
1411 | 1414 |
1412 m_releasing = true; | 1415 m_releasing = true; |
1413 | 1416 |
1414 if (m_clickedInRange) { | 1417 if (m_clickedInRange) { |
1415 mouseMoveEvent(e); | 1418 mouseMoveEvent(e); |
1416 } | 1419 } |
1417 | 1420 |
1418 if (m_navigating || mode == ViewManager::NavigateMode) { | 1421 if (m_navigating || mode == ViewManager::NavigateMode) { |
1419 | 1422 |
1420 m_navigating = false; | 1423 m_navigating = false; |
1421 | 1424 |
1422 if (mode != ViewManager::NavigateMode) { | 1425 if (mode != ViewManager::NavigateMode) { |
1423 // restore cursor | 1426 // restore cursor |
1424 toolModeChanged(); | 1427 toolModeChanged(); |
1425 } | 1428 } |
1426 | 1429 |
1427 if (m_shiftPressed) { | 1430 if (m_shiftPressed) { |
1428 | 1431 |
1429 int x0 = std::min(m_clickPos.x(), m_mousePos.x()); | 1432 int x0 = std::min(m_clickPos.x(), m_mousePos.x()); |
1430 int x1 = std::max(m_clickPos.x(), m_mousePos.x()); | 1433 int x1 = std::max(m_clickPos.x(), m_mousePos.x()); |
1431 | 1434 |
1432 int y0 = std::min(m_clickPos.y(), m_mousePos.y()); | 1435 int y0 = std::min(m_clickPos.y(), m_mousePos.y()); |
1433 int y1 = std::max(m_clickPos.y(), m_mousePos.y()); | 1436 int y1 = std::max(m_clickPos.y(), m_mousePos.y()); |
1434 | 1437 |
1435 zoomToRegion(x0, y0, x1, y1); | 1438 zoomToRegion(x0, y0, x1, y1); |
1436 } | 1439 } |
1437 | 1440 |
1438 } else if (mode == ViewManager::SelectMode) { | 1441 } else if (mode == ViewManager::SelectMode) { |
1439 | 1442 |
1440 if (!hasTopLayerTimeXAxis()) { | 1443 if (!hasTopLayerTimeXAxis()) { |
1441 m_releasing = false; | 1444 m_releasing = false; |
1442 return; | 1445 return; |
1443 } | 1446 } |
1444 | 1447 |
1445 if (m_manager && m_manager->haveInProgressSelection()) { | 1448 if (m_manager && m_manager->haveInProgressSelection()) { |
1446 | 1449 |
1447 bool exclusive; | 1450 bool exclusive; |
1448 Selection selection = m_manager->getInProgressSelection(exclusive); | 1451 Selection selection = m_manager->getInProgressSelection(exclusive); |
1449 | 1452 |
1450 if (selection.getEndFrame() < selection.getStartFrame() + 2) { | 1453 if (selection.getEndFrame() < selection.getStartFrame() + 2) { |
1451 selection = Selection(); | 1454 selection = Selection(); |
1452 } | 1455 } |
1453 | 1456 |
1454 m_manager->clearInProgressSelection(); | 1457 m_manager->clearInProgressSelection(); |
1455 | 1458 |
1456 if (exclusive) { | 1459 if (exclusive) { |
1457 m_manager->setSelection(selection); | 1460 m_manager->setSelection(selection); |
1458 } else { | 1461 } else { |
1459 m_manager->addSelection(selection); | 1462 m_manager->addSelection(selection); |
1460 } | 1463 } |
1461 } | 1464 } |
1462 | 1465 |
1463 update(); | 1466 update(); |
1464 | 1467 |
1465 } else if (mode == ViewManager::DrawMode) { | 1468 } else if (mode == ViewManager::DrawMode) { |
1466 | 1469 |
1467 Layer *layer = getSelectedLayer(); | 1470 Layer *layer = getSelectedLayer(); |
1468 if (layer && layer->isLayerEditable()) { | 1471 if (layer && layer->isLayerEditable()) { |
1469 layer->drawEnd(this, e); | 1472 layer->drawEnd(this, e); |
1470 update(); | 1473 update(); |
1471 } | 1474 } |
1472 | 1475 |
1473 } else if (mode == ViewManager::EraseMode) { | 1476 } else if (mode == ViewManager::EraseMode) { |
1474 | 1477 |
1475 Layer *layer = getSelectedLayer(); | 1478 Layer *layer = getSelectedLayer(); |
1476 if (layer && layer->isLayerEditable()) { | 1479 if (layer && layer->isLayerEditable()) { |
1477 layer->eraseEnd(this, e); | 1480 layer->eraseEnd(this, e); |
1478 update(); | 1481 update(); |
1479 } | 1482 } |
1480 | 1483 |
1481 } else if (mode == ViewManager::EditMode) { | 1484 } else if (mode == ViewManager::NoteEditMode) { |
1482 | 1485 |
1483 //GF: temporary | 1486 //GF: handle mouse release for NoteEditMode (note: works but will need to re-think this a bit later) |
1484 Layer *layer = getSelectedLayer(); | 1487 Layer *layer = getSelectedLayer(); |
1485 if (layer && layer->isLayerEditable()) { | 1488 if (layer && layer->isLayerEditable()) { |
1486 layer->splitEnd(this, e); | 1489 layer->splitEnd(this, e); |
1487 update(); } | 1490 update(); } |
1488 | 1491 |
1494 update(); | 1497 update(); |
1495 } | 1498 } |
1496 } | 1499 } |
1497 } | 1500 } |
1498 | 1501 |
1502 } else if (mode == ViewManager::EditMode) { | |
1503 | |
1504 // GF: edited this previously, but restored to original state | |
1505 if (m_editing) { | |
1506 if (!editSelectionEnd(e)) { | |
1507 Layer *layer = getSelectedLayer(); | |
1508 if (layer && layer->isLayerEditable()) { | |
1509 layer->editEnd(this, e); | |
1510 update(); | |
1511 } | |
1512 } | |
1513 } | |
1514 | |
1499 } else if (mode == ViewManager::MeasureMode) { | 1515 } else if (mode == ViewManager::MeasureMode) { |
1500 | 1516 |
1501 Layer *layer = getTopLayer(); | 1517 Layer *layer = getTopLayer(); |
1502 if (layer) layer->measureEnd(this, e); | 1518 if (layer) layer->measureEnd(this, e); |
1503 if (m_measureCursor1) setCursor(*m_measureCursor1); | 1519 if (m_measureCursor1) setCursor(*m_measureCursor1); |
1540 | 1556 |
1541 QPoint prevPoint = m_identifyPoint; | 1557 QPoint prevPoint = m_identifyPoint; |
1542 m_identifyPoint = e->pos(); | 1558 m_identifyPoint = e->pos(); |
1543 | 1559 |
1544 if (!m_clickedInRange) { | 1560 if (!m_clickedInRange) { |
1545 | 1561 |
1546 if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) { | 1562 if (mode == ViewManager::SelectMode && hasTopLayerTimeXAxis()) { |
1547 bool closeToLeft = false, closeToRight = false; | 1563 bool closeToLeft = false, closeToRight = false; |
1548 getSelectionAt(e->x(), closeToLeft, closeToRight); | 1564 getSelectionAt(e->x(), closeToLeft, closeToRight); |
1549 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { | 1565 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) { |
1550 setCursor(Qt::SizeHorCursor); | 1566 setCursor(Qt::SizeHorCursor); |
1551 } else { | 1567 } else { |
1552 setCursor(Qt::ArrowCursor); | 1568 setCursor(Qt::ArrowCursor); |
1553 } | 1569 } |
1554 } | 1570 } |
1555 | 1571 |
1556 if (!m_manager->isPlaying()) { | 1572 if (!m_manager->isPlaying()) { |
1557 | 1573 |
1558 bool updating = false; | 1574 bool updating = false; |
1559 | 1575 |
1579 update(); | 1595 update(); |
1580 } | 1596 } |
1581 } | 1597 } |
1582 } | 1598 } |
1583 | 1599 |
1584 return; | 1600 return; |
1585 } | 1601 } |
1586 | 1602 |
1587 if (m_navigating || mode == ViewManager::NavigateMode) { | 1603 if (m_navigating || mode == ViewManager::NavigateMode) { |
1588 | 1604 |
1589 if (m_shiftPressed) { | 1605 if (m_shiftPressed) { |
1590 | 1606 |
1591 m_mousePos = e->pos(); | 1607 m_mousePos = e->pos(); |
1592 update(); | 1608 update(); |
1593 | 1609 |
1594 } else { | 1610 } else { |
1595 | 1611 |
1596 dragTopLayer(e); | 1612 dragTopLayer(e); |
1597 } | 1613 } |
1598 | 1614 |
1599 } else if (mode == ViewManager::SelectMode) { | 1615 } else if (mode == ViewManager::SelectMode) { |
1602 | 1618 |
1603 dragExtendSelection(e); | 1619 dragExtendSelection(e); |
1604 | 1620 |
1605 } else if (mode == ViewManager::DrawMode) { | 1621 } else if (mode == ViewManager::DrawMode) { |
1606 | 1622 |
1607 Layer *layer = getSelectedLayer(); | 1623 Layer *layer = getSelectedLayer(); |
1608 if (layer && layer->isLayerEditable()) { | 1624 if (layer && layer->isLayerEditable()) { |
1609 layer->drawDrag(this, e); | 1625 layer->drawDrag(this, e); |
1610 } | 1626 } |
1611 | 1627 |
1612 } else if (mode == ViewManager::EraseMode) { | 1628 } else if (mode == ViewManager::EraseMode) { |
1613 | 1629 |
1614 Layer *layer = getSelectedLayer(); | 1630 Layer *layer = getSelectedLayer(); |
1615 if (layer && layer->isLayerEditable()) { | 1631 if (layer && layer->isLayerEditable()) { |
1616 layer->eraseDrag(this, e); | 1632 layer->eraseDrag(this, e); |
1617 } | 1633 } |
1618 | 1634 |
1619 } else if (mode == ViewManager::EditMode) { | 1635 } else if (mode == ViewManager::EditMode) { |
1620 | 1636 |
1621 bool resist = true; | 1637 bool resist = true; |
1622 | 1638 |
1625 // ... but don't set it false if shift has been | 1641 // ... but don't set it false if shift has been |
1626 // released -- we want the state when we started | 1642 // released -- we want the state when we started |
1627 // dragging to be used most of the time | 1643 // dragging to be used most of the time |
1628 } | 1644 } |
1629 | 1645 |
1630 if (m_shiftPressed) resist = false; | 1646 if (m_shiftPressed) resist = false; |
1631 | 1647 |
1632 m_dragMode = updateDragMode | 1648 m_dragMode = updateDragMode |
1633 (m_dragMode, | 1649 (m_dragMode, |
1634 m_clickPos, | 1650 m_clickPos, |
1635 e->pos(), | 1651 e->pos(), |
1698 | 1714 |
1699 void | 1715 void |
1700 Pane::zoomToRegion(int x0, int y0, int x1, int y1) | 1716 Pane::zoomToRegion(int x0, int y0, int x1, int y1) |
1701 { | 1717 { |
1702 int w = x1 - x0; | 1718 int w = x1 - x0; |
1703 | 1719 |
1704 long newStartFrame = getFrameForX(x0); | 1720 long newStartFrame = getFrameForX(x0); |
1705 | 1721 |
1706 long visibleFrames = getEndFrame() - getStartFrame(); | 1722 long visibleFrames = getEndFrame() - getStartFrame(); |
1707 if (newStartFrame <= -visibleFrames) { | 1723 if (newStartFrame <= -visibleFrames) { |
1708 newStartFrame = -visibleFrames + 1; | 1724 newStartFrame = -visibleFrames + 1; |
1709 } | 1725 } |
1710 | 1726 |
1711 if (newStartFrame >= long(getModelsEndFrame())) { | 1727 if (newStartFrame >= long(getModelsEndFrame())) { |
1712 newStartFrame = getModelsEndFrame() - 1; | 1728 newStartFrame = getModelsEndFrame() - 1; |
1713 } | 1729 } |
1714 | 1730 |
1715 float ratio = float(w) / float(width()); | 1731 float ratio = float(w) / float(width()); |
1716 // std::cerr << "ratio: " << ratio << std::endl; | 1732 // std::cerr << "ratio: " << ratio << std::endl; |
1717 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio); | 1733 size_t newZoomLevel = (size_t)nearbyint(m_zoomLevel * ratio); |
1718 if (newZoomLevel < 1) newZoomLevel = 1; | 1734 if (newZoomLevel < 1) newZoomLevel = 1; |
1719 | 1735 |
1720 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl; | 1736 // std::cerr << "start: " << m_startFrame << ", level " << m_zoomLevel << std::endl; |
1721 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); | 1737 setZoomLevel(getZoomConstraintBlockSize(newZoomLevel)); |
1722 setStartFrame(newStartFrame); | 1738 setStartFrame(newStartFrame); |
1723 | 1739 |
1724 QString unit; | 1740 QString unit; |
1725 float min, max; | 1741 float min, max; |
1794 m_dragMode == FreeDrag) { | 1810 m_dragMode == FreeDrag) { |
1795 | 1811 |
1796 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); | 1812 long frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); |
1797 | 1813 |
1798 size_t newCentreFrame = m_dragCentreFrame; | 1814 size_t newCentreFrame = m_dragCentreFrame; |
1799 | 1815 |
1800 if (frameOff < 0) { | 1816 if (frameOff < 0) { |
1801 newCentreFrame -= frameOff; | 1817 newCentreFrame -= frameOff; |
1802 } else if (newCentreFrame >= size_t(frameOff)) { | 1818 } else if (newCentreFrame >= size_t(frameOff)) { |
1803 newCentreFrame -= frameOff; | 1819 newCentreFrame -= frameOff; |
1804 } else { | 1820 } else { |
1805 newCentreFrame = 0; | 1821 newCentreFrame = 0; |
1806 } | 1822 } |
1807 | 1823 |
1808 #ifdef DEBUG_PANE | 1824 #ifdef DEBUG_PANE |
1809 SVDEBUG << "Pane::dragTopLayer: newCentreFrame = " << newCentreFrame << | 1825 SVDEBUG << "Pane::dragTopLayer: newCentreFrame = " << newCentreFrame << |
1810 ", models end frame = " << getModelsEndFrame() << endl; | 1826 ", models end frame = " << getModelsEndFrame() << endl; |
1811 #endif | 1827 #endif |
1812 | 1828 |
1813 if (newCentreFrame >= getModelsEndFrame()) { | 1829 if (newCentreFrame >= getModelsEndFrame()) { |
1922 { | 1938 { |
1923 int mouseFrame = getFrameForX(e->x()); | 1939 int mouseFrame = getFrameForX(e->x()); |
1924 size_t resolution = 1; | 1940 size_t resolution = 1; |
1925 int snapFrameLeft = mouseFrame; | 1941 int snapFrameLeft = mouseFrame; |
1926 int snapFrameRight = mouseFrame; | 1942 int snapFrameRight = mouseFrame; |
1927 | 1943 |
1928 Layer *layer = getSelectedLayer(); | 1944 Layer *layer = getSelectedLayer(); |
1929 if (layer && !m_shiftPressed) { | 1945 if (layer && !m_shiftPressed) { |
1930 layer->snapToFeatureFrame(this, snapFrameLeft, | 1946 layer->snapToFeatureFrame(this, snapFrameLeft, |
1931 resolution, Layer::SnapLeft); | 1947 resolution, Layer::SnapLeft); |
1932 layer->snapToFeatureFrame(this, snapFrameRight, | 1948 layer->snapToFeatureFrame(this, snapFrameRight, |
1933 resolution, Layer::SnapRight); | 1949 resolution, Layer::SnapRight); |
1934 } | 1950 } |
1935 | 1951 |
1936 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; | 1952 // std::cerr << "snap: frame = " << mouseFrame << ", start frame = " << m_selectionStartFrame << ", left = " << snapFrameLeft << ", right = " << snapFrameRight << std::endl; |
1937 | 1953 |
1938 if (snapFrameLeft < 0) snapFrameLeft = 0; | 1954 if (snapFrameLeft < 0) snapFrameLeft = 0; |
1939 if (snapFrameRight < 0) snapFrameRight = 0; | 1955 if (snapFrameRight < 0) snapFrameRight = 0; |
1940 | 1956 |
1941 size_t min, max; | 1957 size_t min, max; |
1942 | 1958 |
1943 if (m_selectionStartFrame > size_t(snapFrameLeft)) { | 1959 if (m_selectionStartFrame > size_t(snapFrameLeft)) { |
1944 min = snapFrameLeft; | 1960 min = snapFrameLeft; |
1945 max = m_selectionStartFrame; | 1961 max = m_selectionStartFrame; |
1946 } else if (size_t(snapFrameRight) > m_selectionStartFrame) { | 1962 } else if (size_t(snapFrameRight) > m_selectionStartFrame) { |
1947 min = m_selectionStartFrame; | 1963 min = m_selectionStartFrame; |
2011 (e->buttons() & Qt::MidButton)); | 2027 (e->buttons() & Qt::MidButton)); |
2012 | 2028 |
2013 if (mode == ViewManager::NavigateMode || | 2029 if (mode == ViewManager::NavigateMode || |
2014 mode == ViewManager::EditMode) { | 2030 mode == ViewManager::EditMode) { |
2015 | 2031 |
2016 Layer *layer = getSelectedLayer(); | 2032 Layer *layer = getSelectedLayer(); |
2017 if (layer && layer->isLayerEditable()) { | 2033 if (layer && layer->isLayerEditable()) { |
2018 if (layer->editOpen(this, e)) relocate = false; | 2034 if (layer->editOpen(this, e)) relocate = false; |
2019 } | 2035 } |
2020 | 2036 |
2021 } else if (mode == ViewManager::MeasureMode) { | 2037 } else if (mode == ViewManager::MeasureMode) { |
2022 | 2038 |
2023 Layer *layer = getTopLayer(); | 2039 Layer *layer = getTopLayer(); |
2024 if (layer) layer->measureDoubleClick(this, e); | 2040 if (layer) layer->measureDoubleClick(this, e); |
2072 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl; | 2088 //std::cerr << "wheelEvent, delta " << e->delta() << std::endl; |
2073 | 2089 |
2074 int count = e->delta(); | 2090 int count = e->delta(); |
2075 | 2091 |
2076 if (count > 0) { | 2092 if (count > 0) { |
2077 if (count >= 120) count /= 120; | 2093 if (count >= 120) count /= 120; |
2078 else count = 1; | 2094 else count = 1; |
2079 } | 2095 } |
2080 | 2096 |
2081 if (count < 0) { | 2097 if (count < 0) { |
2082 if (count <= -120) count /= 120; | 2098 if (count <= -120) count /= 120; |
2083 else count = -1; | 2099 else count = -1; |
2084 } | 2100 } |
2085 | 2101 |
2086 if (e->modifiers() & Qt::ControlModifier) { | 2102 if (e->modifiers() & Qt::ControlModifier) { |
2087 | 2103 |
2088 // Scroll left or right, rapidly | 2104 // Scroll left or right, rapidly |
2089 | 2105 |
2090 if (getStartFrame() < 0 && | 2106 if (getStartFrame() < 0 && |
2091 getEndFrame() >= getModelsEndFrame()) return; | 2107 getEndFrame() >= getModelsEndFrame()) return; |
2092 | 2108 |
2093 long delta = ((width() / 2) * count * m_zoomLevel); | 2109 long delta = ((width() / 2) * count * m_zoomLevel); |
2094 | 2110 |
2095 if (int(m_centreFrame) < delta) { | 2111 if (int(m_centreFrame) < delta) { |
2096 setCentreFrame(0); | 2112 setCentreFrame(0); |
2097 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { | 2113 } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { |
2098 setCentreFrame(getModelsEndFrame()); | 2114 setCentreFrame(getModelsEndFrame()); |
2099 } else { | 2115 } else { |
2100 setCentreFrame(m_centreFrame - delta); | 2116 setCentreFrame(m_centreFrame - delta); |
2101 } | 2117 } |
2102 | 2118 |
2103 } else if (e->modifiers() & Qt::ShiftModifier) { | 2119 } else if (e->modifiers() & Qt::ShiftModifier) { |
2104 | 2120 |
2105 // Zoom vertically | 2121 // Zoom vertically |
2106 | 2122 |
2116 m_vthumb->scroll(e->delta() > 0); | 2132 m_vthumb->scroll(e->delta() > 0); |
2117 } | 2133 } |
2118 | 2134 |
2119 } else { | 2135 } else { |
2120 | 2136 |
2121 // Zoom in or out | 2137 // Zoom in or out |
2122 | 2138 |
2123 int newZoomLevel = m_zoomLevel; | 2139 int newZoomLevel = m_zoomLevel; |
2124 | 2140 |
2125 while (count > 0) { | 2141 while (count > 0) { |
2126 if (newZoomLevel <= 2) { | 2142 if (newZoomLevel <= 2) { |
2127 newZoomLevel = 1; | 2143 newZoomLevel = 1; |
2128 break; | 2144 break; |
2129 } | 2145 } |
2130 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, | 2146 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel - 1, |
2131 ZoomConstraint::RoundDown); | 2147 ZoomConstraint::RoundDown); |
2132 --count; | 2148 --count; |
2133 } | 2149 } |
2134 | 2150 |
2135 while (count < 0) { | 2151 while (count < 0) { |
2136 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, | 2152 newZoomLevel = getZoomConstraintBlockSize(newZoomLevel + 1, |
2137 ZoomConstraint::RoundUp); | 2153 ZoomConstraint::RoundUp); |
2138 ++count; | 2154 ++count; |
2139 } | 2155 } |
2140 | 2156 |
2141 if (newZoomLevel != m_zoomLevel) { | 2157 if (newZoomLevel != m_zoomLevel) { |
2142 setZoomLevel(newZoomLevel); | 2158 setZoomLevel(newZoomLevel); |
2143 } | 2159 } |
2144 } | 2160 } |
2145 | 2161 |
2146 emit paneInteractedWith(); | 2162 emit paneInteractedWith(); |
2147 } | 2163 } |
2148 | 2164 |
2314 | 2330 |
2315 bool | 2331 bool |
2316 Pane::editSelectionStart(QMouseEvent *e) | 2332 Pane::editSelectionStart(QMouseEvent *e) |
2317 { | 2333 { |
2318 if (!m_identifyFeatures || | 2334 if (!m_identifyFeatures || |
2319 !m_manager || | 2335 !m_manager || |
2320 m_manager->getToolMode() != ViewManager::EditMode) { | 2336 m_manager->getToolMode() != ViewManager::EditMode) { |
2321 return false; | 2337 return false; |
2322 } | 2338 } |
2323 | 2339 |
2324 bool closeToLeft, closeToRight; | 2340 bool closeToLeft, closeToRight; |
2325 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight)); | 2341 Selection s(getSelectionAt(e->x(), closeToLeft, closeToRight)); |
2326 if (s.isEmpty()) return false; | 2342 if (s.isEmpty()) return false; |
2346 | 2362 |
2347 int offset = m_mousePos.x() - m_clickPos.x(); | 2363 int offset = m_mousePos.x() - m_clickPos.x(); |
2348 Layer *layer = getSelectedLayer(); | 2364 Layer *layer = getSelectedLayer(); |
2349 | 2365 |
2350 if (offset == 0 || !layer) { | 2366 if (offset == 0 || !layer) { |
2351 m_editingSelection = Selection(); | 2367 m_editingSelection = Selection(); |
2352 return true; | 2368 return true; |
2353 } | 2369 } |
2354 | 2370 |
2355 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; | 2371 int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; |
2356 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; | 2372 int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; |
2357 | 2373 |
2359 long f1 = getFrameForX(p1); | 2375 long f1 = getFrameForX(p1); |
2360 | 2376 |
2361 Selection newSelection(f0, f1); | 2377 Selection newSelection(f0, f1); |
2362 | 2378 |
2363 if (m_editingSelectionEdge == 0) { | 2379 if (m_editingSelectionEdge == 0) { |
2364 | 2380 |
2365 CommandHistory::getInstance()->startCompoundOperation | 2381 CommandHistory::getInstance()->startCompoundOperation |
2366 (tr("Drag Selection"), true); | 2382 (tr("Drag Selection"), true); |
2367 | 2383 |
2368 layer->moveSelection(m_editingSelection, f0); | 2384 layer->moveSelection(m_editingSelection, f0); |
2369 | 2385 |
2370 } else { | 2386 } else { |
2371 | 2387 |
2372 CommandHistory::getInstance()->startCompoundOperation | 2388 CommandHistory::getInstance()->startCompoundOperation |
2373 (tr("Resize Selection"), true); | 2389 (tr("Resize Selection"), true); |
2374 | 2390 |
2375 if (m_editingSelectionEdge < 0) { | 2391 if (m_editingSelectionEdge < 0) { |
2376 f1 = m_editingSelection.getEndFrame(); | 2392 f1 = m_editingSelection.getEndFrame(); |
2377 } else { | 2393 } else { |
2378 f0 = m_editingSelection.getStartFrame(); | 2394 f0 = m_editingSelection.getStartFrame(); |
2379 } | 2395 } |
2380 | 2396 |
2381 newSelection = Selection(f0, f1); | 2397 newSelection = Selection(f0, f1); |
2382 layer->resizeSelection(m_editingSelection, newSelection); | 2398 layer->resizeSelection(m_editingSelection, newSelection); |
2383 } | 2399 } |
2384 | 2400 |
2385 m_manager->removeSelection(m_editingSelection); | 2401 m_manager->removeSelection(m_editingSelection); |
2386 m_manager->addSelection(newSelection); | 2402 m_manager->addSelection(newSelection); |
2387 | 2403 |
2407 } | 2423 } |
2408 | 2424 |
2409 switch (mode) { | 2425 switch (mode) { |
2410 | 2426 |
2411 case ViewManager::NavigateMode: | 2427 case ViewManager::NavigateMode: |
2412 setCursor(Qt::PointingHandCursor); | 2428 setCursor(Qt::PointingHandCursor); |
2413 break; | 2429 break; |
2414 | 2430 |
2415 case ViewManager::SelectMode: | 2431 case ViewManager::SelectMode: |
2416 setCursor(Qt::ArrowCursor); | 2432 setCursor(Qt::ArrowCursor); |
2417 break; | 2433 break; |
2418 | 2434 |
2419 case ViewManager::EditMode: | 2435 case ViewManager::EditMode: |
2420 setCursor(Qt::UpArrowCursor); | 2436 setCursor(Qt::UpArrowCursor); |
2421 break; | 2437 break; |
2422 | 2438 |
2423 case ViewManager::DrawMode: | 2439 case ViewManager::DrawMode: |
2424 setCursor(Qt::CrossCursor); | 2440 setCursor(Qt::CrossCursor); |
2425 break; | 2441 break; |
2426 | 2442 |
2427 case ViewManager::EraseMode: | 2443 case ViewManager::EraseMode: |
2428 setCursor(Qt::CrossCursor); | 2444 setCursor(Qt::CrossCursor); |
2429 break; | 2445 break; |
2430 | 2446 |
2431 case ViewManager::MeasureMode: | 2447 case ViewManager::MeasureMode: |
2432 if (m_measureCursor1) setCursor(*m_measureCursor1); | 2448 if (m_measureCursor1) setCursor(*m_measureCursor1); |
2433 break; | 2449 break; |
2434 | 2450 |
2435 /* | 2451 // GF: NoteEditMode uses the same default cursor as EditMode, but it will change in a context sensitive manner. |
2452 case ViewManager::NoteEditMode: | |
2453 setCursor(Qt::UpArrowCursor); | |
2454 break; | |
2455 | |
2456 /* | |
2436 case ViewManager::TextMode: | 2457 case ViewManager::TextMode: |
2437 setCursor(Qt::IBeamCursor); | 2458 setCursor(Qt::IBeamCursor); |
2438 break; | 2459 break; |
2439 */ | 2460 */ |
2440 } | 2461 } |
2441 } | 2462 } |
2442 | 2463 |
2443 void | 2464 void |
2569 } | 2590 } |
2570 | 2591 |
2571 } else if (mode == ViewManager::DrawMode) { | 2592 } else if (mode == ViewManager::DrawMode) { |
2572 | 2593 |
2573 //!!! could call through to a layer function to find out exact meaning | 2594 //!!! could call through to a layer function to find out exact meaning |
2574 if (editable) { | 2595 if (editable) { |
2575 help = tr("Click to add a new item in the active layer"); | 2596 help = tr("Click to add a new item in the active layer"); |
2576 } | 2597 } |
2577 | 2598 |
2578 } else if (mode == ViewManager::EraseMode) { | 2599 } else if (mode == ViewManager::EraseMode) { |
2579 | 2600 |
2580 //!!! could call through to a layer function to find out exact meaning | 2601 //!!! could call through to a layer function to find out exact meaning |
2581 if (editable) { | 2602 if (editable) { |
2582 help = tr("Click to erase an item from the active layer"); | 2603 help = tr("Click to erase an item from the active layer"); |
2583 } | 2604 } |
2584 | 2605 |
2585 } else if (mode == ViewManager::EditMode) { | 2606 } else if (mode == ViewManager::EditMode) { |
2586 | 2607 |
2587 //!!! could call through to layer | 2608 //!!! could call through to layer |
2588 if (editable) { | 2609 if (editable) { |
2589 help = tr("Click and drag an item in the active layer to move it; hold Shift to override initial resistance"); | 2610 help = tr("Click and drag an item in the active layer to move it; hold Shift to override initial resistance"); |
2590 if (pos) { | 2611 if (pos) { |
2591 bool closeToLeft = false, closeToRight = false; | 2612 bool closeToLeft = false, closeToRight = false; |
2592 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight); | 2613 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight); |
2593 if (!selection.isEmpty()) { | 2614 if (!selection.isEmpty()) { |
2627 Pane::toXml(QTextStream &stream, | 2648 Pane::toXml(QTextStream &stream, |
2628 QString indent, QString extraAttributes) const | 2649 QString indent, QString extraAttributes) const |
2629 { | 2650 { |
2630 View::toXml | 2651 View::toXml |
2631 (stream, indent, | 2652 (stream, indent, |
2632 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3") | 2653 QString("type=\"pane\" centreLineVisible=\"%1\" height=\"%2\" %3") |
2633 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes)); | 2654 .arg(m_centreLineVisible).arg(height()).arg(extraAttributes)); |
2634 } | 2655 } |
2635 | 2656 |
2636 | 2657 |