comparison main/MainWindow.cpp @ 423:97cd3d2c032a templating

Start to add templates menu; add default template
author Chris Cannam
date Mon, 09 May 2011 11:57:02 +0100
parents 37fb42c2d0e7
children eaab4c65c7bc
comparison
equal deleted inserted replaced
422:37fb42c2d0e7 423:97cd3d2c032a
28 #include "data/osc/OSCQueue.h" 28 #include "data/osc/OSCQueue.h"
29 #include "framework/Document.h" 29 #include "framework/Document.h"
30 #include "framework/TransformUserConfigurator.h" 30 #include "framework/TransformUserConfigurator.h"
31 #include "view/ViewManager.h" 31 #include "view/ViewManager.h"
32 #include "base/Preferences.h" 32 #include "base/Preferences.h"
33 #include "base/ResourceFinder.h"
33 #include "layer/WaveformLayer.h" 34 #include "layer/WaveformLayer.h"
34 #include "layer/TimeRulerLayer.h" 35 #include "layer/TimeRulerLayer.h"
35 #include "layer/TimeInstantLayer.h" 36 #include "layer/TimeInstantLayer.h"
36 #include "layer/TimeValueLayer.h" 37 #include "layer/TimeValueLayer.h"
37 #include "layer/NoteLayer.h" 38 #include "layer/NoteLayer.h"
425 m_recentFilesMenu = menu->addMenu(tr("Open &Recent")); 426 m_recentFilesMenu = menu->addMenu(tr("Open &Recent"));
426 m_recentFilesMenu->setTearOffEnabled(true); 427 m_recentFilesMenu->setTearOffEnabled(true);
427 setupRecentFilesMenu(); 428 setupRecentFilesMenu();
428 connect(&m_recentFiles, SIGNAL(recentChanged()), 429 connect(&m_recentFiles, SIGNAL(recentChanged()),
429 this, SLOT(setupRecentFilesMenu())); 430 this, SLOT(setupRecentFilesMenu()));
431
432 menu->addSeparator();
433
434 m_templatesMenu = menu->addMenu(tr("Set Session Open Template"));
435 m_templatesMenu->setTearOffEnabled(true);
436 setupTemplatesMenu();
430 437
431 menu->addSeparator(); 438 menu->addSeparator();
432 439
433 icon = il.load("filesave"); 440 icon = il.load("filesave");
434 icon.addPixmap(il.loadPixmap("filesave-22")); 441 icon.addPixmap(il.loadPixmap("filesave-22"));
1621 m_recentFilesMenu->addAction(action); 1628 m_recentFilesMenu->addAction(action);
1622 } 1629 }
1623 } 1630 }
1624 1631
1625 void 1632 void
1633 MainWindow::setupTemplatesMenu()
1634 {
1635 m_templatesMenu->clear();
1636
1637 QSettings settings;
1638 settings.beginGroup("MainWindow");
1639 QString deflt = settings.value("sessiontemplate", "").toString();
1640 setDefaultSessionTemplate(deflt);
1641 settings.endGroup();
1642
1643 QActionGroup *templatesGroup = new QActionGroup(this);
1644
1645 QAction *action = new QAction(tr("Default"), this);
1646 action->setObjectName("default");
1647 connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate()));
1648 action->setCheckable(true);
1649 action->setChecked(deflt == "" || deflt == "default");
1650 templatesGroup->addAction(action);
1651 m_templatesMenu->addAction(action);
1652
1653 m_templatesMenu->addSeparator();
1654
1655 QStringList templates = ResourceFinder().getResourceFiles("templates", "xml");
1656 foreach (QString t, templates) {
1657 QString tname = QFileInfo(t).baseName();
1658 if (tname.toLower() == "default") continue;
1659 action = new QAction(tname, this);
1660 action->setObjectName(t);
1661 connect(action, SIGNAL(triggered()), this, SLOT(changeTemplate()));
1662 action->setCheckable(true);
1663 action->setChecked(deflt == tname);
1664 templatesGroup->addAction(action);
1665 m_templatesMenu->addAction(action);
1666 }
1667
1668 if (!templates.empty()) m_templatesMenu->addSeparator();
1669
1670 action = new QAction(tr("Save Session as New Template..."), this);
1671 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAsTemplate()));
1672 m_templatesMenu->addAction(action);
1673 }
1674
1675 void
1626 MainWindow::setupRecentTransformsMenu() 1676 MainWindow::setupRecentTransformsMenu()
1627 { 1677 {
1628 m_recentTransformsMenu->clear(); 1678 m_recentTransformsMenu->clear();
1629 vector<QString> transforms = m_recentTransforms.getRecent(); 1679 vector<QString> transforms = m_recentTransforms.getRecent();
1630 for (size_t i = 0; i < transforms.size(); ++i) { 1680 for (size_t i = 0; i < transforms.size(); ++i) {
2746 } else if (status == FileOpenWrongMode) { 2796 } else if (status == FileOpenWrongMode) {
2747 emit hideSplash(); 2797 emit hideSplash();
2748 QMessageBox::critical(this, tr("Failed to open location"), 2798 QMessageBox::critical(this, tr("Failed to open location"),
2749 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)); 2799 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));
2750 } 2800 }
2801 }
2802
2803 void
2804 MainWindow::changeTemplate()
2805 {
2806 //!!!
2751 } 2807 }
2752 2808
2753 void 2809 void
2754 MainWindow::paneAdded(Pane *pane) 2810 MainWindow::paneAdded(Pane *pane)
2755 { 2811 {