Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 95:2678a1f132d2
* Add slice layers (so you can display a slice of a colour 3d plot as if it were
a spectrum)
* Make spectrum layer a subclass of slice layer
author | Chris Cannam |
---|---|
date | Fri, 26 Jan 2007 16:59:57 +0000 |
parents | 14cc0a78f340 |
children | 398889687f3d |
comparison
equal
deleted
inserted
replaced
94:5828afd1d229 | 95:2678a1f132d2 |
---|---|
28 #include "layer/WaveformLayer.h" | 28 #include "layer/WaveformLayer.h" |
29 #include "layer/TimeRulerLayer.h" | 29 #include "layer/TimeRulerLayer.h" |
30 #include "layer/TimeInstantLayer.h" | 30 #include "layer/TimeInstantLayer.h" |
31 #include "layer/TimeValueLayer.h" | 31 #include "layer/TimeValueLayer.h" |
32 #include "layer/Colour3DPlotLayer.h" | 32 #include "layer/Colour3DPlotLayer.h" |
33 #include "layer/SliceLayer.h" | |
34 #include "layer/SliceableLayer.h" | |
33 #include "widgets/Fader.h" | 35 #include "widgets/Fader.h" |
34 #include "view/Overview.h" | 36 #include "view/Overview.h" |
35 #include "widgets/PropertyBox.h" | 37 #include "widgets/PropertyBox.h" |
36 #include "widgets/PropertyStack.h" | 38 #include "widgets/PropertyStack.h" |
37 #include "widgets/AudioDial.h" | 39 #include "widgets/AudioDial.h" |
114 m_mainMenusCreated(false), | 116 m_mainMenusCreated(false), |
115 m_paneMenu(0), | 117 m_paneMenu(0), |
116 m_layerMenu(0), | 118 m_layerMenu(0), |
117 m_transformsMenu(0), | 119 m_transformsMenu(0), |
118 m_existingLayersMenu(0), | 120 m_existingLayersMenu(0), |
121 m_sliceMenu(0), | |
119 m_recentFilesMenu(0), | 122 m_recentFilesMenu(0), |
120 m_recentTransformsMenu(0), | 123 m_recentTransformsMenu(0), |
121 m_rightButtonMenu(0), | 124 m_rightButtonMenu(0), |
122 m_rightButtonLayerMenu(0), | 125 m_rightButtonLayerMenu(0), |
123 m_rightButtonTransformsMenu(0), | 126 m_rightButtonTransformsMenu(0), |
1046 | 1049 |
1047 menu->addSeparator(); | 1050 menu->addSeparator(); |
1048 | 1051 |
1049 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer")); | 1052 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer")); |
1050 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu); | 1053 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu); |
1051 setupExistingLayersMenu(); | 1054 |
1055 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer")); | |
1056 m_rightButtonLayerMenu->addMenu(m_sliceMenu); | |
1057 | |
1058 setupExistingLayersMenus(); | |
1052 | 1059 |
1053 m_rightButtonLayerMenu->addSeparator(); | 1060 m_rightButtonLayerMenu->addSeparator(); |
1054 menu->addSeparator(); | 1061 menu->addSeparator(); |
1055 | 1062 |
1056 action = new QAction(tr("&Rename Layer..."), this); | 1063 action = new QAction(tr("&Rename Layer..."), this); |
1325 m_recentTransformsMenu->addAction(ti->second); | 1332 m_recentTransformsMenu->addAction(ti->second); |
1326 } | 1333 } |
1327 } | 1334 } |
1328 | 1335 |
1329 void | 1336 void |
1330 MainWindow::setupExistingLayersMenu() | 1337 MainWindow::setupExistingLayersMenus() |
1331 { | 1338 { |
1332 if (!m_existingLayersMenu) return; // should have been created by setupMenus | 1339 if (!m_existingLayersMenu) return; // should have been created by setupMenus |
1333 | 1340 |
1334 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl; | 1341 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl; |
1335 | 1342 |
1336 m_existingLayersMenu->clear(); | 1343 m_existingLayersMenu->clear(); |
1337 m_existingLayerActions.clear(); | 1344 m_existingLayerActions.clear(); |
1338 | 1345 |
1346 m_sliceMenu->clear(); | |
1347 m_sliceActions.clear(); | |
1348 | |
1339 vector<Layer *> orderedLayers; | 1349 vector<Layer *> orderedLayers; |
1340 set<Layer *> observedLayers; | 1350 set<Layer *> observedLayers; |
1351 set<Layer *> sliceableLayers; | |
1352 | |
1353 LayerFactory *factory = LayerFactory::getInstance(); | |
1341 | 1354 |
1342 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { | 1355 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) { |
1343 | 1356 |
1344 Pane *pane = m_paneStack->getPane(i); | 1357 Pane *pane = m_paneStack->getPane(i); |
1345 if (!pane) continue; | 1358 if (!pane) continue; |
1356 // std::cerr << "found new layer " << layer << " (name = " | 1369 // std::cerr << "found new layer " << layer << " (name = " |
1357 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl; | 1370 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl; |
1358 | 1371 |
1359 orderedLayers.push_back(layer); | 1372 orderedLayers.push_back(layer); |
1360 observedLayers.insert(layer); | 1373 observedLayers.insert(layer); |
1374 | |
1375 if (factory->isLayerSliceable(layer)) { | |
1376 sliceableLayers.insert(layer); | |
1377 } | |
1361 } | 1378 } |
1362 } | 1379 } |
1363 | 1380 |
1364 map<QString, int> observedNames; | 1381 map<QString, int> observedNames; |
1365 | 1382 |
1366 for (int i = 0; i < orderedLayers.size(); ++i) { | 1383 for (int i = 0; i < orderedLayers.size(); ++i) { |
1367 | 1384 |
1368 QString name = orderedLayers[i]->getLayerPresentationName(); | 1385 Layer *layer = orderedLayers[i]; |
1386 | |
1387 QString name = layer->getLayerPresentationName(); | |
1369 int n = ++observedNames[name]; | 1388 int n = ++observedNames[name]; |
1370 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n); | 1389 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n); |
1371 | 1390 |
1372 QAction *action = new QAction(name, this); | 1391 QIcon icon = QIcon(QString(":/icons/%1.png") |
1392 .arg(factory->getLayerIconName | |
1393 (factory->getLayerType(layer)))); | |
1394 | |
1395 QAction *action = new QAction(icon, name, this); | |
1373 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | 1396 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); |
1374 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | 1397 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); |
1375 m_existingLayerActions[action] = orderedLayers[i]; | 1398 m_existingLayerActions[action] = layer; |
1376 | 1399 |
1377 m_existingLayersMenu->addAction(action); | 1400 m_existingLayersMenu->addAction(action); |
1378 } | 1401 |
1402 if (sliceableLayers.find(layer) != sliceableLayers.end()) { | |
1403 action = new QAction(icon, name, this); | |
1404 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); | |
1405 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool))); | |
1406 m_sliceActions[action] = layer; | |
1407 m_sliceMenu->addAction(action); | |
1408 } | |
1409 } | |
1410 | |
1411 m_sliceMenu->setEnabled(!m_sliceActions.empty()); | |
1379 } | 1412 } |
1380 | 1413 |
1381 void | 1414 void |
1382 MainWindow::setupToolbars() | 1415 MainWindow::setupToolbars() |
1383 { | 1416 { |
3328 m_document->addLayerToView(pane, newLayer); | 3361 m_document->addLayerToView(pane, newLayer); |
3329 m_paneStack->setCurrentLayer(pane, newLayer); | 3362 m_paneStack->setCurrentLayer(pane, newLayer); |
3330 return; | 3363 return; |
3331 } | 3364 } |
3332 | 3365 |
3366 ei = m_sliceActions.find(action); | |
3367 | |
3368 if (ei != m_sliceActions.end()) { | |
3369 Layer *newLayer = m_document->createLayer(LayerFactory::Slice); | |
3370 // document->setModel(newLayer, ei->second->getModel()); | |
3371 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second); | |
3372 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer); | |
3373 if (source && dest) { | |
3374 dest->setSliceableModel(source->getSliceableModel()); | |
3375 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)), | |
3376 dest, SLOT(sliceableModelReplaced(const Model *, const Model *))); | |
3377 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)), | |
3378 dest, SLOT(modelAboutToBeDeleted(Model *))); | |
3379 } | |
3380 m_document->addLayerToView(pane, newLayer); | |
3381 m_paneStack->setCurrentLayer(pane, newLayer); | |
3382 return; | |
3383 } | |
3384 | |
3333 TransformActionMap::iterator i = m_transformActions.find(action); | 3385 TransformActionMap::iterator i = m_transformActions.find(action); |
3334 | 3386 |
3335 if (i == m_transformActions.end()) { | 3387 if (i == m_transformActions.end()) { |
3336 | 3388 |
3337 LayerActionMap::iterator i = m_layerActions.find(action); | 3389 LayerActionMap::iterator i = m_layerActions.find(action); |
3464 (this, tr("Rename Layer"), | 3516 (this, tr("Rename Layer"), |
3465 tr("New name for this layer:"), | 3517 tr("New name for this layer:"), |
3466 QLineEdit::Normal, layer->objectName(), &ok); | 3518 QLineEdit::Normal, layer->objectName(), &ok); |
3467 if (ok) { | 3519 if (ok) { |
3468 layer->setObjectName(newName); | 3520 layer->setObjectName(newName); |
3469 setupExistingLayersMenu(); | 3521 setupExistingLayersMenus(); |
3470 } | 3522 } |
3471 } | 3523 } |
3472 } | 3524 } |
3473 } | 3525 } |
3474 | 3526 |
3573 | 3625 |
3574 void | 3626 void |
3575 MainWindow::layerRemoved(Layer *layer) | 3627 MainWindow::layerRemoved(Layer *layer) |
3576 { | 3628 { |
3577 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl; | 3629 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl; |
3578 setupExistingLayersMenu(); | 3630 setupExistingLayersMenus(); |
3579 updateMenuStates(); | 3631 updateMenuStates(); |
3580 } | 3632 } |
3581 | 3633 |
3582 void | 3634 void |
3583 MainWindow::layerAboutToBeDeleted(Layer *layer) | 3635 MainWindow::layerAboutToBeDeleted(Layer *layer) |
3615 } | 3667 } |
3616 if (!found) m_playSource->removeModel(model); | 3668 if (!found) m_playSource->removeModel(model); |
3617 } | 3669 } |
3618 } | 3670 } |
3619 | 3671 |
3620 setupExistingLayersMenu(); | 3672 setupExistingLayersMenus(); |
3621 updateMenuStates(); | 3673 updateMenuStates(); |
3622 } | 3674 } |
3623 | 3675 |
3624 void | 3676 void |
3625 MainWindow::modelAdded(Model *model) | 3677 MainWindow::modelAdded(Model *model) |