# HG changeset patch # User Chris Cannam # Date 1524751792 -3600 # Node ID 2f828631c9be5b86e774061ff840f5fdce471598 # Parent 5da79d7501f9b589de25352368fed8cddd0a0c9a Update pane and layer menu shortcuts so that the waveform/spectrogram/etc shortcuts (Shift+G etc) always refer to the source model that is in the currently selected pane. This is a potentially confusing backward-incompatible change, but is also quite clearly how it ought to work... diff -r 5da79d7501f9 -r 2f828631c9be main/MainWindow.cpp --- a/main/MainWindow.cpp Thu Apr 26 09:27:24 2018 +0100 +++ b/main/MainWindow.cpp Thu Apr 26 15:09:52 2018 +0100 @@ -1141,6 +1141,63 @@ #endif } +QString +MainWindow::shortcutFor(LayerFactory::LayerType layer, bool isPaneMenu) +{ + QString shortcutText; + +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wswitch-enum" +#endif + + switch (layer) { + case LayerFactory::Waveform: + if (isPaneMenu) { + shortcutText = tr("W"); + } else { + shortcutText = tr("Shift+W"); + } + break; + + case LayerFactory::Spectrogram: + if (isPaneMenu) { + shortcutText = tr("G"); + } else { + shortcutText = tr("Shift+G"); + } + break; + + case LayerFactory::MelodicRangeSpectrogram: + if (isPaneMenu) { + shortcutText = tr("M"); + } else { + shortcutText = tr("Shift+M"); + } + break; + + case LayerFactory::PeakFrequencySpectrogram: + if (isPaneMenu) { + shortcutText = tr("K"); + } else { + shortcutText = tr("Shift+K"); + } + break; + + case LayerFactory::Spectrum: + if (isPaneMenu) { + shortcutText = tr("U"); + } else { + shortcutText = tr("Shift+U"); + } + break; + + default: + break; + } + + return shortcutText; +} + void MainWindow::setupPaneAndLayerMenus() { @@ -1187,8 +1244,6 @@ menu = m_layerMenu; -// menu->addSeparator(); - LayerFactory::LayerTypeSet emptyLayerTypes = LayerFactory::getInstance()->getValidEmptyLayerTypes(); @@ -1251,10 +1306,12 @@ QMenu *submenu = 0; QIcon icon; - QString mainText, shortcutText, tipText, channelText; + QString mainText, tipText, channelText; LayerFactory::LayerType type = backgroundTypes[i]; bool mono = true; + QString shortcutText = shortcutFor(type, menuType == paneMenuType); + // Avoid warnings/errors with -Wextra because we aren't explicitly // handling all layer types (-Wall is OK with this because of the // default but the stricter level insists) @@ -1268,10 +1325,8 @@ icon = il.load("waveform"); mainText = tr("Add &Waveform"); if (menuType == paneMenuType) { - shortcutText = tr("W"); tipText = tr("Add a new pane showing a waveform view"); } else { - shortcutText = tr("Shift+W"); tipText = tr("Add a new layer showing a waveform view"); } mono = false; @@ -1281,10 +1336,8 @@ icon = il.load("spectrogram"); mainText = tr("Add Spectro&gram"); if (menuType == paneMenuType) { - shortcutText = tr("G"); tipText = tr("Add a new pane showing a spectrogram"); } else { - shortcutText = tr("Shift+G"); tipText = tr("Add a new layer showing a spectrogram"); } break; @@ -1293,10 +1346,8 @@ icon = il.load("spectrogram"); mainText = tr("Add &Melodic Range Spectrogram"); if (menuType == paneMenuType) { - shortcutText = tr("M"); tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches"); } else { - shortcutText = tr("Shift+M"); tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches"); } break; @@ -1305,10 +1356,8 @@ icon = il.load("spectrogram"); mainText = tr("Add Pea&k Frequency Spectrogram"); if (menuType == paneMenuType) { - shortcutText = tr("K"); tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies"); } else { - shortcutText = tr("Shift+K"); tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies"); } break; @@ -1317,10 +1366,8 @@ icon = il.load("spectrum"); mainText = tr("Add Spectr&um"); if (menuType == paneMenuType) { - shortcutText = tr("U"); tipText = tr("Add a new pane showing a frequency spectrum"); } else { - shortcutText = tr("Shift+U"); tipText = tr("Add a new layer showing a frequency spectrum"); } break; @@ -1559,6 +1606,34 @@ } void +MainWindow::updateLayerShortcutsFor(Model *model) +{ + set seen; + + for (auto &a : m_paneActions) { + auto type = a.second.layer; + if (a.second.sourceModel == model && seen.find(type) == seen.end()) { + a.first->setShortcut(shortcutFor(type, true)); + seen.insert(type); + } else { + a.first->setShortcut(QString()); + } + } + + seen.clear(); + + for (auto &a : m_layerActions) { + auto type = a.second.layer; + if (a.second.sourceModel == model && seen.find(type) == seen.end()) { + a.first->setShortcut(shortcutFor(type, false)); + seen.insert(type); + } else { + a.first->setShortcut(QString()); + } + } +} + +void MainWindow::setupTransformsMenu() { if (m_transformsMenu) { @@ -4227,24 +4302,29 @@ } } - if (containsMainModel) { - m_panLayer->setModel(getMainModel()); - return; - } - + bool panLayerSet = false; + for (int i = pane->getLayerCount(); i > 0; ) { --i; Layer *layer = pane->getLayer(i); - if (LayerFactory::getInstance()->getLayerType(layer) == - LayerFactory::Waveform) { - RangeSummarisableTimeValueModel *tvm = - dynamic_cast(layer->getModel()); - if (tvm) { + RangeSummarisableTimeValueModel *tvm = + qobject_cast(layer->getModel()); + if (tvm) { + auto type = LayerFactory::getInstance()->getLayerType(layer); + if (type != LayerFactory::TimeRuler) { + updateLayerShortcutsFor(tvm); + } + if (type == LayerFactory::Waveform) { m_panLayer->setModel(tvm); - return; + panLayerSet = true; + break; } } } + + if (containsMainModel && !panLayerSet) { + m_panLayer->setModel(getMainModel()); + } } void diff -r 5da79d7501f9 -r 2f828631c9be main/MainWindow.h --- a/main/MainWindow.h Thu Apr 26 09:27:24 2018 +0100 +++ b/main/MainWindow.h Thu Apr 26 15:09:52 2018 +0100 @@ -246,6 +246,9 @@ int channel; }; + QString shortcutFor(LayerFactory::LayerType, bool isPaneMenu); + void updateLayerShortcutsFor(Model *); + typedef std::map PaneActionMap; PaneActionMap m_paneActions; diff -r 5da79d7501f9 -r 2f828631c9be vext-lock.json --- a/vext-lock.json Thu Apr 26 09:27:24 2018 +0100 +++ b/vext-lock.json Thu Apr 26 15:09:52 2018 +0100 @@ -7,7 +7,7 @@ "pin": "0fb5d4e6edeb" }, "svgui": { - "pin": "97d977091d4e" + "pin": "3ca1be2e2c91" }, "svapp": { "pin": "f03bc1d38cac"