annotate main/MainWindow.cpp @ 588:e8881f405b8f

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