Mercurial > hg > svgui
changeset 1588:0f36e0eca6b0
Add right-button context menu to panner widget
author | Chris Cannam |
---|---|
date | Mon, 30 Mar 2020 11:29:16 +0100 |
parents | 2108af725460 |
children | 27ea5d61b402 |
files | view/Pane.cpp view/Pane.h |
diffstat | 2 files changed, 63 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/view/Pane.cpp Fri Mar 27 14:36:11 2020 +0000 +++ b/view/Pane.cpp Mon Mar 30 11:29:16 2020 +0100 @@ -32,6 +32,7 @@ #include "layer/LayerFactory.h" #include "layer/FlexiNoteLayer.h" +#include "widgets/MenuTitle.h" //!!! ugh #include "data/model/WaveFileModel.h" @@ -46,6 +47,7 @@ #include <QTextStream> #include <QMimeData> #include <QApplication> +#include <QMenu> #include <iostream> #include <cmath> @@ -54,6 +56,7 @@ #include <QFrame> #include <QGridLayout> #include <QPushButton> + #include "widgets/Thumbwheel.h" #include "widgets/Panner.h" #include "widgets/RangeInputDialog.h" @@ -86,6 +89,7 @@ m_hthumb(nullptr), m_vthumb(nullptr), m_reset(nullptr), + m_lastVerticalPannerContextMenu(nullptr), m_mouseInWidget(false), m_playbackFrameMoveScheduled(false), m_playbackFrameMoveTo(0) @@ -102,6 +106,11 @@ cerr << "Pane::Pane(" << this << ") returning" << endl; } +Pane::~Pane() +{ + delete m_lastVerticalPannerContextMenu; +} + void Pane::updateHeadsUpDisplay() { @@ -149,6 +158,11 @@ connect(m_vpan, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); connect(m_vpan, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); + // Panner doesn't provide its own context menu + m_vpan->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_vpan, SIGNAL(customContextMenuRequested(const QPoint &)), + this, SLOT(verticalPannerContextMenuRequested(const QPoint &))); + m_vthumb = new Thumbwheel(Qt::Vertical); m_vthumb->setObjectName(tr("Vertical Zoom")); m_vthumb->setCursor(Qt::ArrowCursor); @@ -2540,6 +2554,44 @@ } void +Pane::verticalPannerContextMenuRequested(const QPoint &pos) +{ + Panner *panner = qobject_cast<Panner *>(sender()); + if (!panner) { + return; + } + + double vmin, vmax, dmin, dmax; + QString unit; + if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit)) { + return; + } + + delete m_lastVerticalPannerContextMenu; + QMenu *m = new QMenu; + m_lastVerticalPannerContextMenu = m; + + MenuTitle::addTitle(m, tr("Vertical Range: %1 - %2 %3") + .arg(dmin).arg(dmax).arg(unit)); + + m->addAction(tr("&Edit..."), + [=]() { + editVerticalPannerExtents(); + }); + m->addAction(tr("&Reset to Default"), + [=]() { + if (m_vthumb) { + // This determines the "size" of the panner box + m_vthumb->resetToDefault(); + } + panner->resetToDefault(); + }); + + m->popup(panner->mapToGlobal(pos)); + m_lastVerticalPannerContextMenu = m; +} + +void Pane::editVerticalPannerExtents() { if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; @@ -2552,7 +2604,7 @@ } RangeInputDialog dialog(tr("Enter new range"), - tr("New vertical display range, from %1 to %2 %4:") + tr("New vertical display range, from %1 to %2 %3:") .arg(vmin).arg(vmax).arg(unit), unit, float(vmin), float(vmax), this); dialog.setRange(float(dmin), float(dmax));
--- a/view/Pane.h Fri Mar 27 14:36:11 2020 +0000 +++ b/view/Pane.h Mon Mar 30 11:29:16 2020 +0100 @@ -30,6 +30,7 @@ class Panner; class NotifyingPushButton; class KeyReference; +class QMenu; class Pane : public View { @@ -37,6 +38,8 @@ public: Pane(QWidget *parent = 0); + virtual ~Pane(); + virtual QString getPropertyContainerIconName() const override { return "pane"; } virtual bool shouldIlluminateLocalFeatures(const Layer *layer, @@ -91,11 +94,12 @@ virtual void modelAlignmentCompletionChanged(ModelId) override; // local slots, not overrides - virtual void horizontalThumbwheelMoved(int value); - virtual void verticalThumbwheelMoved(int value); - virtual void verticalZoomChanged(); - virtual void verticalPannerMoved(float x, float y, float w, float h); - virtual void editVerticalPannerExtents(); + void horizontalThumbwheelMoved(int value); + void verticalThumbwheelMoved(int value); + void verticalZoomChanged(); + void verticalPannerMoved(float x, float y, float w, float h); + void verticalPannerContextMenuRequested(const QPoint &); + void editVerticalPannerExtents(); virtual void layerParametersChanged() override; @@ -207,6 +211,7 @@ Thumbwheel *m_hthumb; Thumbwheel *m_vthumb; NotifyingPushButton *m_reset; + QMenu *m_lastVerticalPannerContextMenu; bool m_mouseInWidget;