Mercurial > hg > svgui
diff 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 |
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));