comparison view/Pane.cpp @ 189:5b7472db612b

* Add large chunks of context help in the optional status bar * Add an extra overlay mode in which even the centre frame is disabled * Fixes to FTP retrieval
author Chris Cannam
date Fri, 19 Jan 2007 13:13:14 +0000
parents dd573e090eed
children fcc043f75c41
comparison
equal deleted inserted replaced
188:dd573e090eed 189:5b7472db612b
33 #include <QGridLayout> 33 #include <QGridLayout>
34 #include <QPushButton> 34 #include <QPushButton>
35 #include "widgets/Thumbwheel.h" 35 #include "widgets/Thumbwheel.h"
36 #include "widgets/Panner.h" 36 #include "widgets/Panner.h"
37 #include "widgets/RangeInputDialog.h" 37 #include "widgets/RangeInputDialog.h"
38 #include "widgets/NotifyingPushButton.h"
38 39
39 using std::cerr; 40 using std::cerr;
40 using std::endl; 41 using std::endl;
41 42
42 Pane::Pane(QWidget *w) : 43 Pane::Pane(QWidget *w) :
97 m_hthumb->setFixedHeight(16); 98 m_hthumb->setFixedHeight(16);
98 m_hthumb->setDefaultValue(0); 99 m_hthumb->setDefaultValue(0);
99 m_hthumb->setSpeed(0.6); 100 m_hthumb->setSpeed(0.6);
100 connect(m_hthumb, SIGNAL(valueChanged(int)), this, 101 connect(m_hthumb, SIGNAL(valueChanged(int)), this,
101 SLOT(horizontalThumbwheelMoved(int))); 102 SLOT(horizontalThumbwheelMoved(int)));
103 connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
104 connect(m_hthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
102 105
103 m_vpan = new Panner; 106 m_vpan = new Panner;
104 layout->addWidget(m_vpan, 0, 1); 107 layout->addWidget(m_vpan, 0, 1);
105 m_vpan->setFixedWidth(12); 108 m_vpan->setFixedWidth(12);
106 m_vpan->setFixedHeight(70); 109 m_vpan->setFixedHeight(70);
107 m_vpan->setAlpha(80, 130); 110 m_vpan->setAlpha(80, 130);
108 connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)), 111 connect(m_vpan, SIGNAL(rectExtentsChanged(float, float, float, float)),
109 this, SLOT(verticalPannerMoved(float, float, float, float))); 112 this, SLOT(verticalPannerMoved(float, float, float, float)));
110 connect(m_vpan, SIGNAL(doubleClicked()), 113 connect(m_vpan, SIGNAL(doubleClicked()),
111 this, SLOT(editVerticalPannerExtents())); 114 this, SLOT(editVerticalPannerExtents()));
115 connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
116 connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
112 117
113 m_vthumb = new Thumbwheel(Qt::Vertical); 118 m_vthumb = new Thumbwheel(Qt::Vertical);
114 m_vthumb->setObjectName(tr("Vertical Zoom")); 119 m_vthumb->setObjectName(tr("Vertical Zoom"));
115 layout->addWidget(m_vthumb, 0, 2); 120 layout->addWidget(m_vthumb, 0, 2);
116 m_vthumb->setFixedWidth(16); 121 m_vthumb->setFixedWidth(16);
117 m_vthumb->setFixedHeight(70); 122 m_vthumb->setFixedHeight(70);
118 connect(m_vthumb, SIGNAL(valueChanged(int)), this, 123 connect(m_vthumb, SIGNAL(valueChanged(int)), this,
119 SLOT(verticalThumbwheelMoved(int))); 124 SLOT(verticalThumbwheelMoved(int)));
125 connect(m_vthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
126 connect(m_vthumb, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
120 127
121 if (layer) { 128 if (layer) {
122 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper(); 129 RangeMapper *rm = layer->getNewVerticalZoomRangeMapper();
123 if (rm) m_vthumb->setRangeMapper(rm); 130 if (rm) m_vthumb->setRangeMapper(rm);
124 } 131 }
125 132
126 QPushButton *reset = new QPushButton; 133 m_reset = new NotifyingPushButton;
127 reset->setFixedHeight(16); 134 m_reset->setFixedHeight(16);
128 reset->setFixedWidth(16); 135 m_reset->setFixedWidth(16);
129 layout->addWidget(reset, 1, 2); 136 layout->addWidget(m_reset, 1, 2);
130 connect(reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault())); 137 connect(m_reset, SIGNAL(clicked()), m_hthumb, SLOT(resetToDefault()));
131 connect(reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault())); 138 connect(m_reset, SIGNAL(clicked()), m_vthumb, SLOT(resetToDefault()));
132 connect(reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault())); 139 connect(m_reset, SIGNAL(clicked()), m_vpan, SLOT(resetToDefault()));
140 connect(m_reset, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
141 connect(m_reset, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
133 } 142 }
134 143
135 int count = 0; 144 int count = 0;
136 int current = 0; 145 int current = 0;
137 int level = 1; 146 int level = 1;
379 388
380 if (dynamic_cast<WaveformLayer *>(*vi)) { 389 if (dynamic_cast<WaveformLayer *>(*vi)) {
381 waveformModel = (*vi)->getModel(); 390 waveformModel = (*vi)->getModel();
382 } 391 }
383 392
384 if (!m_manager || 393 if (!m_manager || !m_manager->shouldShowVerticalScale()) {
385 m_manager->getOverlayMode() == ViewManager::NoOverlays) {
386 break; 394 break;
387 } 395 }
388 396
389 verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint); 397 verticalScaleWidth = (*vi)->getVerticalScaleWidth(this, paint);
390 398
462 } 470 }
463 471
464 int sampleRate = getModelsSampleRate(); 472 int sampleRate = getModelsSampleRate();
465 paint.setBrush(Qt::NoBrush); 473 paint.setBrush(Qt::NoBrush);
466 474
467 if (m_centreLineVisible) { 475 if (m_centreLineVisible &&
468 476 m_manager &&
469 if (hasLightBackground()) { 477 m_manager->shouldShowCentreLine()) {
470 paint.setPen(QColor(50, 50, 50)); 478
471 } else { 479 QColor c = QColor(0, 0, 0);
472 paint.setPen(QColor(200, 200, 200)); 480 if (!hasLightBackground()) {
473 } 481 c = QColor(240, 240, 240);
474 paint.drawLine(width() / 2, 0, width() / 2, height() - 1); 482 }
483 paint.setPen(c);
484 int x = width() / 2 + 1;
485 paint.drawLine(x, 0, x, height() - 1);
486 paint.drawLine(x-1, 1, x+1, 1);
487 paint.drawLine(x-2, 0, x+2, 0);
488 paint.drawLine(x-1, height() - 2, x+1, height() - 2);
489 paint.drawLine(x-2, height() - 1, x+2, height() - 1);
475 490
476 paint.setPen(QColor(50, 50, 50)); 491 paint.setPen(QColor(50, 50, 50));
477 492
478 int y = height() - fontHeight 493 int y = height() - fontHeight
479 + fontAscent - 6; 494 + fontAscent - 6;
497 // y already set correctly 512 // y already set correctly
498 break; 513 break;
499 } 514 }
500 } 515 }
501 516
502 if (m_manager && 517 if (m_manager && m_manager->shouldShowFrameCount()) {
503 m_manager->getOverlayMode() != ViewManager::NoOverlays) {
504 518
505 if (sampleRate) { 519 if (sampleRate) {
506 520
507 QString text(QString::fromStdString 521 QString text(QString::fromStdString
508 (RealTime::frame2RealTime 522 (RealTime::frame2RealTime
527 paint.setPen(QColor(50, 50, 50)); 541 paint.setPen(QColor(50, 50, 50));
528 } 542 }
529 543
530 if (waveformModel && 544 if (waveformModel &&
531 m_manager && 545 m_manager &&
532 m_manager->getOverlayMode() != ViewManager::NoOverlays && 546 m_manager->shouldShowDuration() &&
533 r.y() + r.height() >= height() - fontHeight - 6) { 547 r.y() + r.height() >= height() - fontHeight - 6) {
534 548
535 size_t modelRate = waveformModel->getSampleRate(); 549 size_t modelRate = waveformModel->getSampleRate();
536 size_t mainModelRate = m_manager->getMainModelSampleRate(); 550 size_t mainModelRate = m_manager->getMainModelSampleRate();
537 size_t playbackRate = m_manager->getPlaybackSampleRate(); 551 size_t playbackRate = m_manager->getPlaybackSampleRate();
563 desc, OutlinedText); 577 desc, OutlinedText);
564 } 578 }
565 } 579 }
566 580
567 if (m_manager && 581 if (m_manager &&
568 m_manager->getOverlayMode() == ViewManager::AllOverlays && 582 m_manager->shouldShowLayerNames() &&
569 r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) { 583 r.y() + r.height() >= height() - m_layers.size() * fontHeight - 6) {
570 584
571 std::vector<QString> texts; 585 std::vector<QString> texts;
572 int maxTextWidth = 0; 586 int maxTextWidth = 0;
573 587
737 751
738 void 752 void
739 Pane::mousePressEvent(QMouseEvent *e) 753 Pane::mousePressEvent(QMouseEvent *e)
740 { 754 {
741 if (e->buttons() & Qt::RightButton) { 755 if (e->buttons() & Qt::RightButton) {
756 emit contextHelpChanged("");
742 emit rightButtonMenuRequested(mapToGlobal(e->pos())); 757 emit rightButtonMenuRequested(mapToGlobal(e->pos()));
743 return; 758 return;
744 } 759 }
745 760
746 m_clickPos = e->pos(); 761 m_clickPos = e->pos();
918 Pane::mouseMoveEvent(QMouseEvent *e) 933 Pane::mouseMoveEvent(QMouseEvent *e)
919 { 934 {
920 if (e->buttons() & Qt::RightButton) { 935 if (e->buttons() & Qt::RightButton) {
921 return; 936 return;
922 } 937 }
938
939 updateContextHelp(&e->pos());
923 940
924 ViewManager::ToolMode mode = ViewManager::NavigateMode; 941 ViewManager::ToolMode mode = ViewManager::NavigateMode;
925 if (m_manager) mode = m_manager->getToolMode(); 942 if (m_manager) mode = m_manager->getToolMode();
926 943
927 QPoint prevPoint = m_identifyPoint; 944 QPoint prevPoint = m_identifyPoint;
1269 Pane::leaveEvent(QEvent *) 1286 Pane::leaveEvent(QEvent *)
1270 { 1287 {
1271 bool previouslyIdentifying = m_identifyFeatures; 1288 bool previouslyIdentifying = m_identifyFeatures;
1272 m_identifyFeatures = false; 1289 m_identifyFeatures = false;
1273 if (previouslyIdentifying) update(); 1290 if (previouslyIdentifying) update();
1291 emit contextHelpChanged("");
1274 } 1292 }
1275 1293
1276 void 1294 void
1277 Pane::resizeEvent(QResizeEvent *) 1295 Pane::resizeEvent(QResizeEvent *)
1278 { 1296 {
1618 m_vthumb->setValue(layer->getCurrentVerticalZoomStep()); 1636 m_vthumb->setValue(layer->getCurrentVerticalZoomStep());
1619 } 1637 }
1620 } 1638 }
1621 } 1639 }
1622 1640
1641 void
1642 Pane::updateContextHelp(const QPoint *pos)
1643 {
1644 QString help = "";
1645
1646 if (m_clickedInRange) {
1647 emit contextHelpChanged("");
1648 return;
1649 }
1650
1651 ViewManager::ToolMode mode = ViewManager::NavigateMode;
1652 if (m_manager) mode = m_manager->getToolMode();
1653
1654 bool editable = false;
1655 Layer *layer = getSelectedLayer();
1656 if (layer && layer->isLayerEditable()) {
1657 editable = true;
1658 }
1659
1660 if (mode == ViewManager::NavigateMode) {
1661
1662 help = tr("Click and drag to navigate");
1663
1664 } else if (mode == ViewManager::SelectMode) {
1665
1666 bool haveSelection = (m_manager && !m_manager->getSelections().empty());
1667
1668 if (haveSelection) {
1669 if (editable) {
1670 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; hold Ctrl for multi-select; middle-click and drag to navigate");
1671 } else {
1672 help = tr("Click and drag to select a range; hold Ctrl for multi-select; middle-click and drag to navigate");
1673 }
1674
1675 if (pos) {
1676 bool closeToLeft = false, closeToRight = false;
1677 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
1678 if ((closeToLeft || closeToRight) && !(closeToLeft && closeToRight)) {
1679
1680 help = tr("Click and drag to move the selection boundary");
1681 }
1682 }
1683 } else {
1684 if (editable) {
1685 help = tr("Click and drag to select a range; hold Shift to avoid snapping to items; middle-click to navigate");
1686 } else {
1687 help = tr("Click and drag to select a range; middle-click and drag to navigate");
1688 }
1689 }
1690
1691 } else if (mode == ViewManager::DrawMode) {
1692
1693 //!!! could call through to a layer function to find out exact meaning
1694 if (editable) {
1695 help = tr("Click to add a new item in the active layer");
1696 }
1697
1698 } else if (mode == ViewManager::EditMode) {
1699
1700 //!!! could call through to layer
1701 if (editable) {
1702 help = tr("Click and drag an item in the active layer to move it");
1703 if (pos) {
1704 bool closeToLeft = false, closeToRight = false;
1705 Selection selection = getSelectionAt(pos->x(), closeToLeft, closeToRight);
1706 if (!selection.isEmpty()) {
1707 help = tr("Click and drag to move all items in the selected range");
1708 }
1709 }
1710 }
1711 }
1712
1713 emit contextHelpChanged(help);
1714 }
1715
1716 void
1717 Pane::mouseEnteredWidget()
1718 {
1719 QWidget *w = dynamic_cast<QWidget *>(sender());
1720 if (!w) return;
1721
1722 if (w == m_vpan) {
1723 emit contextHelpChanged(tr("Click and drag to adjust the visible range of the vertical scale"));
1724 } else if (w == m_vthumb) {
1725 emit contextHelpChanged(tr("Click and drag to adjust the vertical zoom level"));
1726 } else if (w == m_hthumb) {
1727 emit contextHelpChanged(tr("Click and drag to adjust the horizontal zoom level"));
1728 } else if (w == m_reset) {
1729 emit contextHelpChanged(tr("Reset horizontal and vertical zoom levels to their defaults"));
1730 }
1731 }
1732
1733 void
1734 Pane::mouseLeftWidget()
1735 {
1736 emit contextHelpChanged("");
1737 }
1738
1623 QString 1739 QString
1624 Pane::toXmlString(QString indent, QString extraAttributes) const 1740 Pane::toXmlString(QString indent, QString extraAttributes) const
1625 { 1741 {
1626 return View::toXmlString 1742 return View::toXmlString
1627 (indent, 1743 (indent,