Mercurial > hg > svgui
comparison view/View.cpp @ 808:40c6c9344ff6 warnfix_no_size_t
Merge from branch tony_integration
author | Chris Cannam |
---|---|
date | Wed, 18 Jun 2014 08:40:46 +0100 |
parents | 4c8ca536b54f 102ffad481e6 |
children | 09026c875301 |
comparison
equal
deleted
inserted
replaced
807:e4773943c9c1 | 808:40c6c9344ff6 |
---|---|
24 #include "layer/TimeRulerLayer.h" | 24 #include "layer/TimeRulerLayer.h" |
25 #include "layer/SingleColourLayer.h" | 25 #include "layer/SingleColourLayer.h" |
26 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" | 26 #include "data/model/PowerOfSqrtTwoZoomConstraint.h" |
27 #include "data/model/RangeSummarisableTimeValueModel.h" | 27 #include "data/model/RangeSummarisableTimeValueModel.h" |
28 | 28 |
29 #include "widgets/IconLoader.h" | |
30 | |
29 #include <QPainter> | 31 #include <QPainter> |
30 #include <QPaintEvent> | 32 #include <QPaintEvent> |
31 #include <QRect> | 33 #include <QRect> |
32 #include <QApplication> | 34 #include <QApplication> |
33 #include <QProgressDialog> | 35 #include <QProgressDialog> |
34 #include <QTextStream> | 36 #include <QTextStream> |
35 #include <QFont> | 37 #include <QFont> |
36 #include <QMessageBox> | 38 #include <QMessageBox> |
39 #include <QPushButton> | |
37 | 40 |
38 #include <iostream> | 41 #include <iostream> |
39 #include <cassert> | 42 #include <cassert> |
40 #include <cmath> | 43 #include <cmath> |
41 | 44 |
51 m_centreFrame(0), | 54 m_centreFrame(0), |
52 m_zoomLevel(1024), | 55 m_zoomLevel(1024), |
53 m_followPan(true), | 56 m_followPan(true), |
54 m_followZoom(true), | 57 m_followZoom(true), |
55 m_followPlay(PlaybackScrollPage), | 58 m_followPlay(PlaybackScrollPage), |
59 m_followPlayIsDetached(false), | |
56 m_playPointerFrame(0), | 60 m_playPointerFrame(0), |
57 m_showProgress(showProgress), | 61 m_showProgress(showProgress), |
58 m_cache(0), | 62 m_cache(0), |
59 m_cacheCentreFrame(0), | 63 m_cacheCentreFrame(0), |
60 m_cacheZoomLevel(1024), | 64 m_cacheZoomLevel(1024), |
514 if (widgetLight != light) return widgetfg; | 518 if (widgetLight != light) return widgetfg; |
515 else if (light) return Qt::black; | 519 else if (light) return Qt::black; |
516 else return Qt::white; | 520 else return Qt::white; |
517 } | 521 } |
518 | 522 |
519 View::LayerProgressBar::LayerProgressBar(QWidget *parent) : | |
520 QProgressBar(parent) | |
521 { | |
522 } | |
523 | |
524 void | 523 void |
525 View::addLayer(Layer *layer) | 524 View::addLayer(Layer *layer) |
526 { | 525 { |
527 delete m_cache; | 526 delete m_cache; |
528 m_cache = 0; | 527 m_cache = 0; |
536 pb->setMinimum(0); | 535 pb->setMinimum(0); |
537 pb->setMaximum(0); | 536 pb->setMaximum(0); |
538 pb->setFixedWidth(80); | 537 pb->setFixedWidth(80); |
539 pb->setTextVisible(false); | 538 pb->setTextVisible(false); |
540 | 539 |
540 QPushButton *cancel = new QPushButton(this); | |
541 cancel->setIcon(IconLoader().load("fileclose")); | |
542 cancel->setFlat(true); | |
543 cancel->setFixedSize(QSize(20, 20)); | |
544 connect(cancel, SIGNAL(clicked()), this, SLOT(cancelClicked())); | |
545 | |
541 ProgressBarRec pbr; | 546 ProgressBarRec pbr; |
547 pbr.cancel = cancel; | |
542 pbr.bar = pb; | 548 pbr.bar = pb; |
543 pbr.lastCheck = 0; | 549 pbr.lastCheck = 0; |
544 pbr.checkTimer = new QTimer(); | 550 pbr.checkTimer = new QTimer(); |
545 connect(pbr.checkTimer, SIGNAL(timeout()), this, | 551 connect(pbr.checkTimer, SIGNAL(timeout()), this, |
546 SLOT(progressCheckStalledTimerElapsed())); | 552 SLOT(progressCheckStalledTimerElapsed())); |
548 m_progressBars[layer] = pbr; | 554 m_progressBars[layer] = pbr; |
549 | 555 |
550 QFont f(pb->font()); | 556 QFont f(pb->font()); |
551 int fs = Preferences::getInstance()->getViewFontSize(); | 557 int fs = Preferences::getInstance()->getViewFontSize(); |
552 f.setPointSize(std::min(fs, int(ceil(fs * 0.85)))); | 558 f.setPointSize(std::min(fs, int(ceil(fs * 0.85)))); |
559 | |
560 cancel->hide(); | |
553 | 561 |
554 pb->setFont(f); | 562 pb->setFont(f); |
555 pb->hide(); | 563 pb->hide(); |
556 | 564 |
557 connect(layer, SIGNAL(layerParametersChanged()), | 565 connect(layer, SIGNAL(layerParametersChanged()), |
591 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { | 599 for (LayerList::iterator i = m_layers.begin(); i != m_layers.end(); ++i) { |
592 if (*i == layer) { | 600 if (*i == layer) { |
593 m_layers.erase(i); | 601 m_layers.erase(i); |
594 if (m_progressBars.find(layer) != m_progressBars.end()) { | 602 if (m_progressBars.find(layer) != m_progressBars.end()) { |
595 delete m_progressBars[layer].bar; | 603 delete m_progressBars[layer].bar; |
604 delete m_progressBars[layer].cancel; | |
596 delete m_progressBars[layer].checkTimer; | 605 delete m_progressBars[layer].checkTimer; |
597 m_progressBars.erase(layer); | 606 m_progressBars.erase(layer); |
598 } | 607 } |
599 break; | 608 break; |
600 } | 609 } |
990 | 999 |
991 bool somethingGoingOn = | 1000 bool somethingGoingOn = |
992 ((QApplication::mouseButtons() != Qt::NoButton) || | 1001 ((QApplication::mouseButtons() != Qt::NoButton) || |
993 (QApplication::keyboardModifiers() & Qt::AltModifier)); | 1002 (QApplication::keyboardModifiers() & Qt::AltModifier)); |
994 | 1003 |
1004 bool pointerInVisibleArea = | |
1005 long(m_playPointerFrame) >= getStartFrame() && | |
1006 (m_playPointerFrame < getEndFrame() || | |
1007 // include old pointer location so we know to refresh when moving out | |
1008 oldPlayPointerFrame < getEndFrame()); | |
1009 | |
995 switch (m_followPlay) { | 1010 switch (m_followPlay) { |
996 | 1011 |
997 case PlaybackScrollContinuous: | 1012 case PlaybackScrollContinuous: |
998 if (!somethingGoingOn) { | 1013 if (!somethingGoingOn) { |
999 setCentreFrame(m_playPointerFrame, false); | 1014 setCentreFrame(m_playPointerFrame, false); |
1000 } | 1015 } |
1001 break; | 1016 break; |
1002 | 1017 |
1003 case PlaybackScrollPage: | 1018 case PlaybackScrollPage: |
1004 { | 1019 |
1005 int xold = getXForFrame(oldPlayPointerFrame); | 1020 if (!pointerInVisibleArea && somethingGoingOn) { |
1006 update(xold - 4, 0, 9, height()); | 1021 |
1007 | 1022 m_followPlayIsDetached = true; |
1008 int w = getEndFrame() - getStartFrame(); | 1023 |
1009 w -= w/5; | 1024 } else if (!pointerInVisibleArea && m_followPlayIsDetached) { |
1010 int sf = (m_playPointerFrame / w) * w - w/8; | 1025 |
1011 | 1026 // do nothing; we aren't tracking until the pointer comes back in |
1012 if (m_manager && | 1027 |
1013 m_manager->isPlaying() && | 1028 } else { |
1014 m_manager->getPlaySelectionMode()) { | 1029 |
1015 MultiSelection::SelectionList selections = m_manager->getSelections(); | 1030 int xold = getXForFrame(oldPlayPointerFrame); |
1016 if (!selections.empty()) { | 1031 update(xold - 4, 0, 9, height()); |
1017 int selectionStart = selections.begin()->getStartFrame(); | 1032 |
1018 if (sf < selectionStart - w / 10) { | 1033 int w = getEndFrame() - getStartFrame(); |
1019 sf = selectionStart - w / 10; | 1034 w -= w/5; |
1020 } | 1035 int sf = (m_playPointerFrame / w) * w - w/8; |
1021 } | 1036 |
1022 } | 1037 if (m_manager && |
1038 m_manager->isPlaying() && | |
1039 m_manager->getPlaySelectionMode()) { | |
1040 MultiSelection::SelectionList selections = m_manager->getSelections(); | |
1041 if (!selections.empty()) { | |
1042 int selectionStart = selections.begin()->getStartFrame(); | |
1043 if (sf < selectionStart - w / 10) { | |
1044 sf = selectionStart - w / 10; | |
1045 } | |
1046 } | |
1047 } | |
1023 | 1048 |
1024 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1049 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1025 cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame " | 1050 cerr << "PlaybackScrollPage: f = " << m_playPointerFrame << ", sf = " << sf << ", start frame " |
1026 << getStartFrame() << endl; | 1051 << getStartFrame() << endl; |
1027 #endif | 1052 #endif |
1028 | 1053 |
1029 // We don't consider scrolling unless the pointer is outside | 1054 // We don't consider scrolling unless the pointer is outside |
1030 // the clearly visible range already | 1055 // the central visible range already |
1031 | 1056 |
1032 int xnew = getXForFrame(m_playPointerFrame); | 1057 int xnew = getXForFrame(m_playPointerFrame); |
1033 | 1058 |
1034 #ifdef DEBUG_VIEW_WIDGET_PAINT | 1059 #ifdef DEBUG_VIEW_WIDGET_PAINT |
1035 cerr << "xnew = " << xnew << ", width = " << width() << endl; | 1060 cerr << "xnew = " << xnew << ", width = " << width() << endl; |
1036 #endif | 1061 #endif |
1037 | 1062 |
1038 if (xnew < width()/8 || xnew > (width()*7)/8) { | 1063 bool shouldScroll = (xnew > (width() * 7) / 8); |
1039 if (!somethingGoingOn) { | 1064 |
1040 int offset = getFrameForX(width()/2) - getStartFrame(); | 1065 if (!m_followPlayIsDetached && (xnew < width() / 8)) { |
1041 int newCentre = sf + offset; | 1066 shouldScroll = true; |
1042 bool changed = setCentreFrame(newCentre, false); | 1067 } |
1043 if (changed) { | 1068 |
1044 xold = getXForFrame(oldPlayPointerFrame); | 1069 if (xnew > width() / 8) { |
1045 update(xold - 4, 0, 9, height()); | 1070 m_followPlayIsDetached = false; |
1046 } | 1071 } else if (somethingGoingOn) { |
1047 } | 1072 m_followPlayIsDetached = true; |
1048 } | 1073 } |
1049 | 1074 |
1050 update(xnew - 4, 0, 9, height()); | 1075 if (!somethingGoingOn && shouldScroll) { |
1051 | 1076 int offset = getFrameForX(width()/2) - getStartFrame(); |
1052 break; | 1077 int newCentre = sf + offset; |
1053 } | 1078 bool changed = setCentreFrame(newCentre, false); |
1079 if (changed) { | |
1080 xold = getXForFrame(oldPlayPointerFrame); | |
1081 update(xold - 4, 0, 9, height()); | |
1082 } | |
1083 } | |
1084 | |
1085 update(xnew - 4, 0, 9, height()); | |
1086 } | |
1087 break; | |
1054 | 1088 |
1055 case PlaybackIgnore: | 1089 case PlaybackIgnore: |
1056 if (m_playPointerFrame >= getStartFrame() && | 1090 if (m_playPointerFrame >= getStartFrame() && |
1057 m_playPointerFrame < getEndFrame()) { | 1091 m_playPointerFrame < getEndFrame()) { |
1058 update(); | 1092 update(); |
1432 setCentreFrame(m_centreFrame - delta, e); | 1466 setCentreFrame(m_centreFrame - delta, e); |
1433 } | 1467 } |
1434 } | 1468 } |
1435 | 1469 |
1436 void | 1470 void |
1437 View::checkProgress(void *object) | 1471 View::cancelClicked() |
1438 { | 1472 { |
1439 if (!m_showProgress) return; | 1473 QPushButton *cancel = qobject_cast<QPushButton *>(sender()); |
1440 | 1474 if (!cancel) return; |
1441 int ph = height(); | |
1442 | 1475 |
1443 for (ProgressMap::iterator i = m_progressBars.begin(); | 1476 for (ProgressMap::iterator i = m_progressBars.begin(); |
1444 i != m_progressBars.end(); ++i) { | 1477 i != m_progressBars.end(); ++i) { |
1445 | 1478 |
1479 if (i->second.cancel == cancel) { | |
1480 | |
1481 Layer *layer = i->first; | |
1482 Model *model = layer->getModel(); | |
1483 | |
1484 if (model) model->abandon(); | |
1485 } | |
1486 } | |
1487 } | |
1488 | |
1489 void | |
1490 View::checkProgress(void *object) | |
1491 { | |
1492 if (!m_showProgress) return; | |
1493 | |
1494 int ph = height(); | |
1495 | |
1496 for (ProgressMap::iterator i = m_progressBars.begin(); | |
1497 i != m_progressBars.end(); ++i) { | |
1498 | |
1446 QProgressBar *pb = i->second.bar; | 1499 QProgressBar *pb = i->second.bar; |
1500 QPushButton *cancel = i->second.cancel; | |
1447 | 1501 |
1448 if (i->first == object) { | 1502 if (i->first == object) { |
1449 | 1503 |
1450 // The timer is used to test for stalls. If the progress | 1504 // The timer is used to test for stalls. If the progress |
1451 // bar does not get updated for some length of time, the | 1505 // bar does not get updated for some length of time, the |
1488 } | 1542 } |
1489 | 1543 |
1490 if (completion >= 100) { | 1544 if (completion >= 100) { |
1491 | 1545 |
1492 pb->hide(); | 1546 pb->hide(); |
1547 cancel->hide(); | |
1493 timer->stop(); | 1548 timer->stop(); |
1494 | 1549 |
1495 } else { | 1550 } else { |
1496 | 1551 |
1497 // cerr << "progress = " << completion << endl; | 1552 // cerr << "progress = " << completion << endl; |
1500 i->second.lastCheck = 0; | 1555 i->second.lastCheck = 0; |
1501 timer->setInterval(2000); | 1556 timer->setInterval(2000); |
1502 timer->start(); | 1557 timer->start(); |
1503 } | 1558 } |
1504 | 1559 |
1560 cancel->move(0, ph - pb->height()/2 - 10); | |
1561 cancel->show(); | |
1562 | |
1505 pb->setValue(completion); | 1563 pb->setValue(completion); |
1506 pb->move(0, ph - pb->height()); | 1564 pb->move(20, ph - pb->height()); |
1507 | 1565 |
1508 pb->show(); | 1566 pb->show(); |
1509 pb->update(); | 1567 pb->update(); |
1510 | 1568 |
1511 ph -= pb->height(); | 1569 ph -= pb->height(); |
1560 | 1618 |
1561 void | 1619 void |
1562 View::paintEvent(QPaintEvent *e) | 1620 View::paintEvent(QPaintEvent *e) |
1563 { | 1621 { |
1564 // Profiler prof("View::paintEvent", false); | 1622 // Profiler prof("View::paintEvent", false); |
1565 // SVDEBUG << "View::paintEvent: centre frame is " << m_centreFrame << endl; | 1623 // cerr << "View::paintEvent: centre frame is " << m_centreFrame << endl; |
1566 | 1624 |
1567 if (m_layers.empty()) { | 1625 if (m_layers.empty()) { |
1568 QFrame::paintEvent(e); | 1626 QFrame::paintEvent(e); |
1569 return; | 1627 return; |
1570 } | 1628 } |
1816 } else if (m_playPointerFrame <= getStartFrame() || | 1874 } else if (m_playPointerFrame <= getStartFrame() || |
1817 m_playPointerFrame >= getEndFrame()) { | 1875 m_playPointerFrame >= getEndFrame()) { |
1818 showPlayPointer = false; | 1876 showPlayPointer = false; |
1819 } else if (m_manager && !m_manager->isPlaying()) { | 1877 } else if (m_manager && !m_manager->isPlaying()) { |
1820 if (m_playPointerFrame == getCentreFrame() && | 1878 if (m_playPointerFrame == getCentreFrame() && |
1879 m_manager->shouldShowCentreLine() && | |
1821 m_followPlay != PlaybackIgnore) { | 1880 m_followPlay != PlaybackIgnore) { |
1881 // Don't show the play pointer when it is redundant with | |
1882 // the centre line | |
1822 showPlayPointer = false; | 1883 showPlayPointer = false; |
1823 } | 1884 } |
1824 } | 1885 } |
1825 | 1886 |
1826 if (showPlayPointer) { | 1887 if (showPlayPointer) { |