Mercurial > hg > sonic-visualiser
comparison main/MainWindow.cpp @ 194:c851c49c79fe
* Make drop behave more sensibly (replace current pane)
| author | Chris Cannam |
|---|---|
| date | Wed, 17 Oct 2007 12:58:45 +0000 |
| parents | 4e030ebb6b36 |
| children | 61bf55e80080 |
comparison
equal
deleted
inserted
replaced
| 193:4e030ebb6b36 | 194:c851c49c79fe |
|---|---|
| 2123 return; | 2123 return; |
| 2124 } | 2124 } |
| 2125 | 2125 |
| 2126 Model *prevPlaybackModel = m_viewManager->getPlaybackModel(); | 2126 Model *prevPlaybackModel = m_viewManager->getPlaybackModel(); |
| 2127 | 2127 |
| 2128 std::set<Model *> soloModels; | 2128 View::ModelSet soloModels = p->getModels(); |
| 2129 | 2129 |
| 2130 for (int i = 0; i < p->getLayerCount(); ++i) { | 2130 for (View::ModelSet::iterator mi = soloModels.begin(); |
| 2131 Layer *layer = p->getLayer(i); | 2131 mi != soloModels.end(); ++mi) { |
| 2132 if (dynamic_cast<TimeRulerLayer *>(layer)) { | 2132 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) { |
| 2133 continue; | 2133 m_viewManager->setPlaybackModel(*mi); |
| 2134 } | |
| 2135 if (layer && layer->getModel()) { | |
| 2136 Model *model = layer->getModel(); | |
| 2137 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { | |
| 2138 m_viewManager->setPlaybackModel(model); | |
| 2139 } | |
| 2140 soloModels.insert(model); | |
| 2141 } | 2134 } |
| 2142 } | 2135 } |
| 2143 | 2136 |
| 2144 RangeSummarisableTimeValueModel *a = | 2137 RangeSummarisableTimeValueModel *a = |
| 2145 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel); | 2138 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel); |
| 3041 delete newModel; | 3034 delete newModel; |
| 3042 m_openingAudioFile = false; | 3035 m_openingAudioFile = false; |
| 3043 return FileOpenFailed; | 3036 return FileOpenFailed; |
| 3044 } | 3037 } |
| 3045 | 3038 |
| 3046 bool setAsMain = true; | |
| 3047 static bool prevSetAsMain = true; | |
| 3048 | |
| 3049 bool realFile = (location == path); | 3039 bool realFile = (location == path); |
| 3050 | 3040 |
| 3051 if (mode == CreateAdditionalModel) setAsMain = false; | 3041 std::cerr << "mode = " << mode << std::endl; |
| 3052 else if (mode == AskUser) { | 3042 |
| 3053 if (m_document->getMainModel()) { | 3043 if (mode == AskUser) { |
| 3054 | 3044 if (getMainModel()) { |
| 3045 | |
| 3046 std::cerr << "ask user, have main model" << std::endl; | |
| 3047 | |
| 3048 static bool prevSetAsMain = true; | |
| 3049 bool setAsMain = true; | |
| 3050 | |
| 3055 QStringList items; | 3051 QStringList items; |
| 3056 items << tr("Replace the existing main waveform") | 3052 items << tr("Replace the existing main waveform") |
| 3057 << tr("Load this file into a new waveform pane"); | 3053 << tr("Load this file into a new waveform pane"); |
| 3058 | 3054 |
| 3059 bool ok = false; | 3055 bool ok = false; |
| 3068 return FileOpenCancelled; | 3064 return FileOpenCancelled; |
| 3069 } | 3065 } |
| 3070 | 3066 |
| 3071 setAsMain = (item == items[0]); | 3067 setAsMain = (item == items[0]); |
| 3072 prevSetAsMain = setAsMain; | 3068 prevSetAsMain = setAsMain; |
| 3073 } | 3069 |
| 3074 } | 3070 if (setAsMain) mode = ReplaceMainModel; |
| 3075 | 3071 else mode = CreateAdditionalModel; |
| 3076 if (setAsMain) { | 3072 |
| 3073 } else { | |
| 3074 mode = ReplaceMainModel; | |
| 3075 } | |
| 3076 } | |
| 3077 | |
| 3078 if (mode == ReplaceCurrentPane) { | |
| 3079 | |
| 3080 std::cerr << "replace current pane" << std::endl; | |
| 3081 | |
| 3082 Pane *pane = m_paneStack->getCurrentPane(); | |
| 3083 if (pane) { | |
| 3084 std::cerr << "have pane" << std::endl; | |
| 3085 | |
| 3086 if (getMainModel()) { | |
| 3087 std::cerr << "have main model" << std::endl; | |
| 3088 | |
| 3089 View::ModelSet models(pane->getModels()); | |
| 3090 if (models.find(getMainModel()) != models.end()) { | |
| 3091 std::cerr << "main model is in pane, setting to ReplaceMainModel" << std::endl; | |
| 3092 mode = ReplaceMainModel; | |
| 3093 } | |
| 3094 } else { | |
| 3095 std::cerr << "no main model, setting to ReplaceMainModel" << std::endl; | |
| 3096 mode = ReplaceMainModel; | |
| 3097 } | |
| 3098 } else { | |
| 3099 std::cerr << "no pane, setting to CreateAdditionalModel" << std::endl; | |
| 3100 mode = CreateAdditionalModel; | |
| 3101 } | |
| 3102 } | |
| 3103 | |
| 3104 if (mode == CreateAdditionalModel && !getMainModel()) { | |
| 3105 std::cerr << "mode is CreateAdditionalModel and no main model, setting to ReplaceMainModel" << std::endl; | |
| 3106 mode = ReplaceMainModel; | |
| 3107 } | |
| 3108 | |
| 3109 std::cerr << "mode now " << mode << std::endl; | |
| 3110 | |
| 3111 if (mode == ReplaceMainModel) { | |
| 3077 | 3112 |
| 3078 Model *prevMain = getMainModel(); | 3113 Model *prevMain = getMainModel(); |
| 3079 if (prevMain) { | 3114 if (prevMain) { |
| 3080 m_playSource->removeModel(prevMain); | 3115 m_playSource->removeModel(prevMain); |
| 3081 PlayParameterRepository::getInstance()->removeModel(prevMain); | 3116 PlayParameterRepository::getInstance()->removeModel(prevMain); |
| 3082 } | 3117 } |
| 3083 | |
| 3084 PlayParameterRepository::getInstance()->addModel(newModel); | 3118 PlayParameterRepository::getInstance()->addModel(newModel); |
| 3085 | 3119 |
| 3086 m_document->setMainModel(newModel); | 3120 m_document->setMainModel(newModel); |
| 3087 setupMenus(); | 3121 setupMenus(); |
| 3088 | 3122 |
| 3102 } | 3136 } |
| 3103 } | 3137 } |
| 3104 | 3138 |
| 3105 if (realFile) m_audioFile = path; | 3139 if (realFile) m_audioFile = path; |
| 3106 | 3140 |
| 3107 } else { // !setAsMain | 3141 } else if (mode == CreateAdditionalModel) { |
| 3108 | 3142 |
| 3109 CommandHistory::getInstance()->startCompoundOperation | 3143 CommandHistory::getInstance()->startCompoundOperation |
| 3110 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true); | 3144 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true); |
| 3111 | 3145 |
| 3112 m_document->addImportedModel(newModel); | 3146 m_document->addImportedModel(newModel); |
| 3120 m_timeRulerLayer = m_document->createMainModelLayer | 3154 m_timeRulerLayer = m_document->createMainModelLayer |
| 3121 (LayerFactory::TimeRuler); | 3155 (LayerFactory::TimeRuler); |
| 3122 } | 3156 } |
| 3123 | 3157 |
| 3124 m_document->addLayerToView(pane, m_timeRulerLayer); | 3158 m_document->addLayerToView(pane, m_timeRulerLayer); |
| 3159 | |
| 3160 Layer *newLayer = m_document->createImportedLayer(newModel); | |
| 3161 | |
| 3162 if (newLayer) { | |
| 3163 m_document->addLayerToView(pane, newLayer); | |
| 3164 } | |
| 3165 | |
| 3166 CommandHistory::getInstance()->endCompoundOperation(); | |
| 3167 | |
| 3168 } else if (mode == ReplaceCurrentPane) { | |
| 3169 | |
| 3170 // We know there is a current pane, otherwise we would have | |
| 3171 // reset the mode to CreateAdditionalModel above; and we know | |
| 3172 // the current pane does not contain the main model, otherwise | |
| 3173 // we would have reset it to ReplaceMainModel. But we don't | |
| 3174 // know whether the pane contains a waveform model at all. | |
| 3175 | |
| 3176 Pane *pane = m_paneStack->getCurrentPane(); | |
| 3177 Layer *replace = 0; | |
| 3178 | |
| 3179 for (int i = 0; i < pane->getLayerCount(); ++i) { | |
| 3180 Layer *layer = pane->getLayer(i); | |
| 3181 if (dynamic_cast<WaveformLayer *>(layer)) { | |
| 3182 replace = layer; | |
| 3183 break; | |
| 3184 } | |
| 3185 } | |
| 3186 | |
| 3187 CommandHistory::getInstance()->startCompoundOperation | |
| 3188 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true); | |
| 3189 | |
| 3190 m_document->addImportedModel(newModel); | |
| 3191 | |
| 3192 if (replace) { | |
| 3193 m_document->removeLayerFromView(pane, replace); | |
| 3194 } | |
| 3125 | 3195 |
| 3126 Layer *newLayer = m_document->createImportedLayer(newModel); | 3196 Layer *newLayer = m_document->createImportedLayer(newModel); |
| 3127 | 3197 |
| 3128 if (newLayer) { | 3198 if (newLayer) { |
| 3129 m_document->addLayerToView(pane, newLayer); | 3199 m_document->addLayerToView(pane, newLayer); |
| 3605 { | 3675 { |
| 3606 if (pane) m_paneStack->setCurrentPane(pane); | 3676 if (pane) m_paneStack->setCurrentPane(pane); |
| 3607 | 3677 |
| 3608 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) { | 3678 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) { |
| 3609 | 3679 |
| 3610 FileOpenStatus status = | 3680 FileOpenStatus status = openURL(*i, ReplaceCurrentPane); |
| 3611 openURL(*i, (m_document->getMainModel() ? | |
| 3612 CreateAdditionalModel : ReplaceMainModel)); | |
| 3613 | 3681 |
| 3614 if (status == FileOpenFailed) { | 3682 if (status == FileOpenFailed) { |
| 3615 QMessageBox::critical(this, tr("Failed to open dropped URL"), | 3683 QMessageBox::critical(this, tr("Failed to open dropped URL"), |
| 3616 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i)); | 3684 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i)); |
| 3617 } else if (status == FileOpenWrongMode) { | 3685 } else if (status == FileOpenWrongMode) { |
