comparison src/MainWindow.cpp @ 27:551e14d04eaa

added NoteEdit tool mode
author gyorgyf
date Sat, 15 Jun 2013 16:16:24 +0100
parents 6479a92f1e0c
children 7e17d5d38c83
comparison
equal deleted inserted replaced
25:6479a92f1e0c 27:551e14d04eaa
181 m_playSpeed->setObjectName(tr("Playback Speedup")); 181 m_playSpeed->setObjectName(tr("Playback Speedup"));
182 m_playSpeed->setDefaultValue(100); 182 m_playSpeed->setDefaultValue(100);
183 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200)); 183 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
184 m_playSpeed->setShowToolTip(true); 184 m_playSpeed->setShowToolTip(true);
185 connect(m_playSpeed, SIGNAL(valueChanged(int)), 185 connect(m_playSpeed, SIGNAL(valueChanged(int)),
186 this, SLOT(playSpeedChanged(int))); 186 this, SLOT(playSpeedChanged(int)));
187 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); 187 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
188 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget())); 188 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
189 189
190 layout->setSpacing(4); 190 layout->setSpacing(4);
191 layout->addWidget(m_overview, 0, 1); 191 layout->addWidget(m_overview, 0, 1);
309 action->setStatusTip(tr("Scroll the current pane to the left")); 309 action->setStatusTip(tr("Scroll the current pane to the left"));
310 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft())); 310 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
311 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); 311 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
312 m_keyReference->registerShortcut(action); 312 m_keyReference->registerShortcut(action);
313 menu->addAction(action); 313 menu->addAction(action);
314 314
315 action = new QAction(tr("Scroll &Right"), this); 315 action = new QAction(tr("Scroll &Right"), this);
316 action->setShortcut(tr("Right")); 316 action->setShortcut(tr("Right"));
317 action->setStatusTip(tr("Scroll the current pane to the right")); 317 action->setStatusTip(tr("Scroll the current pane to the right"));
318 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight())); 318 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
319 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); 319 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
320 m_keyReference->registerShortcut(action); 320 m_keyReference->registerShortcut(action);
321 menu->addAction(action); 321 menu->addAction(action);
322 322
323 action = new QAction(tr("&Jump Left"), this); 323 action = new QAction(tr("&Jump Left"), this);
324 action->setShortcut(tr("Ctrl+Left")); 324 action->setShortcut(tr("Ctrl+Left"));
325 action->setStatusTip(tr("Scroll the current pane a big step to the left")); 325 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
326 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft())); 326 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
327 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); 327 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
328 m_keyReference->registerShortcut(action); 328 m_keyReference->registerShortcut(action);
329 menu->addAction(action); 329 menu->addAction(action);
330 330
331 action = new QAction(tr("J&ump Right"), this); 331 action = new QAction(tr("J&ump Right"), this);
332 action->setShortcut(tr("Ctrl+Right")); 332 action->setShortcut(tr("Ctrl+Right"));
333 action->setStatusTip(tr("Scroll the current pane a big step to the right")); 333 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
334 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight())); 334 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
335 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool))); 335 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
346 action->setStatusTip(tr("Increase the zoom level")); 346 action->setStatusTip(tr("Increase the zoom level"));
347 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn())); 347 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
348 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); 348 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
349 m_keyReference->registerShortcut(action); 349 m_keyReference->registerShortcut(action);
350 menu->addAction(action); 350 menu->addAction(action);
351 351
352 action = new QAction(il.load("zoom-out"), 352 action = new QAction(il.load("zoom-out"),
353 tr("Zoom &Out"), this); 353 tr("Zoom &Out"), this);
354 action->setShortcut(tr("Down")); 354 action->setShortcut(tr("Down"));
355 action->setStatusTip(tr("Decrease the zoom level")); 355 action->setStatusTip(tr("Decrease the zoom level"));
356 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut())); 356 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
357 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); 357 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
358 m_keyReference->registerShortcut(action); 358 m_keyReference->registerShortcut(action);
359 menu->addAction(action); 359 menu->addAction(action);
360 360
361 action = new QAction(tr("Restore &Default Zoom"), this); 361 action = new QAction(tr("Restore &Default Zoom"), this);
362 action->setStatusTip(tr("Restore the zoom level to the default")); 362 action->setStatusTip(tr("Restore the zoom level to the default"));
363 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault())); 363 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
364 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool))); 364 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
365 menu->addAction(action); 365 menu->addAction(action);
416 MainWindow::setupRecentFilesMenu() 416 MainWindow::setupRecentFilesMenu()
417 { 417 {
418 m_recentFilesMenu->clear(); 418 m_recentFilesMenu->clear();
419 vector<QString> files = m_recentFiles.getRecent(); 419 vector<QString> files = m_recentFiles.getRecent();
420 for (size_t i = 0; i < files.size(); ++i) { 420 for (size_t i = 0; i < files.size(); ++i) {
421 QAction *action = new QAction(files[i], this); 421 QAction *action = new QAction(files[i], this);
422 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile())); 422 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
423 if (i == 0) { 423 if (i == 0) {
424 action->setShortcut(tr("Ctrl+R")); 424 action->setShortcut(tr("Ctrl+R"));
425 m_keyReference->registerShortcut 425 m_keyReference->registerShortcut
426 (tr("Re-open"), 426 (tr("Re-open"),
427 action->shortcut(), 427 action->shortcut(),
428 tr("Re-open the current or most recently opened file")); 428 tr("Re-open the current or most recently opened file"));
429 } 429 }
430 m_recentFilesMenu->addAction(action); 430 m_recentFilesMenu->addAction(action);
431 } 431 }
432 } 432 }
433 433
434 void 434 void
435 MainWindow::setupToolbars() 435 MainWindow::setupToolbars()
464 playAction->setCheckable(true); 464 playAction->setCheckable(true);
465 playAction->setShortcut(tr("Space")); 465 playAction->setShortcut(tr("Space"));
466 playAction->setStatusTip(tr("Start or stop playback from the current position")); 466 playAction->setStatusTip(tr("Start or stop playback from the current position"));
467 connect(playAction, SIGNAL(triggered()), this, SLOT(play())); 467 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
468 connect(m_playSource, SIGNAL(playStatusChanged(bool)), 468 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
469 playAction, SLOT(setChecked(bool))); 469 playAction, SLOT(setChecked(bool)));
470 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool))); 470 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
471 471
472 m_ffwdAction = toolbar->addAction(il.load("ffwd"), 472 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
473 tr("Fast Forward")); 473 tr("Fast Forward"));
474 m_ffwdAction->setShortcut(tr("PgDown")); 474 m_ffwdAction->setShortcut(tr("PgDown"));
565 565
566 toolbar = addToolBar(tr("Playback Controls")); 566 toolbar = addToolBar(tr("Playback Controls"));
567 toolbar->addWidget(m_playSpeed); 567 toolbar->addWidget(m_playSpeed);
568 toolbar->addWidget(m_fader); 568 toolbar->addWidget(m_fader);
569 569
570 toolbar = addToolBar(tr("Test actions toolbar")); // GF: temporary toolbar for triggering actions manually 570 toolbar = addToolBar(tr("Test actions toolbar")); // GF: temporary toolbar for triggering actions manually
571 571
572 // GF: TEMP : this created a menu item 572 // GF: TEMP : this created a menu item
573 m_editSelectAction = toolbar->addAction(il.load("move"), tr("Edit")); 573 m_editSelectAction = toolbar->addAction(il.load("move"), tr("Edit"));
574 m_editSelectAction->setShortcut(tr("Home")); 574 m_editSelectAction->setShortcut(tr("Home"));
575 m_editSelectAction->setStatusTip(tr("Edit Notes")); 575 m_editSelectAction->setStatusTip(tr("Edit Notes"));
576 m_editSelectAction->setEnabled(true); 576 m_editSelectAction->setEnabled(true);
577 // connect(test, SIGNAL(triggered()), this, SLOT(about())); 577 // connect(test, SIGNAL(triggered()), this, SLOT(about()));
578 // connect(test, SIGNAL(triggered()), m_analyser, SLOT(resizeLayer())); 578 // connect(test, SIGNAL(triggered()), m_analyser, SLOT(resizeLayer()));
579 connect(m_editSelectAction, SIGNAL(triggered()), this, SLOT(selectEditMode())); 579 connect(m_editSelectAction, SIGNAL(triggered()), this, SLOT(selectNoteEditMode()));
580 // connect(this, SIGNAL(canPlay(bool)), test, SLOT(setEnabled(bool))); 580 // connect(this, SIGNAL(canPlay(bool)), test, SLOT(setEnabled(bool)));
581 menu->addAction(m_editSelectAction); 581 menu->addAction(m_editSelectAction);
582 582
583 Pane::registerShortcuts(*m_keyReference); 583 Pane::registerShortcuts(*m_keyReference);
584 } 584 }
585 585
586 void 586 void
587 MainWindow::selectEditMode() 587 MainWindow::selectNoteEditMode()
588 { 588 {
589 IconLoader il; 589 IconLoader il;
590 if (m_viewManager->getToolMode() == ViewManager::EditMode) { 590 if (m_viewManager->getToolMode() == ViewManager::NoteEditMode) {
591 m_viewManager->setToolMode(ViewManager::NavigateMode); 591 m_viewManager->setToolMode(ViewManager::NavigateMode);
592 m_editSelectAction->setIcon(il.load("move")); 592 m_editSelectAction->setIcon(il.load("move"));
593 } else { 593 } else {
594 std::cerr << "Edit mode selected" << std::endl; 594 std::cerr << "NoteEdit mode selected" << std::endl;
595 m_viewManager->setToolMode(ViewManager::EditMode); 595 m_viewManager->setToolMode(ViewManager::NoteEditMode);
596 m_editSelectAction->setIcon(il.load("navigate")); 596 m_editSelectAction->setIcon(il.load("navigate"));
597 m_editSelectAction->setStatusTip(tr("Navigate")); 597 m_editSelectAction->setStatusTip(tr("Navigate"));
598 } 598 }
599 } 599 }
600 600
601 void 601 void
602 MainWindow::updateMenuStates() 602 MainWindow::updateMenuStates()
603 { 603 {
613 (currentPane != 0); 613 (currentPane != 0);
614 bool haveCurrentLayer = 614 bool haveCurrentLayer =
615 (haveCurrentPane && 615 (haveCurrentPane &&
616 (currentLayer != 0)); 616 (currentLayer != 0));
617 bool haveSelection = 617 bool haveSelection =
618 (m_viewManager && 618 (m_viewManager &&
619 !m_viewManager->getSelections().empty()); 619 !m_viewManager->getSelections().empty());
620 bool haveCurrentEditableLayer = 620 bool haveCurrentEditableLayer =
621 (haveCurrentLayer && 621 (haveCurrentLayer &&
622 currentLayer->isLayerEditable()); 622 currentLayer->isLayerEditable());
623 bool haveCurrentTimeInstantsLayer = 623 bool haveCurrentTimeInstantsLayer =
624 (haveCurrentLayer && 624 (haveCurrentLayer &&
625 qobject_cast<TimeInstantLayer *>(currentLayer)); 625 qobject_cast<TimeInstantLayer *>(currentLayer));
626 bool haveCurrentTimeValueLayer = 626 bool haveCurrentTimeValueLayer =
627 (haveCurrentLayer && 627 (haveCurrentLayer &&
628 qobject_cast<TimeValueLayer *>(currentLayer)); 628 qobject_cast<TimeValueLayer *>(currentLayer));
629 629
630 emit canChangePlaybackSpeed(true); 630 emit canChangePlaybackSpeed(true);
631 int v = m_playSpeed->value(); 631 int v = m_playSpeed->value();
632 emit canSpeedUpPlayback(v < m_playSpeed->maximum()); 632 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
633 emit canSlowDownPlayback(v > m_playSpeed->minimum()); 633 emit canSlowDownPlayback(v > m_playSpeed->minimum());
700 { 700 {
701 if (!checkSaveModified()) return; 701 if (!checkSaveModified()) return;
702 702
703 while (m_paneStack->getPaneCount() > 0) { 703 while (m_paneStack->getPaneCount() > 0) {
704 704
705 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1); 705 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
706 706
707 while (pane->getLayerCount() > 0) { 707 while (pane->getLayerCount() > 0) {
708 m_document->removeLayerFromView 708 m_document->removeLayerFromView
709 (pane, pane->getLayer(pane->getLayerCount() - 1)); 709 (pane, pane->getLayer(pane->getLayerCount() - 1));
710 } 710 }
711 711
712 m_overview->unregisterView(pane); 712 m_overview->unregisterView(pane);
713 m_paneStack->deletePane(pane); 713 m_paneStack->deletePane(pane);
714 } 714 }
715 715
716 while (m_paneStack->getHiddenPaneCount() > 0) { 716 while (m_paneStack->getHiddenPaneCount() > 0) {
717 717
718 Pane *pane = m_paneStack->getHiddenPane 718 Pane *pane = m_paneStack->getHiddenPane
719 (m_paneStack->getHiddenPaneCount() - 1); 719 (m_paneStack->getHiddenPaneCount() - 1);
720 720
721 while (pane->getLayerCount() > 0) { 721 while (pane->getLayerCount() > 0) {
722 m_document->removeLayerFromView 722 m_document->removeLayerFromView
723 (pane, pane->getLayer(pane->getLayerCount() - 1)); 723 (pane, pane->getLayer(pane->getLayerCount() - 1));
724 } 724 }
725 725
726 m_overview->unregisterView(pane); 726 m_overview->unregisterView(pane);
727 m_paneStack->deletePane(pane); 727 m_paneStack->deletePane(pane);
728 } 728 }
729 729
730 delete m_document; 730 delete m_document;
731 m_document = 0; 731 m_document = 0;
732 m_viewManager->clearSelections(); 732 m_viewManager->clearSelections();
800 { 800 {
801 QObject *obj = sender(); 801 QObject *obj = sender();
802 QAction *action = qobject_cast<QAction *>(obj); 802 QAction *action = qobject_cast<QAction *>(obj);
803 803
804 if (!action) { 804 if (!action) {
805 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action" 805 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
806 << std::endl; 806 << std::endl;
807 return; 807 return;
808 } 808 }
809 809
810 QString path = action->text(); 810 QString path = action->text();
811 if (path == "") return; 811 if (path == "") return;
812 812
900 { 900 {
901 // std::cerr << "MainWindow::closeEvent" << std::endl; 901 // std::cerr << "MainWindow::closeEvent" << std::endl;
902 902
903 if (m_openingAudioFile) { 903 if (m_openingAudioFile) {
904 // std::cerr << "Busy - ignoring close event" << std::endl; 904 // std::cerr << "Busy - ignoring close event" << std::endl;
905 e->ignore(); 905 e->ignore();
906 return; 906 return;
907 } 907 }
908 908
909 if (!m_abandoning && !checkSaveModified()) { 909 if (!m_abandoning && !checkSaveModified()) {
910 // std::cerr << "Ignoring close event" << std::endl; 910 // std::cerr << "Ignoring close event" << std::endl;
911 e->ignore(); 911 e->ignore();
912 return; 912 return;
913 } 913 }
914 914
915 QSettings settings; 915 QSettings settings;
916 settings.beginGroup("MainWindow"); 916 settings.beginGroup("MainWindow");
917 settings.setValue("size", size()); 917 settings.setValue("size", size());
976 // cancel. 976 // cancel.
977 977
978 if (!m_documentModified) return true; 978 if (!m_documentModified) return true;
979 979
980 int button = 980 int button =
981 QMessageBox::warning(this, 981 QMessageBox::warning(this,
982 tr("Session modified"), 982 tr("Session modified"),
983 tr("The current session has been modified.\nDo you want to save it?"), 983 tr("The current session has been modified.\nDo you want to save it?"),
984 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, 984 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
985 QMessageBox::Yes); 985 QMessageBox::Yes);
986 986
987 if (button == QMessageBox::Yes) { 987 if (button == QMessageBox::Yes) {
988 saveSession(); 988 saveSession();
989 if (m_documentModified) { // save failed -- don't proceed! 989 if (m_documentModified) { // save failed -- don't proceed!
990 return false; 990 return false;
991 } else { 991 } else {
992 return true; // saved, so it's safe to continue now 992 return true; // saved, so it's safe to continue now
993 } 993 }
994 } else if (button == QMessageBox::No) { 994 } else if (button == QMessageBox::No) {
995 m_documentModified = false; // so we know to abandon it 995 m_documentModified = false; // so we know to abandon it
996 return true; 996 return true;
997 } 997 }
998 998
999 // else cancel 999 // else cancel
1000 return false; 1000 return false;
1001 } 1001 }
1002 1002
1003 void 1003 void
1004 MainWindow::saveSession() 1004 MainWindow::saveSession()
1005 { 1005 {
1006 if (m_sessionFile != "") { 1006 if (m_sessionFile != "") {
1007 if (!saveSessionFile(m_sessionFile)) { 1007 if (!saveSessionFile(m_sessionFile)) {
1008 QMessageBox::critical(this, tr("Failed to save file"), 1008 QMessageBox::critical(this, tr("Failed to save file"),
1009 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile)); 1009 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
1010 } else {
1011 CommandHistory::getInstance()->documentSaved();
1012 documentRestored();
1013 }
1014 } else { 1010 } else {
1015 saveSessionAs(); 1011 CommandHistory::getInstance()->documentSaved();
1012 documentRestored();
1013 }
1014 } else {
1015 saveSessionAs();
1016 } 1016 }
1017 } 1017 }
1018 1018
1019 void 1019 void
1020 MainWindow::saveSessionAs() 1020 MainWindow::saveSessionAs()
1026 QString path = getSaveFileName(FileFinder::SessionFile); 1026 QString path = getSaveFileName(FileFinder::SessionFile);
1027 1027
1028 if (path == "") return; 1028 if (path == "") return;
1029 1029
1030 if (!saveSessionFile(path)) { 1030 if (!saveSessionFile(path)) {
1031 QMessageBox::critical(this, tr("Failed to save file"), 1031 QMessageBox::critical(this, tr("Failed to save file"),
1032 tr("Session file \"%1\" could not be saved.").arg(path)); 1032 tr("Session file \"%1\" could not be saved.").arg(path));
1033 } else { 1033 } else {
1034 setWindowTitle(tr("%1: %2") 1034 setWindowTitle(tr("%1: %2")
1035 .arg(QApplication::applicationName()) 1035 .arg(QApplication::applicationName())
1036 .arg(QFileInfo(path).fileName())); 1036 .arg(QFileInfo(path).fileName()));
1037 m_sessionFile = path; 1037 m_sessionFile = path;
1038 CommandHistory::getInstance()->documentSaved(); 1038 CommandHistory::getInstance()->documentSaved();
1039 documentRestored(); 1039 documentRestored();
1040 m_recentFiles.addFile(path); 1040 m_recentFiles.addFile(path);
1041 } 1041 }
1042 } 1042 }
1043 1043
1044 void 1044 void
1045 MainWindow::renameCurrentLayer() 1045 MainWindow::renameCurrentLayer()
1046 { 1046 {
1047 Pane *pane = m_paneStack->getCurrentPane(); 1047 Pane *pane = m_paneStack->getCurrentPane();
1048 if (pane) { 1048 if (pane) {
1049 Layer *layer = pane->getSelectedLayer(); 1049 Layer *layer = pane->getSelectedLayer();
1050 if (layer) { 1050 if (layer) {
1051 bool ok = false; 1051 bool ok = false;
1052 QString newName = QInputDialog::getText 1052 QString newName = QInputDialog::getText
1053 (this, tr("Rename Layer"), 1053 (this, tr("Rename Layer"),
1054 tr("New name for this layer:"), 1054 tr("New name for this layer:"),
1055 QLineEdit::Normal, layer->objectName(), &ok); 1055 QLineEdit::Normal, layer->objectName(), &ok);
1056 if (ok) { 1056 if (ok) {
1057 layer->setObjectName(newName); 1057 layer->setObjectName(newName);
1058 } 1058 }
1059 } 1059 }
1060 } 1060 }
1061 } 1061 }
1062 1062
1063 void 1063 void
1064 MainWindow::playSpeedChanged(int position) 1064 MainWindow::playSpeedChanged(int position)