Chris@45
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@45
|
2
|
Chris@45
|
3 /*
|
Chris@45
|
4 Sonic Visualiser
|
Chris@45
|
5 An audio file viewer and annotation editor.
|
Chris@45
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@45
|
7 This file copyright 2006-2007 Chris Cannam and QMUL.
|
Chris@45
|
8
|
Chris@45
|
9 This program is free software; you can redistribute it and/or
|
Chris@45
|
10 modify it under the terms of the GNU General Public License as
|
Chris@45
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@45
|
12 License, or (at your option) any later version. See the file
|
Chris@45
|
13 COPYING included with this distribution for more information.
|
Chris@45
|
14 */
|
Chris@45
|
15
|
Chris@45
|
16 #include "MainWindowBase.h"
|
Chris@46
|
17 #include "Document.h"
|
Chris@45
|
18
|
Chris@45
|
19
|
Chris@45
|
20 #include "view/Pane.h"
|
Chris@45
|
21 #include "view/PaneStack.h"
|
Chris@45
|
22 #include "data/model/WaveFileModel.h"
|
Chris@45
|
23 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@45
|
24 #include "data/model/NoteModel.h"
|
matthiasm@267
|
25 #include "data/model/FlexiNoteModel.h"
|
Chris@45
|
26 #include "data/model/Labeller.h"
|
Chris@124
|
27 #include "data/model/TabularModel.h"
|
Chris@45
|
28 #include "view/ViewManager.h"
|
Chris@45
|
29
|
Chris@45
|
30 #include "layer/WaveformLayer.h"
|
Chris@45
|
31 #include "layer/TimeRulerLayer.h"
|
Chris@45
|
32 #include "layer/TimeInstantLayer.h"
|
Chris@45
|
33 #include "layer/TimeValueLayer.h"
|
Chris@45
|
34 #include "layer/Colour3DPlotLayer.h"
|
Chris@45
|
35 #include "layer/SliceLayer.h"
|
Chris@45
|
36 #include "layer/SliceableLayer.h"
|
Chris@45
|
37 #include "layer/ImageLayer.h"
|
Chris@184
|
38 #include "layer/NoteLayer.h"
|
matthiasm@267
|
39 #include "layer/FlexiNoteLayer.h"
|
Chris@184
|
40 #include "layer/RegionLayer.h"
|
Chris@45
|
41
|
Chris@45
|
42 #include "widgets/ListInputDialog.h"
|
Chris@105
|
43 #include "widgets/CommandHistory.h"
|
Chris@109
|
44 #include "widgets/ProgressDialog.h"
|
Chris@109
|
45 #include "widgets/MIDIFileImportDialog.h"
|
Chris@109
|
46 #include "widgets/CSVFormatDialog.h"
|
Chris@123
|
47 #include "widgets/ModelDataTableDialog.h"
|
Chris@341
|
48 #include "widgets/InteractiveFileFinder.h"
|
Chris@45
|
49
|
Chris@45
|
50 #include "audioio/AudioCallbackPlaySource.h"
|
Chris@45
|
51 #include "audioio/AudioCallbackPlayTarget.h"
|
Chris@45
|
52 #include "audioio/AudioTargetFactory.h"
|
Chris@45
|
53 #include "audioio/PlaySpeedRangeMapper.h"
|
Chris@45
|
54 #include "data/fileio/DataFileReaderFactory.h"
|
Chris@45
|
55 #include "data/fileio/PlaylistFileReader.h"
|
Chris@45
|
56 #include "data/fileio/WavFileWriter.h"
|
Chris@45
|
57 #include "data/fileio/CSVFileWriter.h"
|
Chris@45
|
58 #include "data/fileio/MIDIFileWriter.h"
|
Chris@45
|
59 #include "data/fileio/BZipFileDevice.h"
|
Chris@45
|
60 #include "data/fileio/FileSource.h"
|
Chris@152
|
61 #include "data/fileio/AudioFileReaderFactory.h"
|
Chris@134
|
62 #include "rdf/RDFImporter.h"
|
Chris@45
|
63
|
Chris@45
|
64 #include "data/fft/FFTDataServer.h"
|
Chris@45
|
65
|
Chris@45
|
66 #include "base/RecentFiles.h"
|
Chris@45
|
67
|
Chris@45
|
68 #include "base/PlayParameterRepository.h"
|
Chris@45
|
69 #include "base/XmlExportable.h"
|
Chris@45
|
70 #include "base/Profiler.h"
|
Chris@45
|
71 #include "base/Preferences.h"
|
Chris@217
|
72 #include "base/TempWriteFile.h"
|
Chris@217
|
73 #include "base/Exceptions.h"
|
Chris@223
|
74 #include "base/ResourceFinder.h"
|
Chris@45
|
75
|
Chris@45
|
76 #include "data/osc/OSCQueue.h"
|
Chris@157
|
77 #include "data/midi/MIDIInput.h"
|
Chris@45
|
78
|
Chris@45
|
79 #include <QApplication>
|
Chris@45
|
80 #include <QMessageBox>
|
Chris@45
|
81 #include <QGridLayout>
|
Chris@45
|
82 #include <QLabel>
|
Chris@45
|
83 #include <QAction>
|
Chris@45
|
84 #include <QMenuBar>
|
Chris@45
|
85 #include <QToolBar>
|
Chris@45
|
86 #include <QInputDialog>
|
Chris@45
|
87 #include <QStatusBar>
|
Chris@45
|
88 #include <QTreeView>
|
Chris@45
|
89 #include <QFile>
|
Chris@45
|
90 #include <QFileInfo>
|
Chris@45
|
91 #include <QDir>
|
Chris@45
|
92 #include <QTextStream>
|
Chris@45
|
93 #include <QProcess>
|
Chris@45
|
94 #include <QShortcut>
|
Chris@45
|
95 #include <QSettings>
|
Chris@45
|
96 #include <QDateTime>
|
Chris@45
|
97 #include <QProcess>
|
Chris@45
|
98 #include <QCheckBox>
|
Chris@45
|
99 #include <QRegExp>
|
Chris@45
|
100 #include <QScrollArea>
|
Chris@168
|
101 #include <QDesktopWidget>
|
Chris@354
|
102 #include <QSignalMapper>
|
Chris@45
|
103
|
Chris@45
|
104 #include <iostream>
|
Chris@45
|
105 #include <cstdio>
|
Chris@45
|
106 #include <errno.h>
|
Chris@45
|
107
|
Chris@293
|
108
|
Chris@293
|
109
|
Chris@45
|
110
|
Chris@45
|
111 using std::vector;
|
Chris@45
|
112 using std::map;
|
Chris@45
|
113 using std::set;
|
Chris@45
|
114
|
Chris@255
|
115 #ifdef Q_WS_X11
|
Chris@255
|
116 #define Window X11Window
|
Chris@255
|
117 #include <X11/Xlib.h>
|
Chris@255
|
118 #include <X11/Xutil.h>
|
Chris@255
|
119 #include <X11/Xatom.h>
|
Chris@255
|
120 #include <X11/SM/SMlib.h>
|
Chris@255
|
121
|
Chris@255
|
122 static int handle_x11_error(Display *dpy, XErrorEvent *err)
|
Chris@255
|
123 {
|
Chris@255
|
124 char errstr[256];
|
Chris@255
|
125 XGetErrorText(dpy, err->error_code, errstr, 256);
|
Chris@255
|
126 if (err->error_code != BadWindow) {
|
Chris@293
|
127 cerr << "Sonic Visualiser: X Error: "
|
Chris@255
|
128 << errstr << " " << int(err->error_code)
|
Chris@255
|
129 << "\nin major opcode: "
|
Chris@293
|
130 << int(err->request_code) << endl;
|
Chris@255
|
131 }
|
Chris@255
|
132 return 0;
|
Chris@255
|
133 }
|
Chris@255
|
134 #undef Window
|
Chris@255
|
135 #endif
|
Chris@45
|
136
|
Chris@161
|
137 MainWindowBase::MainWindowBase(bool withAudioOutput,
|
Chris@161
|
138 bool withMIDIInput) :
|
Chris@45
|
139 m_document(0),
|
Chris@45
|
140 m_paneStack(0),
|
Chris@45
|
141 m_viewManager(0),
|
Chris@45
|
142 m_timeRulerLayer(0),
|
Chris@45
|
143 m_audioOutput(withAudioOutput),
|
Chris@45
|
144 m_playSource(0),
|
Chris@45
|
145 m_playTarget(0),
|
Chris@113
|
146 m_oscQueue(0),
|
Chris@113
|
147 m_oscQueueStarter(0),
|
Chris@157
|
148 m_midiInput(0),
|
Chris@45
|
149 m_recentFiles("RecentFiles", 20),
|
Chris@54
|
150 m_recentTransforms("RecentTransforms", 20),
|
Chris@45
|
151 m_documentModified(false),
|
Chris@45
|
152 m_openingAudioFile(false),
|
Chris@45
|
153 m_abandoning(false),
|
Chris@121
|
154 m_labeller(0),
|
Chris@357
|
155 m_lastPlayStatusSec(0),
|
Chris@357
|
156 m_initialDarkBackground(false),
|
Chris@378
|
157 m_defaultFfwdRwdStep(2, 0),
|
Chris@390
|
158 m_statusLabel(0),
|
Chris@390
|
159 m_menuShortcutMapper(0)
|
Chris@45
|
160 {
|
Chris@113
|
161 Profiler profiler("MainWindowBase::MainWindowBase");
|
Chris@113
|
162
|
Chris@255
|
163 #ifdef Q_WS_X11
|
Chris@255
|
164 XSetErrorHandler(handle_x11_error);
|
Chris@255
|
165 #endif
|
Chris@255
|
166
|
Chris@45
|
167 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
|
Chris@45
|
168 this, SLOT(documentModified()));
|
Chris@45
|
169 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
|
Chris@45
|
170 this, SLOT(documentRestored()));
|
Chris@45
|
171
|
Chris@45
|
172 m_viewManager = new ViewManager();
|
Chris@45
|
173 connect(m_viewManager, SIGNAL(selectionChanged()),
|
Chris@45
|
174 this, SLOT(updateMenuStates()));
|
Chris@45
|
175 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
|
Chris@45
|
176 this, SLOT(inProgressSelectionChanged()));
|
Chris@45
|
177
|
Chris@105
|
178 // set a sensible default font size for views -- cannot do this
|
Chris@105
|
179 // in Preferences, which is in base and not supposed to use QtGui
|
Chris@105
|
180 int viewFontSize = QApplication::font().pointSize() * 0.9;
|
Chris@105
|
181 QSettings settings;
|
Chris@105
|
182 settings.beginGroup("Preferences");
|
Chris@105
|
183 viewFontSize = settings.value("view-font-size", viewFontSize).toInt();
|
Chris@105
|
184 settings.setValue("view-font-size", viewFontSize);
|
Chris@105
|
185 settings.endGroup();
|
Chris@105
|
186
|
Chris@45
|
187 Preferences::BackgroundMode mode =
|
Chris@45
|
188 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
189 m_initialDarkBackground = m_viewManager->getGlobalDarkBackground();
|
Chris@45
|
190 if (mode != Preferences::BackgroundFromTheme) {
|
Chris@45
|
191 m_viewManager->setGlobalDarkBackground
|
Chris@45
|
192 (mode == Preferences::DarkBackground);
|
Chris@45
|
193 }
|
Chris@45
|
194
|
Chris@45
|
195 m_paneStack = new PaneStack(0, m_viewManager);
|
Chris@45
|
196 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
|
Chris@45
|
197 this, SLOT(currentPaneChanged(Pane *)));
|
Chris@45
|
198 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
|
Chris@45
|
199 this, SLOT(currentLayerChanged(Pane *, Layer *)));
|
Chris@45
|
200 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
|
Chris@45
|
201 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
|
Chris@45
|
202 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
203 this, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
204 connect(m_paneStack, SIGNAL(paneAdded(Pane *)),
|
Chris@45
|
205 this, SLOT(paneAdded(Pane *)));
|
Chris@45
|
206 connect(m_paneStack, SIGNAL(paneHidden(Pane *)),
|
Chris@45
|
207 this, SLOT(paneHidden(Pane *)));
|
Chris@45
|
208 connect(m_paneStack, SIGNAL(paneAboutToBeDeleted(Pane *)),
|
Chris@45
|
209 this, SLOT(paneAboutToBeDeleted(Pane *)));
|
Chris@45
|
210 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)),
|
Chris@45
|
211 this, SLOT(paneDropAccepted(Pane *, QStringList)));
|
Chris@45
|
212 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)),
|
Chris@45
|
213 this, SLOT(paneDropAccepted(Pane *, QString)));
|
Chris@55
|
214 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)),
|
Chris@55
|
215 this, SLOT(paneDeleteButtonClicked(Pane *)));
|
Chris@45
|
216
|
Chris@57
|
217 m_playSource = new AudioCallbackPlaySource(m_viewManager,
|
Chris@57
|
218 QApplication::applicationName());
|
Chris@45
|
219
|
Chris@366
|
220 connect(m_playSource, SIGNAL(sampleRateMismatch(int, int, bool)),
|
Chris@366
|
221 this, SLOT(sampleRateMismatch(int, int, bool)));
|
Chris@45
|
222 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
|
Chris@45
|
223 this, SLOT(audioOverloadPluginDisabled()));
|
Chris@130
|
224 connect(m_playSource, SIGNAL(audioTimeStretchMultiChannelDisabled()),
|
Chris@130
|
225 this, SLOT(audioTimeStretchMultiChannelDisabled()));
|
Chris@45
|
226
|
Chris@45
|
227 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
|
Chris@45
|
228 this, SLOT(outputLevelsChanged(float, float)));
|
Chris@45
|
229
|
Chris@366
|
230 connect(m_viewManager, SIGNAL(playbackFrameChanged(int)),
|
Chris@366
|
231 this, SLOT(playbackFrameChanged(int)));
|
Chris@366
|
232
|
Chris@366
|
233 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(int)),
|
Chris@366
|
234 this, SLOT(globalCentreFrameChanged(int)));
|
Chris@366
|
235
|
Chris@366
|
236 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, int)),
|
Chris@366
|
237 this, SLOT(viewCentreFrameChanged(View *, int)));
|
Chris@366
|
238
|
Chris@366
|
239 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, int, bool)),
|
Chris@366
|
240 this, SLOT(viewZoomLevelChanged(View *, int, bool)));
|
Chris@45
|
241
|
Chris@45
|
242 connect(Preferences::getInstance(),
|
Chris@45
|
243 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@45
|
244 this,
|
Chris@45
|
245 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
|
Chris@45
|
246
|
Chris@45
|
247 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
|
Chris@45
|
248 settings.beginGroup("MainWindow");
|
Chris@230
|
249
|
Chris@45
|
250 labellerType = (Labeller::ValueType)
|
Chris@45
|
251 settings.value("labellertype", (int)labellerType).toInt();
|
Chris@45
|
252 int cycle = settings.value("labellercycle", 4).toInt();
|
Chris@230
|
253
|
Chris@45
|
254 settings.endGroup();
|
Chris@45
|
255
|
Chris@45
|
256 m_labeller = new Labeller(labellerType);
|
Chris@45
|
257 m_labeller->setCounterCycleSize(cycle);
|
Chris@113
|
258
|
Chris@161
|
259 if (withMIDIInput) {
|
Chris@161
|
260 m_midiInput = new MIDIInput(QApplication::applicationName(), this);
|
Chris@161
|
261 }
|
Chris@45
|
262 }
|
Chris@45
|
263
|
Chris@45
|
264 MainWindowBase::~MainWindowBase()
|
Chris@45
|
265 {
|
Chris@233
|
266 SVDEBUG << "MainWindowBase::~MainWindowBase" << endl;
|
Chris@70
|
267 if (m_playTarget) m_playTarget->shutdown();
|
Chris@70
|
268 // delete m_playTarget;
|
Chris@45
|
269 delete m_playSource;
|
Chris@45
|
270 delete m_viewManager;
|
Chris@45
|
271 delete m_oscQueue;
|
Chris@304
|
272 delete m_oscQueueStarter;
|
Chris@157
|
273 delete m_midiInput;
|
Chris@45
|
274 Profiles::getInstance()->dump();
|
Chris@45
|
275 }
|
Chris@45
|
276
|
Chris@113
|
277 void
|
Chris@354
|
278 MainWindowBase::finaliseMenus()
|
Chris@354
|
279 {
|
Chris@390
|
280 delete m_menuShortcutMapper;
|
Chris@390
|
281 m_menuShortcutMapper = 0;
|
Chris@390
|
282
|
Chris@391
|
283 foreach (QShortcut *sc, m_appShortcuts) {
|
Chris@391
|
284 delete sc;
|
Chris@391
|
285 }
|
Chris@391
|
286 m_appShortcuts.clear();
|
Chris@391
|
287
|
Chris@354
|
288 QMenuBar *mb = menuBar();
|
Chris@394
|
289
|
Chris@396
|
290 // This used to find all children of QMenu type, and call
|
Chris@396
|
291 // finaliseMenu on those. But it seems we are getting hold of some
|
Chris@396
|
292 // menus that way that are not actually active in the menu bar and
|
Chris@396
|
293 // are not returned in their parent menu's actions() list, and if
|
Chris@396
|
294 // we finalise those, we end up with duplicate shortcuts in the
|
Chris@396
|
295 // app shortcut mapper. So we should do this by descending the
|
Chris@396
|
296 // menu tree through only those menus accessible via actions()
|
Chris@396
|
297 // from their parents instead.
|
Chris@396
|
298
|
Chris@394
|
299 QList<QMenu *> menus = mb->findChildren<QMenu *>
|
Chris@394
|
300 (QString(), Qt::FindDirectChildrenOnly);
|
Chris@394
|
301
|
Chris@354
|
302 foreach (QMenu *menu, menus) {
|
Chris@354
|
303 if (menu) finaliseMenu(menu);
|
Chris@354
|
304 }
|
Chris@354
|
305 }
|
Chris@354
|
306
|
Chris@354
|
307 void
|
Chris@358
|
308 MainWindowBase::finaliseMenu(QMenu *
|
Chris@358
|
309 #ifdef Q_OS_MAC
|
Chris@358
|
310 menu
|
Chris@358
|
311 #endif
|
Chris@358
|
312 )
|
Chris@354
|
313 {
|
Chris@354
|
314 #ifdef Q_OS_MAC
|
Chris@354
|
315 // See https://bugreports.qt-project.org/browse/QTBUG-38256 and
|
Chris@354
|
316 // our issue #890 http://code.soundsoftware.ac.uk/issues/890 --
|
Chris@354
|
317 // single-key shortcuts that are associated only with a menu
|
Chris@384
|
318 // action (and not with a toolbar button) do not work with Qt 5.x
|
Chris@384
|
319 // under OS/X.
|
Chris@354
|
320 //
|
Chris@354
|
321 // Apparently Cocoa never handled them as a matter of course, but
|
Chris@354
|
322 // earlier versions of Qt picked them up as widget shortcuts and
|
Chris@354
|
323 // handled them anyway. That behaviour was removed to fix a crash
|
Chris@354
|
324 // when invoking a menu while its window was overridden by a modal
|
Chris@354
|
325 // dialog (https://bugreports.qt-project.org/browse/QTBUG-30657).
|
Chris@354
|
326 //
|
Chris@354
|
327 // This workaround restores the single-key shortcut behaviour by
|
Chris@384
|
328 // searching in menus for single-key shortcuts that are associated
|
Chris@384
|
329 // only with the menu and not with a toolbar button, and
|
Chris@384
|
330 // augmenting them with global application shortcuts that invoke
|
Chris@384
|
331 // the relevant actions, testing whether the actions are enabled
|
Chris@384
|
332 // on invocation.
|
Chris@354
|
333 //
|
Chris@384
|
334 // (Previously this acted on all single-key shortcuts in menus,
|
Chris@384
|
335 // and it removed the shortcut from the action when it created
|
Chris@384
|
336 // each new global one, in order to avoid an "ambiguous shortcut"
|
Chris@384
|
337 // error in the case where the action was also associated with a
|
Chris@384
|
338 // toolbar button. But that has the unwelcome side-effect of
|
Chris@384
|
339 // removing the shortcut hint from the menu entry. So now we leave
|
Chris@384
|
340 // the shortcut in the menu action as well as creating a global
|
Chris@384
|
341 // one, and we only act on shortcuts that have no toolbar button,
|
Chris@384
|
342 // i.e. that will not otherwise work. The downside is that if this
|
Chris@384
|
343 // bug is fixed in a future Qt release, we will start getting
|
Chris@384
|
344 // "ambiguous shortcut" errors from the menu entry actions and
|
Chris@384
|
345 // will need to update the code.)
|
Chris@354
|
346
|
Chris@390
|
347 if (!m_menuShortcutMapper) {
|
Chris@390
|
348 m_menuShortcutMapper = new QSignalMapper(this);
|
Chris@392
|
349 connect(m_menuShortcutMapper, SIGNAL(mapped(QObject *)),
|
Chris@392
|
350 this, SLOT(menuActionMapperInvoked(QObject *)));
|
Chris@390
|
351 }
|
Chris@390
|
352
|
Chris@354
|
353 foreach (QAction *a, menu->actions()) {
|
Chris@394
|
354
|
Chris@394
|
355 if (a->isSeparator()) {
|
Chris@394
|
356 continue;
|
Chris@394
|
357 } else if (a->menu()) {
|
Chris@394
|
358 finaliseMenu(a->menu());
|
Chris@394
|
359 } else {
|
Chris@394
|
360
|
Chris@394
|
361 QWidgetList ww = a->associatedWidgets();
|
Chris@394
|
362 bool hasButton = false;
|
Chris@394
|
363 foreach (QWidget *w, ww) {
|
Chris@394
|
364 if (qobject_cast<QAbstractButton *>(w)) {
|
Chris@394
|
365 hasButton = true;
|
Chris@394
|
366 break;
|
Chris@394
|
367 }
|
Chris@394
|
368 }
|
Chris@394
|
369 if (hasButton) continue;
|
Chris@394
|
370 QKeySequence sc = a->shortcut();
|
Chris@394
|
371 if (sc.count() == 1 && !(sc[0] & Qt::KeyboardModifierMask)) {
|
Chris@394
|
372 QShortcut *newSc = new QShortcut(sc, a->parentWidget());
|
Chris@394
|
373 QObject::connect(newSc, SIGNAL(activated()),
|
Chris@394
|
374 m_menuShortcutMapper, SLOT(map()));
|
Chris@394
|
375 m_menuShortcutMapper->setMapping(newSc, a);
|
Chris@394
|
376 m_appShortcuts.push_back(newSc);
|
Chris@384
|
377 }
|
Chris@384
|
378 }
|
Chris@354
|
379 }
|
Chris@354
|
380 #endif
|
Chris@354
|
381 }
|
Chris@354
|
382
|
Chris@354
|
383 void
|
Chris@354
|
384 MainWindowBase::menuActionMapperInvoked(QObject *o)
|
Chris@354
|
385 {
|
Chris@354
|
386 QAction *a = qobject_cast<QAction *>(o);
|
Chris@354
|
387 if (a && a->isEnabled()) {
|
Chris@354
|
388 a->trigger();
|
Chris@354
|
389 }
|
Chris@354
|
390 }
|
Chris@354
|
391
|
Chris@354
|
392 void
|
Chris@168
|
393 MainWindowBase::resizeConstrained(QSize size)
|
Chris@168
|
394 {
|
Chris@168
|
395 QDesktopWidget *desktop = QApplication::desktop();
|
Chris@168
|
396 QRect available = desktop->availableGeometry();
|
Chris@168
|
397 QSize actual(std::min(size.width(), available.width()),
|
Chris@168
|
398 std::min(size.height(), available.height()));
|
Chris@168
|
399 resize(actual);
|
Chris@168
|
400 }
|
Chris@168
|
401
|
Chris@168
|
402 void
|
Chris@304
|
403 MainWindowBase::startOSCQueue()
|
Chris@304
|
404 {
|
Chris@304
|
405 m_oscQueueStarter = new OSCQueueStarter(this);
|
Chris@304
|
406 connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady()));
|
Chris@304
|
407 m_oscQueueStarter->start();
|
Chris@304
|
408 }
|
Chris@304
|
409
|
Chris@304
|
410 void
|
Chris@113
|
411 MainWindowBase::oscReady()
|
Chris@113
|
412 {
|
Chris@113
|
413 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@113
|
414 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
|
Chris@113
|
415 QTimer *oscTimer = new QTimer(this);
|
Chris@113
|
416 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
|
Chris@113
|
417 oscTimer->start(1000);
|
Chris@293
|
418 cerr << "Finished setting up OSC interface" << endl;
|
Chris@113
|
419 }
|
Chris@113
|
420 }
|
Chris@113
|
421
|
Chris@45
|
422 QString
|
Chris@45
|
423 MainWindowBase::getOpenFileName(FileFinder::FileType type)
|
Chris@45
|
424 {
|
Chris@45
|
425 FileFinder *ff = FileFinder::getInstance();
|
Chris@358
|
426
|
Chris@358
|
427 if (type == FileFinder::AnyFile) {
|
Chris@45
|
428 if (getMainModel() != 0 &&
|
Chris@45
|
429 m_paneStack != 0 &&
|
Chris@45
|
430 m_paneStack->getCurrentPane() != 0) { // can import a layer
|
Chris@45
|
431 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
|
Chris@45
|
432 } else {
|
Chris@45
|
433 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
|
Chris@45
|
434 m_sessionFile);
|
Chris@45
|
435 }
|
Chris@358
|
436 }
|
Chris@358
|
437
|
Chris@358
|
438 QString lastPath = m_sessionFile;
|
Chris@358
|
439
|
Chris@358
|
440 if (type == FileFinder::AudioFile) {
|
Chris@358
|
441 lastPath = m_audioFile;
|
Chris@45
|
442 }
|
Chris@358
|
443
|
Chris@358
|
444 return ff->getOpenFileName(type, lastPath);
|
Chris@45
|
445 }
|
Chris@45
|
446
|
Chris@45
|
447 QString
|
Chris@45
|
448 MainWindowBase::getSaveFileName(FileFinder::FileType type)
|
Chris@45
|
449 {
|
Chris@358
|
450 QString lastPath = m_sessionFile;
|
Chris@358
|
451
|
Chris@358
|
452 if (type == FileFinder::AudioFile) {
|
Chris@358
|
453 lastPath = m_audioFile;
|
Chris@358
|
454 }
|
Chris@358
|
455
|
Chris@45
|
456 FileFinder *ff = FileFinder::getInstance();
|
Chris@358
|
457 return ff->getSaveFileName(type, lastPath);
|
Chris@45
|
458 }
|
Chris@45
|
459
|
Chris@45
|
460 void
|
Chris@45
|
461 MainWindowBase::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
|
Chris@45
|
462 {
|
Chris@45
|
463 FileFinder *ff = FileFinder::getInstance();
|
Chris@45
|
464 ff->registerLastOpenedFilePath(type, path);
|
Chris@45
|
465 }
|
Chris@45
|
466
|
Chris@222
|
467 QString
|
Chris@222
|
468 MainWindowBase::getDefaultSessionTemplate() const
|
Chris@222
|
469 {
|
Chris@231
|
470 QSettings settings;
|
Chris@231
|
471 settings.beginGroup("MainWindow");
|
Chris@231
|
472 QString templateName = settings.value("sessiontemplate", "").toString();
|
Chris@231
|
473 if (templateName == "") templateName = "default";
|
Chris@231
|
474 return templateName;
|
Chris@222
|
475 }
|
Chris@222
|
476
|
Chris@222
|
477 void
|
Chris@251
|
478 MainWindowBase::setDefaultSessionTemplate(QString n)
|
Chris@251
|
479 {
|
Chris@251
|
480 QSettings settings;
|
Chris@251
|
481 settings.beginGroup("MainWindow");
|
Chris@251
|
482 settings.setValue("sessiontemplate", n);
|
Chris@251
|
483 }
|
Chris@251
|
484
|
Chris@251
|
485 void
|
Chris@45
|
486 MainWindowBase::updateMenuStates()
|
Chris@45
|
487 {
|
Chris@45
|
488 Pane *currentPane = 0;
|
Chris@45
|
489 Layer *currentLayer = 0;
|
Chris@45
|
490
|
Chris@45
|
491 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
492 if (currentPane) currentLayer = currentPane->getSelectedLayer();
|
Chris@45
|
493
|
Chris@73
|
494 bool havePrevPane = false, haveNextPane = false;
|
Chris@73
|
495 bool havePrevLayer = false, haveNextLayer = false;
|
Chris@73
|
496
|
Chris@73
|
497 if (currentPane) {
|
Chris@73
|
498 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
499 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
500 if (i > 0) havePrevPane = true;
|
Chris@73
|
501 if (i < m_paneStack->getPaneCount()-1) haveNextPane = true;
|
Chris@73
|
502 break;
|
Chris@73
|
503 }
|
Chris@73
|
504 }
|
Chris@73
|
505 if (currentLayer) {
|
Chris@73
|
506 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
507 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
508 if (i > 0) havePrevLayer = true;
|
Chris@73
|
509 if (i < currentPane->getLayerCount()-1) haveNextLayer = true;
|
Chris@73
|
510 break;
|
Chris@73
|
511 }
|
Chris@73
|
512 }
|
Chris@73
|
513 }
|
Chris@73
|
514 }
|
Chris@73
|
515
|
Chris@45
|
516 bool haveCurrentPane =
|
Chris@45
|
517 (currentPane != 0);
|
Chris@45
|
518 bool haveCurrentLayer =
|
Chris@45
|
519 (haveCurrentPane &&
|
Chris@45
|
520 (currentLayer != 0));
|
Chris@45
|
521 bool haveMainModel =
|
Chris@45
|
522 (getMainModel() != 0);
|
Chris@45
|
523 bool havePlayTarget =
|
Chris@45
|
524 (m_playTarget != 0);
|
Chris@45
|
525 bool haveSelection =
|
Chris@45
|
526 (m_viewManager &&
|
Chris@45
|
527 !m_viewManager->getSelections().empty());
|
Chris@45
|
528 bool haveCurrentEditableLayer =
|
Chris@45
|
529 (haveCurrentLayer &&
|
Chris@45
|
530 currentLayer->isLayerEditable());
|
Chris@45
|
531 bool haveCurrentTimeInstantsLayer =
|
Chris@45
|
532 (haveCurrentLayer &&
|
Chris@45
|
533 dynamic_cast<TimeInstantLayer *>(currentLayer));
|
Chris@184
|
534 bool haveCurrentDurationLayer =
|
Chris@184
|
535 (haveCurrentLayer &&
|
Chris@184
|
536 (dynamic_cast<NoteLayer *>(currentLayer) ||
|
matthiasm@267
|
537 dynamic_cast<FlexiNoteLayer *>(currentLayer) ||
|
Chris@184
|
538 dynamic_cast<RegionLayer *>(currentLayer)));
|
Chris@45
|
539 bool haveCurrentColour3DPlot =
|
Chris@45
|
540 (haveCurrentLayer &&
|
Chris@45
|
541 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
|
Chris@45
|
542 bool haveClipboardContents =
|
Chris@45
|
543 (m_viewManager &&
|
Chris@45
|
544 !m_viewManager->getClipboard().empty());
|
Chris@146
|
545 bool haveTabularLayer =
|
Chris@146
|
546 (haveCurrentLayer &&
|
Chris@146
|
547 dynamic_cast<TabularModel *>(currentLayer->getModel()));
|
Chris@45
|
548
|
Chris@45
|
549 emit canAddPane(haveMainModel);
|
Chris@45
|
550 emit canDeleteCurrentPane(haveCurrentPane);
|
Chris@45
|
551 emit canZoom(haveMainModel && haveCurrentPane);
|
Chris@45
|
552 emit canScroll(haveMainModel && haveCurrentPane);
|
Chris@45
|
553 emit canAddLayer(haveMainModel && haveCurrentPane);
|
Chris@45
|
554 emit canImportMoreAudio(haveMainModel);
|
Chris@259
|
555 emit canReplaceMainAudio(haveMainModel);
|
Chris@45
|
556 emit canImportLayer(haveMainModel && haveCurrentPane);
|
Chris@45
|
557 emit canExportAudio(haveMainModel);
|
Chris@289
|
558 emit canChangeSessionTemplate(haveMainModel);
|
Chris@45
|
559 emit canExportLayer(haveMainModel &&
|
Chris@45
|
560 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
|
Chris@45
|
561 emit canExportImage(haveMainModel && haveCurrentPane);
|
Chris@45
|
562 emit canDeleteCurrentLayer(haveCurrentLayer);
|
Chris@45
|
563 emit canRenameLayer(haveCurrentLayer);
|
Chris@45
|
564 emit canEditLayer(haveCurrentEditableLayer);
|
Chris@146
|
565 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer);
|
Chris@45
|
566 emit canMeasureLayer(haveCurrentLayer);
|
Chris@45
|
567 emit canSelect(haveMainModel && haveCurrentPane);
|
Chris@188
|
568 emit canPlay(haveMainModel && havePlayTarget);
|
Chris@45
|
569 emit canFfwd(true);
|
Chris@45
|
570 emit canRewind(true);
|
Chris@87
|
571 emit canPaste(haveClipboardContents);
|
Chris@45
|
572 emit canInsertInstant(haveCurrentPane);
|
Chris@45
|
573 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
|
Chris@184
|
574 emit canInsertItemAtSelection(haveCurrentPane && haveSelection && haveCurrentDurationLayer);
|
Chris@45
|
575 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
|
Chris@45
|
576 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
|
Chris@45
|
577 emit canClearSelection(haveSelection);
|
Chris@45
|
578 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@45
|
579 emit canSave(m_sessionFile != "" && m_documentModified);
|
Chris@359
|
580 emit canSaveAs(haveMainModel);
|
Chris@73
|
581 emit canSelectPreviousPane(havePrevPane);
|
Chris@73
|
582 emit canSelectNextPane(haveNextPane);
|
Chris@73
|
583 emit canSelectPreviousLayer(havePrevLayer);
|
Chris@73
|
584 emit canSelectNextLayer(haveNextLayer);
|
Chris@45
|
585 }
|
Chris@45
|
586
|
Chris@45
|
587 void
|
Chris@45
|
588 MainWindowBase::documentModified()
|
Chris@45
|
589 {
|
Chris@233
|
590 // SVDEBUG << "MainWindowBase::documentModified" << endl;
|
Chris@45
|
591
|
Chris@45
|
592 if (!m_documentModified) {
|
Chris@45
|
593 //!!! this in subclass implementation?
|
Chris@45
|
594 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
|
Chris@45
|
595 }
|
Chris@45
|
596
|
Chris@45
|
597 m_documentModified = true;
|
Chris@45
|
598 updateMenuStates();
|
Chris@45
|
599 }
|
Chris@45
|
600
|
Chris@45
|
601 void
|
Chris@45
|
602 MainWindowBase::documentRestored()
|
Chris@45
|
603 {
|
Chris@233
|
604 // SVDEBUG << "MainWindowBase::documentRestored" << endl;
|
Chris@45
|
605
|
Chris@45
|
606 if (m_documentModified) {
|
Chris@45
|
607 //!!! this in subclass implementation?
|
Chris@45
|
608 QString wt(windowTitle());
|
Chris@45
|
609 wt.replace(tr(" (modified)"), "");
|
Chris@45
|
610 setWindowTitle(wt);
|
Chris@45
|
611 }
|
Chris@45
|
612
|
Chris@45
|
613 m_documentModified = false;
|
Chris@45
|
614 updateMenuStates();
|
Chris@45
|
615 }
|
Chris@45
|
616
|
Chris@45
|
617 void
|
Chris@45
|
618 MainWindowBase::playLoopToggled()
|
Chris@45
|
619 {
|
Chris@45
|
620 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
621
|
Chris@45
|
622 if (action) {
|
Chris@45
|
623 m_viewManager->setPlayLoopMode(action->isChecked());
|
Chris@45
|
624 } else {
|
Chris@45
|
625 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
|
Chris@45
|
626 }
|
Chris@45
|
627 }
|
Chris@45
|
628
|
Chris@45
|
629 void
|
Chris@45
|
630 MainWindowBase::playSelectionToggled()
|
Chris@45
|
631 {
|
Chris@45
|
632 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
633
|
Chris@45
|
634 if (action) {
|
Chris@45
|
635 m_viewManager->setPlaySelectionMode(action->isChecked());
|
Chris@45
|
636 } else {
|
Chris@45
|
637 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
|
Chris@45
|
638 }
|
Chris@45
|
639 }
|
Chris@45
|
640
|
Chris@45
|
641 void
|
Chris@45
|
642 MainWindowBase::playSoloToggled()
|
Chris@45
|
643 {
|
Chris@45
|
644 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
645
|
Chris@45
|
646 if (action) {
|
Chris@45
|
647 m_viewManager->setPlaySoloMode(action->isChecked());
|
Chris@45
|
648 } else {
|
Chris@45
|
649 m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode());
|
Chris@45
|
650 }
|
Chris@45
|
651
|
Chris@45
|
652 if (m_viewManager->getPlaySoloMode()) {
|
Chris@45
|
653 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
654 } else {
|
Chris@45
|
655 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
656 if (m_playSource) {
|
Chris@45
|
657 m_playSource->clearSoloModelSet();
|
Chris@45
|
658 }
|
Chris@45
|
659 }
|
Chris@45
|
660 }
|
Chris@45
|
661
|
Chris@45
|
662 void
|
Chris@45
|
663 MainWindowBase::currentPaneChanged(Pane *p)
|
Chris@45
|
664 {
|
Chris@45
|
665 updateMenuStates();
|
Chris@45
|
666 updateVisibleRangeDisplay(p);
|
Chris@45
|
667
|
Chris@45
|
668 if (!p) return;
|
Chris@45
|
669
|
Chris@45
|
670 if (!(m_viewManager &&
|
Chris@45
|
671 m_playSource &&
|
Chris@45
|
672 m_viewManager->getPlaySoloMode())) {
|
Chris@45
|
673 if (m_viewManager) m_viewManager->setPlaybackModel(0);
|
Chris@45
|
674 return;
|
Chris@45
|
675 }
|
Chris@45
|
676
|
Chris@45
|
677 Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
|
Chris@60
|
678
|
Chris@93
|
679 // What we want here is not the currently playing frame (unless we
|
Chris@93
|
680 // are about to clear out the audio playback buffers -- which may
|
Chris@93
|
681 // or may not be possible, depending on the audio driver). What
|
Chris@93
|
682 // we want is the frame that was last committed to the soundcard
|
Chris@93
|
683 // buffers, as the audio driver will continue playing up to that
|
Chris@93
|
684 // frame before switching to whichever one we decide we want to
|
Chris@93
|
685 // switch to, regardless of our efforts.
|
Chris@93
|
686
|
Chris@93
|
687 int frame = m_playSource->getCurrentBufferedFrame();
|
Chris@93
|
688
|
Chris@388
|
689 cerr << "currentPaneChanged: current frame (in ref model) = " << frame << endl;
|
Chris@45
|
690
|
Chris@45
|
691 View::ModelSet soloModels = p->getModels();
|
Chris@45
|
692
|
Chris@57
|
693 View::ModelSet sources;
|
Chris@57
|
694 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@57
|
695 mi != soloModels.end(); ++mi) {
|
Chris@190
|
696 // If a model in this pane is derived from something else,
|
Chris@190
|
697 // then we want to play that model as well -- if the model
|
Chris@190
|
698 // that's derived from it is not something that is itself
|
Chris@190
|
699 // individually playable (e.g. a waveform)
|
Chris@190
|
700 if (*mi &&
|
Chris@190
|
701 !dynamic_cast<RangeSummarisableTimeValueModel *>(*mi) &&
|
Chris@190
|
702 (*mi)->getSourceModel()) {
|
Chris@57
|
703 sources.insert((*mi)->getSourceModel());
|
Chris@57
|
704 }
|
Chris@57
|
705 }
|
Chris@57
|
706 for (View::ModelSet::iterator mi = sources.begin();
|
Chris@57
|
707 mi != sources.end(); ++mi) {
|
Chris@57
|
708 soloModels.insert(*mi);
|
Chris@57
|
709 }
|
Chris@57
|
710
|
Chris@60
|
711 //!!! Need an "atomic" way of telling the play source that the
|
Chris@60
|
712 //playback model has changed, and changing it on ViewManager --
|
Chris@60
|
713 //the play source should be making the setPlaybackModel call to
|
Chris@60
|
714 //ViewManager
|
Chris@60
|
715
|
Chris@45
|
716 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@45
|
717 mi != soloModels.end(); ++mi) {
|
Chris@45
|
718 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
|
Chris@45
|
719 m_viewManager->setPlaybackModel(*mi);
|
Chris@45
|
720 }
|
Chris@45
|
721 }
|
Chris@45
|
722
|
Chris@45
|
723 RangeSummarisableTimeValueModel *a =
|
Chris@45
|
724 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
|
Chris@45
|
725 RangeSummarisableTimeValueModel *b =
|
Chris@45
|
726 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
|
Chris@45
|
727 getPlaybackModel());
|
Chris@45
|
728
|
Chris@45
|
729 m_playSource->setSoloModelSet(soloModels);
|
Chris@45
|
730
|
Chris@45
|
731 if (a && b && (a != b)) {
|
Chris@60
|
732 if (m_playSource->isPlaying()) m_playSource->play(frame);
|
Chris@45
|
733 }
|
Chris@45
|
734 }
|
Chris@45
|
735
|
Chris@45
|
736 void
|
Chris@45
|
737 MainWindowBase::currentLayerChanged(Pane *p, Layer *)
|
Chris@45
|
738 {
|
Chris@45
|
739 updateMenuStates();
|
Chris@45
|
740 updateVisibleRangeDisplay(p);
|
Chris@45
|
741 }
|
Chris@45
|
742
|
Chris@45
|
743 void
|
Chris@45
|
744 MainWindowBase::selectAll()
|
Chris@45
|
745 {
|
Chris@45
|
746 if (!getMainModel()) return;
|
Chris@45
|
747 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
748 getMainModel()->getEndFrame()));
|
Chris@45
|
749 }
|
Chris@45
|
750
|
Chris@45
|
751 void
|
Chris@45
|
752 MainWindowBase::selectToStart()
|
Chris@45
|
753 {
|
Chris@45
|
754 if (!getMainModel()) return;
|
Chris@45
|
755 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
756 m_viewManager->getGlobalCentreFrame()));
|
Chris@45
|
757 }
|
Chris@45
|
758
|
Chris@45
|
759 void
|
Chris@45
|
760 MainWindowBase::selectToEnd()
|
Chris@45
|
761 {
|
Chris@45
|
762 if (!getMainModel()) return;
|
Chris@45
|
763 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@45
|
764 getMainModel()->getEndFrame()));
|
Chris@45
|
765 }
|
Chris@45
|
766
|
Chris@45
|
767 void
|
Chris@45
|
768 MainWindowBase::selectVisible()
|
Chris@45
|
769 {
|
Chris@45
|
770 Model *model = getMainModel();
|
Chris@45
|
771 if (!model) return;
|
Chris@45
|
772
|
Chris@45
|
773 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
774 if (!currentPane) return;
|
Chris@45
|
775
|
Chris@366
|
776 int startFrame, endFrame;
|
Chris@45
|
777
|
Chris@45
|
778 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@45
|
779 else startFrame = currentPane->getStartFrame();
|
Chris@45
|
780
|
Chris@45
|
781 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@45
|
782 else endFrame = currentPane->getEndFrame();
|
Chris@45
|
783
|
Chris@45
|
784 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@45
|
785 }
|
Chris@45
|
786
|
Chris@45
|
787 void
|
Chris@45
|
788 MainWindowBase::clearSelection()
|
Chris@45
|
789 {
|
Chris@45
|
790 m_viewManager->clearSelections();
|
Chris@45
|
791 }
|
Chris@45
|
792
|
Chris@45
|
793 void
|
Chris@45
|
794 MainWindowBase::cut()
|
Chris@45
|
795 {
|
Chris@45
|
796 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
797 if (!currentPane) return;
|
Chris@45
|
798
|
Chris@45
|
799 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
800 if (!layer) return;
|
Chris@45
|
801
|
Chris@45
|
802 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
803 clipboard.clear();
|
Chris@45
|
804
|
Chris@45
|
805 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
806
|
Chris@45
|
807 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@45
|
808
|
Chris@45
|
809 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
810 i != selections.end(); ++i) {
|
Chris@86
|
811 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
812 layer->deleteSelection(*i);
|
Chris@45
|
813 }
|
Chris@45
|
814
|
Chris@45
|
815 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
816 }
|
Chris@45
|
817
|
Chris@45
|
818 void
|
Chris@45
|
819 MainWindowBase::copy()
|
Chris@45
|
820 {
|
Chris@45
|
821 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
822 if (!currentPane) return;
|
Chris@45
|
823
|
Chris@45
|
824 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
825 if (!layer) return;
|
Chris@45
|
826
|
Chris@45
|
827 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
828 clipboard.clear();
|
Chris@45
|
829
|
Chris@45
|
830 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
831
|
Chris@45
|
832 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
833 i != selections.end(); ++i) {
|
Chris@86
|
834 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
835 }
|
Chris@45
|
836 }
|
Chris@45
|
837
|
Chris@45
|
838 void
|
Chris@45
|
839 MainWindowBase::paste()
|
Chris@45
|
840 {
|
Chris@215
|
841 pasteRelative(0);
|
Chris@215
|
842 }
|
Chris@215
|
843
|
Chris@215
|
844 void
|
Chris@215
|
845 MainWindowBase::pasteAtPlaybackPosition()
|
Chris@215
|
846 {
|
Chris@366
|
847 int pos = getFrame();
|
Chris@215
|
848 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@215
|
849 if (!clipboard.empty()) {
|
Chris@366
|
850 int firstEventFrame = clipboard.getPoints()[0].getFrame();
|
Chris@366
|
851 int offset = 0;
|
Chris@215
|
852 if (firstEventFrame < 0) {
|
Chris@366
|
853 offset = pos - firstEventFrame;
|
Chris@354
|
854 } else if (firstEventFrame < pos) {
|
Chris@366
|
855 offset = pos - firstEventFrame;
|
Chris@215
|
856 } else {
|
Chris@366
|
857 offset = -(firstEventFrame - pos);
|
Chris@215
|
858 }
|
Chris@215
|
859 pasteRelative(offset);
|
Chris@215
|
860 }
|
Chris@215
|
861 }
|
Chris@215
|
862
|
Chris@215
|
863 void
|
Chris@215
|
864 MainWindowBase::pasteRelative(int offset)
|
Chris@215
|
865 {
|
Chris@45
|
866 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
867 if (!currentPane) return;
|
Chris@45
|
868
|
Chris@45
|
869 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
870
|
Chris@45
|
871 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@87
|
872
|
Chris@98
|
873 bool inCompound = false;
|
Chris@87
|
874
|
Chris@87
|
875 if (!layer || !layer->isLayerEditable()) {
|
Chris@87
|
876
|
Chris@87
|
877 CommandHistory::getInstance()->startCompoundOperation
|
Chris@87
|
878 (tr("Paste"), true);
|
Chris@87
|
879
|
Chris@87
|
880 // no suitable current layer: create one of the most
|
Chris@87
|
881 // appropriate sort
|
Chris@87
|
882 LayerFactory::LayerType type =
|
Chris@87
|
883 LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard);
|
Chris@87
|
884 layer = m_document->createEmptyLayer(type);
|
Chris@87
|
885
|
Chris@87
|
886 if (!layer) {
|
Chris@87
|
887 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@87
|
888 return;
|
Chris@45
|
889 }
|
Chris@87
|
890
|
Chris@87
|
891 m_document->addLayerToView(currentPane, layer);
|
Chris@87
|
892 m_paneStack->setCurrentLayer(currentPane, layer);
|
Chris@87
|
893
|
Chris@87
|
894 inCompound = true;
|
Chris@45
|
895 }
|
Chris@45
|
896
|
Chris@215
|
897 layer->paste(currentPane, clipboard, offset, true);
|
Chris@45
|
898
|
Chris@87
|
899 if (inCompound) CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
900 }
|
Chris@45
|
901
|
Chris@45
|
902 void
|
Chris@45
|
903 MainWindowBase::deleteSelected()
|
Chris@45
|
904 {
|
Chris@45
|
905 if (m_paneStack->getCurrentPane() &&
|
Chris@45
|
906 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@45
|
907
|
Chris@45
|
908 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
|
Chris@45
|
909
|
Chris@45
|
910 if (m_viewManager &&
|
Chris@45
|
911 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
|
Chris@45
|
912
|
Chris@45
|
913 layer->deleteCurrentMeasureRect();
|
Chris@45
|
914
|
Chris@45
|
915 } else {
|
Chris@45
|
916
|
Chris@45
|
917 MultiSelection::SelectionList selections =
|
Chris@45
|
918 m_viewManager->getSelections();
|
Chris@45
|
919
|
Chris@45
|
920 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
921 i != selections.end(); ++i) {
|
Chris@45
|
922 layer->deleteSelection(*i);
|
Chris@45
|
923 }
|
Chris@45
|
924 }
|
Chris@45
|
925 }
|
Chris@45
|
926 }
|
Chris@45
|
927
|
Chris@161
|
928 // FrameTimer method
|
Chris@161
|
929
|
Chris@366
|
930 int
|
Chris@161
|
931 MainWindowBase::getFrame() const
|
Chris@161
|
932 {
|
Chris@161
|
933 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@161
|
934 return m_playSource->getCurrentPlayingFrame();
|
Chris@161
|
935 } else {
|
Chris@161
|
936 return m_viewManager->getPlaybackFrame();
|
Chris@161
|
937 }
|
Chris@161
|
938 }
|
Chris@161
|
939
|
Chris@45
|
940 void
|
Chris@45
|
941 MainWindowBase::insertInstant()
|
Chris@45
|
942 {
|
Chris@161
|
943 insertInstantAt(getFrame());
|
Chris@45
|
944 }
|
Chris@45
|
945
|
Chris@45
|
946 void
|
Chris@45
|
947 MainWindowBase::insertInstantsAtBoundaries()
|
Chris@45
|
948 {
|
Chris@45
|
949 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
950 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
951 i != selections.end(); ++i) {
|
Chris@366
|
952 int start = i->getStartFrame();
|
Chris@366
|
953 int end = i->getEndFrame();
|
Chris@45
|
954 if (start != end) {
|
Chris@184
|
955 insertInstantAt(start);
|
Chris@184
|
956 insertInstantAt(end);
|
Chris@45
|
957 }
|
Chris@45
|
958 }
|
Chris@45
|
959 }
|
Chris@45
|
960
|
Chris@45
|
961 void
|
Chris@366
|
962 MainWindowBase::insertInstantAt(int frame)
|
Chris@45
|
963 {
|
Chris@45
|
964 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
965 if (!pane) {
|
Chris@45
|
966 return;
|
Chris@45
|
967 }
|
Chris@45
|
968
|
Chris@74
|
969 frame = pane->alignFromReference(frame);
|
Chris@74
|
970
|
Chris@45
|
971 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@45
|
972 (pane->getSelectedLayer());
|
Chris@45
|
973
|
Chris@45
|
974 if (!layer) {
|
Chris@45
|
975 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
976 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@45
|
977 if (layer) break;
|
Chris@45
|
978 }
|
Chris@45
|
979
|
Chris@45
|
980 if (!layer) {
|
Chris@45
|
981 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
982 (tr("Add Point"), true);
|
Chris@45
|
983 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@45
|
984 if (layer) {
|
Chris@45
|
985 m_document->addLayerToView(pane, layer);
|
Chris@45
|
986 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@45
|
987 }
|
Chris@45
|
988 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
989 }
|
Chris@45
|
990 }
|
Chris@45
|
991
|
Chris@45
|
992 if (layer) {
|
Chris@45
|
993
|
Chris@45
|
994 Model *model = layer->getModel();
|
Chris@45
|
995 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
996 (model);
|
Chris@45
|
997
|
Chris@45
|
998 if (sodm) {
|
Chris@45
|
999 SparseOneDimensionalModel::Point point(frame, "");
|
Chris@45
|
1000
|
Chris@45
|
1001 SparseOneDimensionalModel::Point prevPoint(0);
|
Chris@45
|
1002 bool havePrevPoint = false;
|
Chris@45
|
1003
|
Chris@45
|
1004 SparseOneDimensionalModel::EditCommand *command =
|
Chris@45
|
1005 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
|
Chris@45
|
1006
|
Chris@74
|
1007 if (m_labeller->requiresPrevPoint()) {
|
Chris@45
|
1008
|
Chris@45
|
1009 SparseOneDimensionalModel::PointList prevPoints =
|
Chris@45
|
1010 sodm->getPreviousPoints(frame);
|
Chris@45
|
1011
|
Chris@45
|
1012 if (!prevPoints.empty()) {
|
Chris@45
|
1013 prevPoint = *prevPoints.begin();
|
Chris@45
|
1014 havePrevPoint = true;
|
Chris@45
|
1015 }
|
Chris@45
|
1016 }
|
Chris@45
|
1017
|
Chris@45
|
1018 if (m_labeller) {
|
Chris@45
|
1019
|
Chris@45
|
1020 m_labeller->setSampleRate(sodm->getSampleRate());
|
Chris@45
|
1021
|
Chris@352
|
1022 if (m_labeller->actingOnPrevPoint() && havePrevPoint) {
|
Chris@45
|
1023 command->deletePoint(prevPoint);
|
Chris@45
|
1024 }
|
Chris@45
|
1025
|
Chris@45
|
1026 m_labeller->label<SparseOneDimensionalModel::Point>
|
Chris@45
|
1027 (point, havePrevPoint ? &prevPoint : 0);
|
Chris@45
|
1028
|
Chris@352
|
1029 if (m_labeller->actingOnPrevPoint() && havePrevPoint) {
|
Chris@45
|
1030 command->addPoint(prevPoint);
|
Chris@45
|
1031 }
|
Chris@45
|
1032 }
|
Chris@45
|
1033
|
Chris@45
|
1034 command->addPoint(point);
|
Chris@45
|
1035
|
Chris@45
|
1036 command->setName(tr("Add Point at %1 s")
|
Chris@45
|
1037 .arg(RealTime::frame2RealTime
|
Chris@45
|
1038 (frame,
|
Chris@45
|
1039 sodm->getSampleRate())
|
Chris@45
|
1040 .toText(false).c_str()));
|
Chris@45
|
1041
|
Chris@108
|
1042 Command *c = command->finish();
|
Chris@108
|
1043 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@45
|
1044 }
|
Chris@45
|
1045 }
|
Chris@45
|
1046 }
|
Chris@45
|
1047
|
Chris@45
|
1048 void
|
Chris@184
|
1049 MainWindowBase::insertItemAtSelection()
|
Chris@184
|
1050 {
|
Chris@184
|
1051 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@184
|
1052 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@184
|
1053 i != selections.end(); ++i) {
|
Chris@366
|
1054 int start = i->getStartFrame();
|
Chris@366
|
1055 int end = i->getEndFrame();
|
Chris@184
|
1056 if (start < end) {
|
Chris@184
|
1057 insertItemAt(start, end - start);
|
Chris@184
|
1058 }
|
Chris@184
|
1059 }
|
Chris@184
|
1060 }
|
Chris@184
|
1061
|
Chris@184
|
1062 void
|
Chris@366
|
1063 MainWindowBase::insertItemAt(int frame, int duration)
|
Chris@184
|
1064 {
|
Chris@184
|
1065 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@184
|
1066 if (!pane) {
|
Chris@184
|
1067 return;
|
Chris@184
|
1068 }
|
Chris@184
|
1069
|
Chris@184
|
1070 // ugh!
|
Chris@184
|
1071
|
Chris@366
|
1072 int alignedStart = pane->alignFromReference(frame);
|
Chris@366
|
1073 int alignedEnd = pane->alignFromReference(frame + duration);
|
Chris@184
|
1074 if (alignedStart >= alignedEnd) return;
|
Chris@366
|
1075 int alignedDuration = alignedEnd - alignedStart;
|
Chris@184
|
1076
|
Chris@184
|
1077 Command *c = 0;
|
Chris@184
|
1078
|
Chris@184
|
1079 QString name = tr("Add Item at %1 s")
|
Chris@184
|
1080 .arg(RealTime::frame2RealTime
|
Chris@184
|
1081 (alignedStart,
|
Chris@184
|
1082 getMainModel()->getSampleRate())
|
Chris@184
|
1083 .toText(false).c_str());
|
Chris@184
|
1084
|
Chris@184
|
1085 Layer *layer = pane->getSelectedLayer();
|
Chris@184
|
1086 if (!layer) return;
|
Chris@184
|
1087
|
Chris@184
|
1088 RegionModel *rm = dynamic_cast<RegionModel *>(layer->getModel());
|
Chris@184
|
1089 if (rm) {
|
Chris@184
|
1090 RegionModel::Point point(alignedStart,
|
Chris@185
|
1091 rm->getValueMaximum() + 1,
|
Chris@184
|
1092 alignedDuration,
|
Chris@184
|
1093 "");
|
Chris@184
|
1094 RegionModel::EditCommand *command =
|
Chris@184
|
1095 new RegionModel::EditCommand(rm, tr("Add Point"));
|
Chris@184
|
1096 command->addPoint(point);
|
Chris@184
|
1097 command->setName(name);
|
Chris@184
|
1098 c = command->finish();
|
Chris@184
|
1099 }
|
Chris@184
|
1100
|
Chris@184
|
1101 if (c) {
|
Chris@184
|
1102 CommandHistory::getInstance()->addCommand(c, false);
|
Chris@184
|
1103 return;
|
Chris@184
|
1104 }
|
Chris@184
|
1105
|
Chris@184
|
1106 NoteModel *nm = dynamic_cast<NoteModel *>(layer->getModel());
|
Chris@184
|
1107 if (nm) {
|
Chris@184
|
1108 NoteModel::Point point(alignedStart,
|
Chris@184
|
1109 rm->getValueMinimum(),
|
Chris@184
|
1110 alignedDuration,
|
Chris@184
|
1111 1.f,
|
Chris@184
|
1112 "");
|
Chris@184
|
1113 NoteModel::EditCommand *command =
|
Chris@184
|
1114 new NoteModel::EditCommand(nm, tr("Add Point"));
|
Chris@184
|
1115 command->addPoint(point);
|
Chris@184
|
1116 command->setName(name);
|
Chris@184
|
1117 c = command->finish();
|
Chris@184
|
1118 }
|
Chris@184
|
1119
|
Chris@184
|
1120 if (c) {
|
Chris@184
|
1121 CommandHistory::getInstance()->addCommand(c, false);
|
Chris@184
|
1122 return;
|
Chris@184
|
1123 }
|
matthiasm@267
|
1124
|
matthiasm@268
|
1125 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(layer->getModel());
|
matthiasm@268
|
1126 if (fnm) {
|
matthiasm@267
|
1127 FlexiNoteModel::Point point(alignedStart,
|
matthiasm@267
|
1128 rm->getValueMinimum(),
|
matthiasm@267
|
1129 alignedDuration,
|
matthiasm@267
|
1130 1.f,
|
matthiasm@267
|
1131 "");
|
matthiasm@267
|
1132 FlexiNoteModel::EditCommand *command =
|
matthiasm@268
|
1133 new FlexiNoteModel::EditCommand(fnm, tr("Add Point"));
|
matthiasm@267
|
1134 command->addPoint(point);
|
matthiasm@267
|
1135 command->setName(name);
|
matthiasm@267
|
1136 c = command->finish();
|
matthiasm@267
|
1137 }
|
matthiasm@267
|
1138
|
matthiasm@267
|
1139 if (c) {
|
matthiasm@267
|
1140 CommandHistory::getInstance()->addCommand(c, false);
|
matthiasm@267
|
1141 return;
|
matthiasm@267
|
1142 }
|
Chris@184
|
1143 }
|
Chris@184
|
1144
|
Chris@184
|
1145 void
|
Chris@45
|
1146 MainWindowBase::renumberInstants()
|
Chris@45
|
1147 {
|
Chris@45
|
1148 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1149 if (!pane) return;
|
Chris@45
|
1150
|
Chris@45
|
1151 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@45
|
1152 if (!layer) return;
|
Chris@45
|
1153
|
Chris@45
|
1154 MultiSelection ms(m_viewManager->getSelection());
|
Chris@45
|
1155
|
Chris@45
|
1156 Model *model = layer->getModel();
|
Chris@45
|
1157 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
1158 (model);
|
Chris@45
|
1159 if (!sodm) return;
|
Chris@45
|
1160
|
Chris@45
|
1161 if (!m_labeller) return;
|
Chris@45
|
1162
|
Chris@45
|
1163 Labeller labeller(*m_labeller);
|
Chris@45
|
1164 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@45
|
1165
|
Chris@45
|
1166 // This uses a command
|
Chris@45
|
1167
|
Chris@45
|
1168 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
|
Chris@45
|
1169 }
|
Chris@45
|
1170
|
Chris@45
|
1171 MainWindowBase::FileOpenStatus
|
Chris@373
|
1172 MainWindowBase::openPath(QString fileOrUrl, AudioFileOpenMode mode)
|
Chris@45
|
1173 {
|
Chris@134
|
1174 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000, this);
|
Chris@134
|
1175 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1176 return open(FileSource(fileOrUrl, &dialog), mode);
|
Chris@45
|
1177 }
|
Chris@45
|
1178
|
Chris@45
|
1179 MainWindowBase::FileOpenStatus
|
Chris@45
|
1180 MainWindowBase::open(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1181 {
|
Chris@45
|
1182 FileOpenStatus status;
|
Chris@45
|
1183
|
Chris@45
|
1184 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1185 source.waitForData();
|
Chris@45
|
1186
|
Chris@45
|
1187 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@45
|
1188 m_paneStack != 0 &&
|
Chris@45
|
1189 m_paneStack->getCurrentPane() != 0);
|
Chris@45
|
1190
|
Chris@152
|
1191 bool rdf = (source.getExtension().toLower() == "rdf" ||
|
Chris@152
|
1192 source.getExtension().toLower() == "n3" ||
|
Chris@152
|
1193 source.getExtension().toLower() == "ttl");
|
Chris@152
|
1194
|
Chris@152
|
1195 bool audio = AudioFileReaderFactory::getKnownExtensions().contains
|
Chris@152
|
1196 (source.getExtension().toLower());
|
Chris@145
|
1197
|
Chris@145
|
1198 bool rdfSession = false;
|
Chris@145
|
1199 if (rdf) {
|
Chris@145
|
1200 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1201 RDFImporter::identifyDocumentType
|
Chris@145
|
1202 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
|
Chris@145
|
1203 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
|
Chris@145
|
1204 rdfType == RDFImporter::AudioRef) {
|
Chris@145
|
1205 rdfSession = true;
|
Chris@145
|
1206 } else if (rdfType == RDFImporter::NotRDF) {
|
Chris@145
|
1207 rdf = false;
|
Chris@145
|
1208 }
|
Chris@145
|
1209 }
|
Chris@145
|
1210
|
Chris@145
|
1211 if (rdf) {
|
Chris@145
|
1212 if (rdfSession) {
|
Chris@147
|
1213 bool cancel = false;
|
Chris@147
|
1214 if (!canImportLayer || shouldCreateNewSessionForRDFAudio(&cancel)) {
|
Chris@145
|
1215 return openSession(source);
|
Chris@147
|
1216 } else if (cancel) {
|
Chris@147
|
1217 return FileOpenCancelled;
|
Chris@145
|
1218 } else {
|
Chris@145
|
1219 return openLayer(source);
|
Chris@145
|
1220 }
|
Chris@145
|
1221 } else {
|
Chris@145
|
1222 if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@145
|
1223 return status;
|
Chris@145
|
1224 } else if (!canImportLayer) {
|
Chris@145
|
1225 return FileOpenWrongMode;
|
Chris@145
|
1226 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@145
|
1227 return status;
|
Chris@145
|
1228 } else {
|
Chris@145
|
1229 return FileOpenFailed;
|
Chris@145
|
1230 }
|
Chris@145
|
1231 }
|
Chris@145
|
1232 }
|
Chris@145
|
1233
|
Chris@152
|
1234 if (audio && (status = openAudio(source, mode)) != FileOpenFailed) {
|
Chris@45
|
1235 return status;
|
Chris@45
|
1236 } else if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@45
|
1237 return status;
|
Chris@45
|
1238 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) {
|
Chris@45
|
1239 return status;
|
Chris@45
|
1240 } else if (!canImportLayer) {
|
Chris@45
|
1241 return FileOpenWrongMode;
|
Chris@45
|
1242 } else if ((status = openImage(source)) != FileOpenFailed) {
|
Chris@45
|
1243 return status;
|
Chris@45
|
1244 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@45
|
1245 return status;
|
Chris@45
|
1246 } else {
|
Chris@45
|
1247 return FileOpenFailed;
|
Chris@45
|
1248 }
|
Chris@45
|
1249 }
|
Chris@45
|
1250
|
Chris@45
|
1251 MainWindowBase::FileOpenStatus
|
Chris@227
|
1252 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode,
|
Chris@227
|
1253 QString templateName)
|
Chris@45
|
1254 {
|
Chris@386
|
1255 SVDEBUG << "MainWindowBase::openAudio(" << source.getLocation() << ") with mode " << mode << " and template " << templateName << endl;
|
Chris@45
|
1256
|
Chris@222
|
1257 if (templateName == "") {
|
Chris@231
|
1258 templateName = getDefaultSessionTemplate();
|
Chris@222
|
1259 }
|
Chris@220
|
1260
|
Chris@374
|
1261 // cerr << "template is: \"" << templateName << "\"" << endl;
|
Chris@223
|
1262
|
Chris@45
|
1263 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1264 source.waitForData();
|
Chris@45
|
1265
|
Chris@45
|
1266 m_openingAudioFile = true;
|
Chris@45
|
1267
|
Chris@366
|
1268 int rate = 0;
|
Chris@45
|
1269
|
Chris@360
|
1270 if (Preferences::getInstance()->getFixedSampleRate() != 0) {
|
Chris@360
|
1271 rate = Preferences::getInstance()->getFixedSampleRate();
|
Chris@360
|
1272 } else if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@45
|
1273 rate = m_playSource->getSourceSampleRate();
|
Chris@45
|
1274 }
|
Chris@45
|
1275
|
Chris@45
|
1276 WaveFileModel *newModel = new WaveFileModel(source, rate);
|
Chris@45
|
1277
|
Chris@45
|
1278 if (!newModel->isOK()) {
|
Chris@45
|
1279 delete newModel;
|
Chris@45
|
1280 m_openingAudioFile = false;
|
Chris@45
|
1281 return FileOpenFailed;
|
Chris@45
|
1282 }
|
Chris@45
|
1283
|
Chris@293
|
1284 // cerr << "mode = " << mode << endl;
|
Chris@45
|
1285
|
Chris@45
|
1286 if (mode == AskUser) {
|
Chris@45
|
1287 if (getMainModel()) {
|
Chris@45
|
1288
|
Chris@147
|
1289 QSettings settings;
|
Chris@147
|
1290 settings.beginGroup("MainWindow");
|
Chris@221
|
1291 int lastMode = settings.value("lastaudioopenmode", 0).toBool();
|
Chris@147
|
1292 settings.endGroup();
|
Chris@221
|
1293 int imode = 0;
|
Chris@45
|
1294
|
Chris@45
|
1295 QStringList items;
|
Chris@221
|
1296 items << tr("Close the current session and start a new one")
|
Chris@221
|
1297 << tr("Replace the main audio file in this session")
|
Chris@221
|
1298 << tr("Add the audio file to this session");
|
Chris@45
|
1299
|
Chris@45
|
1300 bool ok = false;
|
Chris@45
|
1301 QString item = ListInputDialog::getItem
|
Chris@45
|
1302 (this, tr("Select target for import"),
|
Chris@221
|
1303 tr("<b>Select a target for import</b><p>You already have an audio file loaded.<br>What would you like to do with the new audio file?"),
|
Chris@221
|
1304 items, lastMode, &ok);
|
Chris@45
|
1305
|
Chris@45
|
1306 if (!ok || item.isEmpty()) {
|
Chris@45
|
1307 delete newModel;
|
Chris@45
|
1308 m_openingAudioFile = false;
|
Chris@45
|
1309 return FileOpenCancelled;
|
Chris@45
|
1310 }
|
Chris@45
|
1311
|
Chris@221
|
1312 for (int i = 0; i < items.size(); ++i) {
|
Chris@221
|
1313 if (item == items[i]) imode = i;
|
Chris@221
|
1314 }
|
Chris@221
|
1315
|
Chris@147
|
1316 settings.beginGroup("MainWindow");
|
Chris@221
|
1317 settings.setValue("lastaudioopenmode", imode);
|
Chris@147
|
1318 settings.endGroup();
|
Chris@45
|
1319
|
Chris@221
|
1320 mode = (AudioFileOpenMode)imode;
|
Chris@45
|
1321
|
Chris@45
|
1322 } else {
|
Chris@221
|
1323 // no main model: make a new session
|
Chris@221
|
1324 mode = ReplaceSession;
|
Chris@45
|
1325 }
|
Chris@45
|
1326 }
|
Chris@45
|
1327
|
Chris@45
|
1328 if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1329
|
Chris@45
|
1330 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1331 if (pane) {
|
Chris@45
|
1332 if (getMainModel()) {
|
Chris@45
|
1333 View::ModelSet models(pane->getModels());
|
Chris@45
|
1334 if (models.find(getMainModel()) != models.end()) {
|
Chris@221
|
1335 // Current pane contains main model: replace that
|
Chris@45
|
1336 mode = ReplaceMainModel;
|
Chris@45
|
1337 }
|
Chris@221
|
1338 // Otherwise the current pane has a non-default model,
|
Chris@221
|
1339 // which we will deal with later
|
Chris@45
|
1340 } else {
|
Chris@221
|
1341 // We have no main model, so start a new session with
|
Chris@221
|
1342 // optional template
|
Chris@221
|
1343 mode = ReplaceSession;
|
Chris@45
|
1344 }
|
Chris@45
|
1345 } else {
|
Chris@221
|
1346 // We seem to have no current pane! Oh well
|
Chris@45
|
1347 mode = CreateAdditionalModel;
|
Chris@45
|
1348 }
|
Chris@45
|
1349 }
|
Chris@45
|
1350
|
Chris@45
|
1351 if (mode == CreateAdditionalModel && !getMainModel()) {
|
Chris@386
|
1352 SVDEBUG << "Mode is CreateAdditionalModel but we have no main model, switching to ReplaceSession mode" << endl;
|
Chris@221
|
1353 mode = ReplaceSession;
|
Chris@221
|
1354 }
|
Chris@221
|
1355
|
Chris@221
|
1356 bool loadedTemplate = false;
|
Chris@221
|
1357
|
Chris@221
|
1358 if (mode == ReplaceSession) {
|
Chris@258
|
1359
|
Chris@258
|
1360 if (!checkSaveModified()) return FileOpenCancelled;
|
Chris@258
|
1361
|
Chris@386
|
1362 SVDEBUG << "SV looking for template " << templateName << endl;
|
Chris@230
|
1363 if (templateName != "") {
|
Chris@230
|
1364 FileOpenStatus tplStatus = openSessionTemplate(templateName);
|
Chris@258
|
1365 if (tplStatus == FileOpenCancelled) {
|
Chris@293
|
1366 cerr << "Template load cancelled" << endl;
|
Chris@258
|
1367 return FileOpenCancelled;
|
Chris@258
|
1368 }
|
Chris@230
|
1369 if (tplStatus != FileOpenFailed) {
|
Chris@293
|
1370 cerr << "Template load succeeded" << endl;
|
Chris@230
|
1371 loadedTemplate = true;
|
Chris@221
|
1372 }
|
Chris@221
|
1373 }
|
Chris@221
|
1374
|
Chris@221
|
1375 if (!loadedTemplate) {
|
Chris@386
|
1376 SVDEBUG << "No template found: closing session, creating new empty document" << endl;
|
Chris@221
|
1377 closeSession();
|
Chris@221
|
1378 createDocument();
|
Chris@221
|
1379 }
|
Chris@221
|
1380
|
Chris@386
|
1381 SVDEBUG << "Now switching to ReplaceMainModel mode" << endl;
|
Chris@45
|
1382 mode = ReplaceMainModel;
|
Chris@45
|
1383 }
|
Chris@45
|
1384
|
Chris@164
|
1385 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1386
|
Chris@45
|
1387 if (mode == ReplaceMainModel) {
|
Chris@45
|
1388
|
Chris@45
|
1389 Model *prevMain = getMainModel();
|
Chris@45
|
1390 if (prevMain) {
|
Chris@45
|
1391 m_playSource->removeModel(prevMain);
|
Chris@108
|
1392 PlayParameterRepository::getInstance()->removePlayable(prevMain);
|
Chris@45
|
1393 }
|
Chris@108
|
1394 PlayParameterRepository::getInstance()->addPlayable(newModel);
|
Chris@45
|
1395
|
Chris@248
|
1396 SVDEBUG << "SV about to call setMainModel(" << newModel << "): prevMain is " << prevMain << endl;
|
Chris@248
|
1397
|
Chris@45
|
1398 m_document->setMainModel(newModel);
|
Chris@45
|
1399
|
Chris@45
|
1400 setupMenus();
|
Chris@45
|
1401
|
dan@210
|
1402 if (loadedTemplate || (m_sessionFile == "")) {
|
Chris@45
|
1403 //!!! shouldn't be dealing directly with title from here -- call a method
|
Chris@57
|
1404 setWindowTitle(tr("%1: %2")
|
Chris@57
|
1405 .arg(QApplication::applicationName())
|
Chris@45
|
1406 .arg(source.getLocation()));
|
Chris@45
|
1407 CommandHistory::getInstance()->clear();
|
Chris@45
|
1408 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
1409 m_documentModified = false;
|
Chris@45
|
1410 } else {
|
Chris@57
|
1411 setWindowTitle(tr("%1: %2 [%3]")
|
Chris@57
|
1412 .arg(QApplication::applicationName())
|
Chris@45
|
1413 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@45
|
1414 .arg(source.getLocation()));
|
Chris@45
|
1415 if (m_documentModified) {
|
Chris@45
|
1416 m_documentModified = false;
|
Chris@45
|
1417 documentModified(); // so as to restore "(modified)" window title
|
Chris@45
|
1418 }
|
Chris@45
|
1419 }
|
Chris@45
|
1420
|
Chris@45
|
1421 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
|
Chris@45
|
1422
|
Chris@45
|
1423 } else if (mode == CreateAdditionalModel) {
|
Chris@45
|
1424
|
Chris@45
|
1425 CommandHistory::getInstance()->startCompoundOperation
|
Chris@219
|
1426 (tr("Import \"%1\"").arg(source.getBasename()), true);
|
Chris@45
|
1427
|
Chris@45
|
1428 m_document->addImportedModel(newModel);
|
Chris@45
|
1429
|
Chris@45
|
1430 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
1431 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
1432
|
Chris@45
|
1433 Pane *pane = command->getPane();
|
Chris@45
|
1434
|
Chris@47
|
1435 if (m_timeRulerLayer) {
|
Chris@47
|
1436 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@47
|
1437 }
|
Chris@45
|
1438
|
Chris@45
|
1439 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1440
|
Chris@45
|
1441 if (newLayer) {
|
Chris@45
|
1442 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1443 }
|
Chris@45
|
1444
|
Chris@45
|
1445 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1446
|
Chris@45
|
1447 } else if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1448
|
Chris@45
|
1449 // We know there is a current pane, otherwise we would have
|
Chris@45
|
1450 // reset the mode to CreateAdditionalModel above; and we know
|
Chris@45
|
1451 // the current pane does not contain the main model, otherwise
|
Chris@45
|
1452 // we would have reset it to ReplaceMainModel. But we don't
|
Chris@45
|
1453 // know whether the pane contains a waveform model at all.
|
Chris@45
|
1454
|
Chris@45
|
1455 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1456 Layer *replace = 0;
|
Chris@45
|
1457
|
Chris@45
|
1458 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@45
|
1459 Layer *layer = pane->getLayer(i);
|
Chris@45
|
1460 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@45
|
1461 replace = layer;
|
Chris@45
|
1462 break;
|
Chris@45
|
1463 }
|
Chris@45
|
1464 }
|
Chris@45
|
1465
|
Chris@45
|
1466 CommandHistory::getInstance()->startCompoundOperation
|
Chris@219
|
1467 (tr("Import \"%1\"").arg(source.getBasename()), true);
|
Chris@45
|
1468
|
Chris@45
|
1469 m_document->addImportedModel(newModel);
|
Chris@45
|
1470
|
Chris@45
|
1471 if (replace) {
|
Chris@45
|
1472 m_document->removeLayerFromView(pane, replace);
|
Chris@45
|
1473 }
|
Chris@45
|
1474
|
Chris@45
|
1475 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1476
|
Chris@45
|
1477 if (newLayer) {
|
Chris@45
|
1478 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1479 }
|
Chris@45
|
1480
|
Chris@45
|
1481 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1482 }
|
Chris@45
|
1483
|
Chris@45
|
1484 updateMenuStates();
|
Chris@45
|
1485 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1486 if (!source.isRemote()) {
|
Chris@45
|
1487 // for file dialog
|
Chris@45
|
1488 registerLastOpenedFilePath(FileFinder::AudioFile,
|
Chris@45
|
1489 source.getLocalFilename());
|
Chris@45
|
1490 }
|
Chris@45
|
1491 m_openingAudioFile = false;
|
Chris@45
|
1492
|
Chris@45
|
1493 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
1494
|
Chris@342
|
1495 emit audioFileLoaded();
|
Chris@342
|
1496
|
Chris@45
|
1497 return FileOpenSucceeded;
|
Chris@45
|
1498 }
|
Chris@45
|
1499
|
Chris@45
|
1500 MainWindowBase::FileOpenStatus
|
Chris@45
|
1501 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1502 {
|
Chris@233
|
1503 SVDEBUG << "MainWindowBase::openPlaylist(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1504
|
Chris@45
|
1505 std::set<QString> extensions;
|
Chris@45
|
1506 PlaylistFileReader::getSupportedExtensions(extensions);
|
Chris@152
|
1507 QString extension = source.getExtension().toLower();
|
Chris@45
|
1508 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
|
Chris@45
|
1509
|
Chris@45
|
1510 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1511 source.waitForData();
|
Chris@45
|
1512
|
Chris@45
|
1513 PlaylistFileReader reader(source.getLocalFilename());
|
Chris@45
|
1514 if (!reader.isOK()) return FileOpenFailed;
|
Chris@45
|
1515
|
Chris@45
|
1516 PlaylistFileReader::Playlist playlist = reader.load();
|
Chris@45
|
1517
|
Chris@45
|
1518 bool someSuccess = false;
|
Chris@45
|
1519
|
Chris@45
|
1520 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
|
Chris@45
|
1521 i != playlist.end(); ++i) {
|
Chris@45
|
1522
|
Chris@134
|
1523 ProgressDialog dialog(tr("Opening playlist..."), true, 2000, this);
|
Chris@134
|
1524 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1525 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
|
Chris@45
|
1526
|
Chris@45
|
1527 if (status == FileOpenCancelled) {
|
Chris@45
|
1528 return FileOpenCancelled;
|
Chris@45
|
1529 }
|
Chris@45
|
1530
|
Chris@45
|
1531 if (status == FileOpenSucceeded) {
|
Chris@45
|
1532 someSuccess = true;
|
Chris@45
|
1533 mode = CreateAdditionalModel;
|
Chris@45
|
1534 }
|
Chris@45
|
1535 }
|
Chris@45
|
1536
|
Chris@45
|
1537 if (someSuccess) return FileOpenSucceeded;
|
Chris@45
|
1538 else return FileOpenFailed;
|
Chris@45
|
1539 }
|
Chris@45
|
1540
|
Chris@45
|
1541 MainWindowBase::FileOpenStatus
|
Chris@45
|
1542 MainWindowBase::openLayer(FileSource source)
|
Chris@45
|
1543 {
|
Chris@233
|
1544 SVDEBUG << "MainWindowBase::openLayer(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1545
|
Chris@45
|
1546 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1547
|
Chris@45
|
1548 if (!pane) {
|
Chris@45
|
1549 // shouldn't happen, as the menu action should have been disabled
|
Chris@293
|
1550 cerr << "WARNING: MainWindowBase::openLayer: no current pane" << endl;
|
Chris@45
|
1551 return FileOpenWrongMode;
|
Chris@45
|
1552 }
|
Chris@45
|
1553
|
Chris@45
|
1554 if (!getMainModel()) {
|
Chris@45
|
1555 // shouldn't happen, as the menu action should have been disabled
|
Chris@293
|
1556 cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << endl;
|
Chris@45
|
1557 return FileOpenWrongMode;
|
Chris@45
|
1558 }
|
Chris@45
|
1559
|
Chris@45
|
1560 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1561 source.waitForData();
|
Chris@45
|
1562
|
Chris@45
|
1563 QString path = source.getLocalFilename();
|
Chris@45
|
1564
|
Chris@145
|
1565 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1566 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
|
Chris@145
|
1567
|
Chris@293
|
1568 // cerr << "RDF type: (in layer) " << (int) rdfType << endl;
|
Chris@148
|
1569
|
Chris@145
|
1570 if (rdfType != RDFImporter::NotRDF) {
|
Chris@145
|
1571
|
Chris@145
|
1572 return openLayersFromRDF(source);
|
Chris@134
|
1573
|
Chris@152
|
1574 } else if (source.getExtension().toLower() == "svl" ||
|
Chris@152
|
1575 (source.getExtension().toLower() == "xml" &&
|
Chris@140
|
1576 (SVFileReader::identifyXmlFile(source.getLocalFilename())
|
Chris@140
|
1577 == SVFileReader::SVLayerFile))) {
|
Chris@45
|
1578
|
Chris@45
|
1579 PaneCallback callback(this);
|
Chris@45
|
1580 QFile file(path);
|
Chris@45
|
1581
|
Chris@45
|
1582 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@293
|
1583 cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@294
|
1584 << source.getLocation()
|
Chris@293
|
1585 << "): Failed to open file for reading" << endl;
|
Chris@45
|
1586 return FileOpenFailed;
|
Chris@45
|
1587 }
|
Chris@45
|
1588
|
Chris@45
|
1589 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1590 connect
|
Chris@79
|
1591 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1592 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1593 connect
|
Chris@79
|
1594 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1595 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@45
|
1596 reader.setCurrentPane(pane);
|
Chris@45
|
1597
|
Chris@45
|
1598 QXmlInputSource inputSource(&file);
|
Chris@45
|
1599 reader.parse(inputSource);
|
Chris@45
|
1600
|
Chris@45
|
1601 if (!reader.isOK()) {
|
Chris@293
|
1602 cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@294
|
1603 << source.getLocation()
|
Chris@45
|
1604 << "): Failed to read XML file: "
|
Chris@293
|
1605 << reader.getErrorString() << endl;
|
Chris@45
|
1606 return FileOpenFailed;
|
Chris@45
|
1607 }
|
Chris@45
|
1608
|
Chris@164
|
1609 emit activity(tr("Import layer XML file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1610
|
Chris@45
|
1611 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1612
|
Chris@45
|
1613 if (!source.isRemote()) {
|
Chris@45
|
1614 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@45
|
1615 }
|
Chris@45
|
1616
|
Chris@75
|
1617 return FileOpenSucceeded;
|
Chris@75
|
1618
|
Chris@45
|
1619 } else {
|
Chris@45
|
1620
|
Chris@45
|
1621 try {
|
Chris@45
|
1622
|
Chris@109
|
1623 MIDIFileImportDialog midiDlg(this);
|
Chris@109
|
1624
|
Chris@109
|
1625 Model *model = DataFileReaderFactory::loadNonCSV
|
Chris@109
|
1626 (path, &midiDlg, getMainModel()->getSampleRate());
|
Chris@45
|
1627
|
Chris@109
|
1628 if (!model) {
|
Chris@196
|
1629 CSVFormat format(path);
|
Chris@196
|
1630 format.setSampleRate(getMainModel()->getSampleRate());
|
Chris@196
|
1631 CSVFormatDialog *dialog = new CSVFormatDialog(this, format);
|
Chris@109
|
1632 if (dialog->exec() == QDialog::Accepted) {
|
Chris@109
|
1633 model = DataFileReaderFactory::loadCSV
|
Chris@109
|
1634 (path, dialog->getFormat(),
|
Chris@109
|
1635 getMainModel()->getSampleRate());
|
Chris@109
|
1636 }
|
Chris@109
|
1637 }
|
Chris@109
|
1638
|
Chris@45
|
1639 if (model) {
|
Chris@45
|
1640
|
Chris@233
|
1641 SVDEBUG << "MainWindowBase::openLayer: Have model" << endl;
|
Chris@45
|
1642
|
Chris@164
|
1643 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1644
|
Chris@45
|
1645 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@45
|
1646
|
Chris@45
|
1647 if (newLayer) {
|
Chris@45
|
1648
|
Chris@45
|
1649 m_document->addLayerToView(pane, newLayer);
|
Chris@88
|
1650 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@88
|
1651
|
Chris@45
|
1652 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1653
|
Chris@45
|
1654 if (!source.isRemote()) {
|
Chris@45
|
1655 registerLastOpenedFilePath
|
Chris@45
|
1656 (FileFinder::LayerFile,
|
Chris@45
|
1657 path); // for file dialog
|
Chris@45
|
1658 }
|
Chris@88
|
1659
|
Chris@45
|
1660 return FileOpenSucceeded;
|
Chris@45
|
1661 }
|
Chris@45
|
1662 }
|
Chris@45
|
1663 } catch (DataFileReaderFactory::Exception e) {
|
Chris@45
|
1664 if (e == DataFileReaderFactory::ImportCancelled) {
|
Chris@45
|
1665 return FileOpenCancelled;
|
Chris@45
|
1666 }
|
Chris@45
|
1667 }
|
Chris@45
|
1668 }
|
Chris@45
|
1669
|
Chris@45
|
1670 return FileOpenFailed;
|
Chris@45
|
1671 }
|
Chris@45
|
1672
|
Chris@45
|
1673 MainWindowBase::FileOpenStatus
|
Chris@45
|
1674 MainWindowBase::openImage(FileSource source)
|
Chris@45
|
1675 {
|
Chris@233
|
1676 SVDEBUG << "MainWindowBase::openImage(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1677
|
Chris@45
|
1678 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1679
|
Chris@45
|
1680 if (!pane) {
|
Chris@45
|
1681 // shouldn't happen, as the menu action should have been disabled
|
Chris@293
|
1682 cerr << "WARNING: MainWindowBase::openImage: no current pane" << endl;
|
Chris@45
|
1683 return FileOpenWrongMode;
|
Chris@45
|
1684 }
|
Chris@45
|
1685
|
Chris@45
|
1686 if (!m_document->getMainModel()) {
|
Chris@45
|
1687 return FileOpenWrongMode;
|
Chris@45
|
1688 }
|
Chris@45
|
1689
|
Chris@45
|
1690 bool newLayer = false;
|
Chris@45
|
1691
|
Chris@45
|
1692 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
|
Chris@45
|
1693 if (!il) {
|
Chris@45
|
1694 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
|
Chris@45
|
1695 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
|
Chris@45
|
1696 if (il) break;
|
Chris@45
|
1697 }
|
Chris@45
|
1698 }
|
Chris@45
|
1699 if (!il) {
|
Chris@45
|
1700 il = dynamic_cast<ImageLayer *>
|
Chris@45
|
1701 (m_document->createEmptyLayer(LayerFactory::Image));
|
Chris@45
|
1702 if (!il) return FileOpenFailed;
|
Chris@45
|
1703 newLayer = true;
|
Chris@45
|
1704 }
|
Chris@45
|
1705
|
Chris@45
|
1706 // We don't put the image file in Recent Files
|
Chris@45
|
1707
|
Chris@293
|
1708 cerr << "openImage: trying location \"" << source.getLocation() << "\" in image layer" << endl;
|
Chris@45
|
1709
|
Chris@45
|
1710 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
|
Chris@45
|
1711 if (newLayer) {
|
Chris@52
|
1712 m_document->deleteLayer(il); // also releases its model
|
Chris@45
|
1713 }
|
Chris@45
|
1714 return FileOpenFailed;
|
Chris@45
|
1715 } else {
|
Chris@45
|
1716 if (newLayer) {
|
Chris@45
|
1717 m_document->addLayerToView(pane, il);
|
Chris@45
|
1718 }
|
Chris@45
|
1719 m_paneStack->setCurrentLayer(pane, il);
|
Chris@45
|
1720 }
|
Chris@45
|
1721
|
Chris@45
|
1722 return FileOpenSucceeded;
|
Chris@45
|
1723 }
|
Chris@45
|
1724
|
Chris@45
|
1725 MainWindowBase::FileOpenStatus
|
Chris@373
|
1726 MainWindowBase::openSessionPath(QString fileOrUrl)
|
Chris@45
|
1727 {
|
Chris@134
|
1728 ProgressDialog dialog(tr("Opening session..."), true, 2000, this);
|
Chris@134
|
1729 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1730 return openSession(FileSource(fileOrUrl, &dialog));
|
Chris@45
|
1731 }
|
Chris@45
|
1732
|
Chris@45
|
1733 MainWindowBase::FileOpenStatus
|
Chris@45
|
1734 MainWindowBase::openSession(FileSource source)
|
Chris@45
|
1735 {
|
Chris@233
|
1736 SVDEBUG << "MainWindowBase::openSession(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1737
|
Chris@45
|
1738 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@145
|
1739 source.waitForData();
|
Chris@141
|
1740
|
Chris@341
|
1741 QString sessionExt =
|
Chris@341
|
1742 InteractiveFileFinder::getInstance()->getApplicationSessionExtension();
|
Chris@341
|
1743
|
Chris@341
|
1744 if (source.getExtension().toLower() != sessionExt) {
|
Chris@145
|
1745
|
Chris@145
|
1746 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1747 RDFImporter::identifyDocumentType
|
Chris@145
|
1748 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
|
Chris@145
|
1749
|
Chris@293
|
1750 // cerr << "RDF type: " << (int)rdfType << endl;
|
Chris@148
|
1751
|
Chris@145
|
1752 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
|
Chris@145
|
1753 rdfType == RDFImporter::AudioRef) {
|
Chris@145
|
1754 return openSessionFromRDF(source);
|
Chris@145
|
1755 } else if (rdfType != RDFImporter::NotRDF) {
|
Chris@145
|
1756 return FileOpenFailed;
|
Chris@145
|
1757 }
|
Chris@145
|
1758
|
Chris@152
|
1759 if (source.getExtension().toLower() == "xml") {
|
Chris@140
|
1760 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) ==
|
Chris@140
|
1761 SVFileReader::SVSessionFile) {
|
Chris@293
|
1762 cerr << "This XML file looks like a session file, attempting to open it as a session" << endl;
|
Chris@140
|
1763 } else {
|
Chris@140
|
1764 return FileOpenFailed;
|
Chris@140
|
1765 }
|
Chris@140
|
1766 } else {
|
Chris@140
|
1767 return FileOpenFailed;
|
Chris@140
|
1768 }
|
Chris@140
|
1769 }
|
Chris@45
|
1770
|
Chris@140
|
1771 QXmlInputSource *inputSource = 0;
|
Chris@140
|
1772 BZipFileDevice *bzFile = 0;
|
Chris@140
|
1773 QFile *rawFile = 0;
|
Chris@140
|
1774
|
Chris@341
|
1775 if (source.getExtension().toLower() == sessionExt) {
|
Chris@140
|
1776 bzFile = new BZipFileDevice(source.getLocalFilename());
|
Chris@140
|
1777 if (!bzFile->open(QIODevice::ReadOnly)) {
|
Chris@140
|
1778 delete bzFile;
|
Chris@140
|
1779 return FileOpenFailed;
|
Chris@140
|
1780 }
|
Chris@140
|
1781 inputSource = new QXmlInputSource(bzFile);
|
Chris@140
|
1782 } else {
|
Chris@140
|
1783 rawFile = new QFile(source.getLocalFilename());
|
Chris@140
|
1784 inputSource = new QXmlInputSource(rawFile);
|
Chris@140
|
1785 }
|
Chris@140
|
1786
|
Chris@140
|
1787 if (!checkSaveModified()) {
|
Chris@140
|
1788 if (bzFile) bzFile->close();
|
Chris@140
|
1789 delete inputSource;
|
Chris@140
|
1790 delete bzFile;
|
Chris@140
|
1791 delete rawFile;
|
Chris@140
|
1792 return FileOpenCancelled;
|
Chris@140
|
1793 }
|
Chris@45
|
1794
|
Chris@45
|
1795 QString error;
|
Chris@45
|
1796 closeSession();
|
Chris@45
|
1797 createDocument();
|
Chris@45
|
1798
|
Chris@45
|
1799 PaneCallback callback(this);
|
Chris@45
|
1800 m_viewManager->clearSelections();
|
Chris@45
|
1801
|
Chris@45
|
1802 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1803 connect
|
Chris@79
|
1804 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1805 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1806 connect
|
Chris@79
|
1807 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1808 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@140
|
1809
|
Chris@140
|
1810 reader.parse(*inputSource);
|
Chris@45
|
1811
|
Chris@45
|
1812 if (!reader.isOK()) {
|
Chris@45
|
1813 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@45
|
1814 }
|
Chris@45
|
1815
|
Chris@140
|
1816 if (bzFile) bzFile->close();
|
Chris@140
|
1817
|
Chris@140
|
1818 delete inputSource;
|
Chris@140
|
1819 delete bzFile;
|
Chris@140
|
1820 delete rawFile;
|
Chris@45
|
1821
|
Chris@45
|
1822 bool ok = (error == "");
|
Chris@45
|
1823
|
Chris@45
|
1824 if (ok) {
|
Chris@45
|
1825
|
Chris@164
|
1826 emit activity(tr("Import session file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1827
|
Chris@57
|
1828 setWindowTitle(tr("%1: %2")
|
Chris@57
|
1829 .arg(QApplication::applicationName())
|
Chris@45
|
1830 .arg(source.getLocation()));
|
Chris@45
|
1831
|
Chris@45
|
1832 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
|
Chris@45
|
1833
|
Chris@45
|
1834 setupMenus();
|
Chris@45
|
1835
|
Chris@45
|
1836 CommandHistory::getInstance()->clear();
|
Chris@45
|
1837 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
1838 m_documentModified = false;
|
Chris@45
|
1839 updateMenuStates();
|
Chris@45
|
1840
|
Chris@227
|
1841 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1842
|
Chris@45
|
1843 if (!source.isRemote()) {
|
Chris@45
|
1844 // for file dialog
|
Chris@45
|
1845 registerLastOpenedFilePath(FileFinder::SessionFile,
|
Chris@227
|
1846 source.getLocalFilename());
|
Chris@45
|
1847 }
|
Chris@45
|
1848
|
Chris@342
|
1849 emit sessionLoaded();
|
Chris@342
|
1850
|
Chris@45
|
1851 } else {
|
Chris@57
|
1852 setWindowTitle(QApplication::applicationName());
|
Chris@45
|
1853 }
|
Chris@45
|
1854
|
Chris@45
|
1855 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@45
|
1856 }
|
Chris@45
|
1857
|
Chris@141
|
1858 MainWindowBase::FileOpenStatus
|
Chris@230
|
1859 MainWindowBase::openSessionTemplate(QString templateName)
|
Chris@230
|
1860 {
|
Chris@230
|
1861 // Template in the user's template directory takes
|
Chris@230
|
1862 // priority over a bundled one; we don't unbundle, but
|
Chris@230
|
1863 // open directly from the bundled file (where applicable)
|
Chris@230
|
1864 ResourceFinder rf;
|
Chris@230
|
1865 QString tfile = rf.getResourcePath("templates", templateName + ".svt");
|
Chris@230
|
1866 if (tfile != "") {
|
Chris@294
|
1867 cerr << "SV loading template file " << tfile << endl;
|
Chris@230
|
1868 return openSessionTemplate(FileSource("file:" + tfile));
|
Chris@230
|
1869 } else {
|
Chris@230
|
1870 return FileOpenFailed;
|
Chris@230
|
1871 }
|
Chris@230
|
1872 }
|
Chris@230
|
1873
|
Chris@230
|
1874 MainWindowBase::FileOpenStatus
|
Chris@227
|
1875 MainWindowBase::openSessionTemplate(FileSource source)
|
Chris@227
|
1876 {
|
Chris@294
|
1877 cerr << "MainWindowBase::openSessionTemplate(" << source.getLocation() << ")" << endl;
|
Chris@227
|
1878
|
Chris@227
|
1879 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@227
|
1880 source.waitForData();
|
Chris@227
|
1881
|
Chris@227
|
1882 QXmlInputSource *inputSource = 0;
|
Chris@227
|
1883 QFile *file = 0;
|
Chris@227
|
1884
|
Chris@227
|
1885 file = new QFile(source.getLocalFilename());
|
Chris@227
|
1886 inputSource = new QXmlInputSource(file);
|
Chris@227
|
1887
|
Chris@227
|
1888 if (!checkSaveModified()) {
|
Chris@227
|
1889 delete inputSource;
|
Chris@227
|
1890 delete file;
|
Chris@227
|
1891 return FileOpenCancelled;
|
Chris@227
|
1892 }
|
Chris@227
|
1893
|
Chris@227
|
1894 QString error;
|
Chris@227
|
1895 closeSession();
|
Chris@227
|
1896 createDocument();
|
Chris@227
|
1897
|
Chris@227
|
1898 PaneCallback callback(this);
|
Chris@227
|
1899 m_viewManager->clearSelections();
|
Chris@227
|
1900
|
Chris@227
|
1901 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@227
|
1902 connect
|
Chris@227
|
1903 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@227
|
1904 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@227
|
1905 connect
|
Chris@227
|
1906 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@227
|
1907 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@227
|
1908
|
Chris@227
|
1909 reader.parse(*inputSource);
|
Chris@227
|
1910
|
Chris@227
|
1911 if (!reader.isOK()) {
|
Chris@227
|
1912 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@227
|
1913 }
|
Chris@227
|
1914
|
Chris@227
|
1915 delete inputSource;
|
Chris@227
|
1916 delete file;
|
Chris@227
|
1917
|
Chris@227
|
1918 bool ok = (error == "");
|
Chris@227
|
1919
|
Chris@227
|
1920 setWindowTitle(QApplication::applicationName());
|
Chris@227
|
1921
|
Chris@227
|
1922 if (ok) {
|
Chris@227
|
1923
|
Chris@227
|
1924 emit activity(tr("Open session template \"%1\"").arg(source.getLocation()));
|
Chris@227
|
1925
|
Chris@227
|
1926 setupMenus();
|
Chris@227
|
1927
|
Chris@227
|
1928 CommandHistory::getInstance()->clear();
|
Chris@227
|
1929 CommandHistory::getInstance()->documentSaved();
|
Chris@227
|
1930 m_documentModified = false;
|
Chris@227
|
1931 updateMenuStates();
|
Chris@342
|
1932
|
Chris@342
|
1933 emit sessionLoaded();
|
Chris@227
|
1934 }
|
Chris@227
|
1935
|
Chris@227
|
1936 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@227
|
1937 }
|
Chris@227
|
1938
|
Chris@227
|
1939 MainWindowBase::FileOpenStatus
|
Chris@141
|
1940 MainWindowBase::openSessionFromRDF(FileSource source)
|
Chris@141
|
1941 {
|
Chris@233
|
1942 SVDEBUG << "MainWindowBase::openSessionFromRDF(" << source.getLocation() << ")" << endl;
|
Chris@141
|
1943
|
Chris@141
|
1944 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@141
|
1945 source.waitForData();
|
Chris@141
|
1946
|
Chris@145
|
1947 if (!checkSaveModified()) {
|
Chris@145
|
1948 return FileOpenCancelled;
|
Chris@141
|
1949 }
|
Chris@143
|
1950
|
Chris@145
|
1951 closeSession();
|
Chris@145
|
1952 createDocument();
|
Chris@145
|
1953
|
Chris@145
|
1954 FileOpenStatus status = openLayersFromRDF(source);
|
Chris@141
|
1955
|
Chris@141
|
1956 setupMenus();
|
Chris@141
|
1957
|
Chris@141
|
1958 setWindowTitle(tr("%1: %2")
|
Chris@141
|
1959 .arg(QApplication::applicationName())
|
Chris@141
|
1960 .arg(source.getLocation()));
|
Chris@141
|
1961 CommandHistory::getInstance()->clear();
|
Chris@141
|
1962 CommandHistory::getInstance()->documentSaved();
|
Chris@141
|
1963 m_documentModified = false;
|
Chris@145
|
1964
|
Chris@342
|
1965 emit sessionLoaded();
|
Chris@342
|
1966
|
Chris@145
|
1967 return status;
|
Chris@145
|
1968 }
|
Chris@145
|
1969
|
Chris@145
|
1970 MainWindowBase::FileOpenStatus
|
Chris@145
|
1971 MainWindowBase::openLayersFromRDF(FileSource source)
|
Chris@145
|
1972 {
|
Chris@366
|
1973 int rate = 0;
|
Chris@145
|
1974
|
Chris@233
|
1975 SVDEBUG << "MainWindowBase::openLayersFromRDF" << endl;
|
Chris@186
|
1976
|
Chris@145
|
1977 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this);
|
Chris@145
|
1978 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@145
|
1979
|
Chris@145
|
1980 if (getMainModel()) {
|
Chris@145
|
1981 rate = getMainModel()->getSampleRate();
|
Chris@145
|
1982 } else if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@145
|
1983 rate = m_playSource->getSourceSampleRate();
|
Chris@145
|
1984 }
|
Chris@145
|
1985
|
Chris@145
|
1986 RDFImporter importer
|
Chris@145
|
1987 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate);
|
Chris@145
|
1988
|
Chris@145
|
1989 if (!importer.isOK()) {
|
Chris@147
|
1990 if (importer.getErrorString() != "") {
|
Chris@147
|
1991 QMessageBox::critical
|
Chris@147
|
1992 (this, tr("Failed to import RDF"),
|
Chris@147
|
1993 tr("<b>Failed to import RDF</b><p>Importing data from RDF document at \"%1\" failed: %2</p>")
|
Chris@147
|
1994 .arg(source.getLocation()).arg(importer.getErrorString()));
|
Chris@147
|
1995 }
|
Chris@145
|
1996 return FileOpenFailed;
|
Chris@145
|
1997 }
|
Chris@145
|
1998
|
Chris@145
|
1999 std::vector<Model *> models = importer.getDataModels(&dialog);
|
Chris@145
|
2000
|
Chris@145
|
2001 dialog.setMessage(tr("Importing from RDF..."));
|
Chris@145
|
2002
|
Chris@145
|
2003 if (models.empty()) {
|
Chris@186
|
2004 QMessageBox::critical
|
Chris@186
|
2005 (this, tr("Failed to import RDF"),
|
Chris@186
|
2006 tr("<b>Failed to import RDF</b><p>No suitable data models found for import from RDF document at \"%1\"</p>").arg(source.getLocation()));
|
Chris@145
|
2007 return FileOpenFailed;
|
Chris@145
|
2008 }
|
Chris@145
|
2009
|
Chris@164
|
2010 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation()));
|
Chris@164
|
2011
|
Chris@145
|
2012 std::set<Model *> added;
|
Chris@145
|
2013
|
Chris@221
|
2014 for (int i = 0; i < (int)models.size(); ++i) {
|
Chris@145
|
2015
|
Chris@145
|
2016 Model *m = models[i];
|
Chris@145
|
2017 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m);
|
Chris@145
|
2018
|
Chris@145
|
2019 if (w) {
|
Chris@145
|
2020
|
Chris@145
|
2021 Pane *pane = addPaneToStack();
|
Chris@145
|
2022 Layer *layer = 0;
|
Chris@145
|
2023
|
Chris@145
|
2024 if (m_timeRulerLayer) {
|
Chris@145
|
2025 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@145
|
2026 }
|
Chris@145
|
2027
|
Chris@145
|
2028 if (!getMainModel()) {
|
Chris@145
|
2029 m_document->setMainModel(w);
|
Chris@145
|
2030 layer = m_document->createMainModelLayer(LayerFactory::Waveform);
|
Chris@145
|
2031 } else {
|
Chris@145
|
2032 layer = m_document->createImportedLayer(w);
|
Chris@145
|
2033 }
|
Chris@145
|
2034
|
Chris@145
|
2035 m_document->addLayerToView(pane, layer);
|
Chris@145
|
2036
|
Chris@145
|
2037 added.insert(w);
|
Chris@145
|
2038
|
Chris@221
|
2039 for (int j = 0; j < (int)models.size(); ++j) {
|
Chris@145
|
2040
|
Chris@145
|
2041 Model *dm = models[j];
|
Chris@145
|
2042
|
Chris@145
|
2043 if (dm == m) continue;
|
Chris@145
|
2044 if (dm->getSourceModel() != m) continue;
|
Chris@145
|
2045
|
Chris@145
|
2046 layer = m_document->createImportedLayer(dm);
|
Chris@145
|
2047
|
Chris@145
|
2048 if (layer->isLayerOpaque() ||
|
Chris@145
|
2049 dynamic_cast<Colour3DPlotLayer *>(layer)) {
|
Chris@145
|
2050
|
Chris@156
|
2051 // these always go in a new pane, with nothing
|
Chris@156
|
2052 // else going in the same pane
|
Chris@156
|
2053
|
Chris@145
|
2054 Pane *singleLayerPane = addPaneToStack();
|
Chris@145
|
2055 if (m_timeRulerLayer) {
|
Chris@145
|
2056 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
|
Chris@145
|
2057 }
|
Chris@145
|
2058 m_document->addLayerToView(singleLayerPane, layer);
|
Chris@145
|
2059
|
Chris@156
|
2060 } else if (layer->getLayerColourSignificance() ==
|
Chris@156
|
2061 Layer::ColourHasMeaningfulValue) {
|
Chris@156
|
2062
|
Chris@156
|
2063 // these can go in a pane with something else, but
|
Chris@156
|
2064 // only if none of the something elses also have
|
Chris@156
|
2065 // this quality
|
Chris@156
|
2066
|
Chris@156
|
2067 bool needNewPane = false;
|
Chris@156
|
2068 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@156
|
2069 Layer *otherLayer = pane->getLayer(i);
|
Chris@156
|
2070 if (otherLayer &&
|
Chris@156
|
2071 (otherLayer->getLayerColourSignificance() ==
|
Chris@156
|
2072 Layer::ColourHasMeaningfulValue)) {
|
Chris@156
|
2073 needNewPane = true;
|
Chris@156
|
2074 break;
|
Chris@156
|
2075 }
|
Chris@156
|
2076 }
|
Chris@156
|
2077 if (needNewPane) {
|
Chris@156
|
2078 pane = addPaneToStack();
|
Chris@156
|
2079 }
|
Chris@156
|
2080
|
Chris@156
|
2081 m_document->addLayerToView(pane, layer);
|
Chris@156
|
2082
|
Chris@145
|
2083 } else {
|
Chris@145
|
2084
|
Chris@145
|
2085 if (pane->getLayerCount() > 4) {
|
Chris@145
|
2086 pane = addPaneToStack();
|
Chris@145
|
2087 }
|
Chris@145
|
2088
|
Chris@145
|
2089 m_document->addLayerToView(pane, layer);
|
Chris@145
|
2090 }
|
Chris@145
|
2091
|
Chris@145
|
2092 added.insert(dm);
|
Chris@145
|
2093 }
|
Chris@145
|
2094 }
|
Chris@145
|
2095 }
|
Chris@145
|
2096
|
Chris@221
|
2097 for (int i = 0; i < (int)models.size(); ++i) {
|
Chris@145
|
2098
|
Chris@145
|
2099 Model *m = models[i];
|
Chris@145
|
2100
|
Chris@145
|
2101 if (added.find(m) == added.end()) {
|
Chris@145
|
2102
|
Chris@145
|
2103 Layer *layer = m_document->createImportedLayer(m);
|
Chris@145
|
2104 if (!layer) return FileOpenFailed;
|
Chris@145
|
2105
|
Chris@145
|
2106 Pane *singleLayerPane = addPaneToStack();
|
Chris@145
|
2107 if (m_timeRulerLayer) {
|
Chris@145
|
2108 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
|
Chris@145
|
2109 }
|
Chris@145
|
2110 m_document->addLayerToView(singleLayerPane, layer);
|
Chris@145
|
2111 }
|
Chris@145
|
2112 }
|
Chris@145
|
2113
|
Chris@145
|
2114 m_recentFiles.addFile(source.getLocation());
|
Chris@145
|
2115 return FileOpenSucceeded;
|
Chris@141
|
2116 }
|
Chris@141
|
2117
|
Chris@45
|
2118 void
|
Chris@45
|
2119 MainWindowBase::createPlayTarget()
|
Chris@45
|
2120 {
|
Chris@45
|
2121 if (m_playTarget) return;
|
Chris@45
|
2122
|
Chris@126
|
2123 QSettings settings;
|
Chris@126
|
2124 settings.beginGroup("Preferences");
|
Chris@126
|
2125 QString targetName = settings.value("audio-target", "").toString();
|
Chris@126
|
2126 settings.endGroup();
|
Chris@126
|
2127
|
Chris@126
|
2128 AudioTargetFactory *factory = AudioTargetFactory::getInstance();
|
Chris@126
|
2129
|
Chris@126
|
2130 factory->setDefaultCallbackTarget(targetName);
|
Chris@126
|
2131 m_playTarget = factory->createCallbackTarget(m_playSource);
|
Chris@126
|
2132
|
Chris@45
|
2133 if (!m_playTarget) {
|
Chris@104
|
2134 emit hideSplash();
|
Chris@126
|
2135
|
Chris@126
|
2136 if (factory->isAutoCallbackTarget(targetName)) {
|
Chris@128
|
2137 QMessageBox::warning
|
Chris@45
|
2138 (this, tr("Couldn't open audio device"),
|
Chris@126
|
2139 tr("<b>No audio available</b><p>Could not open an audio device for playback.<p>Automatic audio device detection failed. Audio playback will not be available during this session.</p>"),
|
Chris@45
|
2140 QMessageBox::Ok);
|
Chris@126
|
2141 } else {
|
Chris@126
|
2142 QMessageBox::warning
|
Chris@126
|
2143 (this, tr("Couldn't open audio device"),
|
Chris@126
|
2144 tr("<b>No audio available</b><p>Failed to open your preferred audio device (\"%1\").<p>Audio playback will not be available during this session.</p>")
|
Chris@126
|
2145 .arg(factory->getCallbackTargetDescription(targetName)),
|
Chris@126
|
2146 QMessageBox::Ok);
|
Chris@126
|
2147 }
|
Chris@45
|
2148 }
|
Chris@45
|
2149 }
|
Chris@45
|
2150
|
Chris@45
|
2151 WaveFileModel *
|
Chris@45
|
2152 MainWindowBase::getMainModel()
|
Chris@45
|
2153 {
|
Chris@45
|
2154 if (!m_document) return 0;
|
Chris@45
|
2155 return m_document->getMainModel();
|
Chris@45
|
2156 }
|
Chris@45
|
2157
|
Chris@45
|
2158 const WaveFileModel *
|
Chris@45
|
2159 MainWindowBase::getMainModel() const
|
Chris@45
|
2160 {
|
Chris@45
|
2161 if (!m_document) return 0;
|
Chris@45
|
2162 return m_document->getMainModel();
|
Chris@45
|
2163 }
|
Chris@45
|
2164
|
Chris@45
|
2165 void
|
Chris@45
|
2166 MainWindowBase::createDocument()
|
Chris@45
|
2167 {
|
Chris@45
|
2168 m_document = new Document;
|
Chris@45
|
2169
|
Chris@45
|
2170 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@45
|
2171 this, SLOT(layerAdded(Layer *)));
|
Chris@45
|
2172 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@45
|
2173 this, SLOT(layerRemoved(Layer *)));
|
Chris@45
|
2174 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@45
|
2175 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@45
|
2176 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@45
|
2177 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@45
|
2178
|
Chris@45
|
2179 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@45
|
2180 this, SLOT(modelAdded(Model *)));
|
Chris@45
|
2181 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@45
|
2182 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@45
|
2183 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@45
|
2184 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@45
|
2185
|
Chris@78
|
2186 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
2187 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
2188 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
2189 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@78
|
2190 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
2191 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
2192 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
2193 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@78
|
2194 connect(m_document, SIGNAL(alignmentFailed(QString, QString)),
|
Chris@78
|
2195 this, SLOT(alignmentFailed(QString, QString)));
|
Chris@160
|
2196
|
Chris@160
|
2197 emit replacedDocument();
|
Chris@45
|
2198 }
|
Chris@45
|
2199
|
Chris@45
|
2200 bool
|
Chris@45
|
2201 MainWindowBase::saveSessionFile(QString path)
|
Chris@45
|
2202 {
|
Chris@217
|
2203 try {
|
Chris@217
|
2204
|
Chris@217
|
2205 TempWriteFile temp(path);
|
Chris@217
|
2206
|
Chris@217
|
2207 BZipFileDevice bzFile(temp.getTemporaryFilename());
|
Chris@217
|
2208 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@293
|
2209 cerr << "Failed to open session file \""
|
Chris@294
|
2210 << temp.getTemporaryFilename()
|
Chris@217
|
2211 << "\" for writing: "
|
Chris@293
|
2212 << bzFile.errorString() << endl;
|
Chris@217
|
2213 return false;
|
Chris@217
|
2214 }
|
Chris@217
|
2215
|
Chris@217
|
2216 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@217
|
2217
|
Chris@217
|
2218 QTextStream out(&bzFile);
|
Chris@226
|
2219 toXml(out, false);
|
Chris@217
|
2220 out.flush();
|
Chris@217
|
2221
|
Chris@217
|
2222 QApplication::restoreOverrideCursor();
|
Chris@217
|
2223
|
Chris@217
|
2224 if (!bzFile.isOK()) {
|
Chris@217
|
2225 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@217
|
2226 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@217
|
2227 .arg(path).arg(bzFile.errorString()));
|
Chris@217
|
2228 bzFile.close();
|
Chris@217
|
2229 return false;
|
Chris@217
|
2230 }
|
Chris@217
|
2231
|
Chris@217
|
2232 bzFile.close();
|
Chris@217
|
2233 temp.moveToTarget();
|
Chris@217
|
2234 return true;
|
Chris@217
|
2235
|
Chris@217
|
2236 } catch (FileOperationFailed &f) {
|
Chris@217
|
2237
|
Chris@217
|
2238 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@217
|
2239 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@217
|
2240 .arg(path).arg(f.what()));
|
Chris@45
|
2241 return false;
|
Chris@45
|
2242 }
|
Chris@45
|
2243 }
|
Chris@45
|
2244
|
Chris@224
|
2245 bool
|
Chris@224
|
2246 MainWindowBase::saveSessionTemplate(QString path)
|
Chris@224
|
2247 {
|
Chris@224
|
2248 try {
|
Chris@224
|
2249
|
Chris@224
|
2250 TempWriteFile temp(path);
|
Chris@224
|
2251
|
Chris@224
|
2252 QFile file(temp.getTemporaryFilename());
|
Chris@224
|
2253 if (!file.open(QIODevice::WriteOnly)) {
|
Chris@293
|
2254 cerr << "Failed to open session template file \""
|
Chris@294
|
2255 << temp.getTemporaryFilename()
|
Chris@224
|
2256 << "\" for writing: "
|
Chris@294
|
2257 << file.errorString() << endl;
|
Chris@224
|
2258 return false;
|
Chris@224
|
2259 }
|
Chris@224
|
2260
|
Chris@224
|
2261 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@224
|
2262
|
Chris@224
|
2263 QTextStream out(&file);
|
Chris@226
|
2264 toXml(out, true);
|
Chris@224
|
2265 out.flush();
|
Chris@224
|
2266
|
Chris@224
|
2267 QApplication::restoreOverrideCursor();
|
Chris@224
|
2268
|
Chris@224
|
2269 file.close();
|
Chris@224
|
2270 temp.moveToTarget();
|
Chris@224
|
2271 return true;
|
Chris@224
|
2272
|
Chris@224
|
2273 } catch (FileOperationFailed &f) {
|
Chris@224
|
2274
|
Chris@224
|
2275 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@224
|
2276 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@224
|
2277 .arg(path).arg(f.what()));
|
Chris@224
|
2278 return false;
|
Chris@224
|
2279 }
|
Chris@224
|
2280 }
|
Chris@224
|
2281
|
Chris@45
|
2282 void
|
Chris@226
|
2283 MainWindowBase::toXml(QTextStream &out, bool asTemplate)
|
Chris@45
|
2284 {
|
Chris@45
|
2285 QString indent(" ");
|
Chris@45
|
2286
|
Chris@45
|
2287 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@45
|
2288 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@45
|
2289 out << "<sv>\n";
|
Chris@45
|
2290
|
Chris@226
|
2291 if (asTemplate) {
|
Chris@226
|
2292 m_document->toXmlAsTemplate(out, "", "");
|
Chris@226
|
2293 } else {
|
Chris@226
|
2294 m_document->toXml(out, "", "");
|
Chris@226
|
2295 }
|
Chris@45
|
2296
|
Chris@45
|
2297 out << "<display>\n";
|
Chris@45
|
2298
|
Chris@45
|
2299 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@45
|
2300 .arg(width()).arg(height());
|
Chris@45
|
2301
|
Chris@45
|
2302 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
2303
|
Chris@45
|
2304 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
2305
|
Chris@45
|
2306 if (pane) {
|
Chris@45
|
2307 pane->toXml(out, indent);
|
Chris@45
|
2308 }
|
Chris@45
|
2309 }
|
Chris@45
|
2310
|
Chris@45
|
2311 out << "</display>\n";
|
Chris@45
|
2312
|
Chris@45
|
2313 m_viewManager->getSelection().toXml(out);
|
Chris@45
|
2314
|
Chris@45
|
2315 out << "</sv>\n";
|
Chris@45
|
2316 }
|
Chris@45
|
2317
|
Chris@45
|
2318 Pane *
|
Chris@45
|
2319 MainWindowBase::addPaneToStack()
|
Chris@45
|
2320 {
|
Chris@342
|
2321 cerr << "MainWindowBase::addPaneToStack()" << endl;
|
Chris@45
|
2322 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
2323 CommandHistory::getInstance()->addCommand(command);
|
Chris@57
|
2324 Pane *pane = command->getPane();
|
Chris@57
|
2325 return pane;
|
Chris@45
|
2326 }
|
Chris@45
|
2327
|
Chris@45
|
2328 void
|
Chris@45
|
2329 MainWindowBase::zoomIn()
|
Chris@45
|
2330 {
|
Chris@45
|
2331 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2332 if (currentPane) currentPane->zoom(true);
|
Chris@45
|
2333 }
|
Chris@45
|
2334
|
Chris@45
|
2335 void
|
Chris@45
|
2336 MainWindowBase::zoomOut()
|
Chris@45
|
2337 {
|
Chris@45
|
2338 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2339 if (currentPane) currentPane->zoom(false);
|
Chris@45
|
2340 }
|
Chris@45
|
2341
|
Chris@45
|
2342 void
|
Chris@45
|
2343 MainWindowBase::zoomToFit()
|
Chris@45
|
2344 {
|
Chris@45
|
2345 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2346 if (!currentPane) return;
|
Chris@45
|
2347
|
Chris@45
|
2348 Model *model = getMainModel();
|
Chris@45
|
2349 if (!model) return;
|
Chris@45
|
2350
|
Chris@366
|
2351 int start = model->getStartFrame();
|
Chris@366
|
2352 int end = model->getEndFrame();
|
Chris@60
|
2353 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
|
Chris@366
|
2354 int pixels = currentPane->width();
|
Chris@366
|
2355
|
Chris@366
|
2356 int sw = currentPane->getVerticalScaleWidth();
|
Chris@45
|
2357 if (pixels > sw * 2) pixels -= sw * 2;
|
Chris@45
|
2358 else pixels = 1;
|
Chris@45
|
2359 if (pixels > 4) pixels -= 4;
|
Chris@45
|
2360
|
Chris@366
|
2361 int zoomLevel = (end - start) / pixels;
|
Chris@150
|
2362 if (zoomLevel < 1) zoomLevel = 1;
|
Chris@45
|
2363
|
Chris@45
|
2364 currentPane->setZoomLevel(zoomLevel);
|
Chris@45
|
2365 currentPane->setCentreFrame((start + end) / 2);
|
Chris@45
|
2366 }
|
Chris@45
|
2367
|
Chris@45
|
2368 void
|
Chris@45
|
2369 MainWindowBase::zoomDefault()
|
Chris@45
|
2370 {
|
Chris@45
|
2371 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@302
|
2372 QSettings settings;
|
Chris@302
|
2373 settings.beginGroup("MainWindow");
|
Chris@302
|
2374 int zoom = settings.value("zoom-default", 1024).toInt();
|
Chris@302
|
2375 settings.endGroup();
|
Chris@302
|
2376 if (currentPane) currentPane->setZoomLevel(zoom);
|
Chris@45
|
2377 }
|
Chris@45
|
2378
|
Chris@45
|
2379 void
|
Chris@45
|
2380 MainWindowBase::scrollLeft()
|
Chris@45
|
2381 {
|
Chris@45
|
2382 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2383 if (currentPane) currentPane->scroll(false, false);
|
Chris@45
|
2384 }
|
Chris@45
|
2385
|
Chris@45
|
2386 void
|
Chris@45
|
2387 MainWindowBase::jumpLeft()
|
Chris@45
|
2388 {
|
Chris@45
|
2389 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2390 if (currentPane) currentPane->scroll(false, true);
|
Chris@45
|
2391 }
|
Chris@45
|
2392
|
Chris@45
|
2393 void
|
Chris@162
|
2394 MainWindowBase::peekLeft()
|
Chris@162
|
2395 {
|
Chris@162
|
2396 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@162
|
2397 if (currentPane) currentPane->scroll(false, false, false);
|
Chris@162
|
2398 }
|
Chris@162
|
2399
|
Chris@162
|
2400 void
|
Chris@45
|
2401 MainWindowBase::scrollRight()
|
Chris@45
|
2402 {
|
Chris@45
|
2403 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2404 if (currentPane) currentPane->scroll(true, false);
|
Chris@45
|
2405 }
|
Chris@45
|
2406
|
Chris@45
|
2407 void
|
Chris@45
|
2408 MainWindowBase::jumpRight()
|
Chris@45
|
2409 {
|
Chris@45
|
2410 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2411 if (currentPane) currentPane->scroll(true, true);
|
Chris@45
|
2412 }
|
Chris@45
|
2413
|
Chris@45
|
2414 void
|
Chris@162
|
2415 MainWindowBase::peekRight()
|
Chris@162
|
2416 {
|
Chris@162
|
2417 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@162
|
2418 if (currentPane) currentPane->scroll(true, false, false);
|
Chris@162
|
2419 }
|
Chris@162
|
2420
|
Chris@162
|
2421 void
|
Chris@45
|
2422 MainWindowBase::showNoOverlays()
|
Chris@45
|
2423 {
|
Chris@45
|
2424 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@45
|
2425 }
|
Chris@45
|
2426
|
Chris@45
|
2427 void
|
Chris@45
|
2428 MainWindowBase::showMinimalOverlays()
|
Chris@45
|
2429 {
|
Chris@335
|
2430 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@45
|
2431 }
|
Chris@45
|
2432
|
Chris@45
|
2433 void
|
Chris@45
|
2434 MainWindowBase::showAllOverlays()
|
Chris@45
|
2435 {
|
Chris@45
|
2436 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@45
|
2437 }
|
Chris@45
|
2438
|
Chris@45
|
2439 void
|
Chris@211
|
2440 MainWindowBase::toggleTimeRulers()
|
Chris@211
|
2441 {
|
Chris@211
|
2442 bool haveRulers = false;
|
Chris@211
|
2443 bool someHidden = false;
|
Chris@211
|
2444
|
Chris@211
|
2445 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@211
|
2446
|
Chris@211
|
2447 Pane *pane = m_paneStack->getPane(i);
|
Chris@211
|
2448 if (!pane) continue;
|
Chris@211
|
2449
|
Chris@211
|
2450 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@211
|
2451
|
Chris@211
|
2452 Layer *layer = pane->getLayer(j);
|
Chris@211
|
2453 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@211
|
2454
|
Chris@211
|
2455 haveRulers = true;
|
Chris@211
|
2456 if (layer->isLayerDormant(pane)) someHidden = true;
|
Chris@211
|
2457 }
|
Chris@211
|
2458 }
|
Chris@211
|
2459
|
Chris@211
|
2460 if (haveRulers) {
|
Chris@211
|
2461
|
Chris@211
|
2462 bool show = someHidden;
|
Chris@211
|
2463
|
Chris@211
|
2464 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@211
|
2465
|
Chris@211
|
2466 Pane *pane = m_paneStack->getPane(i);
|
Chris@211
|
2467 if (!pane) continue;
|
Chris@211
|
2468
|
Chris@211
|
2469 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@211
|
2470
|
Chris@211
|
2471 Layer *layer = pane->getLayer(j);
|
Chris@211
|
2472 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@211
|
2473
|
Chris@211
|
2474 layer->showLayer(pane, show);
|
Chris@211
|
2475 }
|
Chris@211
|
2476 }
|
Chris@211
|
2477 }
|
Chris@211
|
2478 }
|
Chris@211
|
2479
|
Chris@211
|
2480 void
|
Chris@45
|
2481 MainWindowBase::toggleZoomWheels()
|
Chris@45
|
2482 {
|
Chris@45
|
2483 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@45
|
2484 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@45
|
2485 } else {
|
Chris@45
|
2486 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@45
|
2487 }
|
Chris@45
|
2488 }
|
Chris@45
|
2489
|
Chris@45
|
2490 void
|
Chris@45
|
2491 MainWindowBase::togglePropertyBoxes()
|
Chris@45
|
2492 {
|
Chris@45
|
2493 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
|
Chris@45
|
2494 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
2495 Preferences::VerticallyStacked) {
|
Chris@45
|
2496 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
2497 } else {
|
Chris@45
|
2498 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
2499 }
|
Chris@45
|
2500 } else {
|
Chris@45
|
2501 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
|
Chris@45
|
2502 }
|
Chris@45
|
2503 }
|
Chris@45
|
2504
|
Chris@378
|
2505 QLabel *
|
Chris@378
|
2506 MainWindowBase::getStatusLabel() const
|
Chris@378
|
2507 {
|
Chris@378
|
2508 if (!m_statusLabel) {
|
Chris@378
|
2509 m_statusLabel = new QLabel();
|
Chris@378
|
2510 statusBar()->addWidget(m_statusLabel, 1);
|
Chris@378
|
2511 }
|
Chris@379
|
2512
|
Chris@379
|
2513 QList<QFrame *> frames = statusBar()->findChildren<QFrame *>();
|
Chris@379
|
2514 foreach (QFrame *f, frames) {
|
Chris@379
|
2515 f->setFrameStyle(QFrame::NoFrame);
|
Chris@379
|
2516 }
|
Chris@379
|
2517
|
Chris@378
|
2518 return m_statusLabel;
|
Chris@378
|
2519 }
|
Chris@378
|
2520
|
Chris@45
|
2521 void
|
Chris@45
|
2522 MainWindowBase::toggleStatusBar()
|
Chris@45
|
2523 {
|
Chris@45
|
2524 QSettings settings;
|
Chris@45
|
2525 settings.beginGroup("MainWindow");
|
Chris@45
|
2526 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@45
|
2527
|
Chris@45
|
2528 if (sb) {
|
Chris@45
|
2529 statusBar()->hide();
|
Chris@45
|
2530 } else {
|
Chris@45
|
2531 statusBar()->show();
|
Chris@45
|
2532 }
|
Chris@45
|
2533
|
Chris@45
|
2534 settings.setValue("showstatusbar", !sb);
|
Chris@45
|
2535
|
Chris@45
|
2536 settings.endGroup();
|
Chris@45
|
2537 }
|
Chris@45
|
2538
|
Chris@45
|
2539 void
|
Chris@256
|
2540 MainWindowBase::toggleCentreLine()
|
Chris@256
|
2541 {
|
Chris@256
|
2542 if (m_viewManager->shouldShowCentreLine()) {
|
Chris@256
|
2543 m_viewManager->setShowCentreLine(false);
|
Chris@256
|
2544 } else {
|
Chris@256
|
2545 m_viewManager->setShowCentreLine(true);
|
Chris@256
|
2546 }
|
Chris@256
|
2547 }
|
Chris@256
|
2548
|
Chris@256
|
2549 void
|
Chris@45
|
2550 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@45
|
2551 {
|
Chris@45
|
2552 if (name == "Property Box Layout") {
|
Chris@45
|
2553 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
|
Chris@45
|
2554 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
2555 Preferences::VerticallyStacked) {
|
Chris@45
|
2556 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
2557 } else {
|
Chris@45
|
2558 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
2559 }
|
Chris@45
|
2560 }
|
Chris@45
|
2561 } else if (name == "Background Mode" && m_viewManager) {
|
Chris@45
|
2562 Preferences::BackgroundMode mode =
|
Chris@45
|
2563 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
2564 if (mode == Preferences::BackgroundFromTheme) {
|
Chris@45
|
2565 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
|
Chris@45
|
2566 } else if (mode == Preferences::DarkBackground) {
|
Chris@45
|
2567 m_viewManager->setGlobalDarkBackground(true);
|
Chris@45
|
2568 } else {
|
Chris@45
|
2569 m_viewManager->setGlobalDarkBackground(false);
|
Chris@45
|
2570 }
|
Chris@45
|
2571 }
|
Chris@45
|
2572 }
|
Chris@45
|
2573
|
Chris@45
|
2574 void
|
Chris@45
|
2575 MainWindowBase::play()
|
Chris@45
|
2576 {
|
Chris@45
|
2577 if (m_playSource->isPlaying()) {
|
Chris@45
|
2578 stop();
|
Chris@45
|
2579 } else {
|
Chris@45
|
2580 playbackFrameChanged(m_viewManager->getPlaybackFrame());
|
Chris@45
|
2581 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@45
|
2582 }
|
Chris@45
|
2583 }
|
Chris@45
|
2584
|
Chris@45
|
2585 void
|
Chris@45
|
2586 MainWindowBase::ffwd()
|
Chris@45
|
2587 {
|
Chris@45
|
2588 if (!getMainModel()) return;
|
Chris@45
|
2589
|
Chris@45
|
2590 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
2591 ++frame;
|
Chris@45
|
2592
|
Chris@85
|
2593 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2594 Layer *layer = getSnapLayer();
|
Chris@366
|
2595 int sr = getMainModel()->getSampleRate();
|
Chris@45
|
2596
|
Chris@45
|
2597 if (!layer) {
|
Chris@45
|
2598
|
Chris@45
|
2599 frame = RealTime::realTime2Frame
|
Chris@357
|
2600 (RealTime::frame2RealTime(frame, sr) + m_defaultFfwdRwdStep, sr);
|
Chris@45
|
2601 if (frame > int(getMainModel()->getEndFrame())) {
|
Chris@45
|
2602 frame = getMainModel()->getEndFrame();
|
Chris@45
|
2603 }
|
Chris@45
|
2604
|
Chris@45
|
2605 } else {
|
Chris@45
|
2606
|
Chris@366
|
2607 int resolution = 0;
|
Chris@166
|
2608 if (pane) frame = pane->alignFromReference(frame);
|
Chris@85
|
2609 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
2610 frame, resolution, Layer::SnapRight)) {
|
Chris@85
|
2611 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
2612 } else {
|
Chris@45
|
2613 frame = getMainModel()->getEndFrame();
|
Chris@45
|
2614 }
|
Chris@45
|
2615 }
|
Chris@45
|
2616
|
Chris@45
|
2617 if (frame < 0) frame = 0;
|
Chris@45
|
2618
|
Chris@45
|
2619 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@366
|
2620 frame = m_viewManager->constrainFrameToSelection(int(frame));
|
Chris@45
|
2621 }
|
Chris@45
|
2622
|
Chris@45
|
2623 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
2624
|
Chris@358
|
2625 if (frame == (int)getMainModel()->getEndFrame() &&
|
Chris@166
|
2626 m_playSource &&
|
Chris@166
|
2627 m_playSource->isPlaying() &&
|
Chris@166
|
2628 !m_viewManager->getPlayLoopMode()) {
|
Chris@166
|
2629 stop();
|
Chris@166
|
2630 }
|
Chris@45
|
2631 }
|
Chris@45
|
2632
|
Chris@45
|
2633 void
|
Chris@45
|
2634 MainWindowBase::ffwdEnd()
|
Chris@45
|
2635 {
|
Chris@45
|
2636 if (!getMainModel()) return;
|
Chris@45
|
2637
|
Chris@139
|
2638 if (m_playSource &&
|
Chris@139
|
2639 m_playSource->isPlaying() &&
|
Chris@139
|
2640 !m_viewManager->getPlayLoopMode()) {
|
Chris@139
|
2641 stop();
|
Chris@139
|
2642 }
|
Chris@139
|
2643
|
Chris@366
|
2644 int frame = getMainModel()->getEndFrame();
|
Chris@45
|
2645
|
Chris@45
|
2646 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
2647 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
2648 }
|
Chris@45
|
2649
|
Chris@45
|
2650 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
2651 }
|
Chris@45
|
2652
|
Chris@45
|
2653 void
|
Chris@166
|
2654 MainWindowBase::ffwdSimilar()
|
Chris@166
|
2655 {
|
Chris@166
|
2656 if (!getMainModel()) return;
|
Chris@166
|
2657
|
Chris@166
|
2658 Layer *layer = getSnapLayer();
|
Chris@166
|
2659 if (!layer) { ffwd(); return; }
|
Chris@166
|
2660
|
Chris@166
|
2661 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@166
|
2662 int frame = m_viewManager->getPlaybackFrame();
|
Chris@166
|
2663
|
Chris@366
|
2664 int resolution = 0;
|
Chris@166
|
2665 if (pane) frame = pane->alignFromReference(frame);
|
Chris@166
|
2666 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
|
Chris@166
|
2667 frame, resolution, Layer::SnapRight)) {
|
Chris@166
|
2668 if (pane) frame = pane->alignToReference(frame);
|
Chris@166
|
2669 } else {
|
Chris@166
|
2670 frame = getMainModel()->getEndFrame();
|
Chris@166
|
2671 }
|
Chris@166
|
2672
|
Chris@166
|
2673 if (frame < 0) frame = 0;
|
Chris@166
|
2674
|
Chris@166
|
2675 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@366
|
2676 frame = m_viewManager->constrainFrameToSelection(int(frame));
|
Chris@166
|
2677 }
|
Chris@166
|
2678
|
Chris@166
|
2679 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
2680
|
Chris@358
|
2681 if (frame == (int)getMainModel()->getEndFrame() &&
|
Chris@166
|
2682 m_playSource &&
|
Chris@166
|
2683 m_playSource->isPlaying() &&
|
Chris@166
|
2684 !m_viewManager->getPlayLoopMode()) {
|
Chris@166
|
2685 stop();
|
Chris@166
|
2686 }
|
Chris@166
|
2687 }
|
Chris@166
|
2688
|
Chris@166
|
2689 void
|
Chris@45
|
2690 MainWindowBase::rewind()
|
Chris@45
|
2691 {
|
Chris@45
|
2692 if (!getMainModel()) return;
|
Chris@45
|
2693
|
Chris@45
|
2694 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
2695 if (frame > 0) --frame;
|
Chris@45
|
2696
|
Chris@85
|
2697 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2698 Layer *layer = getSnapLayer();
|
Chris@366
|
2699 int sr = getMainModel()->getSampleRate();
|
Chris@45
|
2700
|
Chris@45
|
2701 // when rewinding during playback, we want to allow a period
|
Chris@45
|
2702 // following a rewind target point at which the rewind will go to
|
Chris@45
|
2703 // the prior point instead of the immediately neighbouring one
|
Chris@45
|
2704 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@45
|
2705 RealTime ct = RealTime::frame2RealTime(frame, sr);
|
Chris@357
|
2706 ct = ct - RealTime::fromSeconds(0.15);
|
Chris@45
|
2707 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
|
Chris@45
|
2708 frame = RealTime::realTime2Frame(ct, sr);
|
Chris@45
|
2709 }
|
Chris@45
|
2710
|
Chris@45
|
2711 if (!layer) {
|
Chris@45
|
2712
|
Chris@45
|
2713 frame = RealTime::realTime2Frame
|
Chris@357
|
2714 (RealTime::frame2RealTime(frame, sr) - m_defaultFfwdRwdStep, sr);
|
Chris@45
|
2715 if (frame < int(getMainModel()->getStartFrame())) {
|
Chris@45
|
2716 frame = getMainModel()->getStartFrame();
|
Chris@45
|
2717 }
|
Chris@45
|
2718
|
Chris@45
|
2719 } else {
|
Chris@45
|
2720
|
Chris@366
|
2721 int resolution = 0;
|
Chris@166
|
2722 if (pane) frame = pane->alignFromReference(frame);
|
Chris@85
|
2723 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
2724 frame, resolution, Layer::SnapLeft)) {
|
Chris@85
|
2725 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
2726 } else {
|
Chris@45
|
2727 frame = getMainModel()->getStartFrame();
|
Chris@45
|
2728 }
|
Chris@45
|
2729 }
|
Chris@45
|
2730
|
Chris@45
|
2731 if (frame < 0) frame = 0;
|
Chris@45
|
2732
|
Chris@45
|
2733 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@366
|
2734 frame = m_viewManager->constrainFrameToSelection(int(frame));
|
Chris@45
|
2735 }
|
Chris@45
|
2736
|
Chris@45
|
2737 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
2738 }
|
Chris@45
|
2739
|
Chris@45
|
2740 void
|
Chris@45
|
2741 MainWindowBase::rewindStart()
|
Chris@45
|
2742 {
|
Chris@45
|
2743 if (!getMainModel()) return;
|
Chris@45
|
2744
|
Chris@366
|
2745 int frame = getMainModel()->getStartFrame();
|
Chris@45
|
2746
|
Chris@45
|
2747 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
2748 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
2749 }
|
Chris@45
|
2750
|
Chris@45
|
2751 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
2752 }
|
Chris@45
|
2753
|
Chris@166
|
2754 void
|
Chris@166
|
2755 MainWindowBase::rewindSimilar()
|
Chris@166
|
2756 {
|
Chris@166
|
2757 if (!getMainModel()) return;
|
Chris@166
|
2758
|
Chris@166
|
2759 Layer *layer = getSnapLayer();
|
Chris@166
|
2760 if (!layer) { rewind(); return; }
|
Chris@166
|
2761
|
Chris@166
|
2762 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@166
|
2763 int frame = m_viewManager->getPlaybackFrame();
|
Chris@166
|
2764
|
Chris@366
|
2765 int resolution = 0;
|
Chris@166
|
2766 if (pane) frame = pane->alignFromReference(frame);
|
Chris@166
|
2767 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
|
Chris@166
|
2768 frame, resolution, Layer::SnapLeft)) {
|
Chris@166
|
2769 if (pane) frame = pane->alignToReference(frame);
|
Chris@166
|
2770 } else {
|
Chris@166
|
2771 frame = getMainModel()->getStartFrame();
|
Chris@166
|
2772 }
|
Chris@166
|
2773
|
Chris@166
|
2774 if (frame < 0) frame = 0;
|
Chris@166
|
2775
|
Chris@166
|
2776 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@366
|
2777 frame = m_viewManager->constrainFrameToSelection(int(frame));
|
Chris@166
|
2778 }
|
Chris@166
|
2779
|
Chris@166
|
2780 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
2781 }
|
Chris@166
|
2782
|
Chris@45
|
2783 Layer *
|
Chris@45
|
2784 MainWindowBase::getSnapLayer() const
|
Chris@45
|
2785 {
|
Chris@45
|
2786 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2787 if (!pane) return 0;
|
Chris@45
|
2788
|
Chris@45
|
2789 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
2790
|
Chris@45
|
2791 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@45
|
2792 !dynamic_cast<TimeValueLayer *>(layer) &&
|
Chris@194
|
2793 !dynamic_cast<RegionLayer *>(layer) &&
|
Chris@45
|
2794 !dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@45
|
2795
|
Chris@45
|
2796 layer = 0;
|
Chris@45
|
2797
|
Chris@45
|
2798 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
2799 Layer *l = pane->getLayer(i-1);
|
Chris@45
|
2800 if (dynamic_cast<TimeRulerLayer *>(l)) {
|
Chris@45
|
2801 layer = l;
|
Chris@45
|
2802 break;
|
Chris@45
|
2803 }
|
Chris@45
|
2804 }
|
Chris@45
|
2805 }
|
Chris@45
|
2806
|
Chris@45
|
2807 return layer;
|
Chris@45
|
2808 }
|
Chris@45
|
2809
|
Chris@45
|
2810 void
|
Chris@45
|
2811 MainWindowBase::stop()
|
Chris@45
|
2812 {
|
Chris@45
|
2813 m_playSource->stop();
|
Chris@45
|
2814
|
Chris@45
|
2815 if (m_paneStack && m_paneStack->getCurrentPane()) {
|
Chris@45
|
2816 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
|
Chris@45
|
2817 } else {
|
Chris@45
|
2818 m_myStatusMessage = "";
|
Chris@378
|
2819 getStatusLabel()->setText("");
|
Chris@45
|
2820 }
|
Chris@45
|
2821 }
|
Chris@45
|
2822
|
Chris@45
|
2823 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
|
Chris@45
|
2824 m_mw(mw),
|
Chris@45
|
2825 m_pane(0),
|
Chris@45
|
2826 m_prevCurrentPane(0),
|
Chris@45
|
2827 m_added(false)
|
Chris@45
|
2828 {
|
Chris@45
|
2829 }
|
Chris@45
|
2830
|
Chris@45
|
2831 MainWindowBase::AddPaneCommand::~AddPaneCommand()
|
Chris@45
|
2832 {
|
Chris@45
|
2833 if (m_pane && !m_added) {
|
Chris@45
|
2834 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
2835 }
|
Chris@45
|
2836 }
|
Chris@45
|
2837
|
Chris@45
|
2838 QString
|
Chris@45
|
2839 MainWindowBase::AddPaneCommand::getName() const
|
Chris@45
|
2840 {
|
Chris@45
|
2841 return tr("Add Pane");
|
Chris@45
|
2842 }
|
Chris@45
|
2843
|
Chris@45
|
2844 void
|
Chris@45
|
2845 MainWindowBase::AddPaneCommand::execute()
|
Chris@45
|
2846 {
|
Chris@45
|
2847 if (!m_pane) {
|
Chris@45
|
2848 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
2849 m_pane = m_mw->m_paneStack->addPane();
|
Chris@45
|
2850
|
Chris@45
|
2851 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
2852 m_mw, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
2853 } else {
|
Chris@45
|
2854 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
2855 }
|
Chris@45
|
2856
|
Chris@45
|
2857 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@45
|
2858 m_added = true;
|
Chris@45
|
2859 }
|
Chris@45
|
2860
|
Chris@45
|
2861 void
|
Chris@45
|
2862 MainWindowBase::AddPaneCommand::unexecute()
|
Chris@45
|
2863 {
|
Chris@45
|
2864 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
2865 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
2866 m_added = false;
|
Chris@45
|
2867 }
|
Chris@45
|
2868
|
Chris@45
|
2869 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
|
Chris@45
|
2870 m_mw(mw),
|
Chris@45
|
2871 m_pane(pane),
|
Chris@45
|
2872 m_added(true)
|
Chris@45
|
2873 {
|
Chris@45
|
2874 }
|
Chris@45
|
2875
|
Chris@45
|
2876 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
|
Chris@45
|
2877 {
|
Chris@45
|
2878 if (m_pane && !m_added) {
|
Chris@45
|
2879 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
2880 }
|
Chris@45
|
2881 }
|
Chris@45
|
2882
|
Chris@45
|
2883 QString
|
Chris@45
|
2884 MainWindowBase::RemovePaneCommand::getName() const
|
Chris@45
|
2885 {
|
Chris@45
|
2886 return tr("Remove Pane");
|
Chris@45
|
2887 }
|
Chris@45
|
2888
|
Chris@45
|
2889 void
|
Chris@45
|
2890 MainWindowBase::RemovePaneCommand::execute()
|
Chris@45
|
2891 {
|
Chris@45
|
2892 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
2893 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
2894 m_added = false;
|
Chris@45
|
2895 }
|
Chris@45
|
2896
|
Chris@45
|
2897 void
|
Chris@45
|
2898 MainWindowBase::RemovePaneCommand::unexecute()
|
Chris@45
|
2899 {
|
Chris@45
|
2900 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
2901 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
2902 m_added = true;
|
Chris@45
|
2903 }
|
Chris@45
|
2904
|
Chris@45
|
2905 void
|
Chris@45
|
2906 MainWindowBase::deleteCurrentPane()
|
Chris@45
|
2907 {
|
Chris@45
|
2908 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
2909 (tr("Delete Pane"), true);
|
Chris@45
|
2910
|
Chris@45
|
2911 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2912 if (pane) {
|
Chris@45
|
2913 while (pane->getLayerCount() > 0) {
|
Chris@45
|
2914 Layer *layer = pane->getLayer(0);
|
Chris@45
|
2915 if (layer) {
|
Chris@45
|
2916 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
2917 } else {
|
Chris@45
|
2918 break;
|
Chris@45
|
2919 }
|
Chris@45
|
2920 }
|
Chris@45
|
2921
|
Chris@45
|
2922 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@45
|
2923 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
2924 }
|
Chris@45
|
2925
|
Chris@45
|
2926 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
2927
|
Chris@45
|
2928 updateMenuStates();
|
Chris@45
|
2929 }
|
Chris@45
|
2930
|
Chris@45
|
2931 void
|
Chris@45
|
2932 MainWindowBase::deleteCurrentLayer()
|
Chris@45
|
2933 {
|
Chris@45
|
2934 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2935 if (pane) {
|
Chris@45
|
2936 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
2937 if (layer) {
|
Chris@45
|
2938 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
2939 }
|
Chris@45
|
2940 }
|
Chris@45
|
2941 updateMenuStates();
|
Chris@45
|
2942 }
|
Chris@45
|
2943
|
Chris@45
|
2944 void
|
Chris@123
|
2945 MainWindowBase::editCurrentLayer()
|
Chris@123
|
2946 {
|
Chris@123
|
2947 Layer *layer = 0;
|
Chris@123
|
2948 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@123
|
2949 if (pane) layer = pane->getSelectedLayer();
|
Chris@123
|
2950 if (!layer) return;
|
Chris@123
|
2951
|
Chris@123
|
2952 Model *model = layer->getModel();
|
Chris@123
|
2953 if (!model) return;
|
Chris@123
|
2954
|
Chris@124
|
2955 TabularModel *tabular = dynamic_cast<TabularModel *>(model);
|
Chris@124
|
2956 if (!tabular) {
|
Chris@124
|
2957 //!!! how to prevent this function from being active if not
|
Chris@124
|
2958 //appropriate model type? or will we ultimately support
|
Chris@124
|
2959 //tabular display for all editable models?
|
Chris@233
|
2960 SVDEBUG << "NOTE: Not a tabular model" << endl;
|
Chris@124
|
2961 return;
|
Chris@124
|
2962 }
|
Chris@124
|
2963
|
Chris@123
|
2964 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
|
Chris@126
|
2965 if (!m_layerDataDialogMap[layer].isNull()) {
|
Chris@126
|
2966 m_layerDataDialogMap[layer]->show();
|
Chris@126
|
2967 m_layerDataDialogMap[layer]->raise();
|
Chris@126
|
2968 return;
|
Chris@126
|
2969 }
|
Chris@123
|
2970 }
|
Chris@123
|
2971
|
Chris@125
|
2972 QString title = layer->getLayerPresentationName();
|
Chris@125
|
2973
|
Chris@125
|
2974 ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this);
|
Chris@128
|
2975 dialog->setAttribute(Qt::WA_DeleteOnClose);
|
Chris@128
|
2976
|
Chris@128
|
2977 connectLayerEditDialog(dialog);
|
Chris@123
|
2978
|
Chris@128
|
2979 m_layerDataDialogMap[layer] = dialog;
|
Chris@128
|
2980 m_viewDataDialogMap[pane].insert(dialog);
|
Chris@128
|
2981
|
Chris@128
|
2982 dialog->show();
|
Chris@128
|
2983 }
|
Chris@128
|
2984
|
Chris@128
|
2985 void
|
Chris@128
|
2986 MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog)
|
Chris@128
|
2987 {
|
Chris@123
|
2988 connect(m_viewManager,
|
Chris@366
|
2989 SIGNAL(globalCentreFrameChanged(int)),
|
Chris@123
|
2990 dialog,
|
Chris@366
|
2991 SLOT(userScrolledToFrame(int)));
|
Chris@127
|
2992
|
Chris@127
|
2993 connect(m_viewManager,
|
Chris@366
|
2994 SIGNAL(playbackFrameChanged(int)),
|
Chris@127
|
2995 dialog,
|
Chris@366
|
2996 SLOT(playbackScrolledToFrame(int)));
|
Chris@127
|
2997
|
Chris@123
|
2998 connect(dialog,
|
Chris@366
|
2999 SIGNAL(scrollToFrame(int)),
|
Chris@123
|
3000 m_viewManager,
|
Chris@366
|
3001 SLOT(setGlobalCentreFrame(int)));
|
Chris@129
|
3002
|
Chris@129
|
3003 connect(dialog,
|
Chris@366
|
3004 SIGNAL(scrollToFrame(int)),
|
Chris@129
|
3005 m_viewManager,
|
Chris@366
|
3006 SLOT(setPlaybackFrame(int)));
|
Chris@128
|
3007 }
|
Chris@123
|
3008
|
Chris@123
|
3009 void
|
Chris@73
|
3010 MainWindowBase::previousPane()
|
Chris@73
|
3011 {
|
Chris@73
|
3012 if (!m_paneStack) return;
|
Chris@73
|
3013
|
Chris@73
|
3014 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3015 if (!currentPane) return;
|
Chris@73
|
3016
|
Chris@73
|
3017 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
3018 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
3019 if (i == 0) return;
|
Chris@73
|
3020 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
|
Chris@73
|
3021 updateMenuStates();
|
Chris@73
|
3022 return;
|
Chris@73
|
3023 }
|
Chris@73
|
3024 }
|
Chris@73
|
3025 }
|
Chris@73
|
3026
|
Chris@73
|
3027 void
|
Chris@73
|
3028 MainWindowBase::nextPane()
|
Chris@73
|
3029 {
|
Chris@73
|
3030 if (!m_paneStack) return;
|
Chris@73
|
3031
|
Chris@73
|
3032 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3033 if (!currentPane) return;
|
Chris@73
|
3034
|
Chris@73
|
3035 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
3036 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
3037 if (i == m_paneStack->getPaneCount()-1) return;
|
Chris@73
|
3038 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
|
Chris@73
|
3039 updateMenuStates();
|
Chris@73
|
3040 return;
|
Chris@73
|
3041 }
|
Chris@73
|
3042 }
|
Chris@73
|
3043 }
|
Chris@73
|
3044
|
Chris@73
|
3045 void
|
Chris@73
|
3046 MainWindowBase::previousLayer()
|
Chris@73
|
3047 {
|
Chris@73
|
3048 //!!! Not right -- pane lists layers in stacking order
|
Chris@73
|
3049
|
Chris@73
|
3050 if (!m_paneStack) return;
|
Chris@73
|
3051
|
Chris@73
|
3052 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3053 if (!currentPane) return;
|
Chris@73
|
3054
|
Chris@73
|
3055 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@73
|
3056 if (!currentLayer) return;
|
Chris@73
|
3057
|
Chris@73
|
3058 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
3059 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
3060 if (i == 0) return;
|
Chris@73
|
3061 m_paneStack->setCurrentLayer(currentPane,
|
Chris@73
|
3062 currentPane->getLayer(i-1));
|
Chris@73
|
3063 updateMenuStates();
|
Chris@73
|
3064 return;
|
Chris@73
|
3065 }
|
Chris@73
|
3066 }
|
Chris@73
|
3067 }
|
Chris@73
|
3068
|
Chris@73
|
3069 void
|
Chris@73
|
3070 MainWindowBase::nextLayer()
|
Chris@73
|
3071 {
|
Chris@73
|
3072 //!!! Not right -- pane lists layers in stacking order
|
Chris@73
|
3073
|
Chris@73
|
3074 if (!m_paneStack) return;
|
Chris@73
|
3075
|
Chris@73
|
3076 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3077 if (!currentPane) return;
|
Chris@73
|
3078
|
Chris@73
|
3079 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@73
|
3080 if (!currentLayer) return;
|
Chris@73
|
3081
|
Chris@73
|
3082 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
3083 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
3084 if (i == currentPane->getLayerCount()-1) return;
|
Chris@73
|
3085 m_paneStack->setCurrentLayer(currentPane,
|
Chris@73
|
3086 currentPane->getLayer(i+1));
|
Chris@73
|
3087 updateMenuStates();
|
Chris@73
|
3088 return;
|
Chris@73
|
3089 }
|
Chris@73
|
3090 }
|
Chris@73
|
3091 }
|
Chris@73
|
3092
|
Chris@73
|
3093 void
|
Chris@366
|
3094 MainWindowBase::playbackFrameChanged(int frame)
|
Chris@45
|
3095 {
|
Chris@45
|
3096 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3097
|
Chris@187
|
3098 updatePositionStatusDisplays();
|
Chris@187
|
3099
|
Chris@45
|
3100 RealTime now = RealTime::frame2RealTime
|
Chris@45
|
3101 (frame, getMainModel()->getSampleRate());
|
Chris@45
|
3102
|
Chris@45
|
3103 if (now.sec == m_lastPlayStatusSec) return;
|
Chris@45
|
3104
|
Chris@45
|
3105 RealTime then = RealTime::frame2RealTime
|
Chris@45
|
3106 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
|
Chris@45
|
3107
|
Chris@45
|
3108 QString nowStr;
|
Chris@45
|
3109 QString thenStr;
|
Chris@45
|
3110 QString remainingStr;
|
Chris@45
|
3111
|
Chris@45
|
3112 if (then.sec > 10) {
|
Chris@45
|
3113 nowStr = now.toSecText().c_str();
|
Chris@45
|
3114 thenStr = then.toSecText().c_str();
|
Chris@45
|
3115 remainingStr = (then - now).toSecText().c_str();
|
Chris@45
|
3116 m_lastPlayStatusSec = now.sec;
|
Chris@45
|
3117 } else {
|
Chris@45
|
3118 nowStr = now.toText(true).c_str();
|
Chris@45
|
3119 thenStr = then.toText(true).c_str();
|
Chris@45
|
3120 remainingStr = (then - now).toText(true).c_str();
|
Chris@45
|
3121 }
|
Chris@45
|
3122
|
Chris@45
|
3123 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
|
Chris@45
|
3124 .arg(nowStr).arg(thenStr).arg(remainingStr);
|
Chris@45
|
3125
|
Chris@378
|
3126 getStatusLabel()->setText(m_myStatusMessage);
|
Chris@45
|
3127 }
|
Chris@45
|
3128
|
Chris@45
|
3129 void
|
Chris@366
|
3130 MainWindowBase::globalCentreFrameChanged(int )
|
Chris@45
|
3131 {
|
Chris@45
|
3132 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3133 Pane *p = 0;
|
Chris@45
|
3134 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
3135 if (!p->getFollowGlobalPan()) return;
|
Chris@45
|
3136 updateVisibleRangeDisplay(p);
|
Chris@45
|
3137 }
|
Chris@45
|
3138
|
Chris@45
|
3139 void
|
Chris@366
|
3140 MainWindowBase::viewCentreFrameChanged(View *v, int frame)
|
Chris@45
|
3141 {
|
Chris@233
|
3142 // SVDEBUG << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << endl;
|
Chris@123
|
3143
|
Chris@123
|
3144 if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) {
|
Chris@123
|
3145 for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin();
|
Chris@123
|
3146 i != m_viewDataDialogMap[v].end(); ++i) {
|
Chris@127
|
3147 (*i)->userScrolledToFrame(frame);
|
Chris@123
|
3148 }
|
Chris@123
|
3149 }
|
Chris@45
|
3150 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3151 Pane *p = 0;
|
Chris@45
|
3152 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
3153 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
3154 }
|
Chris@45
|
3155
|
Chris@45
|
3156 void
|
Chris@366
|
3157 MainWindowBase::viewZoomLevelChanged(View *v, int , bool )
|
Chris@45
|
3158 {
|
Chris@45
|
3159 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3160 Pane *p = 0;
|
Chris@45
|
3161 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
3162 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
3163 }
|
Chris@45
|
3164
|
Chris@45
|
3165 void
|
Chris@45
|
3166 MainWindowBase::layerAdded(Layer *)
|
Chris@45
|
3167 {
|
Chris@233
|
3168 // SVDEBUG << "MainWindowBase::layerAdded(" << layer << ")" << endl;
|
Chris@45
|
3169 updateMenuStates();
|
Chris@45
|
3170 }
|
Chris@45
|
3171
|
Chris@45
|
3172 void
|
Chris@45
|
3173 MainWindowBase::layerRemoved(Layer *)
|
Chris@45
|
3174 {
|
Chris@233
|
3175 // SVDEBUG << "MainWindowBase::layerRemoved(" << layer << ")" << endl;
|
Chris@45
|
3176 updateMenuStates();
|
Chris@45
|
3177 }
|
Chris@45
|
3178
|
Chris@45
|
3179 void
|
Chris@45
|
3180 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
|
Chris@45
|
3181 {
|
Chris@233
|
3182 // SVDEBUG << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << endl;
|
Chris@123
|
3183
|
Chris@128
|
3184 removeLayerEditDialog(layer);
|
Chris@123
|
3185
|
Chris@47
|
3186 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
|
Chris@293
|
3187 // cerr << "(this is the time ruler layer)" << endl;
|
Chris@45
|
3188 m_timeRulerLayer = 0;
|
Chris@45
|
3189 }
|
Chris@45
|
3190 }
|
Chris@45
|
3191
|
Chris@45
|
3192 void
|
Chris@45
|
3193 MainWindowBase::layerInAView(Layer *layer, bool inAView)
|
Chris@45
|
3194 {
|
Chris@233
|
3195 // SVDEBUG << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << endl;
|
Chris@128
|
3196
|
Chris@128
|
3197 if (!inAView) removeLayerEditDialog(layer);
|
Chris@45
|
3198
|
Chris@45
|
3199 // Check whether we need to add or remove model from play source
|
Chris@45
|
3200 Model *model = layer->getModel();
|
Chris@45
|
3201 if (model) {
|
Chris@45
|
3202 if (inAView) {
|
Chris@45
|
3203 m_playSource->addModel(model);
|
Chris@45
|
3204 } else {
|
Chris@45
|
3205 bool found = false;
|
Chris@45
|
3206 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
3207 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
3208 if (!pane) continue;
|
Chris@45
|
3209 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@45
|
3210 Layer *pl = pane->getLayer(j);
|
Chris@183
|
3211 if (pl &&
|
Chris@183
|
3212 !dynamic_cast<TimeRulerLayer *>(pl) &&
|
Chris@183
|
3213 (pl->getModel() == model)) {
|
Chris@45
|
3214 found = true;
|
Chris@45
|
3215 break;
|
Chris@45
|
3216 }
|
Chris@45
|
3217 }
|
Chris@45
|
3218 if (found) break;
|
Chris@45
|
3219 }
|
Chris@173
|
3220 if (!found) {
|
Chris@173
|
3221 m_playSource->removeModel(model);
|
Chris@173
|
3222 }
|
Chris@45
|
3223 }
|
Chris@45
|
3224 }
|
Chris@45
|
3225
|
Chris@45
|
3226 updateMenuStates();
|
Chris@45
|
3227 }
|
Chris@45
|
3228
|
Chris@45
|
3229 void
|
Chris@128
|
3230 MainWindowBase::removeLayerEditDialog(Layer *layer)
|
Chris@128
|
3231 {
|
Chris@128
|
3232 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
|
Chris@128
|
3233
|
Chris@128
|
3234 ModelDataTableDialog *dialog = m_layerDataDialogMap[layer];
|
Chris@128
|
3235
|
Chris@128
|
3236 for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin();
|
Chris@128
|
3237 vi != m_viewDataDialogMap.end(); ++vi) {
|
Chris@128
|
3238 vi->second.erase(dialog);
|
Chris@128
|
3239 }
|
Chris@128
|
3240
|
Chris@128
|
3241 m_layerDataDialogMap.erase(layer);
|
Chris@128
|
3242 delete dialog;
|
Chris@128
|
3243 }
|
Chris@128
|
3244 }
|
Chris@128
|
3245
|
Chris@128
|
3246 void
|
Chris@45
|
3247 MainWindowBase::modelAdded(Model *model)
|
Chris@45
|
3248 {
|
Chris@233
|
3249 // SVDEBUG << "MainWindowBase::modelAdded(" << model << ")" << endl;
|
gyorgyf@273
|
3250 std::cerr << "\nAdding model " << model->getTypeName() << " to playsource " << std::endl;
|
Chris@45
|
3251 m_playSource->addModel(model);
|
Chris@45
|
3252 }
|
Chris@45
|
3253
|
Chris@45
|
3254 void
|
Chris@45
|
3255 MainWindowBase::mainModelChanged(WaveFileModel *model)
|
Chris@45
|
3256 {
|
Chris@233
|
3257 // SVDEBUG << "MainWindowBase::mainModelChanged(" << model << ")" << endl;
|
Chris@45
|
3258 updateDescriptionLabel();
|
Chris@45
|
3259 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@360
|
3260 if (model && !m_playTarget && m_audioOutput) {
|
Chris@360
|
3261 createPlayTarget();
|
Chris@360
|
3262 }
|
Chris@45
|
3263 }
|
Chris@45
|
3264
|
Chris@45
|
3265 void
|
Chris@45
|
3266 MainWindowBase::modelAboutToBeDeleted(Model *model)
|
Chris@45
|
3267 {
|
Chris@233
|
3268 // SVDEBUG << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << endl;
|
Chris@45
|
3269 if (model == m_viewManager->getPlaybackModel()) {
|
Chris@45
|
3270 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
3271 }
|
Chris@45
|
3272 m_playSource->removeModel(model);
|
Chris@45
|
3273 FFTDataServer::modelAboutToBeDeleted(model);
|
Chris@45
|
3274 }
|
Chris@45
|
3275
|
Chris@45
|
3276 void
|
Chris@55
|
3277 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
|
Chris@55
|
3278 {
|
Chris@55
|
3279 bool found = false;
|
Chris@55
|
3280 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@55
|
3281 if (m_paneStack->getPane(i) == pane) {
|
Chris@55
|
3282 found = true;
|
Chris@55
|
3283 break;
|
Chris@55
|
3284 }
|
Chris@55
|
3285 }
|
Chris@55
|
3286 if (!found) {
|
Chris@233
|
3287 SVDEBUG << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
|
Chris@229
|
3288 << pane << endl;
|
Chris@55
|
3289 return;
|
Chris@55
|
3290 }
|
Chris@55
|
3291
|
Chris@55
|
3292 CommandHistory::getInstance()->startCompoundOperation
|
Chris@55
|
3293 (tr("Delete Pane"), true);
|
Chris@55
|
3294
|
Chris@55
|
3295 while (pane->getLayerCount() > 0) {
|
Chris@55
|
3296 Layer *layer = pane->getLayer(0);
|
Chris@55
|
3297 if (layer) {
|
Chris@55
|
3298 m_document->removeLayerFromView(pane, layer);
|
Chris@55
|
3299 } else {
|
Chris@55
|
3300 break;
|
Chris@55
|
3301 }
|
Chris@55
|
3302 }
|
Chris@55
|
3303
|
Chris@55
|
3304 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@55
|
3305 CommandHistory::getInstance()->addCommand(command);
|
Chris@55
|
3306
|
Chris@55
|
3307 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@55
|
3308
|
Chris@55
|
3309 updateMenuStates();
|
Chris@55
|
3310 }
|
Chris@55
|
3311
|
Chris@55
|
3312 void
|
Chris@45
|
3313 MainWindowBase::pollOSC()
|
Chris@45
|
3314 {
|
Chris@45
|
3315 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@233
|
3316 SVDEBUG << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << endl;
|
Chris@45
|
3317
|
Chris@45
|
3318 if (m_openingAudioFile) return;
|
Chris@45
|
3319
|
Chris@45
|
3320 OSCMessage message = m_oscQueue->readMessage();
|
Chris@45
|
3321
|
Chris@45
|
3322 if (message.getTarget() != 0) {
|
Chris@45
|
3323 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@45
|
3324 }
|
Chris@45
|
3325
|
Chris@45
|
3326 handleOSCMessage(message);
|
Chris@45
|
3327 }
|
Chris@45
|
3328
|
Chris@45
|
3329 void
|
Chris@45
|
3330 MainWindowBase::inProgressSelectionChanged()
|
Chris@45
|
3331 {
|
Chris@45
|
3332 Pane *currentPane = 0;
|
Chris@45
|
3333 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
justin@331
|
3334 if (currentPane) {
|
justin@331
|
3335 //cerr << "JTEST: mouse event on selection pane" << endl;
|
justin@331
|
3336 updateVisibleRangeDisplay(currentPane);
|
justin@331
|
3337 }
|
Chris@45
|
3338 }
|
Chris@45
|
3339
|
Chris@45
|
3340 void
|
Chris@45
|
3341 MainWindowBase::contextHelpChanged(const QString &s)
|
Chris@45
|
3342 {
|
Chris@378
|
3343 QLabel *lab = getStatusLabel();
|
Chris@375
|
3344
|
Chris@45
|
3345 if (s == "" && m_myStatusMessage != "") {
|
Chris@378
|
3346 if (lab->text() != m_myStatusMessage) {
|
Chris@378
|
3347 lab->setText(m_myStatusMessage);
|
Chris@375
|
3348 }
|
Chris@45
|
3349 return;
|
Chris@45
|
3350 }
|
Chris@375
|
3351
|
Chris@378
|
3352 lab->setText(s);
|
Chris@45
|
3353 }
|
Chris@45
|
3354
|
Chris@45
|
3355 void
|
Chris@45
|
3356 MainWindowBase::openHelpUrl(QString url)
|
Chris@45
|
3357 {
|
Chris@45
|
3358 // This method mostly lifted from Qt Assistant source code
|
Chris@45
|
3359
|
Chris@45
|
3360 QProcess *process = new QProcess(this);
|
Chris@45
|
3361 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@45
|
3362
|
Chris@45
|
3363 QStringList args;
|
Chris@45
|
3364
|
Chris@45
|
3365 #ifdef Q_OS_MAC
|
Chris@45
|
3366 args.append(url);
|
Chris@45
|
3367 process->start("open", args);
|
Chris@45
|
3368 #else
|
Chris@45
|
3369 #ifdef Q_OS_WIN32
|
Chris@358
|
3370 QString pf(getenv("ProgramFiles"));
|
Chris@358
|
3371 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@358
|
3372
|
Chris@358
|
3373 args.append(url);
|
Chris@358
|
3374 process->start(command, args);
|
Chris@45
|
3375 #else
|
Chris@45
|
3376 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@45
|
3377 args.append("exec");
|
Chris@45
|
3378 args.append(url);
|
Chris@45
|
3379 process->start("kfmclient", args);
|
Chris@45
|
3380 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@45
|
3381 args.append(url);
|
Chris@45
|
3382 process->start(qgetenv("BROWSER"), args);
|
Chris@45
|
3383 } else {
|
Chris@45
|
3384 args.append(url);
|
Chris@45
|
3385 process->start("firefox", args);
|
Chris@45
|
3386 }
|
Chris@45
|
3387 #endif
|
Chris@45
|
3388 #endif
|
Chris@45
|
3389 }
|
Chris@45
|
3390
|
Chris@180
|
3391
|