Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 346:92c09ced49ed
* Add the spectrogram (etc) layer options (back) to the right-button menu;
make them add the relevant layer based on audio data in whichever pane
the menu was called up from
author | Chris Cannam |
---|---|
date | Tue, 15 Jun 2010 14:40:54 +0000 |
parents | e0c7ee104eb4 |
children | 19feac24407f |
comparison
equal
deleted
inserted
replaced
345:e0c7ee104eb4 | 346:92c09ced49ed |
---|---|
334 if (m_rightButtonTransformsMenu) { | 334 if (m_rightButtonTransformsMenu) { |
335 m_rightButtonTransformsMenu->clear(); | 335 m_rightButtonTransformsMenu->clear(); |
336 } else { | 336 } else { |
337 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform")); | 337 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform")); |
338 m_rightButtonTransformsMenu->setTearOffEnabled(true); | 338 m_rightButtonTransformsMenu->setTearOffEnabled(true); |
339 m_rightButtonMenu->addSeparator(); | |
340 } | |
341 | |
342 // This will be created (if not found) or cleared (if found) in | |
343 // setupPaneAndLayerMenus, but we want to ensure it's created | |
344 // sooner so it can go nearer the top of the right button menu | |
345 if (m_rightButtonLayerMenu) { | |
346 m_rightButtonLayerMenu->clear(); | |
347 } else { | |
348 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer")); | |
349 m_rightButtonLayerMenu->setTearOffEnabled(true); | |
339 m_rightButtonMenu->addSeparator(); | 350 m_rightButtonMenu->addSeparator(); |
340 } | 351 } |
341 | 352 |
342 if (!m_mainMenusCreated) { | 353 if (!m_mainMenusCreated) { |
343 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu); | 354 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu); |
1052 break; | 1063 break; |
1053 | 1064 |
1054 default: break; | 1065 default: break; |
1055 } | 1066 } |
1056 | 1067 |
1057 std::vector<Model *> candidateModels; | 1068 std::vector<Model *> candidateModels = models; |
1058 // if (menuType == paneMenuType) { | |
1059 candidateModels = models; | |
1060 // } else { | |
1061 // candidateModels.push_back(0); | |
1062 // } | |
1063 | 1069 |
1064 for (std::vector<Model *>::iterator mi = | 1070 for (std::vector<Model *>::iterator mi = |
1065 candidateModels.begin(); | 1071 candidateModels.begin(); |
1066 mi != candidateModels.end(); ++mi) { | 1072 mi != candidateModels.end(); ++mi) { |
1067 | 1073 |
1082 | 1088 |
1083 if (c == 1 && channels == 1) continue; | 1089 if (c == 1 && channels == 1) continue; |
1084 bool isDefault = (c == 0); | 1090 bool isDefault = (c == 0); |
1085 bool isOnly = (isDefault && (channels == 1)); | 1091 bool isOnly = (isDefault && (channels == 1)); |
1086 | 1092 |
1087 // if (menuType == layerMenuType) { | 1093 if (isOnly && !plural) { |
1088 // if (isDefault) isOnly = true; | 1094 |
1089 // else continue; | 1095 action = new QAction(icon, mainText, this); |
1090 // } | |
1091 | |
1092 if (isOnly && (!plural /*|| menuType == layerMenuType*/)) { | |
1093 | |
1094 // if (menuType == layerMenuType && type != LayerFactory::Waveform) { | |
1095 // action = new QAction(mainText, this); | |
1096 // } else { | |
1097 action = new QAction(icon, mainText, this); | |
1098 // } | |
1099 | 1096 |
1100 action->setShortcut(shortcutText); | 1097 action->setShortcut(shortcutText); |
1101 action->setStatusTip(tipText); | 1098 action->setStatusTip(tipText); |
1102 if (menuType == paneMenuType) { | 1099 if (menuType == paneMenuType) { |
1103 connect(action, SIGNAL(triggered()), | 1100 connect(action, SIGNAL(triggered()), |
1104 this, SLOT(addPane())); | 1101 this, SLOT(addPane())); |
1105 connect(this, SIGNAL(canAddPane(bool)), | 1102 connect(this, SIGNAL(canAddPane(bool)), |
1106 action, SLOT(setEnabled(bool))); | 1103 action, SLOT(setEnabled(bool))); |
1107 m_paneActions[action] = LayerConfiguration(type); | 1104 m_paneActions[action] = |
1105 LayerConfiguration(type, model); | |
1108 } else { | 1106 } else { |
1109 connect(action, SIGNAL(triggered()), | 1107 connect(action, SIGNAL(triggered()), |
1110 this, SLOT(addLayer())); | 1108 this, SLOT(addLayer())); |
1111 connect(this, SIGNAL(canAddLayer(bool)), | 1109 connect(this, SIGNAL(canAddLayer(bool)), |
1112 action, SLOT(setEnabled(bool))); | 1110 action, SLOT(setEnabled(bool))); |
1113 m_layerActions[action] = LayerConfiguration(type); | 1111 m_layerActions[action] = |
1112 LayerConfiguration(type, model); | |
1114 } | 1113 } |
1115 if (shortcutText != "") { | 1114 if (shortcutText != "") { |
1116 m_keyReference->registerShortcut(action); | 1115 m_keyReference->registerShortcut(action); |
1117 } | 1116 } |
1118 menu->addAction(action); | 1117 menu->addAction(action); |
1169 m_layerActions[action] = | 1168 m_layerActions[action] = |
1170 LayerConfiguration(type, model, c - 1); | 1169 LayerConfiguration(type, model, c - 1); |
1171 } | 1170 } |
1172 | 1171 |
1173 submenu->addAction(action); | 1172 submenu->addAction(action); |
1173 } | |
1174 | |
1175 if (isDefault && menuType == layerMenuType) { | |
1176 action = new QAction(icon, mainText, this); | |
1177 action->setStatusTip(tipText); | |
1178 connect(action, SIGNAL(triggered()), | |
1179 this, SLOT(addLayer())); | |
1180 connect(this, SIGNAL(canAddLayer(bool)), | |
1181 action, SLOT(setEnabled(bool))); | |
1182 m_layerActions[action] = LayerConfiguration(type, 0, 0); | |
1183 m_rightButtonLayerMenu->addAction(action); | |
1174 } | 1184 } |
1175 } | 1185 } |
1176 } | 1186 } |
1177 } | 1187 } |
1178 } | 1188 } |
3076 << " appears in pane action map, but is not reported " | 3086 << " appears in pane action map, but is not reported " |
3077 << "by document as a valid transform source" << std::endl; | 3087 << "by document as a valid transform source" << std::endl; |
3078 } | 3088 } |
3079 } | 3089 } |
3080 | 3090 |
3081 if (!model) model = m_document->getMainModel(); | 3091 if (!model) { |
3092 model = m_document->getMainModel(); | |
3093 } | |
3082 | 3094 |
3083 m_document->setModel(newLayer, model); | 3095 m_document->setModel(newLayer, model); |
3084 | 3096 |
3085 m_document->setChannel(newLayer, configuration.channel); | 3097 m_document->setChannel(newLayer, configuration.channel); |
3086 m_document->addLayerToView(pane, newLayer); | 3098 m_document->addLayerToView(pane, newLayer); |
3171 m_toolActions[ViewManager::DrawMode]->trigger(); | 3183 m_toolActions[ViewManager::DrawMode]->trigger(); |
3172 } | 3184 } |
3173 | 3185 |
3174 } else { | 3186 } else { |
3175 | 3187 |
3176 if (!i->second.sourceModel) { | 3188 Model *model = i->second.sourceModel; |
3177 // e.g. time ruler | 3189 |
3178 newLayer = m_document->createMainModelLayer(type); | 3190 if (!model) { |
3179 } else { | 3191 if (type == LayerFactory::TimeRuler) { |
3192 newLayer = m_document->createMainModelLayer(type); | |
3193 } else { | |
3194 // if model is unspecified and this is not a | |
3195 // time-ruler layer, use the topmost plausible | |
3196 // model from the current pane (if any) -- this is | |
3197 // the case for right-button menu layer additions | |
3198 for (int i = pane->getLayerCount(); i > 0; --i) { | |
3199 Layer *el = pane->getLayer(i-1); | |
3200 if (el && | |
3201 el->getModel() && | |
3202 dynamic_cast<RangeSummarisableTimeValueModel *> | |
3203 (el->getModel())) { | |
3204 model = el->getModel(); | |
3205 } | |
3206 } | |
3207 if (!model) model = getMainModel(); | |
3208 } | |
3209 } | |
3210 | |
3211 if (model) { | |
3180 newLayer = m_document->createLayer(type); | 3212 newLayer = m_document->createLayer(type); |
3181 if (m_document->isKnownModel(i->second.sourceModel)) { | 3213 if (m_document->isKnownModel(model)) { |
3182 m_document->setChannel(newLayer, i->second.channel); | 3214 m_document->setChannel(newLayer, i->second.channel); |
3183 m_document->setModel(newLayer, i->second.sourceModel); | 3215 m_document->setModel(newLayer, model); |
3184 } else { | 3216 } else { |
3185 std::cerr << "WARNING: MainWindow::addLayer: unknown model " | 3217 std::cerr << "WARNING: MainWindow::addLayer: unknown model " |
3186 << i->second.sourceModel | 3218 << model |
3187 << " (\"" | 3219 << " (\"" |
3188 << (i->second.sourceModel ? i->second.sourceModel->objectName().toStdString() : "") | 3220 << (model ? model->objectName().toStdString() : "") |
3189 << "\") in layer action map" | 3221 << "\") in layer action map" |
3190 << std::endl; | 3222 << std::endl; |
3191 } | 3223 } |
3192 } | 3224 } |
3193 } | 3225 } |