comparison view/Pane.cpp @ 802:584b11df8e4f tonioni

Single-click to move pointer needs to wait for double-click timeout (so it knows you're not starting a double-click)
author Chris Cannam
date Mon, 16 Jun 2014 12:50:27 +0100
parents 7555b8b17e6e
children 40c6c9344ff6
comparison
equal deleted inserted replaced
801:8be221f18313 802:584b11df8e4f
39 #include <QDragEnterEvent> 39 #include <QDragEnterEvent>
40 #include <QDropEvent> 40 #include <QDropEvent>
41 #include <QCursor> 41 #include <QCursor>
42 #include <QTextStream> 42 #include <QTextStream>
43 #include <QMimeData> 43 #include <QMimeData>
44 #include <QApplication>
44 45
45 #include <iostream> 46 #include <iostream>
46 #include <cmath> 47 #include <cmath>
47 48
48 //!!! for HUD -- pull out into a separate class 49 //!!! for HUD -- pull out into a separate class
80 m_headsUpDisplay(0), 81 m_headsUpDisplay(0),
81 m_vpan(0), 82 m_vpan(0),
82 m_hthumb(0), 83 m_hthumb(0),
83 m_vthumb(0), 84 m_vthumb(0),
84 m_reset(0), 85 m_reset(0),
85 m_mouseInWidget(false) 86 m_mouseInWidget(false),
87 m_playbackFrameMoveScheduled(false),
88 m_playbackFrameMoveTo(0)
86 { 89 {
87 setObjectName("Pane"); 90 setObjectName("Pane");
88 setMouseTracking(true); 91 setMouseTracking(true);
89 setAcceptDrops(true); 92 setAcceptDrops(true);
90 93
782 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model) 785 Pane::drawModelTimeExtents(QRect r, QPainter &paint, const Model *model)
783 { 786 {
784 int x0 = getXForFrame(model->getStartFrame()); 787 int x0 = getXForFrame(model->getStartFrame());
785 int x1 = getXForFrame(model->getEndFrame()); 788 int x1 = getXForFrame(model->getEndFrame());
786 789
787 int lw = 10;
788
789 paint.save(); 790 paint.save();
790 791
791 QBrush brush; 792 QBrush brush;
792 793
793 if (hasLightBackground()) { 794 if (hasLightBackground()) {
936 llx -= 36; 937 llx -= 36;
937 } 938 }
938 939
939 if (r.x() + r.width() >= llx - fontAscent - 3) { 940 if (r.x() + r.width() >= llx - fontAscent - 3) {
940 941
941 for (size_t i = 0; i < texts.size(); ++i) { 942 for (int i = 0; i < texts.size(); ++i) {
942 943
943 // cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << endl; 944 // cerr << "Pane "<< this << ": text " << i << ": " << texts[i] << endl;
944 945
945 if (i + 1 == texts.size()) { 946 if (i + 1 == texts.size()) {
946 paint.setPen(getForeground()); 947 paint.setPen(getForeground());
1329 float vmin, vmax, dmin, dmax; 1330 float vmin, vmax, dmin, dmax;
1330 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { 1331 if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) {
1331 m_dragStartMinValue = dmin; 1332 m_dragStartMinValue = dmin;
1332 } 1333 }
1333 1334
1335 // Schedule a play-head move to the mouse frame location. This
1336 // will happen only if nothing else of interest happens
1337 // (double-click, drag) before the timeout.
1338 schedulePlaybackFrameMove(getFrameForX(e->x()));
1339
1334 } else if (mode == ViewManager::SelectMode) { 1340 } else if (mode == ViewManager::SelectMode) {
1335 1341
1336 if (!hasTopLayerTimeXAxis()) return; 1342 if (!hasTopLayerTimeXAxis()) return;
1337 1343
1338 bool closeToLeft = false, closeToRight = false; 1344 bool closeToLeft = false, closeToRight = false;
1371 alignToReference(snapFrame + resolution)), 1377 alignToReference(snapFrame + resolution)),
1372 !m_ctrlPressed); 1378 !m_ctrlPressed);
1373 } 1379 }
1374 1380
1375 m_resizing = false; 1381 m_resizing = false;
1382
1383 // Schedule a play-head move to the mouse frame
1384 // location. This will happen only if nothing else of
1385 // interest happens (double-click, drag) before the
1386 // timeout.
1387 schedulePlaybackFrameMove(mouseFrame);
1376 } 1388 }
1377 1389
1378 update(); 1390 update();
1379 1391
1380 } else if (mode == ViewManager::DrawMode) { 1392 } else if (mode == ViewManager::DrawMode) {
1414 1426
1415 emit paneInteractedWith(); 1427 emit paneInteractedWith();
1416 } 1428 }
1417 1429
1418 void 1430 void
1431 Pane::schedulePlaybackFrameMove(int frame)
1432 {
1433 m_playbackFrameMoveTo = frame;
1434 m_playbackFrameMoveScheduled = true;
1435 QTimer::singleShot(QApplication::doubleClickInterval() + 10, this,
1436 SLOT(playbackScheduleTimerElapsed()));
1437 }
1438
1439 void
1440 Pane::playbackScheduleTimerElapsed()
1441 {
1442 if (m_playbackFrameMoveScheduled) {
1443 m_manager->setPlaybackFrame(m_playbackFrameMoveTo);
1444 m_playbackFrameMoveScheduled = false;
1445 }
1446 }
1447
1448 void
1419 Pane::mouseReleaseEvent(QMouseEvent *e) 1449 Pane::mouseReleaseEvent(QMouseEvent *e)
1420 { 1450 {
1421 if (e->buttons() & Qt::RightButton) { 1451 if (e->buttons() & Qt::RightButton) {
1422 return; 1452 return;
1423 } 1453 }
1432 if (m_clickedInRange) { 1462 if (m_clickedInRange) {
1433 mouseMoveEvent(e); 1463 mouseMoveEvent(e);
1434 } 1464 }
1435 1465
1436 int mouseFrame = e ? getFrameForX(e->x()) : 0; 1466 int mouseFrame = e ? getFrameForX(e->x()) : 0;
1437 if (mouseFrame < 0) mouseFrame == 0; 1467 if (mouseFrame < 0) mouseFrame = 0;
1438 1468
1439 if (m_navigating || mode == ViewManager::NavigateMode) { 1469 if (m_navigating || mode == ViewManager::NavigateMode) {
1440 1470
1441 m_navigating = false; 1471 m_navigating = false;
1442 1472
1452 1482
1453 int y0 = std::min(m_clickPos.y(), m_mousePos.y()); 1483 int y0 = std::min(m_clickPos.y(), m_mousePos.y());
1454 int y1 = std::max(m_clickPos.y(), m_mousePos.y()); 1484 int y1 = std::max(m_clickPos.y(), m_mousePos.y());
1455 1485
1456 emit regionOutlined(QRect(x0, y0, x1 - x0, y1 - y0)); 1486 emit regionOutlined(QRect(x0, y0, x1 - x0, y1 - y0));
1457
1458 } else if (m_manager && m_dragMode == UnresolvedDrag) {
1459
1460 // Simple click, no drag made: move play head to the mouse
1461 // frame location
1462 m_manager->setPlaybackFrame(mouseFrame);
1463 } 1487 }
1464 1488
1465 } else if (mode == ViewManager::SelectMode) { 1489 } else if (mode == ViewManager::SelectMode) {
1466 1490
1467 if (!hasTopLayerTimeXAxis()) { 1491 if (!hasTopLayerTimeXAxis()) {
1484 if (exclusive) { 1508 if (exclusive) {
1485 m_manager->setSelection(selection); 1509 m_manager->setSelection(selection);
1486 } else { 1510 } else {
1487 m_manager->addSelection(selection); 1511 m_manager->addSelection(selection);
1488 } 1512 }
1489
1490 } else if (m_manager && !m_manager->haveInProgressSelection()) {
1491
1492 // Simple click, no selection made: move play head to the
1493 // mouse frame location
1494 m_manager->setPlaybackFrame(mouseFrame);
1495 } 1513 }
1496 1514
1497 update(); 1515 update();
1498 1516
1499 } else if (mode == ViewManager::DrawMode) { 1517 } else if (mode == ViewManager::DrawMode) {
1813 layer->measureDrag(this, e); 1831 layer->measureDrag(this, e);
1814 if (layer->hasTimeXAxis()) edgeScrollMaybe(e->x()); 1832 if (layer->hasTimeXAxis()) edgeScrollMaybe(e->x());
1815 } 1833 }
1816 1834
1817 update(); 1835 update();
1836 }
1837
1838 if (m_dragMode != UnresolvedDrag) {
1839 m_playbackFrameMoveScheduled = false;
1818 } 1840 }
1819 } 1841 }
1820 1842
1821 void 1843 void
1822 Pane::zoomToRegion(QRect r) 1844 Pane::zoomToRegion(QRect r)
2085 } 2107 }
2086 2108
2087 edgeScrollMaybe(e->x()); 2109 edgeScrollMaybe(e->x());
2088 2110
2089 update(); 2111 update();
2112
2113 if (min != max) {
2114 m_playbackFrameMoveScheduled = false;
2115 }
2090 } 2116 }
2091 2117
2092 void 2118 void
2093 Pane::edgeScrollMaybe(int x) 2119 Pane::edgeScrollMaybe(int x)
2094 { 2120 {
2121 { 2147 {
2122 if (e->buttons() & Qt::RightButton) { 2148 if (e->buttons() & Qt::RightButton) {
2123 return; 2149 return;
2124 } 2150 }
2125 2151
2126 // cerr << "mouseDoubleClickEvent" << endl; 2152 cerr << "mouseDoubleClickEvent" << endl;
2127 2153
2128 m_clickPos = e->pos(); 2154 m_clickPos = e->pos();
2129 m_clickedInRange = true; 2155 m_clickedInRange = true;
2130 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier); 2156 m_shiftPressed = (e->modifiers() & Qt::ShiftModifier);
2131 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier); 2157 m_ctrlPressed = (e->modifiers() & Qt::ControlModifier);
2132 m_altPressed = (e->modifiers() & Qt::AltModifier); 2158 m_altPressed = (e->modifiers() & Qt::AltModifier);
2159
2160 // cancel any pending move that came from a single click
2161 m_playbackFrameMoveScheduled = false;
2133 2162
2134 ViewManager::ToolMode mode = ViewManager::NavigateMode; 2163 ViewManager::ToolMode mode = ViewManager::NavigateMode;
2135 if (m_manager) mode = m_manager->getToolModeFor(this); 2164 if (m_manager) mode = m_manager->getToolModeFor(this);
2136 2165
2137 bool relocate = (mode == ViewManager::NavigateMode || 2166 bool relocate = (mode == ViewManager::NavigateMode ||