Mercurial > hg > svgui
comparison view/Pane.cpp @ 1588:0f36e0eca6b0
Add right-button context menu to panner widget
author | Chris Cannam |
---|---|
date | Mon, 30 Mar 2020 11:29:16 +0100 |
parents | e6362cf5ff1d |
children | 4739a1b2266f |
comparison
equal
deleted
inserted
replaced
1587:2108af725460 | 1588:0f36e0eca6b0 |
---|---|
30 | 30 |
31 // GF: added so we can propagate the mouse move event to the note layer for context handling. | 31 // GF: added so we can propagate the mouse move event to the note layer for context handling. |
32 #include "layer/LayerFactory.h" | 32 #include "layer/LayerFactory.h" |
33 #include "layer/FlexiNoteLayer.h" | 33 #include "layer/FlexiNoteLayer.h" |
34 | 34 |
35 #include "widgets/MenuTitle.h" | |
35 | 36 |
36 //!!! ugh | 37 //!!! ugh |
37 #include "data/model/WaveFileModel.h" | 38 #include "data/model/WaveFileModel.h" |
38 #include "data/model/AlignmentModel.h" | 39 #include "data/model/AlignmentModel.h" |
39 | 40 |
44 #include <QDropEvent> | 45 #include <QDropEvent> |
45 #include <QCursor> | 46 #include <QCursor> |
46 #include <QTextStream> | 47 #include <QTextStream> |
47 #include <QMimeData> | 48 #include <QMimeData> |
48 #include <QApplication> | 49 #include <QApplication> |
50 #include <QMenu> | |
49 | 51 |
50 #include <iostream> | 52 #include <iostream> |
51 #include <cmath> | 53 #include <cmath> |
52 | 54 |
53 //!!! for HUD -- pull out into a separate class | 55 //!!! for HUD -- pull out into a separate class |
54 #include <QFrame> | 56 #include <QFrame> |
55 #include <QGridLayout> | 57 #include <QGridLayout> |
56 #include <QPushButton> | 58 #include <QPushButton> |
59 | |
57 #include "widgets/Thumbwheel.h" | 60 #include "widgets/Thumbwheel.h" |
58 #include "widgets/Panner.h" | 61 #include "widgets/Panner.h" |
59 #include "widgets/RangeInputDialog.h" | 62 #include "widgets/RangeInputDialog.h" |
60 #include "widgets/NotifyingPushButton.h" | 63 #include "widgets/NotifyingPushButton.h" |
61 | 64 |
84 m_headsUpDisplay(nullptr), | 87 m_headsUpDisplay(nullptr), |
85 m_vpan(nullptr), | 88 m_vpan(nullptr), |
86 m_hthumb(nullptr), | 89 m_hthumb(nullptr), |
87 m_vthumb(nullptr), | 90 m_vthumb(nullptr), |
88 m_reset(nullptr), | 91 m_reset(nullptr), |
92 m_lastVerticalPannerContextMenu(nullptr), | |
89 m_mouseInWidget(false), | 93 m_mouseInWidget(false), |
90 m_playbackFrameMoveScheduled(false), | 94 m_playbackFrameMoveScheduled(false), |
91 m_playbackFrameMoveTo(0) | 95 m_playbackFrameMoveTo(0) |
92 { | 96 { |
93 setObjectName("Pane"); | 97 setObjectName("Pane"); |
98 | 102 |
99 connect(this, SIGNAL(regionOutlined(QRect)), | 103 connect(this, SIGNAL(regionOutlined(QRect)), |
100 this, SLOT(zoomToRegion(QRect))); | 104 this, SLOT(zoomToRegion(QRect))); |
101 | 105 |
102 cerr << "Pane::Pane(" << this << ") returning" << endl; | 106 cerr << "Pane::Pane(" << this << ") returning" << endl; |
107 } | |
108 | |
109 Pane::~Pane() | |
110 { | |
111 delete m_lastVerticalPannerContextMenu; | |
103 } | 112 } |
104 | 113 |
105 void | 114 void |
106 Pane::updateHeadsUpDisplay() | 115 Pane::updateHeadsUpDisplay() |
107 { | 116 { |
146 this, SLOT(verticalPannerMoved(float, float, float, float))); | 155 this, SLOT(verticalPannerMoved(float, float, float, float))); |
147 connect(m_vpan, SIGNAL(doubleClicked()), | 156 connect(m_vpan, SIGNAL(doubleClicked()), |
148 this, SLOT(editVerticalPannerExtents())); | 157 this, SLOT(editVerticalPannerExtents())); |
149 connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); | 158 connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); |
150 connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); | 159 connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); |
160 | |
161 // Panner doesn't provide its own context menu | |
162 m_vpan->setContextMenuPolicy(Qt::CustomContextMenu); | |
163 connect(m_vpan, SIGNAL(customContextMenuRequested(const QPoint &)), | |
164 this, SLOT(verticalPannerContextMenuRequested(const QPoint &))); | |
151 | 165 |
152 m_vthumb = new Thumbwheel(Qt::Vertical); | 166 m_vthumb = new Thumbwheel(Qt::Vertical); |
153 m_vthumb->setObjectName(tr("Vertical Zoom")); | 167 m_vthumb->setObjectName(tr("Vertical Zoom")); |
154 m_vthumb->setCursor(Qt::ArrowCursor); | 168 m_vthumb->setCursor(Qt::ArrowCursor); |
155 layout->addWidget(m_vthumb, 0, 2); | 169 layout->addWidget(m_vthumb, 0, 2); |
2538 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; | 2552 // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; |
2539 setTopLayerDisplayExtents(newmin, newmax); | 2553 setTopLayerDisplayExtents(newmin, newmax); |
2540 } | 2554 } |
2541 | 2555 |
2542 void | 2556 void |
2557 Pane::verticalPannerContextMenuRequested(const QPoint &pos) | |
2558 { | |
2559 Panner *panner = qobject_cast<Panner *>(sender()); | |
2560 if (!panner) { | |
2561 return; | |
2562 } | |
2563 | |
2564 double vmin, vmax, dmin, dmax; | |
2565 QString unit; | |
2566 if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit)) { | |
2567 return; | |
2568 } | |
2569 | |
2570 delete m_lastVerticalPannerContextMenu; | |
2571 QMenu *m = new QMenu; | |
2572 m_lastVerticalPannerContextMenu = m; | |
2573 | |
2574 MenuTitle::addTitle(m, tr("Vertical Range: %1 - %2 %3") | |
2575 .arg(dmin).arg(dmax).arg(unit)); | |
2576 | |
2577 m->addAction(tr("&Edit..."), | |
2578 [=]() { | |
2579 editVerticalPannerExtents(); | |
2580 }); | |
2581 m->addAction(tr("&Reset to Default"), | |
2582 [=]() { | |
2583 if (m_vthumb) { | |
2584 // This determines the "size" of the panner box | |
2585 m_vthumb->resetToDefault(); | |
2586 } | |
2587 panner->resetToDefault(); | |
2588 }); | |
2589 | |
2590 m->popup(panner->mapToGlobal(pos)); | |
2591 m_lastVerticalPannerContextMenu = m; | |
2592 } | |
2593 | |
2594 void | |
2543 Pane::editVerticalPannerExtents() | 2595 Pane::editVerticalPannerExtents() |
2544 { | 2596 { |
2545 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; | 2597 if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; |
2546 | 2598 |
2547 double vmin, vmax, dmin, dmax; | 2599 double vmin, vmax, dmin, dmax; |
2550 || vmax == vmin) { | 2602 || vmax == vmin) { |
2551 return; | 2603 return; |
2552 } | 2604 } |
2553 | 2605 |
2554 RangeInputDialog dialog(tr("Enter new range"), | 2606 RangeInputDialog dialog(tr("Enter new range"), |
2555 tr("New vertical display range, from %1 to %2 %4:") | 2607 tr("New vertical display range, from %1 to %2 %3:") |
2556 .arg(vmin).arg(vmax).arg(unit), | 2608 .arg(vmin).arg(vmax).arg(unit), |
2557 unit, float(vmin), float(vmax), this); | 2609 unit, float(vmin), float(vmax), this); |
2558 dialog.setRange(float(dmin), float(dmax)); | 2610 dialog.setRange(float(dmin), float(dmax)); |
2559 | 2611 |
2560 if (dialog.exec() == QDialog::Accepted) { | 2612 if (dialog.exec() == QDialog::Accepted) { |