annotate main/MainWindow.cpp @ 522:d6ddc2c2a6ed

Fix failure to either export a file or explain why, when exporting an unsupported layer type to rdf
author Chris Cannam
date Tue, 11 Dec 2012 13:07:59 +0000
parents 581c72fb14a4
children a740e96d7fec
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 Sonic Visualiser
Chris@0 5 An audio file viewer and annotation editor.
Chris@0 6 Centre for Digital Music, Queen Mary, University of London.
Chris@200 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@0 8
Chris@0 9 This program is free software; you can redistribute it and/or
Chris@0 10 modify it under the terms of the GNU General Public License as
Chris@0 11 published by the Free Software Foundation; either version 2 of the
Chris@0 12 License, or (at your option) any later version. See the file
Chris@0 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@144 16 #include "../version.h"
Chris@0 17
Chris@0 18 #include "MainWindow.h"
Chris@0 19 #include "PreferencesDialog.h"
Chris@0 20
Chris@1 21 #include "view/Pane.h"
Chris@1 22 #include "view/PaneStack.h"
Chris@1 23 #include "data/model/WaveFileModel.h"
Chris@1 24 #include "data/model/SparseOneDimensionalModel.h"
Chris@415 25 #include "data/model/RangeSummarisableTimeValueModel.h"
Chris@185 26 #include "data/model/NoteModel.h"
Chris@189 27 #include "data/model/Labeller.h"
Chris@222 28 #include "data/osc/OSCQueue.h"
Chris@216 29 #include "framework/Document.h"
Chris@357 30 #include "framework/TransformUserConfigurator.h"
Chris@1 31 #include "view/ViewManager.h"
Chris@0 32 #include "base/Preferences.h"
Chris@423 33 #include "base/ResourceFinder.h"
Chris@0 34 #include "layer/WaveformLayer.h"
Chris@0 35 #include "layer/TimeRulerLayer.h"
Chris@0 36 #include "layer/TimeInstantLayer.h"
Chris@0 37 #include "layer/TimeValueLayer.h"
Chris@307 38 #include "layer/NoteLayer.h"
Chris@0 39 #include "layer/Colour3DPlotLayer.h"
Chris@95 40 #include "layer/SliceLayer.h"
Chris@95 41 #include "layer/SliceableLayer.h"
Chris@193 42 #include "layer/ImageLayer.h"
Chris@340 43 #include "layer/RegionLayer.h"
Chris@0 44 #include "widgets/Fader.h"
Chris@65 45 #include "view/Overview.h"
Chris@0 46 #include "widgets/PropertyBox.h"
Chris@0 47 #include "widgets/PropertyStack.h"
Chris@0 48 #include "widgets/AudioDial.h"
Chris@168 49 #include "widgets/IconLoader.h"
Chris@219 50 #include "widgets/LayerTreeDialog.h"
Chris@0 51 #include "widgets/ListInputDialog.h"
Chris@36 52 #include "widgets/SubdividingMenu.h"
Chris@90 53 #include "widgets/NotifyingPushButton.h"
Chris@162 54 #include "widgets/KeyReference.h"
Chris@273 55 #include "widgets/TransformFinder.h"
Chris@192 56 #include "widgets/LabelCounterInputDialog.h"
Chris@302 57 #include "widgets/ActivityLog.h"
Chris@0 58 #include "audioio/AudioCallbackPlaySource.h"
Chris@0 59 #include "audioio/AudioCallbackPlayTarget.h"
Chris@0 60 #include "audioio/AudioTargetFactory.h"
Chris@59 61 #include "audioio/PlaySpeedRangeMapper.h"
Chris@1 62 #include "data/fileio/DataFileReaderFactory.h"
Chris@180 63 #include "data/fileio/PlaylistFileReader.h"
Chris@1 64 #include "data/fileio/WavFileWriter.h"
Chris@1 65 #include "data/fileio/CSVFileWriter.h"
Chris@185 66 #include "data/fileio/MIDIFileWriter.h"
Chris@1 67 #include "data/fileio/BZipFileDevice.h"
Chris@198 68 #include "data/fileio/FileSource.h"
Chris@91 69 #include "data/fft/FFTDataServer.h"
Chris@304 70 #include "data/midi/MIDIInput.h"
Chris@1 71 #include "base/RecentFiles.h"
Chris@249 72 #include "transform/TransformFactory.h"
Chris@249 73 #include "transform/ModelTransformerFactory.h"
Chris@0 74 #include "base/PlayParameterRepository.h"
Chris@0 75 #include "base/XmlExportable.h"
Chris@248 76 #include "widgets/CommandHistory.h"
Chris@0 77 #include "base/Profiler.h"
Chris@0 78 #include "base/Clipboard.h"
Chris@165 79 #include "base/UnitDatabase.h"
Chris@248 80 #include "layer/ColourDatabase.h"
Chris@265 81 #include "widgets/ModelDataTableDialog.h"
Chris@289 82 #include "rdf/PluginRDFIndexer.h"
Chris@291 83 #include "rdf/RDFExporter.h"
Chris@276 84
Chris@333 85 #include "Surveyer.h"
Chris@334 86 #include "framework/VersionTester.h"
Chris@333 87
Chris@0 88 // For version information
Chris@280 89 #include <vamp/vamp.h>
Chris@280 90 #include <vamp-hostsdk/PluginBase.h>
Chris@0 91 #include "plugin/api/ladspa.h"
Chris@0 92 #include "plugin/api/dssi.h"
Chris@0 93
Chris@0 94 #include <QApplication>
Chris@0 95 #include <QMessageBox>
Chris@0 96 #include <QGridLayout>
Chris@0 97 #include <QLabel>
Chris@0 98 #include <QAction>
Chris@0 99 #include <QMenuBar>
Chris@0 100 #include <QToolBar>
Chris@0 101 #include <QInputDialog>
Chris@0 102 #include <QStatusBar>
Chris@0 103 #include <QTreeView>
Chris@0 104 #include <QFile>
Chris@88 105 #include <QFileInfo>
Chris@88 106 #include <QDir>
Chris@0 107 #include <QTextStream>
Chris@0 108 #include <QProcess>
Chris@7 109 #include <QShortcut>
Chris@5 110 #include <QSettings>
Chris@11 111 #include <QDateTime>
Chris@11 112 #include <QProcess>
Chris@16 113 #include <QCheckBox>
Chris@55 114 #include <QRegExp>
Chris@158 115 #include <QScrollArea>
Chris@425 116 #include <QDesktopServices>
Chris@483 117 #include <QDialogButtonBox>
Chris@426 118 #include <QFileSystemWatcher>
Chris@0 119
Chris@0 120 #include <iostream>
Chris@0 121 #include <cstdio>
Chris@0 122 #include <errno.h>
Chris@0 123
Chris@0 124 using std::cerr;
Chris@0 125 using std::endl;
Chris@0 126
Chris@33 127 using std::vector;
Chris@33 128 using std::map;
Chris@33 129 using std::set;
Chris@33 130
Chris@0 131
Chris@70 132 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
Chris@305 133 MainWindowBase(withAudioOutput, withOSCSupport, true),
Chris@65 134 m_overview(0),
Chris@0 135 m_mainMenusCreated(false),
Chris@0 136 m_paneMenu(0),
Chris@0 137 m_layerMenu(0),
Chris@34 138 m_transformsMenu(0),
Chris@155 139 m_playbackMenu(0),
Chris@0 140 m_existingLayersMenu(0),
Chris@95 141 m_sliceMenu(0),
Chris@34 142 m_recentFilesMenu(0),
Chris@211 143 m_recentTransformsMenu(0),
Chris@426 144 m_templatesMenu(0),
Chris@0 145 m_rightButtonMenu(0),
Chris@0 146 m_rightButtonLayerMenu(0),
Chris@211 147 m_rightButtonTransformsMenu(0),
Chris@155 148 m_rightButtonPlaybackMenu(0),
Chris@207 149 m_soloAction(0),
Chris@207 150 m_soloModified(false),
Chris@207 151 m_prevSolo(false),
Chris@265 152 m_rwdStartAction(0),
Chris@323 153 m_rwdSimilarAction(0),
Chris@265 154 m_rwdAction(0),
Chris@155 155 m_ffwdAction(0),
Chris@323 156 m_ffwdSimilarAction(0),
Chris@265 157 m_ffwdEndAction(0),
Chris@265 158 m_playAction(0),
Chris@265 159 m_playSelectionAction(0),
Chris@265 160 m_playLoopAction(0),
Chris@239 161 m_playControlsSpacer(0),
Chris@239 162 m_playControlsWidth(0),
Chris@162 163 m_preferencesDialog(0),
Chris@219 164 m_layerTreeDialog(0),
Chris@302 165 m_activityLog(new ActivityLog()),
Chris@426 166 m_keyReference(new KeyReference()),
Chris@426 167 m_templateWatcher(0)
Chris@0 168 {
Chris@253 169 Profiler profiler("MainWindow::MainWindow");
Chris@253 170
Chris@518 171 setWindowTitle(QApplication::applicationName());
Chris@0 172
Chris@165 173 UnitDatabase *udb = UnitDatabase::getInstance();
Chris@165 174 udb->registerUnit("Hz");
Chris@165 175 udb->registerUnit("dB");
Chris@165 176 udb->registerUnit("s");
Chris@165 177
Chris@165 178 ColourDatabase *cdb = ColourDatabase::getInstance();
Chris@165 179 cdb->addColour(Qt::black, tr("Black"));
Chris@165 180 cdb->addColour(Qt::darkRed, tr("Red"));
Chris@165 181 cdb->addColour(Qt::darkBlue, tr("Blue"));
Chris@165 182 cdb->addColour(Qt::darkGreen, tr("Green"));
Chris@165 183 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
Chris@165 184 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
Chris@166 185 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
Chris@166 186 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
Chris@166 187 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
Chris@166 188 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
Chris@166 189 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
Chris@166 190 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
Chris@0 191
Chris@0 192 QFrame *frame = new QFrame;
Chris@0 193 setCentralWidget(frame);
Chris@0 194
Chris@0 195 QGridLayout *layout = new QGridLayout;
Chris@180 196
Chris@519 197 m_descriptionLabel = new QLabel;
Chris@0 198
Chris@489 199 m_mainScroll = new QScrollArea(frame);
Chris@489 200 m_mainScroll->setWidgetResizable(true);
Chris@489 201 m_mainScroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Chris@489 202 m_mainScroll->setFrameShape(QFrame::NoFrame);
Chris@489 203
Chris@489 204 m_mainScroll->setWidget(m_paneStack);
Chris@159 205
Chris@65 206 m_overview = new Overview(frame);
Chris@65 207 m_overview->setViewManager(m_viewManager);
Chris@65 208 m_overview->setFixedHeight(40);
Chris@144 209 #ifndef _WIN32
Chris@144 210 // For some reason, the contents of the overview never appear if we
Chris@144 211 // make this setting on Windows. I have no inclination at the moment
Chris@144 212 // to track down the reason why.
Chris@129 213 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
Chris@144 214 #endif
Chris@90 215 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 216 this, SLOT(contextHelpChanged(const QString &)));
Chris@0 217
Chris@0 218 m_panLayer = new WaveformLayer;
Chris@0 219 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
Chris@0 220 m_panLayer->setAggressiveCacheing(true);
Chris@65 221 m_overview->addLayer(m_panLayer);
Chris@174 222
Chris@174 223 if (m_viewManager->getGlobalDarkBackground()) {
Chris@174 224 m_panLayer->setBaseColour
Chris@174 225 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@174 226 } else {
Chris@174 227 m_panLayer->setBaseColour
Chris@174 228 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@200 229 }
Chris@0 230
Chris@0 231 m_fader = new Fader(frame, false);
Chris@90 232 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 233 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@0 234
Chris@0 235 m_playSpeed = new AudioDial(frame);
Chris@12 236 m_playSpeed->setMinimum(0);
Chris@48 237 m_playSpeed->setMaximum(200);
Chris@25 238 m_playSpeed->setValue(100);
Chris@261 239 m_playSpeed->setFixedWidth(32);
Chris@261 240 m_playSpeed->setFixedHeight(32);
Chris@0 241 m_playSpeed->setNotchesVisible(true);
Chris@25 242 m_playSpeed->setPageStep(10);
Chris@60 243 m_playSpeed->setObjectName(tr("Playback Speedup"));
Chris@25 244 m_playSpeed->setDefaultValue(100);
Chris@59 245 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
Chris@60 246 m_playSpeed->setShowToolTip(true);
Chris@0 247 connect(m_playSpeed, SIGNAL(valueChanged(int)),
Chris@0 248 this, SLOT(playSpeedChanged(int)));
Chris@90 249 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
Chris@90 250 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
Chris@90 251
Chris@168 252 IconLoader il;
Chris@168 253
Chris@21 254 QSettings settings;
Chris@21 255 settings.beginGroup("MainWindow");
Chris@21 256 settings.endGroup();
Chris@21 257
Chris@239 258 m_playControlsSpacer = new QFrame;
Chris@239 259
Chris@129 260 layout->setSpacing(4);
Chris@489 261 layout->addWidget(m_mainScroll, 0, 0, 1, 5);
Chris@239 262 layout->addWidget(m_overview, 1, 1);
Chris@239 263 layout->addWidget(m_playControlsSpacer, 1, 2);
Chris@239 264 layout->addWidget(m_playSpeed, 1, 3);
Chris@239 265 layout->addWidget(m_fader, 1, 4);
Chris@239 266
Chris@239 267 m_playControlsWidth =
Chris@240 268 m_fader->width() + m_playSpeed->width() + layout->spacing() * 2;
Chris@239 269
Chris@239 270 layout->setColumnMinimumWidth(0, 14);
Chris@239 271 layout->setColumnStretch(0, 0);
Chris@239 272
Chris@239 273 m_paneStack->setPropertyStackMinWidth(m_playControlsWidth
Chris@239 274 + 2 + layout->spacing());
Chris@239 275 m_playControlsSpacer->setFixedSize(QSize(2, 2));
Chris@239 276
Chris@239 277 layout->setColumnStretch(1, 10);
Chris@239 278
Chris@239 279 connect(m_paneStack, SIGNAL(propertyStacksResized(int)),
Chris@239 280 this, SLOT(propertyStacksResized(int)));
Chris@16 281
Chris@0 282 frame->setLayout(layout);
Chris@0 283
Chris@0 284 setupMenus();
Chris@0 285 setupToolbars();
Chris@155 286 setupHelpMenu();
Chris@0 287
Chris@90 288 statusBar();
Chris@340 289 m_currentLabel = new QLabel;
Chris@340 290 statusBar()->addPermanentWidget(m_currentLabel);
Chris@0 291
Chris@302 292 connect(m_viewManager, SIGNAL(activity(QString)),
Chris@302 293 m_activityLog, SLOT(activityHappened(QString)));
Chris@302 294 connect(m_playSource, SIGNAL(activity(QString)),
Chris@302 295 m_activityLog, SLOT(activityHappened(QString)));
Chris@302 296 connect(CommandHistory::getInstance(), SIGNAL(activity(QString)),
Chris@302 297 m_activityLog, SLOT(activityHappened(QString)));
Chris@310 298 connect(this, SIGNAL(activity(QString)),
Chris@310 299 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 300 connect(this, SIGNAL(replacedDocument()), this, SLOT(documentReplaced()));
Chris@306 301 m_activityLog->hide();
Chris@303 302
Chris@303 303 newSession();
Chris@303 304
Chris@304 305 connect(m_midiInput, SIGNAL(eventsAvailable()),
Chris@304 306 this, SLOT(midiEventsAvailable()));
Chris@281 307
Chris@283 308 TransformFactory::getInstance()->startPopulationThread();
Chris@334 309
Chris@334 310 Surveyer *surveyer = new Surveyer(this);
Chris@334 311 VersionTester *vt = new VersionTester
Chris@334 312 ("sonicvisualiser.org", "/latest-version.txt", SV_VERSION);
Chris@334 313 connect(vt, SIGNAL(newerVersionAvailable(QString)),
Chris@334 314 this, SLOT(newerVersionAvailable(QString)));
Chris@0 315 }
Chris@0 316
Chris@0 317 MainWindow::~MainWindow()
Chris@0 318 {
Chris@438 319 // SVDEBUG << "MainWindow::~MainWindow" << endl;
Chris@162 320 delete m_keyReference;
Chris@504 321 delete m_activityLog;
Chris@163 322 delete m_preferencesDialog;
Chris@219 323 delete m_layerTreeDialog;
Chris@0 324 Profiles::getInstance()->dump();
Chris@438 325 // SVDEBUG << "MainWindow::~MainWindow finishing" << endl;
Chris@0 326 }
Chris@0 327
Chris@81 328 void
Chris@0 329 MainWindow::setupMenus()
Chris@0 330 {
Chris@0 331 if (!m_mainMenusCreated) {
Chris@0 332 m_rightButtonMenu = new QMenu();
Chris@104 333
Chris@104 334 // No -- we don't want tear-off enabled on the right-button
Chris@104 335 // menu. If it is enabled, then simply right-clicking and
Chris@104 336 // releasing will pop up the menu, activate the tear-off, and
Chris@104 337 // leave the torn-off menu window in front of the main window.
Chris@104 338 // That isn't desirable. I'm not sure it ever would be, in a
Chris@104 339 // context menu -- perhaps technically a Qt bug?
Chris@104 340 // m_rightButtonMenu->setTearOffEnabled(true);
Chris@0 341 }
Chris@0 342
Chris@211 343 if (m_rightButtonTransformsMenu) {
Chris@211 344 m_rightButtonTransformsMenu->clear();
Chris@34 345 } else {
Chris@211 346 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
Chris@211 347 m_rightButtonTransformsMenu->setTearOffEnabled(true);
Chris@34 348 m_rightButtonMenu->addSeparator();
Chris@34 349 }
Chris@34 350
Chris@346 351 // This will be created (if not found) or cleared (if found) in
Chris@346 352 // setupPaneAndLayerMenus, but we want to ensure it's created
Chris@346 353 // sooner so it can go nearer the top of the right button menu
Chris@346 354 if (m_rightButtonLayerMenu) {
Chris@346 355 m_rightButtonLayerMenu->clear();
Chris@346 356 } else {
Chris@346 357 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@346 358 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@346 359 m_rightButtonMenu->addSeparator();
Chris@346 360 }
Chris@346 361
Chris@0 362 if (!m_mainMenusCreated) {
Chris@0 363 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
Chris@0 364 m_rightButtonMenu->addSeparator();
Chris@66 365 }
Chris@66 366
Chris@66 367 setupFileMenu();
Chris@66 368 setupEditMenu();
Chris@66 369 setupViewMenu();
Chris@66 370 setupPaneAndLayerMenus();
Chris@211 371 setupTransformsMenu();
Chris@66 372
Chris@66 373 m_mainMenusCreated = true;
Chris@66 374 }
Chris@66 375
Chris@66 376 void
Chris@489 377 MainWindow::goFullScreen()
Chris@489 378 {
Chris@492 379 QWidget *ps = m_mainScroll->takeWidget();
Chris@492 380 ps->setParent(0);
Chris@494 381
Chris@494 382 QShortcut *sc;
Chris@494 383
Chris@494 384 sc = new QShortcut(QKeySequence("Esc"), ps);
Chris@494 385 connect(sc, SIGNAL(activated()), this, SLOT(endFullScreen()));
Chris@494 386
Chris@494 387 sc = new QShortcut(QKeySequence("F11"), ps);
Chris@494 388 connect(sc, SIGNAL(activated()), this, SLOT(endFullScreen()));
Chris@494 389
Chris@494 390 QAction *acts[] = {
Chris@494 391 m_playAction, m_zoomInAction, m_zoomOutAction, m_zoomFitAction,
Chris@494 392 m_scrollLeftAction, m_scrollRightAction, m_showPropertyBoxesAction
Chris@494 393 };
Chris@494 394
Chris@494 395 for (int i = 0; i < sizeof(acts)/sizeof(acts[0]); ++i) {
Chris@494 396 sc = new QShortcut(acts[i]->shortcut(), ps);
Chris@494 397 connect(sc, SIGNAL(activated()), acts[i], SLOT(trigger()));
Chris@494 398 }
Chris@494 399
Chris@492 400 ps->showFullScreen();
Chris@492 401 }
Chris@492 402
Chris@492 403 void
Chris@492 404 MainWindow::endFullScreen()
Chris@492 405 {
Chris@494 406 // these were only created in goFullScreen:
Chris@494 407 QObjectList cl = m_paneStack->children();
Chris@494 408 foreach (QObject *o, cl) {
Chris@494 409 QShortcut *sc = qobject_cast<QShortcut *>(o);
Chris@494 410 if (sc) delete sc;
Chris@494 411 }
Chris@494 412
Chris@492 413 m_mainScroll->setWidget(m_paneStack);
Chris@489 414 }
Chris@489 415
Chris@489 416 void
Chris@66 417 MainWindow::setupFileMenu()
Chris@66 418 {
Chris@66 419 if (m_mainMenusCreated) return;
Chris@66 420
Chris@66 421 QMenu *menu = menuBar()->addMenu(tr("&File"));
Chris@97 422 menu->setTearOffEnabled(true);
Chris@66 423 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
Chris@66 424
Chris@162 425 m_keyReference->setCategory(tr("File and Session Management"));
Chris@162 426
Chris@168 427 IconLoader il;
Chris@168 428
Chris@168 429 QIcon icon = il.load("filenew");
Chris@168 430 icon.addPixmap(il.loadPixmap("filenew-22"));
Chris@66 431 QAction *action = new QAction(icon, tr("&New Session"), this);
Chris@66 432 action->setShortcut(tr("Ctrl+N"));
Chris@518 433 action->setStatusTip(tr("Abandon the current %1 session and start a new one").arg(QApplication::applicationName()));
Chris@66 434 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
Chris@162 435 m_keyReference->registerShortcut(action);
Chris@66 436 menu->addAction(action);
Chris@66 437 toolbar->addAction(action);
Chris@518 438
Chris@168 439 icon = il.load("fileopen");
Chris@168 440 icon.addPixmap(il.loadPixmap("fileopen-22"));
Chris@66 441 action = new QAction(icon, tr("&Open..."), this);
Chris@418 442 action->setShortcut(tr("Ctrl+O"));
Chris@66 443 action->setStatusTip(tr("Open a session file, audio file, or layer"));
Chris@66 444 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
Chris@66 445 toolbar->addAction(action);
Chris@418 446 menu->addAction(action);
Chris@418 447
Chris@418 448 // We want this one to go on the toolbar now, if we add it at all,
Chris@418 449 // but on the menu later
Chris@418 450 QAction *iaction = new QAction(tr("&Import More Audio..."), this);
Chris@418 451 iaction->setShortcut(tr("Ctrl+I"));
Chris@418 452 iaction->setStatusTip(tr("Import an extra audio file into a new pane"));
Chris@418 453 connect(iaction, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
Chris@418 454 connect(this, SIGNAL(canImportMoreAudio(bool)), iaction, SLOT(setEnabled(bool)));
Chris@418 455 m_keyReference->registerShortcut(iaction);
Chris@418 456
Chris@508 457 // We want this one to go on the toolbar now, if we add it at all,
Chris@508 458 // but on the menu later
Chris@508 459 QAction *raction = new QAction(tr("Replace &Main Audio..."), this);
Chris@508 460 raction->setStatusTip(tr("Replace the main audio file of the session with a different file"));
Chris@508 461 connect(raction, SIGNAL(triggered()), this, SLOT(replaceMainAudio()));
Chris@508 462 connect(this, SIGNAL(canReplaceMainAudio(bool)), raction, SLOT(setEnabled(bool)));
Chris@508 463
Chris@418 464 action = new QAction(tr("Open Lo&cation..."), this);
Chris@418 465 action->setShortcut(tr("Ctrl+Shift+O"));
Chris@418 466 action->setStatusTip(tr("Open or import a file from a remote URL"));
Chris@418 467 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
Chris@418 468 m_keyReference->registerShortcut(action);
Chris@418 469 menu->addAction(action);
Chris@418 470
Chris@420 471 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
Chris@418 472 m_recentFilesMenu->setTearOffEnabled(true);
Chris@418 473 setupRecentFilesMenu();
Chris@418 474 connect(&m_recentFiles, SIGNAL(recentChanged()),
Chris@418 475 this, SLOT(setupRecentFilesMenu()));
Chris@418 476
Chris@418 477 menu->addSeparator();
Chris@415 478
Chris@168 479 icon = il.load("filesave");
Chris@168 480 icon.addPixmap(il.loadPixmap("filesave-22"));
Chris@66 481 action = new QAction(icon, tr("&Save Session"), this);
Chris@66 482 action->setShortcut(tr("Ctrl+S"));
Chris@518 483 action->setStatusTip(tr("Save the current session into a %1 session file").arg(QApplication::applicationName()));
Chris@66 484 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
Chris@66 485 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
Chris@162 486 m_keyReference->registerShortcut(action);
Chris@66 487 menu->addAction(action);
Chris@66 488 toolbar->addAction(action);
Chris@0 489
Chris@168 490 icon = il.load("filesaveas");
Chris@168 491 icon.addPixmap(il.loadPixmap("filesaveas-22"));
Chris@66 492 action = new QAction(icon, tr("Save Session &As..."), this);
Chris@336 493 action->setShortcut(tr("Ctrl+Shift+S"));
Chris@518 494 action->setStatusTip(tr("Save the current session into a new %1 session file").arg(QApplication::applicationName()));
Chris@66 495 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
Chris@66 496 menu->addAction(action);
Chris@66 497 toolbar->addAction(action);
Chris@66 498
Chris@66 499 menu->addSeparator();
Chris@66 500
Chris@418 501 /*
Chris@168 502 icon = il.load("fileopenaudio");
Chris@138 503 action = new QAction(icon, tr("&Import Audio File..."), this);
Chris@66 504 action->setShortcut(tr("Ctrl+I"));
Chris@66 505 action->setStatusTip(tr("Import an existing audio file"));
Chris@66 506 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
Chris@162 507 m_keyReference->registerShortcut(action);
Chris@66 508 menu->addAction(action);
Chris@418 509 */
Chris@418 510
Chris@508 511 // the Replace action we made earlier
Chris@508 512 menu->addAction(raction);
Chris@508 513
Chris@418 514 // the Import action we made earlier
Chris@418 515 menu->addAction(iaction);
Chris@66 516
Chris@66 517 action = new QAction(tr("&Export Audio File..."), this);
Chris@66 518 action->setStatusTip(tr("Export selection as an audio file"));
Chris@66 519 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
Chris@66 520 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@66 521 menu->addAction(action);
Chris@66 522
Chris@66 523 menu->addSeparator();
Chris@66 524
Chris@66 525 action = new QAction(tr("Import Annotation &Layer..."), this);
Chris@66 526 action->setShortcut(tr("Ctrl+L"));
Chris@66 527 action->setStatusTip(tr("Import layer data from an existing file"));
Chris@66 528 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
Chris@66 529 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 530 m_keyReference->registerShortcut(action);
Chris@66 531 menu->addAction(action);
Chris@66 532
Chris@66 533 action = new QAction(tr("Export Annotation Layer..."), this);
Chris@66 534 action->setStatusTip(tr("Export layer data to a file"));
Chris@66 535 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
Chris@66 536 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@66 537 menu->addAction(action);
Chris@66 538
Chris@66 539 menu->addSeparator();
Chris@86 540
Chris@121 541 action = new QAction(tr("Export Image File..."), this);
Chris@121 542 action->setStatusTip(tr("Export a single pane to an image file"));
Chris@121 543 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
Chris@121 544 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
Chris@121 545 menu->addAction(action);
Chris@121 546
Chris@121 547 menu->addSeparator();
Chris@121 548
Chris@435 549 QString templatesMenuLabel = tr("Apply Session Template");
Chris@425 550 m_templatesMenu = menu->addMenu(templatesMenuLabel);
Chris@425 551 m_templatesMenu->setTearOffEnabled(true);
Chris@436 552 // We need to have a main model for this option to be useful:
Chris@436 553 // canExportAudio captures that
Chris@436 554 connect(this, SIGNAL(canExportAudio(bool)), m_templatesMenu, SLOT(setEnabled(bool)));
Chris@436 555
Chris@436 556 // Set up the menu in a moment, after m_manageTemplatesAction constructed
Chris@435 557
Chris@435 558 action = new QAction(tr("Export Session as Template..."), this);
Chris@435 559 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate()));
Chris@436 560 // We need to have something in the session for this to be useful:
Chris@436 561 // canDeleteCurrentLayer captures that
Chris@436 562 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
Chris@435 563 menu->addAction(action);
Chris@435 564
Chris@436 565 m_manageTemplatesAction = new QAction(tr("Manage Exported Templates"), this);
Chris@436 566 connect(m_manageTemplatesAction, SIGNAL(triggered()), this, SLOT(manageSavedTemplates()));
Chris@436 567 menu->addAction(m_manageTemplatesAction);
Chris@436 568
Chris@436 569 setupTemplatesMenu();
Chris@425 570
Chris@66 571 action = new QAction(tr("&Preferences..."), this);
Chris@66 572 action->setStatusTip(tr("Adjust the application preferences"));
Chris@66 573 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@66 574 menu->addAction(action);
Chris@0 575
Chris@66 576 menu->addSeparator();
Chris@168 577 action = new QAction(il.load("exit"),
Chris@66 578 tr("&Quit"), this);
Chris@66 579 action->setShortcut(tr("Ctrl+Q"));
Chris@518 580 action->setStatusTip(tr("Exit %1").arg(QApplication::applicationName()));
Chris@500 581 connect(action, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
Chris@162 582 m_keyReference->registerShortcut(action);
Chris@66 583 menu->addAction(action);
Chris@66 584 }
Chris@66 585
Chris@66 586 void
Chris@66 587 MainWindow::setupEditMenu()
Chris@66 588 {
Chris@66 589 if (m_mainMenusCreated) return;
Chris@66 590
Chris@66 591 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
Chris@97 592 menu->setTearOffEnabled(true);
Chris@66 593 CommandHistory::getInstance()->registerMenu(menu);
Chris@66 594
Chris@162 595 m_keyReference->setCategory(tr("Editing"));
Chris@162 596
Chris@66 597 menu->addSeparator();
Chris@66 598
Chris@168 599 IconLoader il;
Chris@168 600
Chris@168 601 QAction *action = new QAction(il.load("editcut"),
Chris@66 602 tr("Cu&t"), this);
Chris@66 603 action->setShortcut(tr("Ctrl+X"));
Chris@90 604 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
Chris@66 605 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
Chris@66 606 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 607 m_keyReference->registerShortcut(action);
Chris@66 608 menu->addAction(action);
Chris@66 609 m_rightButtonMenu->addAction(action);
Chris@66 610
Chris@168 611 action = new QAction(il.load("editcopy"),
Chris@66 612 tr("&Copy"), this);
Chris@66 613 action->setShortcut(tr("Ctrl+C"));
Chris@90 614 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
Chris@66 615 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
Chris@66 616 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 617 m_keyReference->registerShortcut(action);
Chris@66 618 menu->addAction(action);
Chris@66 619 m_rightButtonMenu->addAction(action);
Chris@66 620
Chris@168 621 action = new QAction(il.load("editpaste"),
Chris@66 622 tr("&Paste"), this);
Chris@66 623 action->setShortcut(tr("Ctrl+V"));
Chris@90 624 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
Chris@66 625 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
Chris@66 626 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@162 627 m_keyReference->registerShortcut(action);
Chris@66 628 menu->addAction(action);
Chris@66 629 m_rightButtonMenu->addAction(action);
Chris@66 630
Chris@395 631 action = new QAction(tr("Paste at Playback Position"), this);
Chris@395 632 action->setShortcut(tr("Ctrl+Shift+V"));
Chris@395 633 action->setStatusTip(tr("Paste from the clipboard to the current layer, placing the first item at the playback position"));
Chris@395 634 connect(action, SIGNAL(triggered()), this, SLOT(pasteAtPlaybackPosition()));
Chris@395 635 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
Chris@395 636 m_keyReference->registerShortcut(action);
Chris@395 637 menu->addAction(action);
Chris@395 638 m_rightButtonMenu->addAction(action);
Chris@395 639
Chris@164 640 m_deleteSelectedAction = new QAction(tr("&Delete Selected Items"), this);
Chris@164 641 m_deleteSelectedAction->setShortcut(tr("Del"));
Chris@164 642 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 643 connect(m_deleteSelectedAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
Chris@164 644 connect(this, SIGNAL(canDeleteSelection(bool)), m_deleteSelectedAction, SLOT(setEnabled(bool)));
Chris@164 645 m_keyReference->registerShortcut(m_deleteSelectedAction);
Chris@164 646 menu->addAction(m_deleteSelectedAction);
Chris@164 647 m_rightButtonMenu->addAction(m_deleteSelectedAction);
Chris@66 648
Chris@66 649 menu->addSeparator();
Chris@66 650 m_rightButtonMenu->addSeparator();
Chris@162 651
Chris@162 652 m_keyReference->setCategory(tr("Selection"));
Chris@162 653
Chris@66 654 action = new QAction(tr("Select &All"), this);
Chris@66 655 action->setShortcut(tr("Ctrl+A"));
Chris@90 656 action->setStatusTip(tr("Select the whole duration of the current session"));
Chris@66 657 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
Chris@66 658 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 659 m_keyReference->registerShortcut(action);
Chris@66 660 menu->addAction(action);
Chris@66 661 m_rightButtonMenu->addAction(action);
Chris@0 662
Chris@66 663 action = new QAction(tr("Select &Visible Range"), this);
Chris@66 664 action->setShortcut(tr("Ctrl+Shift+A"));
Chris@90 665 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
Chris@66 666 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
Chris@66 667 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 668 m_keyReference->registerShortcut(action);
Chris@66 669 menu->addAction(action);
Chris@0 670
Chris@66 671 action = new QAction(tr("Select to &Start"), this);
Chris@66 672 action->setShortcut(tr("Shift+Left"));
Chris@90 673 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
Chris@66 674 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
Chris@66 675 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 676 m_keyReference->registerShortcut(action);
Chris@66 677 menu->addAction(action);
Chris@0 678
Chris@66 679 action = new QAction(tr("Select to &End"), this);
Chris@66 680 action->setShortcut(tr("Shift+Right"));
Chris@90 681 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
Chris@66 682 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
Chris@66 683 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
Chris@162 684 m_keyReference->registerShortcut(action);
Chris@66 685 menu->addAction(action);
Chris@66 686
Chris@66 687 action = new QAction(tr("C&lear Selection"), this);
Chris@66 688 action->setShortcut(tr("Esc"));
Chris@90 689 action->setStatusTip(tr("Clear the selection"));
Chris@66 690 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
Chris@66 691 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@162 692 m_keyReference->registerShortcut(action);
Chris@66 693 menu->addAction(action);
Chris@66 694 m_rightButtonMenu->addAction(action);
Chris@66 695
Chris@66 696 menu->addSeparator();
Chris@66 697
Chris@162 698 m_keyReference->setCategory(tr("Tapping Time Instants"));
Chris@162 699
Chris@66 700 action = new QAction(tr("&Insert Instant at Playback Position"), this);
Chris@66 701 action->setShortcut(tr("Enter"));
Chris@90 702 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
Chris@66 703 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
Chris@66 704 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
Chris@162 705 m_keyReference->registerShortcut(action);
Chris@66 706 menu->addAction(action);
Chris@66 707
Chris@162 708 // Laptop shortcut (no keypad Enter key)
Chris@162 709 QString shortcut(tr(";"));
Chris@162 710 connect(new QShortcut(shortcut, this), SIGNAL(activated()),
Chris@162 711 this, SLOT(insertInstant()));
Chris@162 712 m_keyReference->registerAlternativeShortcut(action, shortcut);
Chris@162 713
Chris@81 714 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
Chris@81 715 action->setShortcut(tr("Shift+Enter"));
Chris@163 716 action->setStatusTip(tr("Insert new time instants at the start and end of the current selected regions, in a new layer if necessary"));
Chris@81 717 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
Chris@81 718 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
Chris@162 719 m_keyReference->registerShortcut(action);
Chris@81 720 menu->addAction(action);
Chris@189 721
Chris@338 722 action = new QAction(tr("Insert Item at Selection"), this);
Chris@338 723 action->setShortcut(tr("Ctrl+Shift+Enter"));
Chris@338 724 action->setStatusTip(tr("Insert a new note or region item corresponding to the current selection"));
Chris@338 725 connect(action, SIGNAL(triggered()), this, SLOT(insertItemAtSelection()));
Chris@338 726 connect(this, SIGNAL(canInsertItemAtSelection(bool)), action, SLOT(setEnabled(bool)));
Chris@338 727 m_keyReference->registerShortcut(action);
Chris@338 728 menu->addAction(action);
Chris@338 729
Chris@338 730 menu->addSeparator();
Chris@338 731
Chris@190 732 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with"));
Chris@225 733 numberingMenu->setTearOffEnabled(true);
Chris@189 734 QActionGroup *numberingGroup = new QActionGroup(this);
Chris@189 735
Chris@189 736 Labeller::TypeNameMap types = m_labeller->getTypeNames();
Chris@189 737 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) {
Chris@190 738
Chris@190 739 if (i->first == Labeller::ValueFromLabel ||
Chris@190 740 i->first == Labeller::ValueFromExistingNeighbour) continue;
Chris@190 741
Chris@189 742 action = new QAction(i->second, this);
Chris@189 743 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering()));
Chris@189 744 action->setCheckable(true);
Chris@189 745 action->setChecked(m_labeller->getType() == i->first);
Chris@189 746 numberingGroup->addAction(action);
Chris@189 747 numberingMenu->addAction(action);
Chris@189 748 m_numberingActions[action] = (int)i->first;
Chris@190 749
Chris@190 750 if (i->first == Labeller::ValueFromTwoLevelCounter) {
Chris@192 751
Chris@190 752 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size"));
Chris@190 753 QActionGroup *cycleGroup = new QActionGroup(this);
Chris@190 754
Chris@229 755 int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 16 };
Chris@200 756 for (int i = 0; i < int(sizeof(cycles)/sizeof(cycles[0])); ++i) {
Chris@190 757 action = new QAction(QString("%1").arg(cycles[i]), this);
Chris@190 758 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle()));
Chris@190 759 action->setCheckable(true);
Chris@190 760 action->setChecked(cycles[i] == m_labeller->getCounterCycleSize());
Chris@190 761 cycleGroup->addAction(action);
Chris@190 762 cycleMenu->addAction(action);
Chris@190 763 }
Chris@190 764 }
Chris@190 765
Chris@190 766 if (i->first == Labeller::ValueNone ||
Chris@190 767 i->first == Labeller::ValueFromTwoLevelCounter ||
Chris@190 768 i->first == Labeller::ValueFromRealTime) {
Chris@190 769 numberingMenu->addSeparator();
Chris@190 770 }
Chris@189 771 }
Chris@189 772
Chris@241 773 action = new QAction(tr("Set Numbering Counters..."), this);
Chris@241 774 action->setStatusTip(tr("Set the counters used for counter-based labelling"));
Chris@241 775 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters()));
Chris@241 776 menu->addAction(action);
Chris@241 777
Chris@241 778 action = new QAction(tr("Renumber Selected Instants"), this);
Chris@241 779 action->setStatusTip(tr("Renumber the selected instants using the current labelling scheme"));
Chris@189 780 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants()));
Chris@189 781 connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool)));
Chris@189 782 // m_keyReference->registerShortcut(action);
Chris@189 783 menu->addAction(action);
Chris@66 784 }
Chris@66 785
Chris@66 786 void
Chris@66 787 MainWindow::setupViewMenu()
Chris@66 788 {
Chris@66 789 if (m_mainMenusCreated) return;
Chris@66 790
Chris@168 791 IconLoader il;
Chris@168 792
Chris@90 793 QAction *action = 0;
Chris@90 794
Chris@162 795 m_keyReference->setCategory(tr("Panning and Navigation"));
Chris@162 796
Chris@66 797 QMenu *menu = menuBar()->addMenu(tr("&View"));
Chris@97 798 menu->setTearOffEnabled(true);
Chris@494 799 m_scrollLeftAction = new QAction(tr("Scroll &Left"), this);
Chris@494 800 m_scrollLeftAction->setShortcut(tr("Left"));
Chris@494 801 m_scrollLeftAction->setStatusTip(tr("Scroll the current pane to the left"));
Chris@494 802 connect(m_scrollLeftAction, SIGNAL(triggered()), this, SLOT(scrollLeft()));
Chris@494 803 connect(this, SIGNAL(canScroll(bool)), m_scrollLeftAction, SLOT(setEnabled(bool)));
Chris@494 804 m_keyReference->registerShortcut(m_scrollLeftAction);
Chris@494 805 menu->addAction(m_scrollLeftAction);
Chris@0 806
Chris@494 807 m_scrollRightAction = new QAction(tr("Scroll &Right"), this);
Chris@494 808 m_scrollRightAction->setShortcut(tr("Right"));
Chris@494 809 m_scrollRightAction->setStatusTip(tr("Scroll the current pane to the right"));
Chris@494 810 connect(m_scrollRightAction, SIGNAL(triggered()), this, SLOT(scrollRight()));
Chris@494 811 connect(this, SIGNAL(canScroll(bool)), m_scrollRightAction, SLOT(setEnabled(bool)));
Chris@494 812 m_keyReference->registerShortcut(m_scrollRightAction);
Chris@494 813 menu->addAction(m_scrollRightAction);
Chris@0 814
Chris@90 815 action = new QAction(tr("&Jump Left"), this);
Chris@66 816 action->setShortcut(tr("Ctrl+Left"));
Chris@66 817 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
Chris@66 818 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
Chris@66 819 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 820 m_keyReference->registerShortcut(action);
Chris@66 821 menu->addAction(action);
Chris@0 822
Chris@90 823 action = new QAction(tr("J&ump Right"), this);
Chris@66 824 action->setShortcut(tr("Ctrl+Right"));
Chris@66 825 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
Chris@66 826 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
Chris@66 827 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@162 828 m_keyReference->registerShortcut(action);
Chris@66 829 menu->addAction(action);
Chris@66 830
Chris@308 831 action = new QAction(tr("Peek Left"), this);
Chris@308 832 action->setShortcut(tr("Alt+Left"));
Chris@308 833 action->setStatusTip(tr("Scroll the current pane to the left without moving the playback cursor or other panes"));
Chris@308 834 connect(action, SIGNAL(triggered()), this, SLOT(peekLeft()));
Chris@308 835 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@308 836 m_keyReference->registerShortcut(action);
Chris@308 837 menu->addAction(action);
Chris@308 838
Chris@308 839 action = new QAction(tr("Peek Right"), this);
Chris@308 840 action->setShortcut(tr("Alt+Right"));
Chris@308 841 action->setStatusTip(tr("Scroll the current pane to the right without moving the playback cursor or other panes"));
Chris@308 842 connect(action, SIGNAL(triggered()), this, SLOT(peekRight()));
Chris@308 843 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
Chris@308 844 m_keyReference->registerShortcut(action);
Chris@308 845 menu->addAction(action);
Chris@308 846
Chris@66 847 menu->addSeparator();
Chris@66 848
Chris@162 849 m_keyReference->setCategory(tr("Zoom"));
Chris@162 850
Chris@494 851 m_zoomInAction = new QAction(il.load("zoom-in"),
Chris@494 852 tr("Zoom &In"), this);
Chris@494 853 m_zoomInAction->setShortcut(tr("Up"));
Chris@494 854 m_zoomInAction->setStatusTip(tr("Increase the zoom level"));
Chris@494 855 connect(m_zoomInAction, SIGNAL(triggered()), this, SLOT(zoomIn()));
Chris@494 856 connect(this, SIGNAL(canZoom(bool)), m_zoomInAction, SLOT(setEnabled(bool)));
Chris@494 857 m_keyReference->registerShortcut(m_zoomInAction);
Chris@494 858 menu->addAction(m_zoomInAction);
Chris@0 859
Chris@494 860 m_zoomOutAction = new QAction(il.load("zoom-out"),
Chris@494 861 tr("Zoom &Out"), this);
Chris@494 862 m_zoomOutAction->setShortcut(tr("Down"));
Chris@494 863 m_zoomOutAction->setStatusTip(tr("Decrease the zoom level"));
Chris@494 864 connect(m_zoomOutAction, SIGNAL(triggered()), this, SLOT(zoomOut()));
Chris@494 865 connect(this, SIGNAL(canZoom(bool)), m_zoomOutAction, SLOT(setEnabled(bool)));
Chris@494 866 m_keyReference->registerShortcut(m_zoomOutAction);
Chris@494 867 menu->addAction(m_zoomOutAction);
Chris@0 868
Chris@66 869 action = new QAction(tr("Restore &Default Zoom"), this);
Chris@90 870 action->setStatusTip(tr("Restore the zoom level to the default"));
Chris@66 871 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
Chris@66 872 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
Chris@66 873 menu->addAction(action);
Chris@66 874
Chris@494 875 m_zoomFitAction = new QAction(il.load("zoom-fit"),
Chris@494 876 tr("Zoom to &Fit"), this);
Chris@494 877 m_zoomFitAction->setShortcut(tr("F"));
Chris@494 878 m_zoomFitAction->setStatusTip(tr("Zoom to show the whole file"));
Chris@494 879 connect(m_zoomFitAction, SIGNAL(triggered()), this, SLOT(zoomToFit()));
Chris@494 880 connect(this, SIGNAL(canZoom(bool)), m_zoomFitAction, SLOT(setEnabled(bool)));
Chris@494 881 m_keyReference->registerShortcut(m_zoomFitAction);
Chris@494 882 menu->addAction(m_zoomFitAction);
Chris@90 883
Chris@90 884 menu->addSeparator();
Chris@90 885
Chris@162 886 m_keyReference->setCategory(tr("Display Features"));
Chris@162 887
Chris@497 888 action = new QAction(tr("Show &Centre Line"), this);
Chris@497 889 action->setShortcut(tr("'"));
Chris@497 890 action->setStatusTip(tr("Show or hide the centre line"));
Chris@497 891 connect(action, SIGNAL(triggered()), this, SLOT(toggleCentreLine()));
Chris@497 892 action->setCheckable(true);
Chris@497 893 action->setChecked(true);
Chris@497 894 m_keyReference->registerShortcut(action);
Chris@497 895 menu->addAction(action);
Chris@497 896
Chris@497 897 action = new QAction(tr("Toggle All Time Rulers"), this);
Chris@497 898 action->setShortcut(tr("#"));
Chris@497 899 action->setStatusTip(tr("Show or hide all time rulers"));
Chris@497 900 connect(action, SIGNAL(triggered()), this, SLOT(toggleTimeRulers()));
Chris@497 901 m_keyReference->registerShortcut(action);
Chris@497 902 menu->addAction(action);
Chris@497 903
Chris@497 904 menu->addSeparator();
Chris@497 905
Chris@90 906 QActionGroup *overlayGroup = new QActionGroup(this);
Chris@90 907
Chris@90 908 action = new QAction(tr("Show &No Overlays"), this);
Chris@90 909 action->setShortcut(tr("0"));
Chris@497 910 action->setStatusTip(tr("Hide times, layer names, and scale"));
Chris@90 911 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
Chris@90 912 action->setCheckable(true);
Chris@90 913 action->setChecked(false);
Chris@90 914 overlayGroup->addAction(action);
Chris@162 915 m_keyReference->registerShortcut(action);
Chris@90 916 menu->addAction(action);
Chris@90 917
Chris@90 918 action = new QAction(tr("Show &Minimal Overlays"), this);
Chris@90 919 action->setShortcut(tr("9"));
Chris@497 920 action->setStatusTip(tr("Show times and basic scale"));
Chris@90 921 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
Chris@90 922 action->setCheckable(true);
Chris@90 923 action->setChecked(true);
Chris@90 924 overlayGroup->addAction(action);
Chris@162 925 m_keyReference->registerShortcut(action);
Chris@90 926 menu->addAction(action);
Chris@90 927
Chris@90 928 action = new QAction(tr("Show &All Overlays"), this);
Chris@497 929 action->setShortcut(tr("8"));
Chris@497 930 action->setStatusTip(tr("Show times, layer names, and scale"));
Chris@90 931 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
Chris@90 932 action->setCheckable(true);
Chris@90 933 action->setChecked(false);
Chris@90 934 overlayGroup->addAction(action);
Chris@162 935 m_keyReference->registerShortcut(action);
Chris@90 936 menu->addAction(action);
Chris@387 937
Chris@387 938 menu->addSeparator();
Chris@497 939
Chris@66 940 action = new QAction(tr("Show &Zoom Wheels"), this);
Chris@66 941 action->setShortcut(tr("Z"));
Chris@66 942 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
Chris@66 943 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
Chris@66 944 action->setCheckable(true);
Chris@66 945 action->setChecked(m_viewManager->getZoomWheelsEnabled());
Chris@162 946 m_keyReference->registerShortcut(action);
Chris@66 947 menu->addAction(action);
Chris@387 948
Chris@494 949 m_showPropertyBoxesAction = new QAction(tr("Show Property Bo&xes"), this);
Chris@494 950 m_showPropertyBoxesAction->setShortcut(tr("X"));
Chris@494 951 m_showPropertyBoxesAction->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
Chris@494 952 connect(m_showPropertyBoxesAction, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
Chris@494 953 m_showPropertyBoxesAction->setCheckable(true);
Chris@494 954 m_showPropertyBoxesAction->setChecked(true);
Chris@494 955 m_keyReference->registerShortcut(m_showPropertyBoxesAction);
Chris@494 956 menu->addAction(m_showPropertyBoxesAction);
Chris@0 957
Chris@90 958 action = new QAction(tr("Show Status &Bar"), this);
Chris@90 959 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
Chris@90 960 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
Chris@90 961 action->setCheckable(true);
Chris@90 962 action->setChecked(true);
Chris@90 963 menu->addAction(action);
Chris@90 964
Chris@90 965 QSettings settings;
Chris@90 966 settings.beginGroup("MainWindow");
Chris@90 967 bool sb = settings.value("showstatusbar", true).toBool();
Chris@90 968 if (!sb) {
Chris@90 969 action->setChecked(false);
Chris@90 970 statusBar()->hide();
Chris@90 971 }
Chris@90 972 settings.endGroup();
Chris@90 973
Chris@66 974 menu->addSeparator();
Chris@66 975
Chris@219 976 action = new QAction(tr("Show La&yer Summary"), this);
Chris@219 977 action->setShortcut(tr("Y"));
Chris@90 978 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
Chris@66 979 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
Chris@162 980 m_keyReference->registerShortcut(action);
Chris@66 981 menu->addAction(action);
Chris@306 982
Chris@306 983 action = new QAction(tr("Show Acti&vity Log"), this);
Chris@306 984 action->setStatusTip(tr("Open a window listing interactions and other events"));
Chris@306 985 connect(action, SIGNAL(triggered()), this, SLOT(showActivityLog()));
Chris@306 986 menu->addAction(action);
Chris@493 987
Chris@494 988 menu->addSeparator();
Chris@494 989
Chris@493 990 action = new QAction(tr("Go Full-Screen"), this);
Chris@494 991 action->setShortcut(tr("F11"));
Chris@494 992 action->setStatusTip(tr("Expand the pane area to the whole screen"));
Chris@493 993 connect(action, SIGNAL(triggered()), this, SLOT(goFullScreen()));
Chris@494 994 m_keyReference->registerShortcut(action);
Chris@493 995 menu->addAction(action);
Chris@66 996 }
Chris@66 997
Chris@66 998 void
Chris@66 999 MainWindow::setupPaneAndLayerMenus()
Chris@66 1000 {
Chris@0 1001 if (m_paneMenu) {
Chris@0 1002 m_paneActions.clear();
Chris@0 1003 m_paneMenu->clear();
Chris@0 1004 } else {
Chris@0 1005 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
Chris@97 1006 m_paneMenu->setTearOffEnabled(true);
Chris@0 1007 }
Chris@0 1008
Chris@0 1009 if (m_layerMenu) {
Chris@0 1010 m_layerActions.clear();
Chris@0 1011 m_layerMenu->clear();
Chris@0 1012 } else {
Chris@0 1013 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
Chris@97 1014 m_layerMenu->setTearOffEnabled(true);
Chris@0 1015 }
Chris@0 1016
Chris@345 1017 if (m_rightButtonLayerMenu) {
Chris@345 1018 m_rightButtonLayerMenu->clear();
Chris@345 1019 } else {
Chris@345 1020 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
Chris@345 1021 m_rightButtonLayerMenu->setTearOffEnabled(true);
Chris@345 1022 m_rightButtonMenu->addSeparator();
Chris@345 1023 }
Chris@345 1024
Chris@66 1025 QMenu *menu = m_paneMenu;
Chris@66 1026
Chris@168 1027 IconLoader il;
Chris@168 1028
Chris@162 1029 m_keyReference->setCategory(tr("Managing Panes and Layers"));
Chris@162 1030
Chris@168 1031 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
Chris@155 1032 action->setShortcut(tr("N"));
Chris@66 1033 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
Chris@66 1034 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
Chris@66 1035 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
Chris@232 1036 m_paneActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
Chris@162 1037 m_keyReference->registerShortcut(action);
Chris@66 1038 menu->addAction(action);
Chris@66 1039
Chris@66 1040 menu->addSeparator();
Chris@66 1041
Chris@66 1042 menu = m_layerMenu;
Chris@66 1043
Chris@66 1044 // menu->addSeparator();
Chris@66 1045
Chris@66 1046 LayerFactory::LayerTypeSet emptyLayerTypes =
Chris@66 1047 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@66 1048
Chris@66 1049 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
Chris@66 1050 i != emptyLayerTypes.end(); ++i) {
Chris@66 1051
Chris@66 1052 QIcon icon;
Chris@66 1053 QString mainText, tipText, channelText;
Chris@66 1054 LayerFactory::LayerType type = *i;
Chris@66 1055 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
Chris@66 1056
Chris@168 1057 icon = il.load(LayerFactory::getInstance()->getLayerIconName(type));
Chris@66 1058
Chris@66 1059 mainText = tr("Add New %1 Layer").arg(name);
Chris@66 1060 tipText = tr("Add a new empty layer of type %1").arg(name);
Chris@66 1061
Chris@66 1062 action = new QAction(icon, mainText, this);
Chris@66 1063 action->setStatusTip(tipText);
Chris@66 1064
Chris@66 1065 if (type == LayerFactory::Text) {
Chris@155 1066 action->setShortcut(tr("T"));
Chris@162 1067 m_keyReference->registerShortcut(action);
Chris@66 1068 }
Chris@66 1069
Chris@66 1070 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 1071 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@232 1072 m_layerActions[action] = LayerConfiguration(type);
Chris@66 1073 menu->addAction(action);
Chris@66 1074 m_rightButtonLayerMenu->addAction(action);
Chris@66 1075 }
Chris@66 1076
Chris@66 1077 m_rightButtonLayerMenu->addSeparator();
Chris@66 1078 menu->addSeparator();
Chris@66 1079
Chris@66 1080 LayerFactory::LayerType backgroundTypes[] = {
Chris@66 1081 LayerFactory::Waveform,
Chris@66 1082 LayerFactory::Spectrogram,
Chris@66 1083 LayerFactory::MelodicRangeSpectrogram,
Chris@66 1084 LayerFactory::PeakFrequencySpectrogram,
Chris@66 1085 LayerFactory::Spectrum
Chris@66 1086 };
Chris@66 1087
Chris@66 1088 std::vector<Model *> models;
Chris@224 1089 if (m_document) models = m_document->getTransformInputModels();
Chris@66 1090 bool plural = (models.size() > 1);
Chris@66 1091 if (models.empty()) {
Chris@67 1092 models.push_back(getMainModel()); // probably 0
Chris@66 1093 }
Chris@66 1094
Chris@66 1095 for (unsigned int i = 0;
Chris@66 1096 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
Chris@66 1097
Chris@231 1098 const int paneMenuType = 0, layerMenuType = 1;
Chris@231 1099
Chris@231 1100 for (int menuType = paneMenuType; menuType <= layerMenuType; ++menuType) {
Chris@231 1101
Chris@231 1102 if (menuType == paneMenuType) menu = m_paneMenu;
Chris@66 1103 else menu = m_layerMenu;
Chris@66 1104
Chris@66 1105 QMenu *submenu = 0;
Chris@66 1106
Chris@66 1107 QIcon icon;
Chris@66 1108 QString mainText, shortcutText, tipText, channelText;
Chris@66 1109 LayerFactory::LayerType type = backgroundTypes[i];
Chris@66 1110 bool mono = true;
Chris@66 1111
Chris@66 1112 switch (type) {
Chris@66 1113
Chris@66 1114 case LayerFactory::Waveform:
Chris@168 1115 icon = il.load("waveform");
Chris@66 1116 mainText = tr("Add &Waveform");
Chris@231 1117 if (menuType == paneMenuType) {
Chris@155 1118 shortcutText = tr("W");
Chris@66 1119 tipText = tr("Add a new pane showing a waveform view");
Chris@66 1120 } else {
Chris@348 1121 shortcutText = tr("Shift+W");
Chris@66 1122 tipText = tr("Add a new layer showing a waveform view");
Chris@66 1123 }
Chris@66 1124 mono = false;
Chris@66 1125 break;
Chris@66 1126
Chris@66 1127 case LayerFactory::Spectrogram:
Chris@168 1128 icon = il.load("spectrogram");
Chris@161 1129 mainText = tr("Add Spectro&gram");
Chris@231 1130 if (menuType == paneMenuType) {
Chris@155 1131 shortcutText = tr("G");
Chris@90 1132 tipText = tr("Add a new pane showing a spectrogram");
Chris@66 1133 } else {
Chris@348 1134 shortcutText = tr("Shift+G");
Chris@90 1135 tipText = tr("Add a new layer showing a spectrogram");
Chris@66 1136 }
Chris@66 1137 break;
Chris@66 1138
Chris@66 1139 case LayerFactory::MelodicRangeSpectrogram:
Chris@168 1140 icon = il.load("spectrogram");
Chris@66 1141 mainText = tr("Add &Melodic Range Spectrogram");
Chris@231 1142 if (menuType == paneMenuType) {
Chris@155 1143 shortcutText = tr("M");
Chris@90 1144 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
Chris@66 1145 } else {
Chris@348 1146 shortcutText = tr("Shift+M");
Chris@90 1147 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
Chris@66 1148 }
Chris@66 1149 break;
Chris@66 1150
Chris@66 1151 case LayerFactory::PeakFrequencySpectrogram:
Chris@168 1152 icon = il.load("spectrogram");
Chris@155 1153 mainText = tr("Add Pea&k Frequency Spectrogram");
Chris@231 1154 if (menuType == paneMenuType) {
Chris@155 1155 shortcutText = tr("K");
Chris@66 1156 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
Chris@66 1157 } else {
Chris@348 1158 shortcutText = tr("Shift+K");
Chris@66 1159 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
Chris@66 1160 }
Chris@66 1161 break;
Chris@66 1162
Chris@66 1163 case LayerFactory::Spectrum:
Chris@168 1164 icon = il.load("spectrum");
Chris@66 1165 mainText = tr("Add Spectr&um");
Chris@231 1166 if (menuType == paneMenuType) {
Chris@155 1167 shortcutText = tr("U");
Chris@66 1168 tipText = tr("Add a new pane showing a frequency spectrum");
Chris@66 1169 } else {
Chris@348 1170 shortcutText = tr("Shift+U");
Chris@66 1171 tipText = tr("Add a new layer showing a frequency spectrum");
Chris@66 1172 }
Chris@66 1173 break;
Chris@66 1174
Chris@66 1175 default: break;
Chris@66 1176 }
Chris@66 1177
Chris@346 1178 std::vector<Model *> candidateModels = models;
Chris@66 1179
Chris@66 1180 for (std::vector<Model *>::iterator mi =
Chris@66 1181 candidateModels.begin();
Chris@66 1182 mi != candidateModels.end(); ++mi) {
Chris@66 1183
Chris@66 1184 Model *model = *mi;
Chris@66 1185
Chris@66 1186 int channels = 0;
Chris@66 1187 if (model) {
Chris@66 1188 DenseTimeValueModel *dtvm =
Chris@66 1189 dynamic_cast<DenseTimeValueModel *>(model);
Chris@66 1190 if (dtvm) channels = dtvm->getChannelCount();
Chris@66 1191 }
Chris@66 1192 if (channels < 1 && getMainModel()) {
Chris@66 1193 channels = getMainModel()->getChannelCount();
Chris@66 1194 }
Chris@66 1195 if (channels < 1) channels = 1;
Chris@66 1196
Chris@66 1197 for (int c = 0; c <= channels; ++c) {
Chris@66 1198
Chris@66 1199 if (c == 1 && channels == 1) continue;
Chris@66 1200 bool isDefault = (c == 0);
Chris@66 1201 bool isOnly = (isDefault && (channels == 1));
Chris@66 1202
Chris@346 1203 if (isOnly && !plural) {
Chris@346 1204
Chris@346 1205 action = new QAction(icon, mainText, this);
Chris@67 1206
Chris@66 1207 action->setShortcut(shortcutText);
Chris@66 1208 action->setStatusTip(tipText);
Chris@231 1209 if (menuType == paneMenuType) {
Chris@66 1210 connect(action, SIGNAL(triggered()),
Chris@66 1211 this, SLOT(addPane()));
Chris@66 1212 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1213 action, SLOT(setEnabled(bool)));
Chris@346 1214 m_paneActions[action] =
Chris@346 1215 LayerConfiguration(type, model);
Chris@66 1216 } else {
Chris@66 1217 connect(action, SIGNAL(triggered()),
Chris@66 1218 this, SLOT(addLayer()));
Chris@66 1219 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1220 action, SLOT(setEnabled(bool)));
Chris@346 1221 m_layerActions[action] =
Chris@346 1222 LayerConfiguration(type, model);
Chris@66 1223 }
Chris@162 1224 if (shortcutText != "") {
Chris@162 1225 m_keyReference->registerShortcut(action);
Chris@162 1226 }
Chris@66 1227 menu->addAction(action);
Chris@66 1228
Chris@66 1229 } else {
Chris@66 1230
Chris@66 1231 if (!submenu) {
Chris@66 1232 submenu = menu->addMenu(mainText);
Chris@97 1233 submenu->setTearOffEnabled(true);
Chris@67 1234 } else if (isDefault) {
Chris@67 1235 submenu->addSeparator();
Chris@66 1236 }
Chris@66 1237
Chris@66 1238 QString actionText;
Chris@66 1239 if (c == 0) {
Chris@66 1240 if (mono) {
Chris@66 1241 actionText = tr("&All Channels Mixed");
Chris@66 1242 } else {
Chris@66 1243 actionText = tr("&All Channels");
Chris@66 1244 }
Chris@66 1245 } else {
Chris@66 1246 actionText = tr("Channel &%1").arg(c);
Chris@66 1247 }
Chris@66 1248
Chris@66 1249 if (model) {
Chris@66 1250 actionText = tr("%1: %2")
Chris@66 1251 .arg(model->objectName())
Chris@66 1252 .arg(actionText);
Chris@66 1253 }
Chris@67 1254
Chris@67 1255 if (isDefault) {
Chris@67 1256 action = new QAction(icon, actionText, this);
Chris@67 1257 if (!model || model == getMainModel()) {
Chris@162 1258 action->setShortcut(shortcutText);
Chris@67 1259 }
Chris@67 1260 } else {
Chris@67 1261 action = new QAction(actionText, this);
Chris@67 1262 }
Chris@67 1263
Chris@66 1264 action->setStatusTip(tipText);
Chris@66 1265
Chris@231 1266 if (menuType == paneMenuType) {
Chris@66 1267 connect(action, SIGNAL(triggered()),
Chris@66 1268 this, SLOT(addPane()));
Chris@66 1269 connect(this, SIGNAL(canAddPane(bool)),
Chris@66 1270 action, SLOT(setEnabled(bool)));
Chris@66 1271 m_paneActions[action] =
Chris@232 1272 LayerConfiguration(type, model, c - 1);
Chris@66 1273 } else {
Chris@66 1274 connect(action, SIGNAL(triggered()),
Chris@66 1275 this, SLOT(addLayer()));
Chris@66 1276 connect(this, SIGNAL(canAddLayer(bool)),
Chris@66 1277 action, SLOT(setEnabled(bool)));
Chris@232 1278 m_layerActions[action] =
Chris@232 1279 LayerConfiguration(type, model, c - 1);
Chris@66 1280 }
Chris@66 1281
Chris@66 1282 submenu->addAction(action);
Chris@66 1283 }
Chris@346 1284
Chris@415 1285 if (isDefault && menuType == layerMenuType &&
Chris@415 1286 mi == candidateModels.begin()) {
Chris@415 1287 // only add for one model, one channel, one menu on
Chris@415 1288 // right button -- the action itself will discover
Chris@415 1289 // which model is the correct one (based on pane)
Chris@346 1290 action = new QAction(icon, mainText, this);
Chris@346 1291 action->setStatusTip(tipText);
Chris@346 1292 connect(action, SIGNAL(triggered()),
Chris@346 1293 this, SLOT(addLayer()));
Chris@346 1294 connect(this, SIGNAL(canAddLayer(bool)),
Chris@346 1295 action, SLOT(setEnabled(bool)));
Chris@346 1296 m_layerActions[action] = LayerConfiguration(type, 0, 0);
Chris@346 1297 m_rightButtonLayerMenu->addAction(action);
Chris@346 1298 }
Chris@66 1299 }
Chris@66 1300 }
Chris@66 1301 }
Chris@66 1302 }
Chris@66 1303
Chris@347 1304 m_rightButtonLayerMenu->addSeparator();
Chris@347 1305
Chris@66 1306 menu = m_paneMenu;
Chris@225 1307 menu->addSeparator();
Chris@225 1308
Chris@225 1309 action = new QAction(tr("Switch to Previous Pane"), this);
Chris@225 1310 action->setShortcut(tr("["));
Chris@225 1311 action->setStatusTip(tr("Make the next pane up in the pane stack current"));
Chris@225 1312 connect(action, SIGNAL(triggered()), this, SLOT(previousPane()));
Chris@225 1313 connect(this, SIGNAL(canSelectPreviousPane(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1314 m_keyReference->registerShortcut(action);
Chris@225 1315 menu->addAction(action);
Chris@225 1316
Chris@225 1317 action = new QAction(tr("Switch to Next Pane"), this);
Chris@225 1318 action->setShortcut(tr("]"));
Chris@225 1319 action->setStatusTip(tr("Make the next pane down in the pane stack current"));
Chris@225 1320 connect(action, SIGNAL(triggered()), this, SLOT(nextPane()));
Chris@225 1321 connect(this, SIGNAL(canSelectNextPane(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1322 m_keyReference->registerShortcut(action);
Chris@225 1323 menu->addAction(action);
Chris@66 1324
Chris@66 1325 menu->addSeparator();
Chris@66 1326
Chris@168 1327 action = new QAction(il.load("editdelete"), tr("&Delete Pane"), this);
Chris@155 1328 action->setShortcut(tr("Ctrl+Shift+D"));
Chris@90 1329 action->setStatusTip(tr("Delete the currently active pane"));
Chris@66 1330 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
Chris@66 1331 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1332 m_keyReference->registerShortcut(action);
Chris@66 1333 menu->addAction(action);
Chris@66 1334
Chris@66 1335 menu = m_layerMenu;
Chris@66 1336
Chris@168 1337 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
Chris@66 1338 action->setStatusTip(tr("Add a new layer showing a time ruler"));
Chris@66 1339 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@66 1340 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@232 1341 m_layerActions[action] = LayerConfiguration(LayerFactory::TimeRuler);
Chris@66 1342 menu->addAction(action);
Chris@66 1343
Chris@66 1344 menu->addSeparator();
Chris@66 1345
Chris@66 1346 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
Chris@97 1347 m_existingLayersMenu->setTearOffEnabled(true);
Chris@66 1348 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
Chris@95 1349
Chris@95 1350 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
Chris@97 1351 m_sliceMenu->setTearOffEnabled(true);
Chris@95 1352 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
Chris@95 1353
Chris@95 1354 setupExistingLayersMenus();
Chris@66 1355
Chris@225 1356 /*!!! These don't work correctly -- fix or omit
Chris@225 1357 menu->addSeparator();
Chris@225 1358
Chris@225 1359 action = new QAction(tr("Switch to Previous Layer"), this);
Chris@225 1360 action->setShortcut(tr("{"));
Chris@225 1361 action->setStatusTip(tr("Make the previous layer in the pane current"));
Chris@225 1362 connect(action, SIGNAL(triggered()), this, SLOT(previousLayer()));
Chris@225 1363 connect(this, SIGNAL(canSelectPreviousLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1364 m_keyReference->registerShortcut(action);
Chris@225 1365 menu->addAction(action);
Chris@225 1366
Chris@225 1367 action = new QAction(tr("Switch to Next Layer"), this);
Chris@225 1368 action->setShortcut(tr("}"));
Chris@225 1369 action->setStatusTip(tr("Make the next layer in the pane current"));
Chris@225 1370 connect(action, SIGNAL(triggered()), this, SLOT(nextLayer()));
Chris@225 1371 connect(this, SIGNAL(canSelectNextLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@225 1372 m_keyReference->registerShortcut(action);
Chris@225 1373 menu->addAction(action);
Chris@225 1374 */
Chris@66 1375 m_rightButtonLayerMenu->addSeparator();
Chris@66 1376 menu->addSeparator();
Chris@66 1377
Chris@163 1378 QAction *raction = new QAction(tr("&Rename Layer..."), this);
Chris@163 1379 raction->setShortcut(tr("R"));
Chris@163 1380 raction->setStatusTip(tr("Rename the currently active layer"));
Chris@163 1381 connect(raction, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
Chris@163 1382 connect(this, SIGNAL(canRenameLayer(bool)), raction, SLOT(setEnabled(bool)));
Chris@163 1383 menu->addAction(raction);
Chris@163 1384 m_rightButtonLayerMenu->addAction(raction);
Chris@66 1385
Chris@258 1386 QAction *eaction = new QAction(tr("Edit Layer Data"), this);
Chris@258 1387 eaction->setShortcut(tr("E"));
Chris@258 1388 eaction->setStatusTip(tr("Edit the currently active layer as a data grid"));
Chris@258 1389 connect(eaction, SIGNAL(triggered()), this, SLOT(editCurrentLayer()));
Chris@291 1390 connect(this, SIGNAL(canEditLayerTabular(bool)), eaction, SLOT(setEnabled(bool)));
Chris@258 1391 menu->addAction(eaction);
Chris@258 1392 m_rightButtonLayerMenu->addAction(eaction);
Chris@258 1393
Chris@168 1394 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
Chris@155 1395 action->setShortcut(tr("Ctrl+D"));
Chris@66 1396 action->setStatusTip(tr("Delete the currently active layer"));
Chris@66 1397 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
Chris@66 1398 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@162 1399 m_keyReference->registerShortcut(action);
Chris@66 1400 menu->addAction(action);
Chris@66 1401 m_rightButtonLayerMenu->addAction(action);
Chris@163 1402
Chris@163 1403 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
Chris@258 1404 m_keyReference->registerShortcut(eaction); // edit also after delete
Chris@66 1405 }
Chris@66 1406
Chris@66 1407 void
Chris@211 1408 MainWindow::setupTransformsMenu()
Chris@66 1409 {
Chris@34 1410 if (m_transformsMenu) {
Chris@34 1411 m_transformActions.clear();
Chris@34 1412 m_transformActionsReverse.clear();
Chris@34 1413 m_transformsMenu->clear();
Chris@34 1414 } else {
Chris@97 1415 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
Chris@97 1416 m_transformsMenu->setTearOffEnabled(true);
Chris@286 1417 m_transformsMenu->setSeparatorsCollapsible(true);
Chris@272 1418 }
Chris@34 1419
Chris@288 1420 TransformFactory *factory = TransformFactory::getInstance();
Chris@288 1421
Chris@288 1422 TransformList transforms = factory->getAllTransformDescriptions();
Chris@288 1423 vector<TransformDescription::Type> types = factory->getAllTransformTypes();
Chris@288 1424
Chris@288 1425 map<TransformDescription::Type, map<QString, SubdividingMenu *> > categoryMenus;
Chris@288 1426 map<TransformDescription::Type, map<QString, SubdividingMenu *> > makerMenus;
Chris@288 1427
Chris@288 1428 map<TransformDescription::Type, SubdividingMenu *> byPluginNameMenus;
Chris@288 1429 map<TransformDescription::Type, map<QString, QMenu *> > pluginNameMenus;
Chris@33 1430
Chris@37 1431 set<SubdividingMenu *> pendingMenus;
Chris@37 1432
Chris@211 1433 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
Chris@211 1434 m_recentTransformsMenu->setTearOffEnabled(true);
Chris@211 1435 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
Chris@211 1436 connect(&m_recentTransforms, SIGNAL(recentChanged()),
Chris@211 1437 this, SLOT(setupRecentTransformsMenu()));
Chris@34 1438
Chris@34 1439 m_transformsMenu->addSeparator();
Chris@211 1440 m_rightButtonTransformsMenu->addSeparator();
Chris@34 1441
Chris@288 1442 for (vector<TransformDescription::Type>::iterator i = types.begin();
Chris@288 1443 i != types.end(); ++i) {
Chris@33 1444
Chris@33 1445 if (i != types.begin()) {
Chris@34 1446 m_transformsMenu->addSeparator();
Chris@211 1447 m_rightButtonTransformsMenu->addSeparator();
Chris@33 1448 }
Chris@33 1449
Chris@288 1450 QString byCategoryLabel = tr("%1 by Category")
Chris@288 1451 .arg(factory->getTransformTypeName(*i));
Chris@37 1452 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
Chris@37 1453 20, 40);
Chris@97 1454 byCategoryMenu->setTearOffEnabled(true);
Chris@37 1455 m_transformsMenu->addMenu(byCategoryMenu);
Chris@211 1456 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
Chris@37 1457 pendingMenus.insert(byCategoryMenu);
Chris@33 1458
Chris@288 1459 vector<QString> categories = factory->getTransformCategories(*i);
Chris@33 1460
Chris@33 1461 for (vector<QString>::iterator j = categories.begin();
Chris@33 1462 j != categories.end(); ++j) {
Chris@33 1463
Chris@33 1464 QString category = *j;
Chris@33 1465 if (category == "") category = tr("Unclassified");
Chris@33 1466
Chris@33 1467 if (categories.size() < 2) {
Chris@33 1468 categoryMenus[*i][category] = byCategoryMenu;
Chris@33 1469 continue;
Chris@33 1470 }
Chris@33 1471
Chris@33 1472 QStringList components = category.split(" > ");
Chris@33 1473 QString key;
Chris@33 1474
Chris@33 1475 for (QStringList::iterator k = components.begin();
Chris@33 1476 k != components.end(); ++k) {
Chris@33 1477
Chris@33 1478 QString parentKey = key;
Chris@33 1479 if (key != "") key += " > ";
Chris@33 1480 key += *k;
Chris@33 1481
Chris@33 1482 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
Chris@37 1483 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
Chris@97 1484 m->setTearOffEnabled(true);
Chris@37 1485 pendingMenus.insert(m);
Chris@37 1486 categoryMenus[*i][key] = m;
Chris@33 1487 if (parentKey == "") {
Chris@37 1488 byCategoryMenu->addMenu(m);
Chris@33 1489 } else {
Chris@37 1490 categoryMenus[*i][parentKey]->addMenu(m);
Chris@33 1491 }
Chris@33 1492 }
Chris@33 1493 }
Chris@33 1494 }
Chris@33 1495
Chris@288 1496 QString byPluginNameLabel = tr("%1 by Plugin Name")
Chris@288 1497 .arg(factory->getTransformTypeName(*i));
Chris@36 1498 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
Chris@97 1499 byPluginNameMenus[*i]->setTearOffEnabled(true);
Chris@36 1500 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@211 1501 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
Chris@37 1502 pendingMenus.insert(byPluginNameMenus[*i]);
Chris@34 1503
Chris@288 1504 QString byMakerLabel = tr("%1 by Maker")
Chris@288 1505 .arg(factory->getTransformTypeName(*i));
Chris@37 1506 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
Chris@97 1507 byMakerMenu->setTearOffEnabled(true);
Chris@37 1508 m_transformsMenu->addMenu(byMakerMenu);
Chris@211 1509 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
Chris@37 1510 pendingMenus.insert(byMakerMenu);
Chris@33 1511
Chris@288 1512 vector<QString> makers = factory->getTransformMakers(*i);
Chris@37 1513
Chris@33 1514 for (vector<QString>::iterator j = makers.begin();
Chris@33 1515 j != makers.end(); ++j) {
Chris@33 1516
Chris@33 1517 QString maker = *j;
Chris@33 1518 if (maker == "") maker = tr("Unknown");
Chris@55 1519 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@55 1520
Chris@37 1521 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
Chris@97 1522 makerMenus[*i][maker]->setTearOffEnabled(true);
Chris@37 1523 byMakerMenu->addMenu(makerMenus[*i][maker]);
Chris@37 1524 pendingMenus.insert(makerMenus[*i][maker]);
Chris@33 1525 }
Chris@0 1526 }
Chris@0 1527
Chris@230 1528 // Names should only be duplicated here if they have the same
Chris@230 1529 // plugin name, output name and maker but are in different library
Chris@230 1530 // .so names -- that won't happen often I hope
Chris@230 1531 std::map<QString, QString> idNameSonameMap;
Chris@230 1532 std::set<QString> seenNames, duplicateNames;
Chris@230 1533 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@230 1534 QString name = transforms[i].name;
Chris@230 1535 if (seenNames.find(name) != seenNames.end()) {
Chris@230 1536 duplicateNames.insert(name);
Chris@230 1537 } else {
Chris@230 1538 seenNames.insert(name);
Chris@230 1539 }
Chris@230 1540 }
Chris@230 1541
Chris@0 1542 for (unsigned int i = 0; i < transforms.size(); ++i) {
Chris@0 1543
Chris@107 1544 QString name = transforms[i].name;
Chris@107 1545 if (name == "") name = transforms[i].identifier;
Chris@107 1546
Chris@432 1547 // std::cerr << "Plugin Name: " << name << std::endl;
Chris@80 1548
Chris@288 1549 TransformDescription::Type type = transforms[i].type;
Chris@288 1550 QString typeStr = factory->getTransformTypeName(type);
Chris@33 1551
Chris@33 1552 QString category = transforms[i].category;
Chris@33 1553 if (category == "") category = tr("Unclassified");
Chris@33 1554
Chris@33 1555 QString maker = transforms[i].maker;
Chris@33 1556 if (maker == "") maker = tr("Unknown");
Chris@55 1557 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
Chris@33 1558
Chris@107 1559 QString pluginName = name.section(": ", 0, 0);
Chris@107 1560 QString output = name.section(": ", 1);
Chris@107 1561
Chris@230 1562 if (duplicateNames.find(pluginName) != duplicateNames.end()) {
Chris@230 1563 pluginName = QString("%1 <%2>")
Chris@230 1564 .arg(pluginName)
Chris@230 1565 .arg(transforms[i].identifier.section(':', 1, 1));
Chris@230 1566 if (output == "") name = pluginName;
Chris@230 1567 else name = QString("%1: %2")
Chris@230 1568 .arg(pluginName)
Chris@230 1569 .arg(output);
Chris@230 1570 }
Chris@230 1571
Chris@107 1572 QAction *action = new QAction(tr("%1...").arg(name), this);
Chris@0 1573 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1574 m_transformActions[action] = transforms[i].identifier;
Chris@107 1575 m_transformActionsReverse[transforms[i].identifier] = action;
Chris@0 1576 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@33 1577
Chris@272 1578 action->setStatusTip(transforms[i].longDescription);
Chris@90 1579
Chris@33 1580 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
Chris@33 1581 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1582 << "No category menu for transform \""
Chris@432 1583 << name << "\" (category = \""
Chris@432 1584 << category << "\")" << std::endl;
Chris@33 1585 } else {
Chris@33 1586 categoryMenus[type][category]->addAction(action);
Chris@33 1587 }
Chris@33 1588
Chris@33 1589 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
Chris@33 1590 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
Chris@33 1591 << "No maker menu for transform \""
Chris@432 1592 << name << "\" (maker = \""
Chris@432 1593 << maker << "\")" << std::endl;
Chris@33 1594 } else {
Chris@80 1595 makerMenus[type][maker]->addAction(action);
Chris@33 1596 }
Chris@33 1597
Chris@33 1598 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
Chris@33 1599 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@107 1600 m_transformActions[action] = transforms[i].identifier;
Chris@33 1601 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@272 1602 action->setStatusTip(transforms[i].longDescription);
Chris@33 1603
Chris@432 1604 // cerr << "Transform: \"" << name << "\": plugin name \"" << pluginName << "\"" << endl;
Chris@34 1605
Chris@33 1606 if (pluginNameMenus[type].find(pluginName) ==
Chris@33 1607 pluginNameMenus[type].end()) {
Chris@33 1608
Chris@36 1609 SubdividingMenu *parentMenu = byPluginNameMenus[type];
Chris@97 1610 parentMenu->setTearOffEnabled(true);
Chris@34 1611
Chris@33 1612 if (output == "") {
Chris@36 1613 parentMenu->addAction(pluginName, action);
Chris@33 1614 } else {
Chris@34 1615 pluginNameMenus[type][pluginName] =
Chris@34 1616 parentMenu->addMenu(pluginName);
Chris@33 1617 connect(this, SIGNAL(canAddLayer(bool)),
Chris@33 1618 pluginNameMenus[type][pluginName],
Chris@33 1619 SLOT(setEnabled(bool)));
Chris@33 1620 }
Chris@33 1621 }
Chris@33 1622
Chris@33 1623 if (pluginNameMenus[type].find(pluginName) !=
Chris@33 1624 pluginNameMenus[type].end()) {
Chris@33 1625 pluginNameMenus[type][pluginName]->addAction(action);
Chris@33 1626 }
Chris@0 1627 }
Chris@0 1628
Chris@37 1629 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
Chris@37 1630 i != pendingMenus.end(); ++i) {
Chris@37 1631 (*i)->entriesAdded();
Chris@37 1632 }
Chris@37 1633
Chris@273 1634 m_transformsMenu->addSeparator();
Chris@273 1635 m_rightButtonTransformsMenu->addSeparator();
Chris@273 1636
Chris@273 1637 QAction *action = new QAction(tr("Find a Transform..."), this);
Chris@273 1638 action->setStatusTip(tr("Search for a transform from the installed plugins, by name or description"));
Chris@275 1639 action->setShortcut(tr("Ctrl+M"));
Chris@273 1640 connect(action, SIGNAL(triggered()), this, SLOT(findTransform()));
Chris@287 1641 // connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@275 1642 m_keyReference->registerShortcut(action);
Chris@273 1643 m_transformsMenu->addAction(action);
Chris@273 1644 m_rightButtonTransformsMenu->addAction(action);
Chris@273 1645
Chris@211 1646 setupRecentTransformsMenu();
Chris@66 1647 }
Chris@66 1648
Chris@66 1649 void
Chris@66 1650 MainWindow::setupHelpMenu()
Chris@66 1651 {
Chris@66 1652 QMenu *menu = menuBar()->addMenu(tr("&Help"));
Chris@97 1653 menu->setTearOffEnabled(true);
Chris@66 1654
Chris@162 1655 m_keyReference->setCategory(tr("Help"));
Chris@162 1656
Chris@168 1657 IconLoader il;
Chris@168 1658
Chris@518 1659 QString name = QApplication::applicationName();
Chris@518 1660
Chris@168 1661 QAction *action = new QAction(il.load("help"),
Chris@138 1662 tr("&Help Reference"), this);
Chris@162 1663 action->setShortcut(tr("F1"));
Chris@518 1664 action->setStatusTip(tr("Open the %1 reference manual").arg(name));
Chris@66 1665 connect(action, SIGNAL(triggered()), this, SLOT(help()));
Chris@162 1666 m_keyReference->registerShortcut(action);
Chris@0 1667 menu->addAction(action);
Chris@162 1668
Chris@163 1669 action = new QAction(tr("&Key and Mouse Reference"), this);
Chris@162 1670 action->setShortcut(tr("F2"));
Chris@518 1671 action->setStatusTip(tr("Open a window showing the keystrokes you can use in %1").arg(name));
Chris@162 1672 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
Chris@162 1673 m_keyReference->registerShortcut(action);
Chris@162 1674 menu->addAction(action);
Chris@66 1675
Chris@518 1676 action = new QAction(tr("%1 on the &Web").arg(name), this);
Chris@518 1677 action->setStatusTip(tr("Open the %1 website").arg(name));
Chris@164 1678 connect(action, SIGNAL(triggered()), this, SLOT(website()));
Chris@164 1679 menu->addAction(action);
Chris@164 1680
Chris@518 1681 action = new QAction(tr("&About %1").arg(name), this);
Chris@518 1682 action->setStatusTip(tr("Show information about %1").arg(name));
Chris@66 1683 connect(action, SIGNAL(triggered()), this, SLOT(about()));
Chris@0 1684 menu->addAction(action);
Chris@0 1685 }
Chris@0 1686
Chris@0 1687 void
Chris@0 1688 MainWindow::setupRecentFilesMenu()
Chris@0 1689 {
Chris@0 1690 m_recentFilesMenu->clear();
Chris@34 1691 vector<QString> files = m_recentFiles.getRecent();
Chris@0 1692 for (size_t i = 0; i < files.size(); ++i) {
Chris@0 1693 QAction *action = new QAction(files[i], this);
Chris@0 1694 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
Chris@162 1695 if (i == 0) {
Chris@162 1696 action->setShortcut(tr("Ctrl+R"));
Chris@162 1697 m_keyReference->registerShortcut
Chris@163 1698 (tr("Re-open"),
Chris@163 1699 action->shortcut(),
Chris@163 1700 tr("Re-open the current or most recently opened file"));
Chris@162 1701 }
Chris@0 1702 m_recentFilesMenu->addAction(action);
Chris@0 1703 }
Chris@0 1704 }
Chris@0 1705
Chris@0 1706 void
Chris@423 1707 MainWindow::setupTemplatesMenu()
Chris@423 1708 {
Chris@423 1709 m_templatesMenu->clear();
Chris@423 1710
Chris@455 1711 QAction *defaultAction = new QAction(tr("Standard Waveform"), this);
Chris@435 1712 defaultAction->setObjectName("default");
Chris@435 1713 connect(defaultAction, SIGNAL(triggered()), this, SLOT(applyTemplate()));
Chris@435 1714 m_templatesMenu->addAction(defaultAction);
Chris@435 1715
Chris@435 1716 m_templatesMenu->addSeparator();
Chris@435 1717
Chris@435 1718 QAction *action = 0;
Chris@435 1719
Chris@435 1720 QStringList templates = ResourceFinder().getResourceFiles("templates", "svt");
Chris@435 1721
Chris@436 1722 bool havePersonal = false;
Chris@436 1723
Chris@435 1724 // (ordered by name)
Chris@435 1725 std::set<QString> byName;
Chris@435 1726 foreach (QString t, templates) {
Chris@436 1727 if (!t.startsWith(":")) havePersonal = true;
Chris@435 1728 byName.insert(QFileInfo(t).baseName());
Chris@435 1729 }
Chris@435 1730
Chris@435 1731 foreach (QString t, byName) {
Chris@435 1732 if (t.toLower() == "default") continue;
Chris@435 1733 action = new QAction(t, this);
Chris@435 1734 connect(action, SIGNAL(triggered()), this, SLOT(applyTemplate()));
Chris@435 1735 m_templatesMenu->addAction(action);
Chris@435 1736 }
Chris@435 1737
Chris@435 1738 if (!templates.empty()) m_templatesMenu->addSeparator();
Chris@435 1739
Chris@435 1740 if (!m_templateWatcher) {
Chris@435 1741 m_templateWatcher = new QFileSystemWatcher(this);
Chris@435 1742 m_templateWatcher->addPath(ResourceFinder().getResourceSaveDir("templates"));
Chris@435 1743 connect(m_templateWatcher, SIGNAL(directoryChanged(const QString &)),
Chris@435 1744 this, SLOT(setupTemplatesMenu()));
Chris@435 1745 }
Chris@436 1746
Chris@436 1747 QAction *setDefaultAction = new QAction(tr("Choose Default Template..."), this);
Chris@436 1748 setDefaultAction->setObjectName("set_default_template");
Chris@436 1749 connect(setDefaultAction, SIGNAL(triggered()), this, SLOT(preferences()));
Chris@436 1750 m_templatesMenu->addSeparator();
Chris@436 1751 m_templatesMenu->addAction(setDefaultAction);
Chris@436 1752
Chris@436 1753 m_manageTemplatesAction->setEnabled(havePersonal);
Chris@435 1754 }
Chris@435 1755
Chris@423 1756
Chris@423 1757 void
Chris@211 1758 MainWindow::setupRecentTransformsMenu()
Chris@34 1759 {
Chris@211 1760 m_recentTransformsMenu->clear();
Chris@211 1761 vector<QString> transforms = m_recentTransforms.getRecent();
Chris@34 1762 for (size_t i = 0; i < transforms.size(); ++i) {
Chris@211 1763 TransformActionReverseMap::iterator ti =
Chris@34 1764 m_transformActionsReverse.find(transforms[i]);
Chris@34 1765 if (ti == m_transformActionsReverse.end()) {
Chris@211 1766 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
Chris@34 1767 << "Unknown transform \"" << transforms[i].toStdString()
Chris@34 1768 << "\" in recent transforms list" << std::endl;
Chris@34 1769 continue;
Chris@34 1770 }
Chris@162 1771 if (i == 0) {
Chris@162 1772 ti->second->setShortcut(tr("Ctrl+T"));
Chris@162 1773 m_keyReference->registerShortcut
Chris@211 1774 (tr("Repeat Transform"),
Chris@162 1775 ti->second->shortcut(),
Chris@163 1776 tr("Re-select the most recently run transform"));
Chris@216 1777 } else {
Chris@216 1778 ti->second->setShortcut(QString(""));
Chris@162 1779 }
Chris@211 1780 m_recentTransformsMenu->addAction(ti->second);
Chris@34 1781 }
Chris@34 1782 }
Chris@34 1783
Chris@34 1784 void
Chris@95 1785 MainWindow::setupExistingLayersMenus()
Chris@0 1786 {
Chris@0 1787 if (!m_existingLayersMenu) return; // should have been created by setupMenus
Chris@0 1788
Chris@438 1789 // SVDEBUG << "MainWindow::setupExistingLayersMenu" << endl;
Chris@0 1790
Chris@0 1791 m_existingLayersMenu->clear();
Chris@0 1792 m_existingLayerActions.clear();
Chris@0 1793
Chris@95 1794 m_sliceMenu->clear();
Chris@95 1795 m_sliceActions.clear();
Chris@95 1796
Chris@168 1797 IconLoader il;
Chris@168 1798
Chris@33 1799 vector<Layer *> orderedLayers;
Chris@33 1800 set<Layer *> observedLayers;
Chris@95 1801 set<Layer *> sliceableLayers;
Chris@95 1802
Chris@95 1803 LayerFactory *factory = LayerFactory::getInstance();
Chris@0 1804
Chris@0 1805 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@0 1806
Chris@0 1807 Pane *pane = m_paneStack->getPane(i);
Chris@0 1808 if (!pane) continue;
Chris@0 1809
Chris@0 1810 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 1811
Chris@0 1812 Layer *layer = pane->getLayer(j);
Chris@0 1813 if (!layer) continue;
Chris@0 1814 if (observedLayers.find(layer) != observedLayers.end()) {
Chris@137 1815 // std::cerr << "found duplicate layer " << layer << std::endl;
Chris@0 1816 continue;
Chris@0 1817 }
Chris@0 1818
Chris@0 1819 // std::cerr << "found new layer " << layer << " (name = "
Chris@432 1820 // << layer->getLayerPresentationName() << ")" << std::endl;
Chris@0 1821
Chris@0 1822 orderedLayers.push_back(layer);
Chris@0 1823 observedLayers.insert(layer);
Chris@95 1824
Chris@95 1825 if (factory->isLayerSliceable(layer)) {
Chris@95 1826 sliceableLayers.insert(layer);
Chris@95 1827 }
Chris@0 1828 }
Chris@0 1829 }
Chris@0 1830
Chris@33 1831 map<QString, int> observedNames;
Chris@0 1832
Chris@137 1833 for (size_t i = 0; i < orderedLayers.size(); ++i) {
Chris@0 1834
Chris@95 1835 Layer *layer = orderedLayers[i];
Chris@95 1836
Chris@95 1837 QString name = layer->getLayerPresentationName();
Chris@0 1838 int n = ++observedNames[name];
Chris@0 1839 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
Chris@0 1840
Chris@168 1841 QIcon icon = il.load(factory->getLayerIconName
Chris@168 1842 (factory->getLayerType(layer)));
Chris@95 1843
Chris@95 1844 QAction *action = new QAction(icon, name, this);
Chris@0 1845 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@0 1846 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1847 m_existingLayerActions[action] = layer;
Chris@0 1848
Chris@0 1849 m_existingLayersMenu->addAction(action);
Chris@95 1850
Chris@95 1851 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
Chris@95 1852 action = new QAction(icon, name, this);
Chris@95 1853 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
Chris@95 1854 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@95 1855 m_sliceActions[action] = layer;
Chris@95 1856 m_sliceMenu->addAction(action);
Chris@95 1857 }
Chris@0 1858 }
Chris@95 1859
Chris@95 1860 m_sliceMenu->setEnabled(!m_sliceActions.empty());
Chris@0 1861 }
Chris@0 1862
Chris@0 1863 void
Chris@0 1864 MainWindow::setupToolbars()
Chris@0 1865 {
Chris@162 1866 m_keyReference->setCategory(tr("Playback and Transport Controls"));
Chris@162 1867
Chris@168 1868 IconLoader il;
Chris@168 1869
Chris@155 1870 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
Chris@155 1871 menu->setTearOffEnabled(true);
Chris@155 1872 m_rightButtonMenu->addSeparator();
Chris@155 1873 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
Chris@155 1874
Chris@155 1875 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
Chris@155 1876
Chris@265 1877 m_rwdStartAction = toolbar->addAction(il.load("rewind-start"),
Chris@265 1878 tr("Rewind to Start"));
Chris@265 1879 m_rwdStartAction->setShortcut(tr("Home"));
Chris@265 1880 m_rwdStartAction->setStatusTip(tr("Rewind to the start"));
Chris@265 1881 connect(m_rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
Chris@265 1882 connect(this, SIGNAL(canPlay(bool)), m_rwdStartAction, SLOT(setEnabled(bool)));
Chris@265 1883
Chris@265 1884 m_rwdAction = toolbar->addAction(il.load("rewind"), tr("Rewind"));
Chris@155 1885 m_rwdAction->setShortcut(tr("PgUp"));
Chris@163 1886 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
Chris@155 1887 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
Chris@155 1888 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
Chris@155 1889
Chris@323 1890 m_rwdSimilarAction = new QAction(tr("Rewind to Similar Point"), this);
Chris@323 1891 m_rwdSimilarAction->setShortcut(tr("Shift+PgUp"));
Chris@323 1892 m_rwdSimilarAction->setStatusTip(tr("Rewind to the previous similarly valued time instant"));
Chris@323 1893 connect(m_rwdSimilarAction, SIGNAL(triggered()), this, SLOT(rewindSimilar()));
Chris@323 1894 connect(this, SIGNAL(canRewind(bool)), m_rwdSimilarAction, SLOT(setEnabled(bool)));
Chris@323 1895
Chris@265 1896 m_playAction = toolbar->addAction(il.load("playpause"),
Chris@265 1897 tr("Play / Pause"));
Chris@265 1898 m_playAction->setCheckable(true);
Chris@265 1899 m_playAction->setShortcut(tr("Space"));
Chris@265 1900 m_playAction->setStatusTip(tr("Start or stop playback from the current position"));
Chris@265 1901 connect(m_playAction, SIGNAL(triggered()), this, SLOT(play()));
Chris@0 1902 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@265 1903 m_playAction, SLOT(setChecked(bool)));
Chris@305 1904 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
Chris@305 1905 this, SLOT(playStatusChanged(bool)));
Chris@265 1906 connect(this, SIGNAL(canPlay(bool)), m_playAction, SLOT(setEnabled(bool)));
Chris@155 1907
Chris@168 1908 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
Chris@286 1909 tr("Fast Forward"));
Chris@155 1910 m_ffwdAction->setShortcut(tr("PgDown"));
Chris@163 1911 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
Chris@155 1912 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
Chris@155 1913 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
Chris@155 1914
Chris@323 1915 m_ffwdSimilarAction = new QAction(tr("Fast Forward to Similar Point"), this);
Chris@323 1916 m_ffwdSimilarAction->setShortcut(tr("Shift+PgDown"));
Chris@323 1917 m_ffwdSimilarAction->setStatusTip(tr("Fast-forward to the next similarly valued time instant"));
Chris@323 1918 connect(m_ffwdSimilarAction, SIGNAL(triggered()), this, SLOT(ffwdSimilar()));
Chris@323 1919 connect(this, SIGNAL(canFfwd(bool)), m_ffwdSimilarAction, SLOT(setEnabled(bool)));
Chris@323 1920
Chris@265 1921 m_ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
Chris@265 1922 tr("Fast Forward to End"));
Chris@265 1923 m_ffwdEndAction->setShortcut(tr("End"));
Chris@265 1924 m_ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
Chris@265 1925 connect(m_ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
Chris@265 1926 connect(this, SIGNAL(canPlay(bool)), m_ffwdEndAction, SLOT(setEnabled(bool)));
Chris@0 1927
Chris@0 1928 toolbar = addToolBar(tr("Play Mode Toolbar"));
Chris@0 1929
Chris@265 1930 m_playSelectionAction = toolbar->addAction(il.load("playselection"),
Chris@265 1931 tr("Constrain Playback to Selection"));
Chris@265 1932 m_playSelectionAction->setCheckable(true);
Chris@265 1933 m_playSelectionAction->setChecked(m_viewManager->getPlaySelectionMode());
Chris@265 1934 m_playSelectionAction->setShortcut(tr("s"));
Chris@265 1935 m_playSelectionAction->setStatusTip(tr("Constrain playback to the selected regions"));
Chris@69 1936 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
Chris@265 1937 m_playSelectionAction, SLOT(setChecked(bool)));
Chris@265 1938 connect(m_playSelectionAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
Chris@265 1939 connect(this, SIGNAL(canPlaySelection(bool)), m_playSelectionAction, SLOT(setEnabled(bool)));
Chris@265 1940
Chris@265 1941 m_playLoopAction = toolbar->addAction(il.load("playloop"),
Chris@265 1942 tr("Loop Playback"));
Chris@265 1943 m_playLoopAction->setCheckable(true);
Chris@265 1944 m_playLoopAction->setChecked(m_viewManager->getPlayLoopMode());
Chris@265 1945 m_playLoopAction->setShortcut(tr("l"));
Chris@265 1946 m_playLoopAction->setStatusTip(tr("Loop playback"));
Chris@69 1947 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
Chris@265 1948 m_playLoopAction, SLOT(setChecked(bool)));
Chris@265 1949 connect(m_playLoopAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
Chris@265 1950 connect(this, SIGNAL(canPlay(bool)), m_playLoopAction, SLOT(setEnabled(bool)));
Chris@155 1951
Chris@207 1952 m_soloAction = toolbar->addAction(il.load("solo"),
Chris@323 1953 tr("Solo Current Pane"));
Chris@207 1954 m_soloAction->setCheckable(true);
Chris@207 1955 m_soloAction->setChecked(m_viewManager->getPlaySoloMode());
Chris@207 1956 m_prevSolo = m_viewManager->getPlaySoloMode();
Chris@207 1957 m_soloAction->setShortcut(tr("o"));
Chris@207 1958 m_soloAction->setStatusTip(tr("Solo the current pane during playback"));
Chris@180 1959 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
Chris@207 1960 m_soloAction, SLOT(setChecked(bool)));
Chris@207 1961 connect(m_soloAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
Chris@207 1962 connect(this, SIGNAL(canChangeSolo(bool)), m_soloAction, SLOT(setEnabled(bool)));
Chris@180 1963
Chris@208 1964 QAction *alAction = 0;
Chris@208 1965 if (Document::canAlign()) {
Chris@208 1966 alAction = toolbar->addAction(il.load("align"),
Chris@208 1967 tr("Align File Timelines"));
Chris@208 1968 alAction->setCheckable(true);
Chris@208 1969 alAction->setChecked(m_viewManager->getAlignMode());
Chris@208 1970 alAction->setStatusTip(tr("Treat multiple audio files as versions of the same work, and align their timelines"));
Chris@208 1971 connect(m_viewManager, SIGNAL(alignModeChanged(bool)),
Chris@208 1972 alAction, SLOT(setChecked(bool)));
Chris@208 1973 connect(alAction, SIGNAL(triggered()), this, SLOT(alignToggled()));
Chris@208 1974 connect(this, SIGNAL(canAlign(bool)), alAction, SLOT(setEnabled(bool)));
Chris@208 1975 }
Chris@206 1976
Chris@265 1977 m_keyReference->registerShortcut(m_playAction);
Chris@265 1978 m_keyReference->registerShortcut(m_playSelectionAction);
Chris@265 1979 m_keyReference->registerShortcut(m_playLoopAction);
Chris@207 1980 m_keyReference->registerShortcut(m_soloAction);
Chris@208 1981 if (alAction) m_keyReference->registerShortcut(alAction);
Chris@162 1982 m_keyReference->registerShortcut(m_rwdAction);
Chris@162 1983 m_keyReference->registerShortcut(m_ffwdAction);
Chris@323 1984 m_keyReference->registerShortcut(m_rwdSimilarAction);
Chris@323 1985 m_keyReference->registerShortcut(m_ffwdSimilarAction);
Chris@265 1986 m_keyReference->registerShortcut(m_rwdStartAction);
Chris@265 1987 m_keyReference->registerShortcut(m_ffwdEndAction);
Chris@265 1988
Chris@265 1989 menu->addAction(m_playAction);
Chris@265 1990 menu->addAction(m_playSelectionAction);
Chris@265 1991 menu->addAction(m_playLoopAction);
Chris@207 1992 menu->addAction(m_soloAction);
Chris@208 1993 if (alAction) menu->addAction(alAction);
Chris@155 1994 menu->addSeparator();
Chris@155 1995 menu->addAction(m_rwdAction);
Chris@155 1996 menu->addAction(m_ffwdAction);
Chris@155 1997 menu->addSeparator();
Chris@323 1998 menu->addAction(m_rwdSimilarAction);
Chris@323 1999 menu->addAction(m_ffwdSimilarAction);
Chris@323 2000 menu->addSeparator();
Chris@265 2001 menu->addAction(m_rwdStartAction);
Chris@265 2002 menu->addAction(m_ffwdEndAction);
Chris@155 2003 menu->addSeparator();
Chris@155 2004
Chris@265 2005 m_rightButtonPlaybackMenu->addAction(m_playAction);
Chris@265 2006 m_rightButtonPlaybackMenu->addAction(m_playSelectionAction);
Chris@265 2007 m_rightButtonPlaybackMenu->addAction(m_playLoopAction);
Chris@207 2008 m_rightButtonPlaybackMenu->addAction(m_soloAction);
Chris@208 2009 if (alAction) m_rightButtonPlaybackMenu->addAction(alAction);
Chris@155 2010 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 2011 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
Chris@155 2012 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
Chris@155 2013 m_rightButtonPlaybackMenu->addSeparator();
Chris@265 2014 m_rightButtonPlaybackMenu->addAction(m_rwdStartAction);
Chris@265 2015 m_rightButtonPlaybackMenu->addAction(m_ffwdEndAction);
Chris@155 2016 m_rightButtonPlaybackMenu->addSeparator();
Chris@155 2017
Chris@155 2018 QAction *fastAction = menu->addAction(tr("Speed Up"));
Chris@155 2019 fastAction->setShortcut(tr("Ctrl+PgUp"));
Chris@163 2020 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
Chris@155 2021 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
Chris@155 2022 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
Chris@155 2023
Chris@155 2024 QAction *slowAction = menu->addAction(tr("Slow Down"));
Chris@155 2025 slowAction->setShortcut(tr("Ctrl+PgDown"));
Chris@163 2026 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
Chris@155 2027 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
Chris@155 2028 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
Chris@155 2029
Chris@155 2030 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
Chris@155 2031 normalAction->setShortcut(tr("Ctrl+Home"));
Chris@163 2032 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
Chris@155 2033 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
Chris@155 2034 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
Chris@155 2035
Chris@162 2036 m_keyReference->registerShortcut(fastAction);
Chris@162 2037 m_keyReference->registerShortcut(slowAction);
Chris@162 2038 m_keyReference->registerShortcut(normalAction);
Chris@162 2039
Chris@155 2040 m_rightButtonPlaybackMenu->addAction(fastAction);
Chris@155 2041 m_rightButtonPlaybackMenu->addAction(slowAction);
Chris@155 2042 m_rightButtonPlaybackMenu->addAction(normalAction);
Chris@0 2043
Chris@0 2044 toolbar = addToolBar(tr("Edit Toolbar"));
Chris@0 2045 CommandHistory::getInstance()->registerToolbar(toolbar);
Chris@0 2046
Chris@162 2047 m_keyReference->setCategory(tr("Tool Selection"));
Chris@162 2048
Chris@0 2049 toolbar = addToolBar(tr("Tools Toolbar"));
Chris@0 2050 QActionGroup *group = new QActionGroup(this);
Chris@0 2051
Chris@168 2052 QAction *action = toolbar->addAction(il.load("navigate"),
Chris@155 2053 tr("Navigate"));
Chris@0 2054 action->setCheckable(true);
Chris@0 2055 action->setChecked(true);
Chris@0 2056 action->setShortcut(tr("1"));
Chris@90 2057 action->setStatusTip(tr("Navigate"));
Chris@0 2058 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
Chris@0 2059 group->addAction(action);
Chris@162 2060 m_keyReference->registerShortcut(action);
Chris@0 2061 m_toolActions[ViewManager::NavigateMode] = action;
Chris@0 2062
Chris@168 2063 action = toolbar->addAction(il.load("select"),
Chris@0 2064 tr("Select"));
Chris@0 2065 action->setCheckable(true);
Chris@0 2066 action->setShortcut(tr("2"));
Chris@90 2067 action->setStatusTip(tr("Select ranges"));
Chris@0 2068 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
Chris@0 2069 group->addAction(action);
Chris@162 2070 m_keyReference->registerShortcut(action);
Chris@0 2071 m_toolActions[ViewManager::SelectMode] = action;
Chris@0 2072
Chris@168 2073 action = toolbar->addAction(il.load("move"),
Chris@0 2074 tr("Edit"));
Chris@0 2075 action->setCheckable(true);
Chris@0 2076 action->setShortcut(tr("3"));
Chris@90 2077 action->setStatusTip(tr("Edit items in layer"));
Chris@0 2078 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
Chris@0 2079 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 2080 group->addAction(action);
Chris@162 2081 m_keyReference->registerShortcut(action);
Chris@0 2082 m_toolActions[ViewManager::EditMode] = action;
Chris@0 2083
Chris@168 2084 action = toolbar->addAction(il.load("draw"),
Chris@0 2085 tr("Draw"));
Chris@0 2086 action->setCheckable(true);
Chris@0 2087 action->setShortcut(tr("4"));
Chris@90 2088 action->setStatusTip(tr("Draw new items in layer"));
Chris@0 2089 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
Chris@0 2090 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@0 2091 group->addAction(action);
Chris@162 2092 m_keyReference->registerShortcut(action);
Chris@0 2093 m_toolActions[ViewManager::DrawMode] = action;
Chris@0 2094
Chris@217 2095 action = toolbar->addAction(il.load("erase"),
Chris@217 2096 tr("Erase"));
Chris@217 2097 action->setCheckable(true);
Chris@217 2098 action->setShortcut(tr("5"));
Chris@217 2099 action->setStatusTip(tr("Erase items from layer"));
Chris@217 2100 connect(action, SIGNAL(triggered()), this, SLOT(toolEraseSelected()));
Chris@217 2101 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@217 2102 group->addAction(action);
Chris@217 2103 m_keyReference->registerShortcut(action);
Chris@217 2104 m_toolActions[ViewManager::EraseMode] = action;
Chris@217 2105
Chris@265 2106 action = toolbar->addAction(il.load("measure"), tr("Measure"));
Chris@151 2107 action->setCheckable(true);
Chris@217 2108 action->setShortcut(tr("6"));
Chris@151 2109 action->setStatusTip(tr("Make measurements in layer"));
Chris@151 2110 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
Chris@169 2111 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
Chris@151 2112 group->addAction(action);
Chris@162 2113 m_keyReference->registerShortcut(action);
Chris@151 2114 m_toolActions[ViewManager::MeasureMode] = action;
Chris@151 2115
Chris@0 2116 toolNavigateSelected();
Chris@163 2117
Chris@163 2118 Pane::registerShortcuts(*m_keyReference);
Chris@0 2119 }
Chris@0 2120
Chris@0 2121 void
Chris@265 2122 MainWindow::connectLayerEditDialog(ModelDataTableDialog *dialog)
Chris@265 2123 {
Chris@265 2124 MainWindowBase::connectLayerEditDialog(dialog);
Chris@265 2125 QToolBar *toolbar = dialog->getPlayToolbar();
Chris@265 2126 if (toolbar) {
Chris@265 2127 toolbar->addAction(m_rwdStartAction);
Chris@265 2128 toolbar->addAction(m_rwdAction);
Chris@265 2129 toolbar->addAction(m_playAction);
Chris@265 2130 toolbar->addAction(m_ffwdAction);
Chris@265 2131 toolbar->addAction(m_ffwdEndAction);
Chris@265 2132 }
Chris@265 2133 }
Chris@265 2134
Chris@265 2135 void
Chris@0 2136 MainWindow::updateMenuStates()
Chris@0 2137 {
Chris@200 2138 MainWindowBase::updateMenuStates();
Chris@200 2139
Chris@117 2140 Pane *currentPane = 0;
Chris@117 2141 Layer *currentLayer = 0;
Chris@117 2142
Chris@117 2143 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@117 2144 if (currentPane) currentLayer = currentPane->getSelectedLayer();
Chris@117 2145
Chris@0 2146 bool haveCurrentPane =
Chris@117 2147 (currentPane != 0);
Chris@0 2148 bool haveCurrentLayer =
Chris@117 2149 (haveCurrentPane &&
Chris@117 2150 (currentLayer != 0));
Chris@206 2151 bool havePlayTarget =
Chris@206 2152 (m_playTarget != 0);
Chris@0 2153 bool haveSelection =
Chris@0 2154 (m_viewManager &&
Chris@0 2155 !m_viewManager->getSelections().empty());
Chris@0 2156 bool haveCurrentEditableLayer =
Chris@0 2157 (haveCurrentLayer &&
Chris@117 2158 currentLayer->isLayerEditable());
Chris@0 2159 bool haveCurrentTimeInstantsLayer =
Chris@0 2160 (haveCurrentLayer &&
Chris@117 2161 dynamic_cast<TimeInstantLayer *>(currentLayer));
Chris@0 2162 bool haveCurrentTimeValueLayer =
Chris@0 2163 (haveCurrentLayer &&
Chris@117 2164 dynamic_cast<TimeValueLayer *>(currentLayer));
Chris@207 2165
Chris@314 2166 bool alignMode = m_viewManager && m_viewManager->getAlignMode();
Chris@314 2167 emit canChangeSolo(havePlayTarget && !alignMode);
Chris@207 2168 emit canAlign(havePlayTarget && m_document && m_document->canAlign());
Chris@206 2169
Chris@200 2170 emit canChangePlaybackSpeed(true);
Chris@200 2171 int v = m_playSpeed->value();
Chris@200 2172 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
Chris@200 2173 emit canSlowDownPlayback(v > m_playSpeed->minimum());
Chris@155 2174
Chris@164 2175 if (m_viewManager &&
Chris@164 2176 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
Chris@164 2177 emit canDeleteSelection(haveCurrentLayer);
Chris@164 2178 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
Chris@164 2179 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
Chris@164 2180 } else {
Chris@164 2181 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
Chris@164 2182 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
Chris@164 2183 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
Chris@164 2184 }
Chris@164 2185
Chris@155 2186 if (m_ffwdAction && m_rwdAction) {
Chris@155 2187 if (haveCurrentTimeInstantsLayer) {
Chris@155 2188 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
Chris@155 2189 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
Chris@155 2190 m_rwdAction->setText(tr("Rewind to Previous Instant"));
Chris@155 2191 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
Chris@155 2192 } else if (haveCurrentTimeValueLayer) {
Chris@155 2193 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
Chris@155 2194 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
Chris@155 2195 m_rwdAction->setText(tr("Rewind to Previous Point"));
Chris@155 2196 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
Chris@155 2197 } else {
Chris@155 2198 m_ffwdAction->setText(tr("Fast Forward"));
Chris@155 2199 m_ffwdAction->setStatusTip(tr("Fast forward"));
Chris@155 2200 m_rwdAction->setText(tr("Rewind"));
Chris@155 2201 m_rwdAction->setStatusTip(tr("Rewind"));
Chris@155 2202 }
Chris@155 2203 }
Chris@0 2204 }
Chris@0 2205
Chris@0 2206 void
Chris@0 2207 MainWindow::updateDescriptionLabel()
Chris@0 2208 {
Chris@0 2209 if (!getMainModel()) {
Chris@0 2210 m_descriptionLabel->setText(tr("No audio file loaded."));
Chris@0 2211 return;
Chris@0 2212 }
Chris@0 2213
Chris@0 2214 QString description;
Chris@0 2215
Chris@0 2216 size_t ssr = getMainModel()->getSampleRate();
Chris@0 2217 size_t tsr = ssr;
Chris@0 2218 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
Chris@0 2219
Chris@0 2220 if (ssr != tsr) {
Chris@0 2221 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
Chris@0 2222 } else {
Chris@0 2223 description = QString("%1Hz").arg(ssr);
Chris@0 2224 }
Chris@0 2225
Chris@0 2226 description = QString("%1 - %2")
Chris@0 2227 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
Chris@0 2228 .toText(false).c_str())
Chris@0 2229 .arg(description);
Chris@0 2230
Chris@0 2231 m_descriptionLabel->setText(description);
Chris@0 2232 }
Chris@0 2233
Chris@0 2234 void
Chris@0 2235 MainWindow::documentModified()
Chris@0 2236 {
Chris@200 2237 //!!!
Chris@200 2238 MainWindowBase::documentModified();
Chris@0 2239 }
Chris@0 2240
Chris@0 2241 void
Chris@0 2242 MainWindow::documentRestored()
Chris@0 2243 {
Chris@200 2244 //!!!
Chris@200 2245 MainWindowBase::documentRestored();
Chris@0 2246 }
Chris@0 2247
Chris@0 2248 void
Chris@0 2249 MainWindow::toolNavigateSelected()
Chris@0 2250 {
Chris@0 2251 m_viewManager->setToolMode(ViewManager::NavigateMode);
Chris@0 2252 }
Chris@0 2253
Chris@0 2254 void
Chris@0 2255 MainWindow::toolSelectSelected()
Chris@0 2256 {
Chris@0 2257 m_viewManager->setToolMode(ViewManager::SelectMode);
Chris@0 2258 }
Chris@0 2259
Chris@0 2260 void
Chris@0 2261 MainWindow::toolEditSelected()
Chris@0 2262 {
Chris@0 2263 m_viewManager->setToolMode(ViewManager::EditMode);
Chris@0 2264 }
Chris@0 2265
Chris@0 2266 void
Chris@0 2267 MainWindow::toolDrawSelected()
Chris@0 2268 {
Chris@0 2269 m_viewManager->setToolMode(ViewManager::DrawMode);
Chris@0 2270 }
Chris@0 2271
Chris@151 2272 void
Chris@217 2273 MainWindow::toolEraseSelected()
Chris@217 2274 {
Chris@217 2275 m_viewManager->setToolMode(ViewManager::EraseMode);
Chris@217 2276 }
Chris@217 2277
Chris@217 2278 void
Chris@151 2279 MainWindow::toolMeasureSelected()
Chris@151 2280 {
Chris@151 2281 m_viewManager->setToolMode(ViewManager::MeasureMode);
Chris@151 2282 }
Chris@151 2283
Chris@0 2284 void
Chris@0 2285 MainWindow::importAudio()
Chris@0 2286 {
Chris@88 2287 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2288
Chris@0 2289 if (path != "") {
Chris@417 2290 if (openAudio(path, ReplaceSession) == FileOpenFailed) {
Chris@247 2291 emit hideSplash();
Chris@0 2292 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2293 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@0 2294 }
Chris@0 2295 }
Chris@0 2296 }
Chris@0 2297
Chris@0 2298 void
Chris@0 2299 MainWindow::importMoreAudio()
Chris@0 2300 {
Chris@88 2301 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@0 2302
Chris@0 2303 if (path != "") {
Chris@197 2304 if (openAudio(path, CreateAdditionalModel) == FileOpenFailed) {
Chris@247 2305 emit hideSplash();
Chris@0 2306 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2307 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@0 2308 }
Chris@0 2309 }
Chris@0 2310 }
Chris@0 2311
Chris@0 2312 void
Chris@508 2313 MainWindow::replaceMainAudio()
Chris@508 2314 {
Chris@508 2315 QString path = getOpenFileName(FileFinder::AudioFile);
Chris@508 2316
Chris@508 2317 if (path != "") {
Chris@508 2318 if (openAudio(path, ReplaceMainModel) == FileOpenFailed) {
Chris@508 2319 emit hideSplash();
Chris@508 2320 QMessageBox::critical(this, tr("Failed to open file"),
Chris@508 2321 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
Chris@508 2322 }
Chris@508 2323 }
Chris@508 2324 }
Chris@508 2325
Chris@508 2326 void
Chris@0 2327 MainWindow::exportAudio()
Chris@0 2328 {
Chris@0 2329 if (!getMainModel()) return;
Chris@0 2330
Chris@320 2331 RangeSummarisableTimeValueModel *model = getMainModel();
Chris@320 2332 std::set<RangeSummarisableTimeValueModel *> otherModels;
Chris@320 2333 RangeSummarisableTimeValueModel *current = model;
Chris@320 2334 if (m_paneStack) {
Chris@320 2335 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@320 2336 Pane *pane = m_paneStack->getPane(i);
Chris@320 2337 if (!pane) continue;
Chris@320 2338 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@320 2339 Layer *layer = pane->getLayer(j);
Chris@320 2340 if (!layer) continue;
Chris@432 2341 cerr << "layer = " << layer->objectName() << endl;
Chris@320 2342 Model *m = layer->getModel();
Chris@320 2343 RangeSummarisableTimeValueModel *wm =
Chris@320 2344 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
Chris@320 2345 if (wm) {
Chris@432 2346 cerr << "found: " << wm->objectName() << endl;
Chris@320 2347 otherModels.insert(wm);
Chris@320 2348 if (pane == m_paneStack->getCurrentPane()) {
Chris@320 2349 current = wm;
Chris@320 2350 }
Chris@320 2351 }
Chris@320 2352 }
Chris@320 2353 }
Chris@320 2354 }
Chris@320 2355 if (!otherModels.empty()) {
Chris@320 2356 std::map<QString, RangeSummarisableTimeValueModel *> m;
Chris@320 2357 m[tr("1. %2").arg(model->objectName())] = model;
Chris@320 2358 int n = 2;
Chris@320 2359 int c = 0;
Chris@320 2360 for (std::set<RangeSummarisableTimeValueModel *>::const_iterator i
Chris@320 2361 = otherModels.begin();
Chris@320 2362 i != otherModels.end(); ++i) {
Chris@320 2363 if (*i == model) continue;
Chris@320 2364 m[tr("%1. %2").arg(n).arg((*i)->objectName())] = *i;
Chris@320 2365 ++n;
Chris@320 2366 if (*i == current) c = n-1;
Chris@320 2367 }
Chris@320 2368 QStringList items;
Chris@320 2369 for (std::map<QString, RangeSummarisableTimeValueModel *>
Chris@320 2370 ::const_iterator i = m.begin();
Chris@320 2371 i != m.end(); ++i) {
Chris@320 2372 items << i->first;
Chris@320 2373 }
Chris@325 2374 if (items.size() > 1) {
Chris@325 2375 bool ok = false;
Chris@325 2376 QString item = QInputDialog::getItem
Chris@325 2377 (this, tr("Select audio file to export"),
Chris@325 2378 tr("Which audio file do you want to export from?"),
Chris@325 2379 items, c, false, &ok);
Chris@325 2380 if (!ok || item.isEmpty()) return;
Chris@325 2381 if (m.find(item) == m.end()) {
Chris@325 2382 cerr << "WARNING: Model " << item.toStdString()
Chris@325 2383 << " not found in list!" << endl;
Chris@325 2384 } else {
Chris@325 2385 model = m[item];
Chris@325 2386 }
Chris@320 2387 }
Chris@320 2388 }
Chris@320 2389
Chris@88 2390 QString path = getSaveFileName(FileFinder::AudioFile);
Chris@0 2391 if (path == "") return;
Chris@0 2392
Chris@0 2393 bool ok = false;
Chris@0 2394 QString error;
Chris@0 2395
Chris@0 2396 MultiSelection ms = m_viewManager->getSelection();
Chris@0 2397 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@0 2398
Chris@0 2399 bool multiple = false;
Chris@0 2400
Chris@38 2401 MultiSelection *selectionToWrite = 0;
Chris@38 2402
Chris@38 2403 if (selections.size() == 1) {
Chris@0 2404
Chris@0 2405 QStringList items;
Chris@0 2406 items << tr("Export the selected region only")
Chris@0 2407 << tr("Export the whole audio file");
Chris@0 2408
Chris@0 2409 bool ok = false;
Chris@0 2410 QString item = ListInputDialog::getItem
Chris@0 2411 (this, tr("Select region to export"),
Chris@0 2412 tr("Which region from the original audio file do you want to export?"),
Chris@0 2413 items, 0, &ok);
Chris@0 2414
Chris@0 2415 if (!ok || item.isEmpty()) return;
Chris@0 2416
Chris@38 2417 if (item == items[0]) selectionToWrite = &ms;
Chris@38 2418
Chris@38 2419 } else if (selections.size() > 1) {
Chris@0 2420
Chris@0 2421 QStringList items;
Chris@0 2422 items << tr("Export the selected regions into a single audio file")
Chris@0 2423 << tr("Export the selected regions into separate files")
Chris@0 2424 << tr("Export the whole audio file");
Chris@0 2425
Chris@0 2426 QString item = ListInputDialog::getItem
Chris@0 2427 (this, tr("Select region to export"),
Chris@0 2428 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
Chris@0 2429 items, 0, &ok);
Chris@0 2430
Chris@0 2431 if (!ok || item.isEmpty()) return;
Chris@0 2432
Chris@0 2433 if (item == items[0]) {
Chris@0 2434
Chris@38 2435 selectionToWrite = &ms;
Chris@38 2436
Chris@38 2437 } else if (item == items[1]) {
Chris@0 2438
Chris@0 2439 multiple = true;
Chris@0 2440
Chris@0 2441 int n = 1;
Chris@0 2442 QString base = path;
Chris@0 2443 base.replace(".wav", "");
Chris@0 2444
Chris@0 2445 for (MultiSelection::SelectionList::iterator i = selections.begin();
Chris@0 2446 i != selections.end(); ++i) {
Chris@0 2447
Chris@0 2448 MultiSelection subms;
Chris@0 2449 subms.setSelection(*i);
Chris@0 2450
Chris@0 2451 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
Chris@0 2452 ++n;
Chris@0 2453
Chris@0 2454 if (QFileInfo(subpath).exists()) {
Chris@0 2455 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
Chris@0 2456 break;
Chris@0 2457 }
Chris@0 2458
Chris@38 2459 WavFileWriter subwriter(subpath,
Chris@320 2460 model->getSampleRate(),
Chris@428 2461 model->getChannelCount(),
Chris@428 2462 WavFileWriter::WriteToTemporary);
Chris@320 2463 subwriter.writeModel(model, &subms);
Chris@0 2464 ok = subwriter.isOK();
Chris@0 2465
Chris@0 2466 if (!ok) {
Chris@0 2467 error = subwriter.getError();
Chris@0 2468 break;
Chris@0 2469 }
Chris@0 2470 }
Chris@0 2471 }
Chris@0 2472 }
Chris@0 2473
Chris@38 2474 if (!multiple) {
Chris@38 2475 WavFileWriter writer(path,
Chris@320 2476 model->getSampleRate(),
Chris@428 2477 model->getChannelCount(),
Chris@428 2478 WavFileWriter::WriteToTemporary);
Chris@320 2479 writer.writeModel(model, selectionToWrite);
Chris@38 2480 ok = writer.isOK();
Chris@38 2481 error = writer.getError();
Chris@0 2482 }
Chris@0 2483
Chris@0 2484 if (ok) {
Chris@310 2485 if (multiple) {
Chris@310 2486 emit activity(tr("Export multiple audio files"));
Chris@310 2487 } else {
Chris@310 2488 emit activity(tr("Export audio to \"%1\"").arg(path));
Chris@34 2489 m_recentFiles.addFile(path);
Chris@0 2490 }
Chris@0 2491 } else {
Chris@0 2492 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2493 }
Chris@0 2494 }
Chris@0 2495
Chris@0 2496 void
Chris@0 2497 MainWindow::importLayer()
Chris@0 2498 {
Chris@0 2499 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2500
Chris@0 2501 if (!pane) {
Chris@0 2502 // shouldn't happen, as the menu action should have been disabled
Chris@0 2503 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
Chris@0 2504 return;
Chris@0 2505 }
Chris@0 2506
Chris@0 2507 if (!getMainModel()) {
Chris@0 2508 // shouldn't happen, as the menu action should have been disabled
Chris@0 2509 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
Chris@0 2510 return;
Chris@0 2511 }
Chris@0 2512
Chris@88 2513 QString path = getOpenFileName(FileFinder::LayerFile);
Chris@0 2514
Chris@0 2515 if (path != "") {
Chris@0 2516
Chris@197 2517 FileOpenStatus status = openLayer(path);
Chris@193 2518
Chris@193 2519 if (status == FileOpenFailed) {
Chris@247 2520 emit hideSplash();
Chris@0 2521 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2522 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
Chris@0 2523 return;
Chris@193 2524 } else if (status == FileOpenWrongMode) {
Chris@247 2525 emit hideSplash();
Chris@193 2526 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2527 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2528 }
Chris@0 2529 }
Chris@0 2530 }
Chris@0 2531
Chris@0 2532 void
Chris@0 2533 MainWindow::exportLayer()
Chris@0 2534 {
Chris@0 2535 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 2536 if (!pane) return;
Chris@0 2537
Chris@0 2538 Layer *layer = pane->getSelectedLayer();
Chris@0 2539 if (!layer) return;
Chris@0 2540
Chris@0 2541 Model *model = layer->getModel();
Chris@0 2542 if (!model) return;
Chris@0 2543
Chris@185 2544 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
Chris@185 2545
Chris@185 2546 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
Chris@185 2547
Chris@185 2548 QString path = getSaveFileName(type);
Chris@0 2549
Chris@0 2550 if (path == "") return;
Chris@0 2551
Chris@0 2552 if (QFileInfo(path).suffix() == "") path += ".svl";
Chris@0 2553
Chris@185 2554 QString suffix = QFileInfo(path).suffix().toLower();
Chris@185 2555
Chris@0 2556 QString error;
Chris@0 2557
Chris@185 2558 if (suffix == "xml" || suffix == "svl") {
Chris@0 2559
Chris@0 2560 QFile file(path);
Chris@0 2561 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
Chris@0 2562 error = tr("Failed to open file %1 for writing").arg(path);
Chris@0 2563 } else {
Chris@0 2564 QTextStream out(&file);
Chris@0 2565 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
Chris@0 2566 << "<!DOCTYPE sonic-visualiser>\n"
Chris@0 2567 << "<sv>\n"
Chris@0 2568 << " <data>\n";
Chris@0 2569
Chris@0 2570 model->toXml(out, " ");
Chris@0 2571
Chris@0 2572 out << " </data>\n"
Chris@0 2573 << " <display>\n";
Chris@0 2574
Chris@0 2575 layer->toXml(out, " ");
Chris@0 2576
Chris@0 2577 out << " </display>\n"
Chris@0 2578 << "</sv>\n";
Chris@0 2579 }
Chris@0 2580
Chris@185 2581 } else if (suffix == "mid" || suffix == "midi") {
Chris@185 2582
Chris@185 2583 NoteModel *nm = dynamic_cast<NoteModel *>(model);
Chris@185 2584
Chris@185 2585 if (!nm) {
Chris@185 2586 error = tr("Can't export non-note layers to MIDI");
Chris@185 2587 } else {
Chris@185 2588 MIDIFileWriter writer(path, nm);
Chris@185 2589 writer.write();
Chris@185 2590 if (!writer.isOK()) {
Chris@185 2591 error = writer.getError();
Chris@185 2592 }
Chris@185 2593 }
Chris@185 2594
Chris@291 2595 } else if (suffix == "ttl" || suffix == "n3") {
Chris@291 2596
Chris@522 2597 if (!RDFExporter::canExportModel(model)) {
Chris@522 2598 error = tr("Sorry, cannot export this layer type to RDF (supported types are: region, note, text, time instants, time values)");
Chris@522 2599 } else {
Chris@522 2600 RDFExporter exporter(path, model);
Chris@522 2601 exporter.write();
Chris@522 2602 if (!exporter.isOK()) {
Chris@522 2603 error = exporter.getError();
Chris@522 2604 }
Chris@291 2605 }
Chris@291 2606
Chris@0 2607 } else {
Chris@0 2608
Chris@0 2609 CSVFileWriter writer(path, model,
Chris@185 2610 ((suffix == "csv") ? "," : "\t"));
Chris@0 2611 writer.write();
Chris@0 2612
Chris@0 2613 if (!writer.isOK()) {
Chris@0 2614 error = writer.getError();
Chris@0 2615 }
Chris@0 2616 }
Chris@0 2617
Chris@0 2618 if (error != "") {
Chris@0 2619 QMessageBox::critical(this, tr("Failed to write file"), error);
Chris@0 2620 } else {
Chris@34 2621 m_recentFiles.addFile(path);
Chris@310 2622 emit activity(tr("Export layer to \"%1\"").arg(path));
Chris@0 2623 }
Chris@0 2624 }
Chris@0 2625
Chris@121 2626 void
Chris@121 2627 MainWindow::exportImage()
Chris@121 2628 {
Chris@121 2629 Pane *pane = m_paneStack->getCurrentPane();
Chris@121 2630 if (!pane) return;
Chris@121 2631
Chris@121 2632 QString path = getSaveFileName(FileFinder::ImageFile);
Chris@121 2633
Chris@121 2634 if (path == "") return;
Chris@121 2635
Chris@121 2636 if (QFileInfo(path).suffix() == "") path += ".png";
Chris@121 2637
Chris@123 2638 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
Chris@123 2639
Chris@123 2640 QSize total, visible, selected;
Chris@123 2641 total = pane->getImageSize();
Chris@123 2642 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
Chris@123 2643 pane->getLastVisibleFrame());
Chris@123 2644
Chris@123 2645 size_t sf0 = 0, sf1 = 0;
Chris@123 2646
Chris@123 2647 if (haveSelection) {
Chris@123 2648 MultiSelection::SelectionList selections = m_viewManager->getSelections();
Chris@123 2649 sf0 = selections.begin()->getStartFrame();
Chris@123 2650 MultiSelection::SelectionList::iterator e = selections.end();
Chris@123 2651 --e;
Chris@123 2652 sf1 = e->getEndFrame();
Chris@123 2653 selected = pane->getImageSize(sf0, sf1);
Chris@123 2654 }
Chris@123 2655
Chris@123 2656 QStringList items;
Chris@125 2657 items << tr("Export the whole pane (%1x%2 pixels)")
Chris@123 2658 .arg(total.width()).arg(total.height());
Chris@123 2659 items << tr("Export the visible area only (%1x%2 pixels)")
Chris@123 2660 .arg(visible.width()).arg(visible.height());
Chris@123 2661 if (haveSelection) {
Chris@123 2662 items << tr("Export the selection extent (%1x%2 pixels)")
Chris@123 2663 .arg(selected.width()).arg(selected.height());
Chris@124 2664 } else {
Chris@124 2665 items << tr("Export the selection extent");
Chris@123 2666 }
Chris@123 2667
Chris@123 2668 QSettings settings;
Chris@123 2669 settings.beginGroup("MainWindow");
Chris@123 2670 int deflt = settings.value("lastimageexportregion", 0).toInt();
Chris@123 2671 if (deflt == 2 && !haveSelection) deflt = 1;
Chris@124 2672 if (deflt == 0 && total.width() > 32767) deflt = 1;
Chris@124 2673
Chris@124 2674 ListInputDialog *lid = new ListInputDialog
Chris@123 2675 (this, tr("Select region to export"),
Chris@123 2676 tr("Which region of the current pane do you want to export as an image?"),
Chris@124 2677 items, deflt);
Chris@124 2678
Chris@124 2679 if (!haveSelection) {
Chris@124 2680 lid->setItemAvailability(2, false);
Chris@124 2681 }
Chris@124 2682 if (total.width() > 32767) { // appears to be the limit of a QImage
Chris@124 2683 lid->setItemAvailability(0, false);
Chris@124 2684 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
Chris@124 2685 }
Chris@124 2686
Chris@124 2687 bool ok = lid->exec();
Chris@124 2688 QString item = lid->getCurrentString();
Chris@124 2689 delete lid;
Chris@123 2690
Chris@123 2691 if (!ok || item.isEmpty()) return;
Chris@123 2692
Chris@123 2693 settings.setValue("lastimageexportregion", deflt);
Chris@123 2694
Chris@123 2695 QImage *image = 0;
Chris@123 2696
Chris@123 2697 if (item == items[0]) {
Chris@123 2698 image = pane->toNewImage();
Chris@123 2699 } else if (item == items[1]) {
Chris@123 2700 image = pane->toNewImage(pane->getFirstVisibleFrame(),
Chris@123 2701 pane->getLastVisibleFrame());
Chris@123 2702 } else if (haveSelection) {
Chris@123 2703 image = pane->toNewImage(sf0, sf1);
Chris@123 2704 }
Chris@123 2705
Chris@121 2706 if (!image) return;
Chris@121 2707
Chris@121 2708 if (!image->save(path, "PNG")) {
Chris@121 2709 QMessageBox::critical(this, tr("Failed to save image file"),
Chris@121 2710 tr("Failed to save image file %1").arg(path));
Chris@121 2711 }
Chris@121 2712
Chris@121 2713 delete image;
Chris@121 2714 }
Chris@121 2715
Chris@0 2716 void
Chris@0 2717 MainWindow::newSession()
Chris@0 2718 {
Chris@0 2719 if (!checkSaveModified()) return;
Chris@0 2720
Chris@0 2721 closeSession();
Chris@0 2722 createDocument();
Chris@0 2723
Chris@0 2724 Pane *pane = m_paneStack->addPane();
Chris@0 2725
Chris@90 2726 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
Chris@116 2727 this, SLOT(contextHelpChanged(const QString &)));
Chris@90 2728
Chris@0 2729 if (!m_timeRulerLayer) {
Chris@0 2730 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 2731 (LayerFactory::TimeRuler);
Chris@0 2732 }
Chris@0 2733
Chris@0 2734 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 2735
Chris@0 2736 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
Chris@0 2737 m_document->addLayerToView(pane, waveform);
Chris@0 2738
Chris@65 2739 m_overview->registerView(pane);
Chris@0 2740
Chris@0 2741 CommandHistory::getInstance()->clear();
Chris@0 2742 CommandHistory::getInstance()->documentSaved();
Chris@0 2743 documentRestored();
Chris@0 2744 updateMenuStates();
Chris@0 2745 }
Chris@0 2746
Chris@0 2747 void
Chris@303 2748 MainWindow::documentReplaced()
Chris@303 2749 {
Chris@303 2750 if (m_document) {
Chris@303 2751 connect(m_document, SIGNAL(activity(QString)),
Chris@303 2752 m_activityLog, SLOT(activityHappened(QString)));
Chris@303 2753 }
Chris@303 2754 }
Chris@303 2755
Chris@303 2756 void
Chris@0 2757 MainWindow::closeSession()
Chris@0 2758 {
Chris@0 2759 if (!checkSaveModified()) return;
Chris@0 2760
Chris@0 2761 while (m_paneStack->getPaneCount() > 0) {
Chris@0 2762
Chris@0 2763 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
Chris@0 2764
Chris@0 2765 while (pane->getLayerCount() > 0) {
Chris@0 2766 m_document->removeLayerFromView
Chris@0 2767 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2768 }
Chris@0 2769
Chris@65 2770 m_overview->unregisterView(pane);
Chris@0 2771 m_paneStack->deletePane(pane);
Chris@0 2772 }
Chris@0 2773
Chris@0 2774 while (m_paneStack->getHiddenPaneCount() > 0) {
Chris@0 2775
Chris@0 2776 Pane *pane = m_paneStack->getHiddenPane
Chris@0 2777 (m_paneStack->getHiddenPaneCount() - 1);
Chris@0 2778
Chris@0 2779 while (pane->getLayerCount() > 0) {
Chris@0 2780 m_document->removeLayerFromView
Chris@0 2781 (pane, pane->getLayer(pane->getLayerCount() - 1));
Chris@0 2782 }
Chris@0 2783
Chris@65 2784 m_overview->unregisterView(pane);
Chris@0 2785 m_paneStack->deletePane(pane);
Chris@0 2786 }
Chris@0 2787
Chris@504 2788 delete m_layerTreeDialog.data();
Chris@504 2789 delete m_preferencesDialog.data();
Chris@504 2790
Chris@504 2791 m_activityLog->hide();
Chris@504 2792 m_keyReference->hide();
Chris@504 2793
Chris@0 2794 delete m_document;
Chris@0 2795 m_document = 0;
Chris@0 2796 m_viewManager->clearSelections();
Chris@0 2797 m_timeRulerLayer = 0; // document owned this
Chris@0 2798
Chris@0 2799 m_sessionFile = "";
Chris@518 2800 setWindowTitle(QApplication::applicationName());
Chris@0 2801
Chris@0 2802 CommandHistory::getInstance()->clear();
Chris@0 2803 CommandHistory::getInstance()->documentSaved();
Chris@0 2804 documentRestored();
Chris@0 2805 }
Chris@0 2806
Chris@0 2807 void
Chris@0 2808 MainWindow::openSession()
Chris@0 2809 {
Chris@0 2810 if (!checkSaveModified()) return;
Chris@0 2811
Chris@0 2812 QString orig = m_audioFile;
Chris@0 2813 if (orig == "") orig = ".";
Chris@0 2814 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2815
Chris@88 2816 QString path = getOpenFileName(FileFinder::SessionFile);
Chris@0 2817
Chris@0 2818 if (path.isEmpty()) return;
Chris@0 2819
Chris@200 2820 if (openSessionFile(path) == FileOpenFailed) {
Chris@247 2821 emit hideSplash();
Chris@0 2822 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2823 tr("<b>File open failed</b><p>Session file \"%1\" could not be opened").arg(path));
Chris@0 2824 }
Chris@0 2825 }
Chris@0 2826
Chris@0 2827 void
Chris@0 2828 MainWindow::openSomething()
Chris@0 2829 {
Chris@0 2830 QString orig = m_audioFile;
Chris@0 2831 if (orig == "") orig = ".";
Chris@0 2832 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 2833
Chris@88 2834 QString path = getOpenFileName(FileFinder::AnyFile);
Chris@0 2835
Chris@0 2836 if (path.isEmpty()) return;
Chris@0 2837
Chris@422 2838 FileOpenStatus status = open(path, ReplaceSession);
Chris@193 2839
Chris@193 2840 if (status == FileOpenFailed) {
Chris@247 2841 emit hideSplash();
Chris@193 2842 QMessageBox::critical(this, tr("Failed to open file"),
Chris@193 2843 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
Chris@193 2844 } else if (status == FileOpenWrongMode) {
Chris@247 2845 emit hideSplash();
Chris@193 2846 QMessageBox::critical(this, tr("Failed to open file"),
Chris@294 2847 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2848 }
Chris@0 2849 }
Chris@0 2850
Chris@0 2851 void
Chris@86 2852 MainWindow::openLocation()
Chris@86 2853 {
Chris@103 2854 QSettings settings;
Chris@103 2855 settings.beginGroup("MainWindow");
Chris@103 2856 QString lastLocation = settings.value("lastremote", "").toString();
Chris@103 2857
Chris@86 2858 bool ok = false;
Chris@86 2859 QString text = QInputDialog::getText
Chris@86 2860 (this, tr("Open Location"),
Chris@86 2861 tr("Please enter the URL of the location to open:"),
Chris@103 2862 QLineEdit::Normal, lastLocation, &ok);
Chris@103 2863
Chris@103 2864 if (!ok) return;
Chris@103 2865
Chris@103 2866 settings.setValue("lastremote", text);
Chris@103 2867
Chris@103 2868 if (text.isEmpty()) return;
Chris@86 2869
Chris@419 2870 FileOpenStatus status = open(text, AskUser);
Chris@193 2871
Chris@193 2872 if (status == FileOpenFailed) {
Chris@247 2873 emit hideSplash();
Chris@86 2874 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2875 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
Chris@193 2876 } else if (status == FileOpenWrongMode) {
Chris@247 2877 emit hideSplash();
Chris@193 2878 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 2879 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(text));
Chris@86 2880 }
Chris@86 2881 }
Chris@86 2882
Chris@86 2883 void
Chris@0 2884 MainWindow::openRecentFile()
Chris@0 2885 {
Chris@0 2886 QObject *obj = sender();
Chris@0 2887 QAction *action = dynamic_cast<QAction *>(obj);
Chris@0 2888
Chris@0 2889 if (!action) {
Chris@0 2890 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
Chris@0 2891 << std::endl;
Chris@0 2892 return;
Chris@0 2893 }
Chris@0 2894
Chris@0 2895 QString path = action->text();
Chris@0 2896 if (path == "") return;
Chris@0 2897
Chris@422 2898 FileOpenStatus status = open(path, ReplaceSession);
Chris@193 2899
Chris@193 2900 if (status == FileOpenFailed) {
Chris@247 2901 emit hideSplash();
Chris@193 2902 QMessageBox::critical(this, tr("Failed to open location"),
Chris@193 2903 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
Chris@193 2904 } else if (status == FileOpenWrongMode) {
Chris@247 2905 emit hideSplash();
Chris@193 2906 QMessageBox::critical(this, tr("Failed to open location"),
Chris@294 2907 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(path));
Chris@0 2908 }
Chris@0 2909 }
Chris@0 2910
Chris@0 2911 void
Chris@435 2912 MainWindow::applyTemplate()
Chris@435 2913 {
Chris@435 2914 QObject *s = sender();
Chris@435 2915 QAction *action = qobject_cast<QAction *>(s);
Chris@435 2916
Chris@435 2917 if (!action) {
Chris@435 2918 std::cerr << "WARNING: MainWindow::applyTemplate: sender is not an action"
Chris@435 2919 << std::endl;
Chris@435 2920 return;
Chris@435 2921 }
Chris@435 2922
Chris@435 2923 QString n = action->objectName();
Chris@435 2924 if (n == "") n = action->text();
Chris@435 2925
Chris@435 2926 if (n == "") {
Chris@435 2927 std::cerr << "WARNING: MainWindow::applyTemplate: sender has no name"
Chris@435 2928 << std::endl;
Chris@435 2929 return;
Chris@435 2930 }
Chris@435 2931
Chris@435 2932 QString mainModelLocation;
Chris@435 2933 WaveFileModel *mm = getMainModel();
Chris@435 2934 if (mm) mainModelLocation = mm->getLocation();
Chris@435 2935 if (mainModelLocation != "") {
Chris@435 2936 openAudio(mainModelLocation, ReplaceSession, n);
Chris@435 2937 } else {
Chris@435 2938 openSessionTemplate(n);
Chris@435 2939 }
Chris@435 2940 }
Chris@435 2941
Chris@435 2942 void
Chris@425 2943 MainWindow::saveSessionAsTemplate()
Chris@425 2944 {
Chris@483 2945 QDialog *d = new QDialog;
Chris@483 2946 d->setWindowTitle(tr("Enter template name"));
Chris@483 2947
Chris@483 2948 QGridLayout *layout = new QGridLayout;
Chris@483 2949 d->setLayout(layout);
Chris@483 2950
Chris@483 2951 layout->addWidget(new QLabel(tr("Please enter a name for the saved template:")),
Chris@483 2952 0, 0);
Chris@483 2953 QLineEdit *lineEdit = new QLineEdit;
Chris@483 2954 layout->addWidget(lineEdit, 1, 0);
Chris@483 2955 QCheckBox *makeDefault = new QCheckBox(tr("Set as default template for future audio files"));
Chris@483 2956 layout->addWidget(makeDefault, 2, 0);
Chris@425 2957
Chris@483 2958 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok |
Chris@483 2959 QDialogButtonBox::Cancel);
Chris@483 2960 layout->addWidget(bb, 3, 0);
Chris@483 2961 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
Chris@483 2962 connect(bb, SIGNAL(accepted()), d, SLOT(accept()));
Chris@483 2963 connect(bb, SIGNAL(rejected()), d, SLOT(reject()));
Chris@483 2964
Chris@483 2965 if (d->exec() == QDialog::Accepted) {
Chris@483 2966
Chris@483 2967 QString name = lineEdit->text();
Chris@483 2968 name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_");
Chris@483 2969
Chris@483 2970 ResourceFinder rf;
Chris@483 2971 QString dir = rf.getResourceSaveDir("templates");
Chris@483 2972 QString filename = QString("%1/%2.svt").arg(dir).arg(name);
Chris@483 2973 if (QFile(filename).exists()) {
Chris@483 2974 if (QMessageBox::warning(this,
Chris@483 2975 tr("Template file exists"),
Chris@483 2976 tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name),
Chris@483 2977 QMessageBox::Ok | QMessageBox::Cancel,
Chris@483 2978 QMessageBox::Cancel) != QMessageBox::Ok) {
Chris@483 2979 return;
Chris@483 2980 }
Chris@483 2981 }
Chris@483 2982
Chris@483 2983 if (saveSessionTemplate(filename)) {
Chris@483 2984 if (makeDefault->isChecked()) {
Chris@483 2985 setDefaultSessionTemplate(name);
Chris@483 2986 }
Chris@431 2987 }
Chris@431 2988 }
Chris@425 2989 }
Chris@425 2990
Chris@425 2991 void
Chris@425 2992 MainWindow::manageSavedTemplates()
Chris@425 2993 {
Chris@425 2994 ResourceFinder rf;
Chris@425 2995 QDesktopServices::openUrl("file:" + rf.getResourceSaveDir("templates"));
Chris@423 2996 }
Chris@423 2997
Chris@423 2998 void
Chris@200 2999 MainWindow::paneAdded(Pane *pane)
Chris@200 3000 {
Chris@200 3001 if (m_overview) m_overview->registerView(pane);
Chris@200 3002 }
Chris@200 3003
Chris@200 3004 void
Chris@200 3005 MainWindow::paneHidden(Pane *pane)
Chris@200 3006 {
Chris@200 3007 if (m_overview) m_overview->unregisterView(pane);
Chris@200 3008 }
Chris@200 3009
Chris@200 3010 void
Chris@200 3011 MainWindow::paneAboutToBeDeleted(Pane *pane)
Chris@200 3012 {
Chris@200 3013 if (m_overview) m_overview->unregisterView(pane);
Chris@200 3014 }
Chris@200 3015
Chris@200 3016 void
Chris@193 3017 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
Chris@193 3018 {
Chris@193 3019 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 3020
Chris@193 3021 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
Chris@193 3022
Chris@295 3023 FileOpenStatus status;
Chris@295 3024
Chris@295 3025 if (i == uriList.begin()) {
Chris@295 3026 status = open(*i, ReplaceCurrentPane);
Chris@295 3027 } else {
Chris@295 3028 status = open(*i, CreateAdditionalModel);
Chris@295 3029 }
Chris@193 3030
Chris@193 3031 if (status == FileOpenFailed) {
Chris@247 3032 emit hideSplash();
Chris@193 3033 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@193 3034 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
Chris@295 3035 break;
Chris@193 3036 } else if (status == FileOpenWrongMode) {
Chris@247 3037 emit hideSplash();
Chris@193 3038 QMessageBox::critical(this, tr("Failed to open dropped URL"),
Chris@294 3039 tr("<b>Audio required</b><p>Unable to load layer data from \"%1\" without an audio file.<br>Please load at least one audio file before importing annotations.").arg(*i));
Chris@295 3040 break;
Chris@295 3041 } else if (status == FileOpenCancelled) {
Chris@295 3042 break;
Chris@193 3043 }
Chris@193 3044 }
Chris@193 3045 }
Chris@193 3046
Chris@193 3047 void
Chris@193 3048 MainWindow::paneDropAccepted(Pane *pane, QString text)
Chris@193 3049 {
Chris@193 3050 if (pane) m_paneStack->setCurrentPane(pane);
Chris@193 3051
Chris@193 3052 QUrl testUrl(text);
Chris@193 3053 if (testUrl.scheme() == "file" ||
Chris@193 3054 testUrl.scheme() == "http" ||
Chris@193 3055 testUrl.scheme() == "ftp") {
Chris@193 3056 QStringList list;
Chris@193 3057 list.push_back(text);
Chris@193 3058 paneDropAccepted(pane, list);
Chris@193 3059 return;
Chris@193 3060 }
Chris@193 3061
Chris@193 3062 //!!! open as text -- but by importing as if a CSV, or just adding
Chris@193 3063 //to a text layer?
Chris@193 3064 }
Chris@193 3065
Chris@193 3066 void
Chris@0 3067 MainWindow::closeEvent(QCloseEvent *e)
Chris@0 3068 {
Chris@500 3069 // std::cerr << "MainWindow::closeEvent" << std::endl;
Chris@118 3070
Chris@136 3071 if (m_openingAudioFile) {
Chris@137 3072 // std::cerr << "Busy - ignoring close event" << std::endl;
Chris@136 3073 e->ignore();
Chris@136 3074 return;
Chris@136 3075 }
Chris@136 3076
Chris@70 3077 if (!m_abandoning && !checkSaveModified()) {
Chris@500 3078 // std::cerr << "Close refused by user - ignoring close event" << endl;
Chris@0 3079 e->ignore();
Chris@0 3080 return;
Chris@0 3081 }
Chris@0 3082
Chris@5 3083 QSettings settings;
Chris@5 3084 settings.beginGroup("MainWindow");
Chris@5 3085 settings.setValue("size", size());
Chris@5 3086 settings.setValue("position", pos());
Chris@5 3087 settings.endGroup();
Chris@5 3088
Chris@163 3089 if (m_preferencesDialog &&
Chris@163 3090 m_preferencesDialog->isVisible()) {
Chris@164 3091 closeSession(); // otherwise we'll have to wait for prefs changes
Chris@163 3092 m_preferencesDialog->applicationClosing(false);
Chris@163 3093 }
Chris@163 3094
Chris@200 3095 closeSession();
Chris@200 3096
Chris@0 3097 e->accept();
Chris@489 3098
Chris@0 3099 return;
Chris@0 3100 }
Chris@0 3101
Chris@0 3102 bool
Chris@11 3103 MainWindow::commitData(bool mayAskUser)
Chris@11 3104 {
Chris@11 3105 if (mayAskUser) {
Chris@163 3106 bool rv = checkSaveModified();
Chris@163 3107 if (rv) {
Chris@163 3108 if (m_preferencesDialog &&
Chris@163 3109 m_preferencesDialog->isVisible()) {
Chris@163 3110 m_preferencesDialog->applicationClosing(false);
Chris@163 3111 }
Chris@163 3112 }
Chris@163 3113 return rv;
Chris@11 3114 } else {
Chris@163 3115 if (m_preferencesDialog &&
Chris@163 3116 m_preferencesDialog->isVisible()) {
Chris@163 3117 m_preferencesDialog->applicationClosing(true);
Chris@163 3118 }
Chris@11 3119 if (!m_documentModified) return true;
Chris@11 3120
Chris@11 3121 // If we can't check with the user first, then we can't save
Chris@11 3122 // to the original session file (even if we have it) -- have
Chris@11 3123 // to use a temporary file
Chris@11 3124
Chris@11 3125 QString svDirBase = ".sv1";
Chris@11 3126 QString svDir = QDir::home().filePath(svDirBase);
Chris@11 3127
Chris@11 3128 if (!QFileInfo(svDir).exists()) {
Chris@11 3129 if (!QDir::home().mkdir(svDirBase)) return false;
Chris@11 3130 } else {
Chris@11 3131 if (!QFileInfo(svDir).isDir()) return false;
Chris@11 3132 }
Chris@11 3133
Chris@11 3134 // This name doesn't have to be unguessable
Chris@93 3135 #ifndef _WIN32
Chris@11 3136 QString fname = QString("tmp-%1-%2.sv")
Chris@11 3137 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
Chris@11 3138 .arg(QProcess().pid());
Chris@93 3139 #else
Chris@93 3140 QString fname = QString("tmp-%1.sv")
Chris@93 3141 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
Chris@93 3142 #endif
Chris@11 3143 QString fpath = QDir(svDir).filePath(fname);
Chris@11 3144 if (saveSessionFile(fpath)) {
Chris@34 3145 m_recentFiles.addFile(fpath);
Chris@310 3146 emit activity(tr("Export image to \"%1\"").arg(fpath));
Chris@11 3147 return true;
Chris@11 3148 } else {
Chris@11 3149 return false;
Chris@11 3150 }
Chris@11 3151 }
Chris@11 3152 }
Chris@11 3153
Chris@11 3154 bool
Chris@0 3155 MainWindow::checkSaveModified()
Chris@0 3156 {
Chris@0 3157 // Called before some destructive operation (e.g. new session,
Chris@0 3158 // exit program). Return true if we can safely proceed, false to
Chris@0 3159 // cancel.
Chris@0 3160
Chris@0 3161 if (!m_documentModified) return true;
Chris@0 3162
Chris@247 3163 emit hideSplash();
Chris@247 3164
Chris@0 3165 int button =
Chris@0 3166 QMessageBox::warning(this,
Chris@0 3167 tr("Session modified"),
Chris@207 3168 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?"),
Chris@165 3169 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
Chris@165 3170 QMessageBox::Yes);
Chris@0 3171
Chris@0 3172 if (button == QMessageBox::Yes) {
Chris@0 3173 saveSession();
Chris@0 3174 if (m_documentModified) { // save failed -- don't proceed!
Chris@0 3175 return false;
Chris@0 3176 } else {
Chris@0 3177 return true; // saved, so it's safe to continue now
Chris@0 3178 }
Chris@0 3179 } else if (button == QMessageBox::No) {
Chris@0 3180 m_documentModified = false; // so we know to abandon it
Chris@0 3181 return true;
Chris@0 3182 }
Chris@0 3183
Chris@0 3184 // else cancel
Chris@0 3185 return false;
Chris@0 3186 }
Chris@0 3187
Chris@290 3188 bool
Chris@294 3189 MainWindow::shouldCreateNewSessionForRDFAudio(bool *cancel)
Chris@290 3190 {
Chris@294 3191 //!!! This is very similar to part of MainWindowBase::openAudio --
Chris@294 3192 //!!! make them a bit more uniform
Chris@294 3193
Chris@294 3194 QSettings settings;
Chris@294 3195 settings.beginGroup("MainWindow");
Chris@294 3196 bool prevNewSession = settings.value("newsessionforrdfaudio", true).toBool();
Chris@294 3197 settings.endGroup();
Chris@294 3198 bool newSession = true;
Chris@294 3199
Chris@294 3200 QStringList items;
Chris@294 3201 items << tr("Close the current session and create a new one")
Chris@294 3202 << tr("Add this data to the current session");
Chris@294 3203
Chris@294 3204 bool ok = false;
Chris@294 3205 QString item = ListInputDialog::getItem
Chris@294 3206 (this, tr("Select target for import"),
Chris@294 3207 tr("<b>Select a target for import</b><p>This RDF document refers to one or more audio files.<br>You already have an audio waveform loaded.<br>What would you like to do with the new data?"),
Chris@294 3208 items, prevNewSession ? 0 : 1, &ok);
Chris@294 3209
Chris@294 3210 if (!ok || item.isEmpty()) {
Chris@294 3211 *cancel = true;
Chris@290 3212 return false;
Chris@290 3213 }
Chris@294 3214
Chris@294 3215 newSession = (item == items[0]);
Chris@294 3216 settings.beginGroup("MainWindow");
Chris@294 3217 settings.setValue("newsessionforrdfaudio", newSession);
Chris@294 3218 settings.endGroup();
Chris@294 3219
Chris@294 3220 if (newSession) return true;
Chris@294 3221 else return false;
Chris@290 3222 }
Chris@290 3223
Chris@0 3224 void
Chris@0 3225 MainWindow::saveSession()
Chris@0 3226 {
Chris@0 3227 if (m_sessionFile != "") {
Chris@0 3228 if (!saveSessionFile(m_sessionFile)) {
Chris@0 3229 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 3230 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
Chris@0 3231 } else {
Chris@0 3232 CommandHistory::getInstance()->documentSaved();
Chris@0 3233 documentRestored();
Chris@0 3234 }
Chris@0 3235 } else {
Chris@0 3236 saveSessionAs();
Chris@0 3237 }
Chris@0 3238 }
Chris@0 3239
Chris@0 3240 void
Chris@0 3241 MainWindow::saveSessionAs()
Chris@0 3242 {
Chris@0 3243 QString orig = m_audioFile;
Chris@0 3244 if (orig == "") orig = ".";
Chris@0 3245 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
Chris@0 3246
Chris@88 3247 QString path = getSaveFileName(FileFinder::SessionFile);
Chris@81 3248
Chris@81 3249 if (path == "") return;
Chris@0 3250
Chris@0 3251 if (!saveSessionFile(path)) {
Chris@0 3252 QMessageBox::critical(this, tr("Failed to save file"),
Chris@193 3253 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
Chris@0 3254 } else {
Chris@518 3255 setWindowTitle(tr("%1: %1")
Chris@518 3256 .arg(QApplication::applicationName())
Chris@0 3257 .arg(QFileInfo(path).fileName()));
Chris@0 3258 m_sessionFile = path;
Chris@0 3259 CommandHistory::getInstance()->documentSaved();
Chris@0 3260 documentRestored();
Chris@34 3261 m_recentFiles.addFile(path);
Chris@310 3262 emit activity(tr("Save session as \"%1\"").arg(path));
Chris@0 3263 }
Chris@0 3264 }
Chris@0 3265
Chris@90 3266 void
Chris@72 3267 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
Chris@72 3268 {
Chris@200 3269 MainWindowBase::preferenceChanged(name);
Chris@200 3270
Chris@200 3271 if (name == "Background Mode" && m_viewManager) {
Chris@180 3272 if (m_viewManager->getGlobalDarkBackground()) {
Chris@180 3273 m_panLayer->setBaseColour
Chris@180 3274 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
Chris@180 3275 } else {
Chris@180 3276 m_panLayer->setBaseColour
Chris@180 3277 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
Chris@180 3278 }
Chris@200 3279 }
Chris@0 3280 }
Chris@0 3281
Chris@0 3282 void
Chris@239 3283 MainWindow::propertyStacksResized(int width)
Chris@239 3284 {
Chris@438 3285 // SVDEBUG << "MainWindow::propertyStacksResized(" << width << ")" << endl;
Chris@239 3286
Chris@239 3287 if (!m_playControlsSpacer) return;
Chris@239 3288
Chris@239 3289 int spacerWidth = width - m_playControlsWidth - 4;
Chris@239 3290
Chris@438 3291 // SVDEBUG << "resizing spacer from " << m_playControlsSpacer->width() << " to " << spacerWidth << endl;
Chris@239 3292
Chris@239 3293 m_playControlsSpacer->setFixedSize(QSize(spacerWidth, 2));
Chris@239 3294 }
Chris@239 3295
Chris@239 3296 void
Chris@0 3297 MainWindow::addPane()
Chris@0 3298 {
Chris@0 3299 QObject *s = sender();
Chris@0 3300 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3301
Chris@0 3302 if (!action) {
Chris@0 3303 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
Chris@0 3304 << std::endl;
Chris@0 3305 return;
Chris@0 3306 }
Chris@0 3307
Chris@0 3308 PaneActionMap::iterator i = m_paneActions.find(action);
Chris@0 3309
Chris@0 3310 if (i == m_paneActions.end()) {
Chris@0 3311 std::cerr << "WARNING: MainWindow::addPane: unknown action "
Chris@432 3312 << action->objectName() << std::endl;
Chris@0 3313 return;
Chris@0 3314 }
Chris@0 3315
Chris@69 3316 addPane(i->second, action->text());
Chris@69 3317 }
Chris@69 3318
Chris@69 3319 void
Chris@232 3320 MainWindow::addPane(const LayerConfiguration &configuration, QString text)
Chris@69 3321 {
Chris@69 3322 CommandHistory::getInstance()->startCompoundOperation(text, true);
Chris@0 3323
Chris@0 3324 AddPaneCommand *command = new AddPaneCommand(this);
Chris@0 3325 CommandHistory::getInstance()->addCommand(command);
Chris@0 3326
Chris@0 3327 Pane *pane = command->getPane();
Chris@0 3328
Chris@69 3329 if (configuration.layer == LayerFactory::Spectrum) {
Chris@109 3330 pane->setPlaybackFollow(PlaybackScrollContinuous);
Chris@110 3331 pane->setFollowGlobalZoom(false);
Chris@112 3332 pane->setZoomLevel(512);
Chris@7 3333 }
Chris@7 3334
Chris@69 3335 if (configuration.layer != LayerFactory::TimeRuler &&
Chris@69 3336 configuration.layer != LayerFactory::Spectrum) {
Chris@8 3337
Chris@0 3338 if (!m_timeRulerLayer) {
Chris@0 3339 // std::cerr << "no time ruler layer, creating one" << std::endl;
Chris@0 3340 m_timeRulerLayer = m_document->createMainModelLayer
Chris@0 3341 (LayerFactory::TimeRuler);
Chris@0 3342 }
Chris@0 3343
Chris@438 3344 // SVDEBUG << "adding time ruler layer " << m_timeRulerLayer << endl;
Chris@0 3345
Chris@0 3346 m_document->addLayerToView(pane, m_timeRulerLayer);
Chris@0 3347 }
Chris@0 3348
Chris@69 3349 Layer *newLayer = m_document->createLayer(configuration.layer);
Chris@69 3350
Chris@69 3351 Model *suggestedModel = configuration.sourceModel;
Chris@66 3352 Model *model = 0;
Chris@66 3353
Chris@66 3354 if (suggestedModel) {
Chris@66 3355
Chris@66 3356 // check its validity
Chris@224 3357 std::vector<Model *> inputModels = m_document->getTransformInputModels();
Chris@66 3358 for (size_t j = 0; j < inputModels.size(); ++j) {
Chris@66 3359 if (inputModels[j] == suggestedModel) {
Chris@66 3360 model = suggestedModel;
Chris@66 3361 break;
Chris@66 3362 }
Chris@66 3363 }
Chris@66 3364
Chris@66 3365 if (!model) {
Chris@66 3366 std::cerr << "WARNING: Model " << (void *)suggestedModel
Chris@66 3367 << " appears in pane action map, but is not reported "
Chris@66 3368 << "by document as a valid transform source" << std::endl;
Chris@66 3369 }
Chris@66 3370 }
Chris@66 3371
Chris@346 3372 if (!model) {
Chris@346 3373 model = m_document->getMainModel();
Chris@346 3374 }
Chris@66 3375
Chris@66 3376 m_document->setModel(newLayer, model);
Chris@66 3377
Chris@69 3378 m_document->setChannel(newLayer, configuration.channel);
Chris@0 3379 m_document->addLayerToView(pane, newLayer);
Chris@0 3380
Chris@0 3381 m_paneStack->setCurrentPane(pane);
Chris@70 3382 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3383
Chris@438 3384 // SVDEBUG << "MainWindow::addPane: global centre frame is "
Chris@433 3385 // << m_viewManager->getGlobalCentreFrame() << endl;
Chris@130 3386 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
Chris@73 3387
Chris@0 3388 CommandHistory::getInstance()->endCompoundOperation();
Chris@0 3389
Chris@0 3390 updateMenuStates();
Chris@0 3391 }
Chris@0 3392
Chris@0 3393 void
Chris@0 3394 MainWindow::addLayer()
Chris@0 3395 {
Chris@0 3396 QObject *s = sender();
Chris@0 3397 QAction *action = dynamic_cast<QAction *>(s);
Chris@0 3398
Chris@0 3399 if (!action) {
Chris@0 3400 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
Chris@0 3401 << std::endl;
Chris@0 3402 return;
Chris@0 3403 }
Chris@0 3404
Chris@0 3405 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3406
Chris@0 3407 if (!pane) {
Chris@0 3408 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@0 3409 return;
Chris@0 3410 }
Chris@0 3411
Chris@0 3412 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
Chris@0 3413
Chris@0 3414 if (ei != m_existingLayerActions.end()) {
Chris@0 3415 Layer *newLayer = ei->second;
Chris@0 3416 m_document->addLayerToView(pane, newLayer);
Chris@0 3417 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3418 return;
Chris@0 3419 }
Chris@0 3420
Chris@95 3421 ei = m_sliceActions.find(action);
Chris@95 3422
Chris@95 3423 if (ei != m_sliceActions.end()) {
Chris@95 3424 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
Chris@95 3425 // document->setModel(newLayer, ei->second->getModel());
Chris@95 3426 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
Chris@95 3427 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
Chris@95 3428 if (source && dest) {
Chris@205 3429 //!!!???
Chris@95 3430 dest->setSliceableModel(source->getSliceableModel());
Chris@95 3431 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
Chris@95 3432 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
Chris@95 3433 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
Chris@95 3434 dest, SLOT(modelAboutToBeDeleted(Model *)));
Chris@95 3435 }
Chris@95 3436 m_document->addLayerToView(pane, newLayer);
Chris@95 3437 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@95 3438 return;
Chris@95 3439 }
Chris@95 3440
Chris@211 3441 TransformActionMap::iterator i = m_transformActions.find(action);
Chris@34 3442
Chris@34 3443 if (i == m_transformActions.end()) {
Chris@0 3444
Chris@0 3445 LayerActionMap::iterator i = m_layerActions.find(action);
Chris@0 3446
Chris@0 3447 if (i == m_layerActions.end()) {
Chris@0 3448 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
Chris@432 3449 << action->objectName() << std::endl;
Chris@0 3450 return;
Chris@0 3451 }
Chris@0 3452
Chris@232 3453 LayerFactory::LayerType type = i->second.layer;
Chris@0 3454
Chris@0 3455 LayerFactory::LayerTypeSet emptyTypes =
Chris@0 3456 LayerFactory::getInstance()->getValidEmptyLayerTypes();
Chris@0 3457
Chris@499 3458 Layer *newLayer = 0;
Chris@0 3459
Chris@0 3460 if (emptyTypes.find(type) != emptyTypes.end()) {
Chris@0 3461
Chris@0 3462 newLayer = m_document->createEmptyLayer(type);
Chris@217 3463 if (newLayer) {
Chris@217 3464 m_toolActions[ViewManager::DrawMode]->trigger();
Chris@217 3465 }
Chris@0 3466
Chris@0 3467 } else {
Chris@0 3468
Chris@346 3469 Model *model = i->second.sourceModel;
Chris@346 3470
Chris@415 3471 cerr << "model = "<< model << endl;
Chris@415 3472
Chris@346 3473 if (!model) {
Chris@346 3474 if (type == LayerFactory::TimeRuler) {
Chris@346 3475 newLayer = m_document->createMainModelLayer(type);
Chris@346 3476 } else {
Chris@346 3477 // if model is unspecified and this is not a
Chris@415 3478 // time-ruler layer, use any plausible model from
Chris@415 3479 // the current pane -- this is the case for
Chris@415 3480 // right-button menu layer additions
Chris@415 3481 Pane::ModelSet ms = pane->getModels();
Chris@415 3482 foreach (Model *m, ms) {
Chris@415 3483 RangeSummarisableTimeValueModel *r =
Chris@415 3484 dynamic_cast<RangeSummarisableTimeValueModel *>(m);
Chris@415 3485 if (r) model = m;
Chris@346 3486 }
Chris@346 3487 if (!model) model = getMainModel();
Chris@346 3488 }
Chris@346 3489 }
Chris@346 3490
Chris@346 3491 if (model) {
Chris@238 3492 newLayer = m_document->createLayer(type);
Chris@346 3493 if (m_document->isKnownModel(model)) {
Chris@238 3494 m_document->setChannel(newLayer, i->second.channel);
Chris@346 3495 m_document->setModel(newLayer, model);
Chris@238 3496 } else {
Chris@238 3497 std::cerr << "WARNING: MainWindow::addLayer: unknown model "
Chris@346 3498 << model
Chris@238 3499 << " (\""
Chris@346 3500 << (model ? model->objectName().toStdString() : "")
Chris@238 3501 << "\") in layer action map"
Chris@238 3502 << std::endl;
Chris@238 3503 }
Chris@232 3504 }
Chris@238 3505 }
Chris@0 3506
Chris@217 3507 if (newLayer) {
Chris@217 3508 m_document->addLayerToView(pane, newLayer);
Chris@217 3509 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@217 3510 }
Chris@0 3511
Chris@0 3512 return;
Chris@0 3513 }
Chris@0 3514
Chris@224 3515 //!!! want to do something like this, but it's not supported in
Chris@224 3516 //ModelTransformerFactory yet
Chris@224 3517 /*
Chris@0 3518 int channel = -1;
Chris@0 3519 // pick up the default channel from any existing layers on the same pane
Chris@0 3520 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@0 3521 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
Chris@0 3522 if (c != -1) {
Chris@0 3523 channel = c;
Chris@0 3524 break;
Chris@0 3525 }
Chris@0 3526 }
Chris@224 3527 */
Chris@0 3528
Chris@33 3529 // We always ask for configuration, even if the plugin isn't
Chris@33 3530 // supposed to be configurable, because we need to let the user
Chris@33 3531 // change the execution context (block size etc).
Chris@0 3532
Chris@224 3533 QString transformId = i->second;
Chris@274 3534
Chris@274 3535 addLayer(transformId);
Chris@274 3536 }
Chris@274 3537
Chris@274 3538 void
Chris@274 3539 MainWindow::addLayer(QString transformId)
Chris@274 3540 {
Chris@274 3541 Pane *pane = m_paneStack->getCurrentPane();
Chris@274 3542 if (!pane) {
Chris@274 3543 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
Chris@274 3544 return;
Chris@274 3545 }
Chris@274 3546
Chris@224 3547 Transform transform = TransformFactory::getInstance()->
Chris@224 3548 getDefaultTransformFor(transformId);
Chris@27 3549
Chris@66 3550 std::vector<Model *> candidateInputModels =
Chris@224 3551 m_document->getTransformInputModels();
Chris@53 3552
Chris@219 3553 Model *defaultInputModel = 0;
Chris@219 3554 for (int j = 0; j < pane->getLayerCount(); ++j) {
Chris@219 3555 Layer *layer = pane->getLayer(j);
Chris@219 3556 if (!layer) continue;
Chris@243 3557 if (LayerFactory::getInstance()->getLayerType(layer) !=
Chris@243 3558 LayerFactory::Waveform &&
Chris@243 3559 !layer->isLayerOpaque()) continue;
Chris@219 3560 Model *model = layer->getModel();
Chris@219 3561 if (!model) continue;
Chris@219 3562 for (size_t k = 0; k < candidateInputModels.size(); ++k) {
Chris@219 3563 if (candidateInputModels[k] == model) {
Chris@219 3564 defaultInputModel = model;
Chris@219 3565 break;
Chris@219 3566 }
Chris@219 3567 }
Chris@219 3568 if (defaultInputModel) break;
Chris@219 3569 }
Chris@219 3570
Chris@184 3571 size_t startFrame = 0, duration = 0;
Chris@184 3572 size_t endFrame = 0;
Chris@184 3573 m_viewManager->getSelection().getExtents(startFrame, endFrame);
Chris@184 3574 if (endFrame > startFrame) duration = endFrame - startFrame;
Chris@184 3575 else startFrame = 0;
Chris@184 3576
Chris@357 3577 TransformUserConfigurator configurator;
Chris@357 3578
Chris@224 3579 ModelTransformer::Input input = ModelTransformerFactory::getInstance()->
Chris@224 3580 getConfigurationForTransform
Chris@211 3581 (transform,
Chris@211 3582 candidateInputModels,
Chris@219 3583 defaultInputModel,
Chris@211 3584 m_playSource,
Chris@211 3585 startFrame,
Chris@357 3586 duration,
Chris@357 3587 &configurator);
Chris@211 3588
Chris@224 3589 if (!input.getModel()) return;
Chris@224 3590
Chris@438 3591 // SVDEBUG << "MainWindow::addLayer: Input model is " << input.getModel() << " \"" << input.getModel()->objectName() << "\"" << endl << "transform:" << endl << transform.toXmlString() << endl;
Chris@224 3592
Chris@224 3593 Layer *newLayer = m_document->createDerivedLayer(transform, input);
Chris@0 3594
Chris@0 3595 if (newLayer) {
Chris@0 3596 m_document->addLayerToView(pane, newLayer);
Chris@224 3597 m_document->setChannel(newLayer, input.getChannel());
Chris@224 3598 m_recentTransforms.add(transformId);
Chris@70 3599 m_paneStack->setCurrentLayer(pane, newLayer);
Chris@0 3600 }
Chris@0 3601
Chris@0 3602 updateMenuStates();
Chris@0 3603 }
Chris@0 3604
Chris@0 3605 void
Chris@0 3606 MainWindow::renameCurrentLayer()
Chris@0 3607 {
Chris@0 3608 Pane *pane = m_paneStack->getCurrentPane();
Chris@0 3609 if (pane) {
Chris@0 3610 Layer *layer = pane->getSelectedLayer();
Chris@0 3611 if (layer) {
Chris@0 3612 bool ok = false;
Chris@0 3613 QString newName = QInputDialog::getText
Chris@0 3614 (this, tr("Rename Layer"),
Chris@0 3615 tr("New name for this layer:"),
Chris@0 3616 QLineEdit::Normal, layer->objectName(), &ok);
Chris@0 3617 if (ok) {
Chris@239 3618 layer->setPresentationName(newName);
Chris@95 3619 setupExistingLayersMenus();
Chris@0 3620 }
Chris@0 3621 }
Chris@0 3622 }
Chris@0 3623 }
Chris@0 3624
Chris@0 3625 void
Chris@272 3626 MainWindow::findTransform()
Chris@272 3627 {
Chris@274 3628 TransformFinder *finder = new TransformFinder(this);
Chris@274 3629 if (!finder->exec()) {
Chris@274 3630 delete finder;
Chris@274 3631 return;
Chris@273 3632 }
Chris@274 3633 TransformId transform = finder->getTransform();
Chris@274 3634 delete finder;
Chris@287 3635
Chris@287 3636 if (getMainModel() != 0 && m_paneStack->getCurrentPane() != 0) {
Chris@287 3637 addLayer(transform);
Chris@287 3638 }
Chris@272 3639 }
Chris@272 3640
Chris@272 3641 void
Chris@207 3642 MainWindow::playSoloToggled()
Chris@207 3643 {
Chris@207 3644 MainWindowBase::playSoloToggled();
Chris@207 3645 m_soloModified = true;
Chris@207 3646 }
Chris@207 3647
Chris@207 3648 void
Chris@206 3649 MainWindow::alignToggled()
Chris@206 3650 {
Chris@206 3651 QAction *action = dynamic_cast<QAction *>(sender());
Chris@206 3652
Chris@207 3653 if (!m_viewManager) return;
Chris@207 3654
Chris@206 3655 if (action) {
Chris@206 3656 m_viewManager->setAlignMode(action->isChecked());
Chris@206 3657 } else {
Chris@206 3658 m_viewManager->setAlignMode(!m_viewManager->getAlignMode());
Chris@206 3659 }
Chris@206 3660
Chris@206 3661 if (m_viewManager->getAlignMode()) {
Chris@207 3662 m_prevSolo = m_soloAction->isChecked();
Chris@208 3663 if (!m_soloAction->isChecked()) {
Chris@208 3664 m_soloAction->setChecked(true);
Chris@208 3665 MainWindowBase::playSoloToggled();
Chris@208 3666 }
Chris@207 3667 m_soloModified = false;
Chris@207 3668 emit canChangeSolo(false);
Chris@206 3669 m_document->alignModels();
Chris@206 3670 m_document->setAutoAlignment(true);
Chris@206 3671 } else {
Chris@207 3672 if (!m_soloModified) {
Chris@208 3673 if (m_soloAction->isChecked() != m_prevSolo) {
Chris@208 3674 m_soloAction->setChecked(m_prevSolo);
Chris@208 3675 MainWindowBase::playSoloToggled();
Chris@208 3676 }
Chris@207 3677 }
Chris@207 3678 emit canChangeSolo(true);
Chris@206 3679 m_document->setAutoAlignment(false);
Chris@206 3680 }
Chris@206 3681
Chris@206 3682 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
Chris@206 3683
Chris@206 3684 Pane *pane = m_paneStack->getPane(i);
Chris@206 3685 if (!pane) continue;
Chris@206 3686
Chris@206 3687 pane->update();
Chris@206 3688 }
Chris@206 3689 }
Chris@206 3690
Chris@206 3691 void
Chris@59 3692 MainWindow::playSpeedChanged(int position)
Chris@0 3693 {
Chris@59 3694 PlaySpeedRangeMapper mapper(0, 200);
Chris@60 3695
Chris@60 3696 float percent = m_playSpeed->mappedValue();
Chris@60 3697 float factor = mapper.getFactorForValue(percent);
Chris@60 3698
Chris@267 3699 // std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
Chris@60 3700
Chris@59 3701 bool something = (position != 100);
Chris@155 3702
Chris@59 3703 int pc = lrintf(percent);
Chris@21 3704
Chris@155 3705 if (!something) {
Chris@155 3706 contextHelpChanged(tr("Playback speed: Normal"));
Chris@155 3707 } else {
Chris@155 3708 contextHelpChanged(tr("Playback speed: %1%2%")
Chris@155 3709 .arg(position > 100 ? "+" : "")
Chris@155 3710 .arg(pc));
Chris@155 3711 }
Chris@155 3712
Chris@240 3713 m_playSource->setTimeStretch(factor);
Chris@155 3714
Chris@155 3715 updateMenuStates();
Chris@16 3716 }
Chris@16 3717
Chris@26 3718 void
Chris@155 3719 MainWindow::speedUpPlayback()
Chris@155 3720 {
Chris@155 3721 int value = m_playSpeed->value();
Chris@155 3722 value = value + m_playSpeed->pageStep();
Chris@155 3723 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
Chris@155 3724 m_playSpeed->setValue(value);
Chris@155 3725 }
Chris@155 3726
Chris@155 3727 void
Chris@155 3728 MainWindow::slowDownPlayback()
Chris@155 3729 {
Chris@155 3730 int value = m_playSpeed->value();
Chris@155 3731 value = value - m_playSpeed->pageStep();
Chris@155 3732 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
Chris@155 3733 m_playSpeed->setValue(value);
Chris@155 3734 }
Chris@155 3735
Chris@155 3736 void
Chris@155 3737 MainWindow::restoreNormalPlayback()
Chris@155 3738 {
Chris@155 3739 m_playSpeed->setValue(m_playSpeed->defaultValue());
Chris@155 3740 }
Chris@155 3741
Chris@155 3742 void
Chris@227 3743 MainWindow::currentPaneChanged(Pane *pane)
Chris@227 3744 {
Chris@228 3745 MainWindowBase::currentPaneChanged(pane);
Chris@228 3746
Chris@227 3747 if (!pane || !m_panLayer) return;
Chris@227 3748 for (int i = pane->getLayerCount(); i > 0; ) {
Chris@227 3749 --i;
Chris@227 3750 Layer *layer = pane->getLayer(i);
Chris@227 3751 if (LayerFactory::getInstance()->getLayerType(layer) ==
Chris@227 3752 LayerFactory::Waveform) {
Chris@227 3753 RangeSummarisableTimeValueModel *tvm =
Chris@227 3754 dynamic_cast<RangeSummarisableTimeValueModel *>(layer->getModel());
Chris@227 3755 if (tvm) {
Chris@227 3756 m_panLayer->setModel(tvm);
Chris@227 3757 return;
Chris@227 3758 }
Chris@227 3759 }
Chris@227 3760 }
Chris@227 3761 }
Chris@227 3762
Chris@227 3763 void
Chris@116 3764 MainWindow::updateVisibleRangeDisplay(Pane *p) const
Chris@116 3765 {
Chris@116 3766 if (!getMainModel() || !p) {
Chris@116 3767 return;
Chris@116 3768 }
Chris@116 3769
Chris@117 3770 bool haveSelection = false;
Chris@117 3771 size_t startFrame = 0, endFrame = 0;
Chris@117 3772
Chris@117 3773 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
Chris@117 3774
Chris@117 3775 bool exclusive = false;
Chris@117 3776 Selection s = m_viewManager->getInProgressSelection(exclusive);
Chris@117 3777
Chris@117 3778 if (!s.isEmpty()) {
Chris@117 3779 haveSelection = true;
Chris@117 3780 startFrame = s.getStartFrame();
Chris@117 3781 endFrame = s.getEndFrame();
Chris@117 3782 }
Chris@117 3783 }
Chris@117 3784
Chris@117 3785 if (!haveSelection) {
Chris@117 3786 startFrame = p->getFirstVisibleFrame();
Chris@117 3787 endFrame = p->getLastVisibleFrame();
Chris@117 3788 }
Chris@117 3789
Chris@116 3790 RealTime start = RealTime::frame2RealTime
Chris@117 3791 (startFrame, getMainModel()->getSampleRate());
Chris@116 3792
Chris@116 3793 RealTime end = RealTime::frame2RealTime
Chris@117 3794 (endFrame, getMainModel()->getSampleRate());
Chris@116 3795
Chris@116 3796 RealTime duration = end - start;
Chris@116 3797
Chris@116 3798 QString startStr, endStr, durationStr;
Chris@116 3799 startStr = start.toText(true).c_str();
Chris@116 3800 endStr = end.toText(true).c_str();
Chris@116 3801 durationStr = duration.toText(true).c_str();
Chris@116 3802
Chris@117 3803 if (haveSelection) {
Chris@117 3804 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
Chris@117 3805 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3806 } else {
Chris@117 3807 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
Chris@117 3808 .arg(startStr).arg(endStr).arg(durationStr);
Chris@117 3809 }
Chris@116 3810
Chris@116 3811 statusBar()->showMessage(m_myStatusMessage);
Chris@340 3812
Chris@340 3813 updatePositionStatusDisplays();
Chris@340 3814 }
Chris@340 3815
Chris@340 3816 void
Chris@340 3817 MainWindow::updatePositionStatusDisplays() const
Chris@340 3818 {
Chris@340 3819 if (!statusBar()->isVisible()) return;
Chris@340 3820
Chris@340 3821 Pane *pane = 0;
Chris@340 3822 size_t frame = m_viewManager->getPlaybackFrame();
Chris@340 3823
Chris@340 3824 if (m_paneStack) pane = m_paneStack->getCurrentPane();
Chris@340 3825 if (!pane) return;
Chris@340 3826
Chris@340 3827 int layers = pane->getLayerCount();
Chris@340 3828 if (layers == 0) m_currentLabel->setText("");
Chris@340 3829
Chris@340 3830 for (int i = layers-1; i >= 0; --i) {
Chris@340 3831 Layer *layer = pane->getLayer(i);
Chris@340 3832 if (!layer) continue;
Chris@340 3833 if (!layer->isLayerEditable()) continue;
Chris@340 3834 QString label = layer->getLabelPreceding
Chris@340 3835 (pane->alignFromReference(frame));
Chris@340 3836 m_currentLabel->setText(label);
Chris@340 3837 break;
Chris@340 3838 }
Chris@116 3839 }
Chris@116 3840
Chris@116 3841 void
Chris@0 3842 MainWindow::outputLevelsChanged(float left, float right)
Chris@0 3843 {
Chris@0 3844 m_fader->setPeakLeft(left);
Chris@0 3845 m_fader->setPeakRight(right);
Chris@0 3846 }
Chris@0 3847
Chris@0 3848 void
Chris@0 3849 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
Chris@0 3850 bool willResample)
Chris@0 3851 {
Chris@0 3852 if (!willResample) {
Chris@247 3853 emit hideSplash();
Chris@0 3854 QMessageBox::information
Chris@0 3855 (this, tr("Sample rate mismatch"),
Chris@193 3856 tr("<b>Wrong sample rate</b><p>The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).<p>The file will play at the wrong speed and pitch.<p>Change the <i>Resample mismatching files on import</i> option under <i>File</i> -> <i>Preferences</i> if you want to alter this behaviour.")
Chris@0 3857 .arg(requested).arg(actual));
Chris@0 3858 }
Chris@0 3859
Chris@0 3860 updateDescriptionLabel();
Chris@0 3861 }
Chris@0 3862
Chris@0 3863 void
Chris@42 3864 MainWindow::audioOverloadPluginDisabled()
Chris@42 3865 {
Chris@42 3866 QMessageBox::information
Chris@42 3867 (this, tr("Audio processing overload"),
Chris@193 3868 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
Chris@42 3869 }
Chris@42 3870
Chris@42 3871 void
Chris@266 3872 MainWindow::audioTimeStretchMultiChannelDisabled()
Chris@266 3873 {
Chris@266 3874 static bool shownOnce = false;
Chris@266 3875 if (shownOnce) return;
Chris@266 3876 QMessageBox::information
Chris@266 3877 (this, tr("Audio processing overload"),
Chris@266 3878 tr("<b>Overloaded</b><p>Audio playback speed processing has been reduced to a single channel, due to a processing overload."));
Chris@266 3879 shownOnce = true;
Chris@266 3880 }
Chris@266 3881
Chris@266 3882 void
Chris@304 3883 MainWindow::midiEventsAvailable()
Chris@304 3884 {
Chris@307 3885 Pane *currentPane = 0;
Chris@307 3886 NoteLayer *currentNoteLayer = 0;
Chris@309 3887 TimeValueLayer *currentTimeValueLayer = 0;
Chris@307 3888
Chris@307 3889 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 3890 if (currentPane) {
Chris@307 3891 currentNoteLayer = dynamic_cast<NoteLayer *>
Chris@307 3892 (currentPane->getSelectedLayer());
Chris@309 3893 currentTimeValueLayer = dynamic_cast<TimeValueLayer *>
Chris@309 3894 (currentPane->getSelectedLayer());
Chris@307 3895 }
Chris@307 3896
Chris@305 3897 // This is called through a serialised signal/slot invocation
Chris@305 3898 // (across threads). It could happen quite some time after the
Chris@305 3899 // event was actually received, which is why event timestamping
Chris@305 3900 // happens in the MIDI input class and not here.
Chris@307 3901
Chris@305 3902 while (m_midiInput->getEventsAvailable() > 0) {
Chris@308 3903
Chris@305 3904 MIDIEvent ev(m_midiInput->readEvent());
Chris@307 3905
Chris@309 3906 size_t frame = currentPane->alignFromReference(ev.getTime());
Chris@309 3907
Chris@308 3908 bool noteOn = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 3909 ev.getVelocity() > 0);
Chris@308 3910
Chris@308 3911 bool noteOff = (ev.getMessageType() == MIDIConstants::MIDI_NOTE_OFF ||
Chris@308 3912 (ev.getMessageType() == MIDIConstants::MIDI_NOTE_ON &&
Chris@308 3913 ev.getVelocity() == 0));
Chris@308 3914
Chris@307 3915 if (currentNoteLayer) {
Chris@307 3916
Chris@310 3917 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 3918
Chris@308 3919 if (noteOn) {
Chris@307 3920
Chris@309 3921 currentNoteLayer->addNoteOn(frame,
Chris@307 3922 ev.getPitch(),
Chris@307 3923 ev.getVelocity());
Chris@307 3924
Chris@308 3925 } else if (noteOff) {
Chris@307 3926
Chris@309 3927 currentNoteLayer->addNoteOff(frame,
Chris@307 3928 ev.getPitch());
Chris@307 3929
Chris@307 3930 }
Chris@307 3931
Chris@309 3932 continue;
Chris@309 3933 }
Chris@309 3934
Chris@309 3935 if (currentTimeValueLayer) {
Chris@308 3936
Chris@308 3937 if (!noteOn) continue;
Chris@310 3938
Chris@310 3939 if (!m_playSource || !m_playSource->isPlaying()) continue;
Chris@310 3940
Chris@309 3941 Model *model = static_cast<Layer *>(currentTimeValueLayer)->getModel();
Chris@309 3942 SparseTimeValueModel *tvm =
Chris@309 3943 dynamic_cast<SparseTimeValueModel *>(model);
Chris@309 3944 if (tvm) {
Chris@309 3945 SparseTimeValueModel::Point point(frame, ev.getPitch() % 12, "");
Chris@309 3946 SparseTimeValueModel::AddPointCommand *command =
Chris@309 3947 new SparseTimeValueModel::AddPointCommand
Chris@309 3948 (tvm, point, tr("Add Point"));
Chris@309 3949 CommandHistory::getInstance()->addCommand(command);
Chris@309 3950 }
Chris@309 3951 continue;
Chris@309 3952
Chris@305 3953 }
Chris@309 3954
Chris@309 3955 if (!noteOn) continue;
Chris@309 3956 insertInstantAt(ev.getTime());
Chris@304 3957 }
Chris@304 3958 }
Chris@304 3959
Chris@304 3960 void
Chris@305 3961 MainWindow::playStatusChanged(bool playing)
Chris@305 3962 {
Chris@307 3963 Pane *currentPane = 0;
Chris@307 3964 NoteLayer *currentNoteLayer = 0;
Chris@307 3965
Chris@307 3966 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
Chris@307 3967 if (currentPane) {
Chris@307 3968 currentNoteLayer = dynamic_cast<NoteLayer *>(currentPane->getSelectedLayer());
Chris@307 3969 }
Chris@307 3970
Chris@307 3971 if (currentNoteLayer) {
Chris@307 3972 currentNoteLayer->abandonNoteOns();
Chris@307 3973 }
Chris@305 3974 }
Chris@305 3975
Chris@305 3976 void
Chris@200 3977 MainWindow::layerRemoved(Layer *layer)
Chris@0 3978 {
Chris@95 3979 setupExistingLayersMenus();
Chris@200 3980 MainWindowBase::layerRemoved(layer);
Chris@0 3981 }
Chris@0 3982
Chris@0 3983 void
Chris@0 3984 MainWindow::layerInAView(Layer *layer, bool inAView)
Chris@0 3985 {
Chris@95 3986 setupExistingLayersMenus();
Chris@200 3987 MainWindowBase::layerInAView(layer, inAView);
Chris@0 3988 }
Chris@0 3989
Chris@0 3990 void
Chris@0 3991 MainWindow::modelAdded(Model *model)
Chris@0 3992 {
Chris@200 3993 MainWindowBase::modelAdded(model);
Chris@66 3994 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@66 3995 setupPaneAndLayerMenus();
Chris@66 3996 }
Chris@0 3997 }
Chris@0 3998
Chris@0 3999 void
Chris@0 4000 MainWindow::mainModelChanged(WaveFileModel *model)
Chris@0 4001 {
Chris@0 4002 m_panLayer->setModel(model);
Chris@200 4003
Chris@200 4004 MainWindowBase::mainModelChanged(model);
Chris@200 4005
Chris@200 4006 if (m_playTarget) {
Chris@200 4007 connect(m_fader, SIGNAL(valueChanged(float)),
Chris@200 4008 m_playTarget, SLOT(setOutputGain(float)));
Chris@200 4009 }
Chris@0 4010 }
Chris@0 4011
Chris@0 4012 void
Chris@200 4013 MainWindow::setInstantsNumbering()
Chris@0 4014 {
Chris@200 4015 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 4016 if (!a) return;
Chris@200 4017
Chris@200 4018 int type = m_numberingActions[a];
Chris@200 4019
Chris@200 4020 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
Chris@200 4021
Chris@200 4022 QSettings settings;
Chris@200 4023 settings.beginGroup("MainWindow");
Chris@200 4024 settings.setValue("labellertype", type);
Chris@200 4025 settings.endGroup();
Chris@200 4026 }
Chris@200 4027
Chris@200 4028 void
Chris@200 4029 MainWindow::setInstantsCounterCycle()
Chris@200 4030 {
Chris@200 4031 QAction *a = dynamic_cast<QAction *>(sender());
Chris@200 4032 if (!a) return;
Chris@200 4033
Chris@200 4034 int cycle = a->text().toInt();
Chris@200 4035 if (cycle == 0) return;
Chris@200 4036
Chris@200 4037 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
Chris@200 4038
Chris@200 4039 QSettings settings;
Chris@200 4040 settings.beginGroup("MainWindow");
Chris@200 4041 settings.setValue("labellercycle", cycle);
Chris@200 4042 settings.endGroup();
Chris@200 4043 }
Chris@200 4044
Chris@200 4045 void
Chris@200 4046 MainWindow::resetInstantsCounters()
Chris@200 4047 {
Chris@200 4048 LabelCounterInputDialog dialog(m_labeller, this);
Chris@241 4049 dialog.setWindowTitle(tr("Reset Counters"));
Chris@200 4050 dialog.exec();
Chris@0 4051 }
Chris@0 4052
Chris@0 4053 void
Chris@233 4054 MainWindow::modelGenerationFailed(QString transformName, QString message)
Chris@233 4055 {
Chris@247 4056 emit hideSplash();
Chris@247 4057
Chris@233 4058 if (message != "") {
Chris@233 4059
Chris@233 4060 QMessageBox::warning
Chris@233 4061 (this,
Chris@233 4062 tr("Failed to generate layer"),
Chris@233 4063 tr("<b>Layer generation failed</b><p>Failed to generate derived layer.<p>The layer transform \"%1\" failed:<p>%2")
Chris@233 4064 .arg(transformName).arg(message),
Chris@233 4065 QMessageBox::Ok);
Chris@233 4066 } else {
Chris@233 4067 QMessageBox::warning
Chris@233 4068 (this,
Chris@233 4069 tr("Failed to generate layer"),
Chris@233 4070 tr("<b>Layer generation failed</b><p>Failed to generate a derived layer.<p>The layer transform \"%1\" failed.<p>No error information is available.")
Chris@233 4071 .arg(transformName),
Chris@233 4072 QMessageBox::Ok);
Chris@233 4073 }
Chris@233 4074 }
Chris@233 4075
Chris@233 4076 void
Chris@233 4077 MainWindow::modelGenerationWarning(QString transformName, QString message)
Chris@233 4078 {
Chris@247 4079 emit hideSplash();
Chris@247 4080
Chris@233 4081 QMessageBox::warning
Chris@233 4082 (this, tr("Warning"), message, QMessageBox::Ok);
Chris@233 4083 }
Chris@233 4084
Chris@233 4085 void
Chris@233 4086 MainWindow::modelRegenerationFailed(QString layerName,
Chris@233 4087 QString transformName, QString message)
Chris@233 4088 {
Chris@247 4089 emit hideSplash();
Chris@247 4090
Chris@233 4091 if (message != "") {
Chris@233 4092
Chris@233 4093 QMessageBox::warning
Chris@233 4094 (this,
Chris@233 4095 tr("Failed to regenerate layer"),
Chris@233 4096 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed:<p>%3")
Chris@233 4097 .arg(layerName).arg(transformName).arg(message),
Chris@233 4098 QMessageBox::Ok);
Chris@233 4099 } else {
Chris@233 4100 QMessageBox::warning
Chris@233 4101 (this,
Chris@233 4102 tr("Failed to regenerate layer"),
Chris@233 4103 tr("<b>Layer generation failed</b><p>Failed to regenerate derived layer \"%1\" using new data model as input.<p>The layer transform \"%2\" failed.<p>No error information is available.")
Chris@233 4104 .arg(layerName).arg(transformName),
Chris@233 4105 QMessageBox::Ok);
Chris@233 4106 }
Chris@233 4107 }
Chris@233 4108
Chris@233 4109 void
Chris@233 4110 MainWindow::modelRegenerationWarning(QString layerName,
Chris@233 4111 QString transformName, QString message)
Chris@233 4112 {
Chris@247 4113 emit hideSplash();
Chris@247 4114
Chris@233 4115 QMessageBox::warning
Chris@233 4116 (this, tr("Warning"), tr("<b>Warning when regenerating layer</b><p>When regenerating the derived layer \"%1\" using new data model as input:<p>%2").arg(layerName).arg(message), QMessageBox::Ok);
Chris@233 4117 }
Chris@233 4118
Chris@233 4119 void
Chris@233 4120 MainWindow::alignmentFailed(QString transformName, QString message)
Chris@0 4121 {
Chris@247 4122 emit hideSplash();
Chris@247 4123
Chris@0 4124 QMessageBox::warning
Chris@0 4125 (this,
Chris@233 4126 tr("Failed to calculate alignment"),
Chris@233 4127 tr("<b>Alignment calculation failed</b><p>Failed to calculate an audio alignment using transform \"%1\":<p>%2")
Chris@233 4128 .arg(transformName).arg(message),
Chris@165 4129 QMessageBox::Ok);
Chris@0 4130 }
Chris@0 4131
Chris@0 4132 void
Chris@0 4133 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
Chris@0 4134 {
Chris@438 4135 // SVDEBUG << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << endl;
Chris@0 4136 m_paneStack->setCurrentPane(pane);
Chris@0 4137 m_rightButtonMenu->popup(position);
Chris@0 4138 }
Chris@0 4139
Chris@0 4140 void
Chris@0 4141 MainWindow::showLayerTree()
Chris@0 4142 {
Chris@219 4143 if (!m_layerTreeDialog.isNull()) {
Chris@219 4144 m_layerTreeDialog->show();
Chris@219 4145 m_layerTreeDialog->raise();
Chris@177 4146 return;
Chris@177 4147 }
Chris@177 4148
Chris@219 4149 m_layerTreeDialog = new LayerTreeDialog(m_paneStack);
Chris@232 4150 m_layerTreeDialog->setAttribute(Qt::WA_DeleteOnClose); // see below
Chris@219 4151 m_layerTreeDialog->show();
Chris@0 4152 }
Chris@0 4153
Chris@0 4154 void
Chris@306 4155 MainWindow::showActivityLog()
Chris@306 4156 {
Chris@306 4157 m_activityLog->show();
Chris@306 4158 m_activityLog->raise();
Chris@306 4159 m_activityLog->scrollToEnd();
Chris@306 4160 }
Chris@306 4161
Chris@306 4162 void
Chris@0 4163 MainWindow::preferences()
Chris@0 4164 {
Chris@436 4165 bool goToTemplateTab =
Chris@436 4166 (sender() && sender()->objectName() == "set_default_template");
Chris@436 4167
Chris@0 4168 if (!m_preferencesDialog.isNull()) {
Chris@0 4169 m_preferencesDialog->show();
Chris@0 4170 m_preferencesDialog->raise();
Chris@436 4171 if (goToTemplateTab) {
Chris@436 4172 m_preferencesDialog->switchToTab(PreferencesDialog::TemplateTab);
Chris@436 4173 }
Chris@0 4174 return;
Chris@0 4175 }
Chris@0 4176
Chris@0 4177 m_preferencesDialog = new PreferencesDialog(this);
Chris@0 4178
Chris@0 4179 // DeleteOnClose is safe here, because m_preferencesDialog is a
Chris@0 4180 // QPointer that will be zeroed when the dialog is deleted. We
Chris@0 4181 // use it in preference to leaving the dialog lying around because
Chris@0 4182 // if you Cancel the dialog, it resets the preferences state
Chris@0 4183 // without resetting its own widgets, so its state will be
Chris@0 4184 // incorrect when next shown unless we construct it afresh
Chris@0 4185 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
Chris@0 4186
Chris@0 4187 m_preferencesDialog->show();
Chris@436 4188 if (goToTemplateTab) {
Chris@436 4189 m_preferencesDialog->switchToTab(PreferencesDialog::TemplateTab);
Chris@436 4190 }
Chris@0 4191 }
Chris@0 4192
Chris@0 4193 void
Chris@90 4194 MainWindow::mouseEnteredWidget()
Chris@90 4195 {
Chris@90 4196 QWidget *w = dynamic_cast<QWidget *>(sender());
Chris@90 4197 if (!w) return;
Chris@90 4198
Chris@90 4199 if (w == m_fader) {
Chris@116 4200 contextHelpChanged(tr("Adjust the master playback level"));
Chris@90 4201 } else if (w == m_playSpeed) {
Chris@116 4202 contextHelpChanged(tr("Adjust the master playback speed"));
Chris@90 4203 }
Chris@90 4204 }
Chris@90 4205
Chris@90 4206 void
Chris@90 4207 MainWindow::mouseLeftWidget()
Chris@90 4208 {
Chris@116 4209 contextHelpChanged("");
Chris@116 4210 }
Chris@116 4211
Chris@116 4212 void
Chris@0 4213 MainWindow::website()
Chris@0 4214 {
Chris@0 4215 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
Chris@0 4216 }
Chris@0 4217
Chris@0 4218 void
Chris@0 4219 MainWindow::help()
Chris@0 4220 {
Chris@318 4221 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/%1/en/").arg(SV_VERSION));
Chris@0 4222 }
Chris@0 4223
Chris@0 4224 void
Chris@0 4225 MainWindow::about()
Chris@0 4226 {
Chris@0 4227 bool debug = false;
Chris@0 4228 QString version = "(unknown version)";
Chris@0 4229
Chris@0 4230 #ifdef BUILD_DEBUG
Chris@0 4231 debug = true;
Chris@285 4232 #endif // BUILD_DEBUG
Chris@0 4233 #ifdef SV_VERSION
Chris@0 4234 #ifdef SVNREV
Chris@0 4235 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
Chris@285 4236 #else // !SVNREV
Chris@0 4237 version = tr("Release %1").arg(SV_VERSION);
Chris@285 4238 #endif // SVNREV
Chris@285 4239 #else // !SV_VERSION
Chris@0 4240 #ifdef SVNREV
Chris@0 4241 version = tr("Unreleased : Revision %1").arg(SVNREV);
Chris@285 4242 #endif // SVNREV
Chris@285 4243 #endif // SV_VERSION
Chris@0 4244
Chris@0 4245 QString aboutText;
Chris@0 4246
Chris@0 4247 aboutText += tr("<h3>About Sonic Visualiser</h3>");
Chris@285 4248 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.<br><a href=\"http://www.sonicvisualiser.org/\">http://www.sonicvisualiser.org/</a></p>");
Chris@285 4249 aboutText += tr("<p><small>%1 : %2 configuration</small></p>")
Chris@0 4250 .arg(version)
Chris@0 4251 .arg(debug ? tr("Debug") : tr("Release"));
Chris@0 4252
Chris@285 4253 aboutText += "<small>";
Chris@285 4254
Chris@285 4255 aboutText += tr("With Qt v%1 &copy; Nokia Corporation").arg(QT_VERSION_STR);
Chris@285 4256
Chris@0 4257 #ifdef HAVE_JACK
Chris@93 4258 #ifdef JACK_VERSION
Chris@285 4259 aboutText += tr("<br>With JACK audio output library v%1 &copy; Paul Davis and Jack O'Quin").arg(JACK_VERSION);
Chris@285 4260 #else // !JACK_VERSION
Chris@257 4261 aboutText += tr("<br>With JACK audio output library &copy; Paul Davis and Jack O'Quin");
Chris@285 4262 #endif // JACK_VERSION
Chris@285 4263 #endif // HAVE_JACK
Chris@0 4264 #ifdef HAVE_PORTAUDIO
Chris@257 4265 aboutText += tr("<br>With PortAudio audio output library &copy; Ross Bencina and Phil Burk");
Chris@285 4266 #endif // HAVE_PORTAUDIO
Chris@257 4267 #ifdef HAVE_LIBPULSE
Chris@285 4268 #ifdef LIBPULSE_VERSION
Chris@285 4269 aboutText += tr("<br>With PulseAudio audio output library v%1 &copy; Lennart Poettering and Pierre Ossman").arg(LIBPULSE_VERSION);
Chris@285 4270 #else // !LIBPULSE_VERSION
Chris@257 4271 aboutText += tr("<br>With PulseAudio audio output library &copy; Lennart Poettering and Pierre Ossman");
Chris@285 4272 #endif // LIBPULSE_VERSION
Chris@285 4273 #endif // HAVE_LIBPULSE
Chris@0 4274 #ifdef HAVE_OGGZ
Chris@93 4275 #ifdef OGGZ_VERSION
Chris@0 4276 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) &copy; CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
Chris@285 4277 #else // !OGGZ_VERSION
Chris@93 4278 aboutText += tr("<br>With Ogg file decoder &copy; CSIRO Australia");
Chris@285 4279 #endif // OGGZ_VERSION
Chris@285 4280 #endif // HAVE_OGGZ
Chris@0 4281 #ifdef HAVE_MAD
Chris@93 4282 #ifdef MAD_VERSION
Chris@285 4283 aboutText += tr("<br>With MAD mp3 decoder v%1 &copy; Underbit Technologies Inc").arg(MAD_VERSION);
Chris@285 4284 #else // !MAD_VERSION
Chris@93 4285 aboutText += tr("<br>With MAD mp3 decoder &copy; Underbit Technologies Inc");
Chris@285 4286 #endif // MAD_VERSION
Chris@285 4287 #endif // HAVE_MAD
Chris@0 4288 #ifdef HAVE_SAMPLERATE
Chris@93 4289 #ifdef SAMPLERATE_VERSION
Chris@285 4290 aboutText += tr("<br>With libsamplerate v%1 &copy; Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
Chris@285 4291 #else // !SAMPLERATE_VERSION
Chris@93 4292 aboutText += tr("<br>With libsamplerate &copy; Erik de Castro Lopo");
Chris@285 4293 #endif // SAMPLERATE_VERSION
Chris@285 4294 #endif // HAVE_SAMPLERATE
Chris@0 4295 #ifdef HAVE_SNDFILE
Chris@93 4296 #ifdef SNDFILE_VERSION
Chris@285 4297 aboutText += tr("<br>With libsndfile v%1 &copy; Erik de Castro Lopo").arg(SNDFILE_VERSION);
Chris@285 4298 #else // !SNDFILE_VERSION
Chris@93 4299 aboutText += tr("<br>With libsndfile &copy; Erik de Castro Lopo");
Chris@285 4300 #endif // SNDFILE_VERSION
Chris@285 4301 #endif // HAVE_SNDFILE
Chris@127 4302 #ifdef HAVE_FFTW3F
Chris@93 4303 #ifdef FFTW3_VERSION
Chris@285 4304 aboutText += tr("<br>With FFTW3 v%1 &copy; Matteo Frigo and MIT").arg(FFTW3_VERSION);
Chris@285 4305 #else // !FFTW3_VERSION
Chris@93 4306 aboutText += tr("<br>With FFTW3 &copy; Matteo Frigo and MIT");
Chris@285 4307 #endif // FFTW3_VERSION
Chris@285 4308 #endif // HAVE_FFTW3F
Chris@267 4309 #ifdef HAVE_RUBBERBAND
Chris@267 4310 #ifdef RUBBERBAND_VERSION
Chris@285 4311 aboutText += tr("<br>With Rubber Band v%1 &copy; Chris Cannam").arg(RUBBERBAND_VERSION);
Chris@285 4312 #else // !RUBBERBAND_VERSION
Chris@267 4313 aboutText += tr("<br>With Rubber Band &copy; Chris Cannam");
Chris@285 4314 #endif // RUBBERBAND_VERSION
Chris@285 4315 #endif // HAVE_RUBBERBAND
Chris@0 4316 #ifdef HAVE_VAMP
Chris@114 4317 aboutText += tr("<br>With Vamp plugin support (API v%1, host SDK v%2) &copy; Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
Chris@285 4318 #endif // !HAVE_VAMP
Chris@0 4319 aboutText += tr("<br>With LADSPA plugin support (API v%1) &copy; Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
Chris@0 4320 aboutText += tr("<br>With DSSI plugin support (API v%1) &copy; Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
Chris@285 4321 #ifdef RAPTOR_VERSION
Chris@285 4322 aboutText += tr("<br>With Raptor RDF parser v%1 &copy; Dave Beckett and the University of Bristol").arg(RAPTOR_VERSION);
Chris@285 4323 #else // !RAPTOR_VERSION
Chris@285 4324 aboutText += tr("<br>With Raptor RDF parser &copy; Dave Beckett and the University of Bristol");
Chris@285 4325 #endif // RAPTOR_VERSION
Chris@285 4326 #ifdef RASQAL_VERSION
Chris@285 4327 aboutText += tr("<br>With Rasqal RDF query engine v%1 &copy; Dave Beckett and the University of Bristol").arg(RASQAL_VERSION);
Chris@285 4328 #else // !RASQAL_VERSION
Chris@285 4329 aboutText += tr("<br>With Rasqal RDF query engine &copy; Dave Beckett and the University of Bristol");
Chris@285 4330 #endif // RASQAL_VERSION
Chris@285 4331 #ifdef HAVE_REDLAND
Chris@285 4332 #ifdef REDLAND_VERSION
Chris@285 4333 aboutText += tr("<br>With Redland RDF datastore v%1 &copy; Dave Beckett and the University of Bristol").arg(REDLAND_VERSION);
Chris@285 4334 #else // !REDLAND_VERSION
Chris@285 4335 aboutText += tr("<br>With Redland RDF datastore &copy; Dave Beckett and the University of Bristol");
Chris@285 4336 #endif // REDLAND_VERSION
Chris@285 4337 #endif // HAVE_REDLAND
Chris@285 4338
Chris@300 4339 aboutText += tr("<br>With RtMidi &copy; Gary P. Scavone");
Chris@300 4340
Chris@69 4341 #ifdef HAVE_LIBLO
Chris@93 4342 #ifdef LIBLO_VERSION
Chris@285 4343 aboutText += tr("<br>With liblo Lite OSC library v%1 &copy; Steve Harris").arg(LIBLO_VERSION);
Chris@285 4344 #else // !LIBLO_VERSION
Chris@327 4345 aboutText += tr("<br>With liblo Lite OSC library &copy; Steve Harris");
Chris@285 4346 #endif // LIBLO_VERSION
Chris@285 4347
Chris@285 4348 if (m_oscQueue && m_oscQueue->isOK()) {
Chris@285 4349 aboutText += tr("</small><p><small>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
Chris@285 4350 }
Chris@285 4351
Chris@285 4352 aboutText += "</small></p>";
Chris@285 4353 #endif // HAVE_LIBLO
Chris@285 4354
Chris@285 4355 #ifndef BUILD_STATIC
Chris@285 4356 aboutText.replace(tr("With "), tr("Using "));
Chris@93 4357 #endif
Chris@0 4358
Chris@0 4359 aboutText +=
Chris@510 4360 "<p><small>Sonic Visualiser Copyright &copy; 2005&ndash;2012 Chris Cannam and "
Chris@285 4361 "Queen Mary, University of London.</small></p>"
Chris@285 4362 "<p><small>This program is free software; you can redistribute it and/or "
Chris@231 4363 "modify it under the terms of the GNU General Public License as "
Chris@231 4364 "published by the Free Software Foundation; either version 2 of the "
Chris@0 4365 "License, or (at your option) any later version.<br>See the file "
Chris@285 4366 "COPYING included with this distribution for more information.</small></p>";
Chris@0 4367
Chris@0 4368 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
Chris@0 4369 }
Chris@0 4370
Chris@162 4371 void
Chris@162 4372 MainWindow::keyReference()
Chris@162 4373 {
Chris@162 4374 m_keyReference->show();
Chris@162 4375 }
Chris@162 4376
Chris@333 4377 void
Chris@333 4378 MainWindow::newerVersionAvailable(QString version)
Chris@333 4379 {
Chris@334 4380 QSettings settings;
Chris@334 4381 settings.beginGroup("NewerVersionWarning");
Chris@334 4382 QString tag = QString("version-%1-available-show").arg(version);
Chris@334 4383 if (settings.value(tag, true).toBool()) {
Chris@334 4384 QString title(tr("Newer version available"));
Chris@334 4385 QString text(tr("<h3>Newer version available</h3><p>You are using version %1 of Sonic Visualiser, but version %3 is now available.</p><p>Please see the <a href=\"http://sonicvisualiser.org/\">Sonic Visualiser website</a> for more information.</p>").arg(SV_VERSION).arg(version));
Chris@334 4386 QMessageBox::information(this, title, text);
Chris@334 4387 settings.setValue(tag, false);
Chris@334 4388 }
Chris@334 4389 settings.endGroup();
Chris@333 4390 }
Chris@333 4391
Chris@333 4392