Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 1794:2f828631c9be
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...
author | Chris Cannam |
---|---|
date | Thu, 26 Apr 2018 15:09:52 +0100 |
parents | 07bd0eaa8114 |
children | bea6e7bced25 |
comparison
equal
deleted
inserted
replaced
1793:5da79d7501f9 | 1794:2f828631c9be |
---|---|
1139 m_keyReference->registerShortcut(action); | 1139 m_keyReference->registerShortcut(action); |
1140 menu->addAction(action); | 1140 menu->addAction(action); |
1141 #endif | 1141 #endif |
1142 } | 1142 } |
1143 | 1143 |
1144 QString | |
1145 MainWindow::shortcutFor(LayerFactory::LayerType layer, bool isPaneMenu) | |
1146 { | |
1147 QString shortcutText; | |
1148 | |
1149 #ifdef __GNUC__ | |
1150 #pragma GCC diagnostic ignored "-Wswitch-enum" | |
1151 #endif | |
1152 | |
1153 switch (layer) { | |
1154 case LayerFactory::Waveform: | |
1155 if (isPaneMenu) { | |
1156 shortcutText = tr("W"); | |
1157 } else { | |
1158 shortcutText = tr("Shift+W"); | |
1159 } | |
1160 break; | |
1161 | |
1162 case LayerFactory::Spectrogram: | |
1163 if (isPaneMenu) { | |
1164 shortcutText = tr("G"); | |
1165 } else { | |
1166 shortcutText = tr("Shift+G"); | |
1167 } | |
1168 break; | |
1169 | |
1170 case LayerFactory::MelodicRangeSpectrogram: | |
1171 if (isPaneMenu) { | |
1172 shortcutText = tr("M"); | |
1173 } else { | |
1174 shortcutText = tr("Shift+M"); | |
1175 } | |
1176 break; | |
1177 | |
1178 case LayerFactory::PeakFrequencySpectrogram: | |
1179 if (isPaneMenu) { | |
1180 shortcutText = tr("K"); | |
1181 } else { | |
1182 shortcutText = tr("Shift+K"); | |
1183 } | |
1184 break; | |
1185 | |
1186 case LayerFactory::Spectrum: | |
1187 if (isPaneMenu) { | |
1188 shortcutText = tr("U"); | |
1189 } else { | |
1190 shortcutText = tr("Shift+U"); | |
1191 } | |
1192 break; | |
1193 | |
1194 default: | |
1195 break; | |
1196 } | |
1197 | |
1198 return shortcutText; | |
1199 } | |
1200 | |
1144 void | 1201 void |
1145 MainWindow::setupPaneAndLayerMenus() | 1202 MainWindow::setupPaneAndLayerMenus() |
1146 { | 1203 { |
1147 if (m_paneMenu) { | 1204 if (m_paneMenu) { |
1148 m_paneActions.clear(); | 1205 m_paneActions.clear(); |
1184 menu->addAction(action); | 1241 menu->addAction(action); |
1185 | 1242 |
1186 menu->addSeparator(); | 1243 menu->addSeparator(); |
1187 | 1244 |
1188 menu = m_layerMenu; | 1245 menu = m_layerMenu; |
1189 | |
1190 // menu->addSeparator(); | |
1191 | 1246 |
1192 LayerFactory::LayerTypeSet emptyLayerTypes = | 1247 LayerFactory::LayerTypeSet emptyLayerTypes = |
1193 LayerFactory::getInstance()->getValidEmptyLayerTypes(); | 1248 LayerFactory::getInstance()->getValidEmptyLayerTypes(); |
1194 | 1249 |
1195 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin(); | 1250 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin(); |
1249 else menu = m_layerMenu; | 1304 else menu = m_layerMenu; |
1250 | 1305 |
1251 QMenu *submenu = 0; | 1306 QMenu *submenu = 0; |
1252 | 1307 |
1253 QIcon icon; | 1308 QIcon icon; |
1254 QString mainText, shortcutText, tipText, channelText; | 1309 QString mainText, tipText, channelText; |
1255 LayerFactory::LayerType type = backgroundTypes[i]; | 1310 LayerFactory::LayerType type = backgroundTypes[i]; |
1256 bool mono = true; | 1311 bool mono = true; |
1312 | |
1313 QString shortcutText = shortcutFor(type, menuType == paneMenuType); | |
1257 | 1314 |
1258 // Avoid warnings/errors with -Wextra because we aren't explicitly | 1315 // Avoid warnings/errors with -Wextra because we aren't explicitly |
1259 // handling all layer types (-Wall is OK with this because of the | 1316 // handling all layer types (-Wall is OK with this because of the |
1260 // default but the stricter level insists) | 1317 // default but the stricter level insists) |
1261 #ifdef __GNUC__ | 1318 #ifdef __GNUC__ |
1266 | 1323 |
1267 case LayerFactory::Waveform: | 1324 case LayerFactory::Waveform: |
1268 icon = il.load("waveform"); | 1325 icon = il.load("waveform"); |
1269 mainText = tr("Add &Waveform"); | 1326 mainText = tr("Add &Waveform"); |
1270 if (menuType == paneMenuType) { | 1327 if (menuType == paneMenuType) { |
1271 shortcutText = tr("W"); | |
1272 tipText = tr("Add a new pane showing a waveform view"); | 1328 tipText = tr("Add a new pane showing a waveform view"); |
1273 } else { | 1329 } else { |
1274 shortcutText = tr("Shift+W"); | |
1275 tipText = tr("Add a new layer showing a waveform view"); | 1330 tipText = tr("Add a new layer showing a waveform view"); |
1276 } | 1331 } |
1277 mono = false; | 1332 mono = false; |
1278 break; | 1333 break; |
1279 | 1334 |
1280 case LayerFactory::Spectrogram: | 1335 case LayerFactory::Spectrogram: |
1281 icon = il.load("spectrogram"); | 1336 icon = il.load("spectrogram"); |
1282 mainText = tr("Add Spectro&gram"); | 1337 mainText = tr("Add Spectro&gram"); |
1283 if (menuType == paneMenuType) { | 1338 if (menuType == paneMenuType) { |
1284 shortcutText = tr("G"); | |
1285 tipText = tr("Add a new pane showing a spectrogram"); | 1339 tipText = tr("Add a new pane showing a spectrogram"); |
1286 } else { | 1340 } else { |
1287 shortcutText = tr("Shift+G"); | |
1288 tipText = tr("Add a new layer showing a spectrogram"); | 1341 tipText = tr("Add a new layer showing a spectrogram"); |
1289 } | 1342 } |
1290 break; | 1343 break; |
1291 | 1344 |
1292 case LayerFactory::MelodicRangeSpectrogram: | 1345 case LayerFactory::MelodicRangeSpectrogram: |
1293 icon = il.load("spectrogram"); | 1346 icon = il.load("spectrogram"); |
1294 mainText = tr("Add &Melodic Range Spectrogram"); | 1347 mainText = tr("Add &Melodic Range Spectrogram"); |
1295 if (menuType == paneMenuType) { | 1348 if (menuType == paneMenuType) { |
1296 shortcutText = tr("M"); | |
1297 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches"); | 1349 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches"); |
1298 } else { | 1350 } else { |
1299 shortcutText = tr("Shift+M"); | |
1300 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches"); | 1351 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches"); |
1301 } | 1352 } |
1302 break; | 1353 break; |
1303 | 1354 |
1304 case LayerFactory::PeakFrequencySpectrogram: | 1355 case LayerFactory::PeakFrequencySpectrogram: |
1305 icon = il.load("spectrogram"); | 1356 icon = il.load("spectrogram"); |
1306 mainText = tr("Add Pea&k Frequency Spectrogram"); | 1357 mainText = tr("Add Pea&k Frequency Spectrogram"); |
1307 if (menuType == paneMenuType) { | 1358 if (menuType == paneMenuType) { |
1308 shortcutText = tr("K"); | |
1309 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies"); | 1359 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies"); |
1310 } else { | 1360 } else { |
1311 shortcutText = tr("Shift+K"); | |
1312 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies"); | 1361 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies"); |
1313 } | 1362 } |
1314 break; | 1363 break; |
1315 | 1364 |
1316 case LayerFactory::Spectrum: | 1365 case LayerFactory::Spectrum: |
1317 icon = il.load("spectrum"); | 1366 icon = il.load("spectrum"); |
1318 mainText = tr("Add Spectr&um"); | 1367 mainText = tr("Add Spectr&um"); |
1319 if (menuType == paneMenuType) { | 1368 if (menuType == paneMenuType) { |
1320 shortcutText = tr("U"); | |
1321 tipText = tr("Add a new pane showing a frequency spectrum"); | 1369 tipText = tr("Add a new pane showing a frequency spectrum"); |
1322 } else { | 1370 } else { |
1323 shortcutText = tr("Shift+U"); | |
1324 tipText = tr("Add a new layer showing a frequency spectrum"); | 1371 tipText = tr("Add a new layer showing a frequency spectrum"); |
1325 } | 1372 } |
1326 break; | 1373 break; |
1327 | 1374 |
1328 default: break; | 1375 default: break; |
1557 | 1604 |
1558 finaliseMenus(); | 1605 finaliseMenus(); |
1559 } | 1606 } |
1560 | 1607 |
1561 void | 1608 void |
1609 MainWindow::updateLayerShortcutsFor(Model *model) | |
1610 { | |
1611 set<LayerFactory::LayerType> seen; | |
1612 | |
1613 for (auto &a : m_paneActions) { | |
1614 auto type = a.second.layer; | |
1615 if (a.second.sourceModel == model && seen.find(type) == seen.end()) { | |
1616 a.first->setShortcut(shortcutFor(type, true)); | |
1617 seen.insert(type); | |
1618 } else { | |
1619 a.first->setShortcut(QString()); | |
1620 } | |
1621 } | |
1622 | |
1623 seen.clear(); | |
1624 | |
1625 for (auto &a : m_layerActions) { | |
1626 auto type = a.second.layer; | |
1627 if (a.second.sourceModel == model && seen.find(type) == seen.end()) { | |
1628 a.first->setShortcut(shortcutFor(type, false)); | |
1629 seen.insert(type); | |
1630 } else { | |
1631 a.first->setShortcut(QString()); | |
1632 } | |
1633 } | |
1634 } | |
1635 | |
1636 void | |
1562 MainWindow::setupTransformsMenu() | 1637 MainWindow::setupTransformsMenu() |
1563 { | 1638 { |
1564 if (m_transformsMenu) { | 1639 if (m_transformsMenu) { |
1565 m_transformActions.clear(); | 1640 m_transformActions.clear(); |
1566 m_transformActionsReverse.clear(); | 1641 m_transformActionsReverse.clear(); |
4225 containsMainModel = true; | 4300 containsMainModel = true; |
4226 break; | 4301 break; |
4227 } | 4302 } |
4228 } | 4303 } |
4229 | 4304 |
4230 if (containsMainModel) { | 4305 bool panLayerSet = false; |
4231 m_panLayer->setModel(getMainModel()); | 4306 |
4232 return; | |
4233 } | |
4234 | |
4235 for (int i = pane->getLayerCount(); i > 0; ) { | 4307 for (int i = pane->getLayerCount(); i > 0; ) { |
4236 --i; | 4308 --i; |
4237 Layer *layer = pane->getLayer(i); | 4309 Layer *layer = pane->getLayer(i); |
4238 if (LayerFactory::getInstance()->getLayerType(layer) == | 4310 RangeSummarisableTimeValueModel *tvm = |
4239 LayerFactory::Waveform) { | 4311 qobject_cast<RangeSummarisableTimeValueModel *>(layer->getModel()); |
4240 RangeSummarisableTimeValueModel *tvm = | 4312 if (tvm) { |
4241 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel()); | 4313 auto type = LayerFactory::getInstance()->getLayerType(layer); |
4242 if (tvm) { | 4314 if (type != LayerFactory::TimeRuler) { |
4315 updateLayerShortcutsFor(tvm); | |
4316 } | |
4317 if (type == LayerFactory::Waveform) { | |
4243 m_panLayer->setModel(tvm); | 4318 m_panLayer->setModel(tvm); |
4244 return; | 4319 panLayerSet = true; |
4320 break; | |
4245 } | 4321 } |
4246 } | 4322 } |
4323 } | |
4324 | |
4325 if (containsMainModel && !panLayerSet) { | |
4326 m_panLayer->setModel(getMainModel()); | |
4247 } | 4327 } |
4248 } | 4328 } |
4249 | 4329 |
4250 void | 4330 void |
4251 MainWindow::updateVisibleRangeDisplay(Pane *p) const | 4331 MainWindow::updateVisibleRangeDisplay(Pane *p) const |